From 0c0e47b6ca2b88481891f742ee0e11cdef21c957 Mon Sep 17 00:00:00 2001 From: Dan Smith Date: Thu, 26 Jul 2012 09:11:05 -0700 Subject: Check instance lock in compute/api This adds a check for the instance lock in compute/api.py, which: 1. Helps avoid the need to call into the manager just to be stopped by the lock there 2. Returns a failure to the user right away when an operation cannot be completed due to the lock 3. Avoids the potential for task_state to get into an unhappy state because a user unknowingly attempts an action whilst an instance is locked 4. Avoids the manager from having to re-do the lock check by stuffing a flag into RequestContext when the check has already been done by api.py Various tests needed to be fixed up in order to pass fake instances with the locked attribute. We could make the decorator ignore instances without it, but I think it's more explicit to push that requirement into the tests. This fixes bug 872541 Change-Id: I1127e31d86a061a93a64ee1eb4a4d900d8bf49b5 --- nova/context.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'nova/context.py') diff --git a/nova/context.py b/nova/context.py index 5712193fb..66697b567 100644 --- a/nova/context.py +++ b/nova/context.py @@ -45,7 +45,7 @@ class RequestContext(object): roles=None, remote_address=None, timestamp=None, request_id=None, auth_token=None, overwrite=True, quota_class=None, user_name=None, project_name=None, - service_catalog=None, **kwargs): + service_catalog=None, instance_lock_checked=False, **kwargs): """ :param read_deleted: 'no' indicates deleted records are hidden, 'yes' indicates deleted records are visible, 'only' indicates that @@ -81,6 +81,7 @@ class RequestContext(object): self.request_id = request_id self.auth_token = auth_token self.service_catalog = service_catalog + self.instance_lock_checked = instance_lock_checked # NOTE(markmc): this attribute is currently only used by the # rs_limits turnstile pre-processor. @@ -123,7 +124,8 @@ class RequestContext(object): 'quota_class': self.quota_class, 'user_name': self.user_name, 'service_catalog': self.service_catalog, - 'project_name': self.project_name} + 'project_name': self.project_name, + 'instance_lock_checked': self.instance_lock_checked} @classmethod def from_dict(cls, values): -- cgit