summaryrefslogtreecommitdiff
path: root/nova/tests/unit/test_metadata.py
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/tests/unit/test_metadata.py
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/tests/unit/test_metadata.py')
-rw-r--r--nova/tests/unit/test_metadata.py18
1 files changed, 8 insertions, 10 deletions
diff --git a/nova/tests/unit/test_metadata.py b/nova/tests/unit/test_metadata.py
index 8aebd4c2d6..89d5a73224 100644
--- a/nova/tests/unit/test_metadata.py
+++ b/nova/tests/unit/test_metadata.py
@@ -165,14 +165,6 @@ def fake_request(testcase, mdinst, relpath, address="127.0.0.1",
return response
-class FakeDeviceMetadata(metadata_obj.DeviceMetadata):
- pass
-
-
-class FakeDeviceBus(metadata_obj.DeviceBus):
- pass
-
-
def fake_metadata_objects():
nic_obj = metadata_obj.NetworkInterfaceMetadata(
bus=metadata_obj.PCIDeviceBus(address='0000:00:01.0'),
@@ -202,9 +194,9 @@ def fake_metadata_objects():
path='/dev/sda',
tags=['baz'],
)
- fake_device_obj = FakeDeviceMetadata()
+ fake_device_obj = metadata_obj.DeviceMetadata()
device_with_fake_bus_obj = metadata_obj.NetworkInterfaceMetadata(
- bus=FakeDeviceBus(),
+ bus=metadata_obj.DeviceBus(),
mac='00:00:00:00:00:00',
tags=['foo']
)
@@ -397,6 +389,12 @@ class MetadataTestCase(test.TestCase):
self.assertRaises(base.InvalidMetadataPath,
md.lookup, "/2009-04-04/meta-data/kernel-id")
+ def test_instance_is_sanitized(self):
+ inst = self.instance.obj_clone()
+ inst._will_not_pass = True
+ md = fake_InstanceMetadata(self, inst)
+ self.assertFalse(hasattr(md.instance, '_will_not_pass'))
+
def test_check_version(self):
inst = self.instance.obj_clone()
md = fake_InstanceMetadata(self, inst)