summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStanislaw Pitucha <stanislaw.pitucha@hp.com>2013-03-27 16:17:38 +0000
committerStanislaw Pitucha <stanislaw.pitucha@hp.com>2013-03-28 13:51:35 +0000
commit2da5ea6e5685ae5c349fc1d175594aecbe0a0e23 (patch)
tree2f3d1c897f2e28c3f7c995f672acdf273690136d
parentf281afd2ba30c6efa0fb64737a5cb93e1dd28b8c (diff)
Ensure only pickle-able objects live in metadata
Conductor api has been added to InstanceMetadata object, but it cannot be serialised. This breaks storing metadata in memcache, because the information needs to be passed through pickle. Since the field was not used outside of the constructor, it can be removed to fix the problem. Also add a test that pickles a sample InstanceMetadata to catch similar failures in the future. Fixes bug 1160900 Change-Id: I7e8cef5a131290eaa1402d48295026bcac6baff6
-rw-r--r--nova/api/metadata/base.py5
-rw-r--r--nova/tests/test_metadata.py11
2 files changed, 13 insertions, 3 deletions
diff --git a/nova/api/metadata/base.py b/nova/api/metadata/base.py
index 90dcb9ca5..1f5e5b5b9 100644
--- a/nova/api/metadata/base.py
+++ b/nova/api/metadata/base.py
@@ -99,13 +99,12 @@ class InstanceMetadata():
self.extra_md = extra_md
if conductor_api:
- self.conductor_api = conductor_api
+ capi = conductor_api
else:
- self.conductor_api = conductor.API()
+ capi = conductor.API()
ctxt = context.get_admin_context()
- capi = self.conductor_api
self.availability_zone = ec2utils.get_availability_zone_by_host(
instance['host'], capi)
diff --git a/nova/tests/test_metadata.py b/nova/tests/test_metadata.py
index e695ab5fe..01f274f7c 100644
--- a/nova/tests/test_metadata.py
+++ b/nova/tests/test_metadata.py
@@ -25,6 +25,11 @@ import hmac
import json
import re
+try:
+ import cPickle as pickle
+except ImportError:
+ import pickle
+
from oslo.config import cfg
import webob
@@ -132,6 +137,12 @@ class MetadataTestCase(test.TestCase):
fake_network.stub_out_nw_api_get_instance_nw_info(self.stubs,
spectacular=True)
+ def test_can_pickle_metadata(self):
+ # Make sure that InstanceMetadata is possible to pickle. This is
+ # required for memcache backend to work correctly.
+ md = fake_InstanceMetadata(self.stubs, copy.copy(self.instance))
+ pickle.dumps(md, protocol=0)
+
def test_user_data(self):
inst = copy.copy(self.instance)
inst['user_data'] = base64.b64encode("happy")