summaryrefslogtreecommitdiff
path: root/nova/api/metadata
diff options
context:
space:
mode:
authorDan Smith <dansmith@redhat.com>2017-06-29 09:42:20 -0700
committerDan Smith <dansmith@redhat.com>2017-06-29 11:53:11 -0700
commit2fee972bde4a04d398d32aa6c8b6d27819db697b (patch)
tree98524e67bd0fe12993ef2b7899a736bc1cc6f848 /nova/api/metadata
parentb79f57a31d9321be471ca9add5a63976f2320830 (diff)
downloadnova-2fee972bde4a04d398d32aa6c8b6d27819db697b.tar.gz
Sanitize instance in InstanceMetadata to avoid un-pickleable context
This is a more strategic fix for the issue of us trying to pickle an instance with a context that has complex data structures inside (i.e. SQLAlchemy connections) into the oslo cache. The right solution is for us to stop storing random python objects (InstanceMetadata) in the cache with pickle. However, that's a larger change and more complex for deployers to roll over. This attempts to sanitize the instance before we pickle it to get things working again. Change-Id: Ie7d97ce5c62c8fb9da5822590a64210521f8ae7a Closes-Bug: #1694666
Diffstat (limited to 'nova/api/metadata')
-rw-r--r--nova/api/metadata/base.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/nova/api/metadata/base.py b/nova/api/metadata/base.py
index 0d57d1abe5..5e25693957 100644
--- a/nova/api/metadata/base.py
+++ b/nova/api/metadata/base.py
@@ -124,6 +124,15 @@ class InstanceMetadata(object):
ctxt = context.get_admin_context()
+ # NOTE(danms): Sanitize the instance to limit the amount of stuff
+ # inside that may not pickle well (i.e. context). We also touch
+ # some of the things we'll lazy load later to make sure we keep their
+ # values in what we cache.
+ instance.ec2_ids
+ instance.keypairs
+ instance = objects.Instance.obj_from_primitive(
+ instance.obj_to_primitive())
+
# The default value of mimeType is set to MIME_TYPE_TEXT_PLAIN
self.set_mimetype(MIME_TYPE_TEXT_PLAIN)
self.instance = instance