From c46d41719e0c8199dc17ef566413889692644ef5 Mon Sep 17 00:00:00 2001 From: Jesper Schmitz Mouridsen Date: Fri, 17 Jun 2022 10:29:00 +0000 Subject: [PATCH] Serialize message_* properties of RequestContext Change Idc00b125b33b added the ability to store and retrieve user message data in the request context, but it neglected to add code to make sure they would persist across serialization and deserialization of the request context object, as happens in the create-backup workflow. As a result, when a user message needed to be created to describe an error condition in the backup driver, instead we'd get an exception raised: "TypeError: 'NoneType' object is not subscriptable". This patch fixes the issue by making sure the message_* properties persist across serialization/deserialization of RequestContext objects. Closes-Bug: 1978729 Change-Id: Ibdaaf39abafbae6bfcb9fdf9fb7a55d968ad9f11 Signed-off-by: Jesper Schmitz Mouridsen --- cinder/context.py | 15 ++++++++++++--- ...ug-1978729-cinder-backup-4cd87c4d71b7713e.yaml | 8 ++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 releasenotes/notes/bug-1978729-cinder-backup-4cd87c4d71b7713e.yaml diff --git a/cinder/context.py b/cinder/context.py index 594c8606831..737646875b9 100644 --- a/cinder/context.py +++ b/cinder/context.py @@ -91,6 +91,9 @@ class RequestContext(context.RequestContext): quota_class=None, service_catalog: Optional[dict] = None, user_auth_plugin=None, + message_resource_id = None, + message_resource_type = None, + message_action = None, **kwargs): """Initialize RequestContext. @@ -117,9 +120,9 @@ class RequestContext(context.RequestContext): timestamp = timeutils.parse_isotime(timestamp) self.timestamp = timestamp self.quota_class = quota_class - self.message_resource_id = None - self.message_resource_type = None - self.message_action = None + self.message_resource_id = message_resource_id + self.message_resource_type = message_resource_type + self.message_action = message_action if service_catalog: # Only include required parts of service_catalog @@ -174,6 +177,9 @@ class RequestContext(context.RequestContext): result['quota_class'] = self.quota_class result['service_catalog'] = self.service_catalog result['request_id'] = self.request_id + result['message_resource_id'] = self.message_resource_id + result['message_resource_type'] = self.message_resource_type + result['message_action'] = self.message_action return result @classmethod @@ -194,6 +200,9 @@ class RequestContext(context.RequestContext): auth_token=values.get('auth_token'), user_domain_id=values.get('user_domain_id'), project_domain_id=values.get('project_domain_id'), + message_resource_id = values.get('message_resource_id'), + message_resource_type = values.get('message_resource_type'), + message_action = values.get('message_action') ) def authorize(self, diff --git a/releasenotes/notes/bug-1978729-cinder-backup-4cd87c4d71b7713e.yaml b/releasenotes/notes/bug-1978729-cinder-backup-4cd87c4d71b7713e.yaml new file mode 100644 index 00000000000..42359b0d2be --- /dev/null +++ b/releasenotes/notes/bug-1978729-cinder-backup-4cd87c4d71b7713e.yaml @@ -0,0 +1,8 @@ +--- +fixes: + - | + `Bug #1978729 `_: Fixed + context.message_action is None on errors by backup drivers. The message_* + properties of the context were not passed during rpc, which caused a double + exception when a backup driver raised an exception, masking the actual backup + driver exception.