summaryrefslogtreecommitdiffstats
path: root/nova/tests
diff options
context:
space:
mode:
authorRick Harris <rick.harris@rackspace.com>2011-03-14 20:38:05 +0000
committerRick Harris <rick.harris@rackspace.com>2011-03-14 20:38:05 +0000
commit7fe5052f9e8dbaebce45b44a545be9707f6480a6 (patch)
tree012adf91b0805f592e54ebf0a0c99414c4c48dbb /nova/tests
parent7fde254ec53aeb88301e5592853961b2b9c87ef4 (diff)
Adding instance_id as Glance image_property
Diffstat (limited to 'nova/tests')
-rw-r--r--nova/tests/api/openstack/fakes.py19
-rw-r--r--nova/tests/api/openstack/test_images.py41
2 files changed, 58 insertions, 2 deletions
diff --git a/nova/tests/api/openstack/fakes.py b/nova/tests/api/openstack/fakes.py
index e50d11a3d..1c7d926ba 100644
--- a/nova/tests/api/openstack/fakes.py
+++ b/nova/tests/api/openstack/fakes.py
@@ -132,6 +132,19 @@ def stub_out_compute_api_snapshot(stubs):
stubs.Set(nova.compute.API, 'snapshot', snapshot)
+def stub_out_glance_add_image(stubs, sent_to_glance):
+ """
+ We return the metadata sent to glance by modifying the sent_to_glance dict
+ in place.
+ """
+ orig_add_image = glance_client.Client.add_image
+ def fake_add_image(context, metadata, data=None):
+ sent_to_glance['metadata'] = metadata
+ sent_to_glance['data'] = data
+ return orig_add_image(metadata, data)
+ stubs.Set(glance_client.Client, 'add_image', fake_add_image)
+
+
def stub_out_glance(stubs, initial_fixtures=None):
class FakeGlanceClient:
@@ -153,8 +166,10 @@ def stub_out_glance(stubs, initial_fixtures=None):
raise glance_exc.NotFound
def fake_add_image(self, image_meta, data=None):
- id = ''.join(random.choice(string.letters) for _ in range(20))
- image_meta['id'] = id
+ if 'id' not in image_meta:
+ image_id = ''.join(random.choice(string.letters)
+ for _ in range(20))
+ image_meta['id'] = image_id
self.fixtures.append(image_meta)
return image_meta
diff --git a/nova/tests/api/openstack/test_images.py b/nova/tests/api/openstack/test_images.py
index 76f758929..0e6d538f9 100644
--- a/nova/tests/api/openstack/test_images.py
+++ b/nova/tests/api/openstack/test_images.py
@@ -28,6 +28,7 @@ import tempfile
import stubout
import webob
+from glance import client as glance_client
from nova import context
from nova import exception
from nova import flags
@@ -166,11 +167,51 @@ class GlanceImageServiceTest(test.TestCase,
self.service = utils.import_object(service_class)
self.context = context.RequestContext(None, None)
self.service.delete_all()
+ self.sent_to_glance = {}
+ fakes.stub_out_glance_add_image(self.stubs, self.sent_to_glance)
def tearDown(self):
self.stubs.UnsetAll()
super(GlanceImageServiceTest, self).tearDown()
+ def test_create_propertified_images_with_instance_id(self):
+ """
+ Some attributes are passed to Glance as image-properties (ex.
+ instance_id).
+
+ This tests asserts that the ImageService exposes them as if they were
+ first-class attribrutes, but that they are passed to Glance as image
+ properties.
+ """
+ fixture = {'id': 123, 'instance_id': 42, 'name': 'test image'}
+ image_id = self.service.create(self.context, fixture)['id']
+
+ expected = {'id': 123,
+ 'name': 'test image',
+ 'properties': {'instance_id': 42}}
+ self.assertDictMatch(self.sent_to_glance['metadata'], expected)
+
+ # The ImageService shouldn't leak the fact that the instance_id
+ # happens to be stored as a property in Glance
+ expected = {'id': 123, 'instance_id': 42, 'name': 'test image'}
+ image_meta = self.service.show(self.context, image_id)
+ self.assertDictMatch(image_meta, expected)
+
+ def test_create_propertified_images_without_instance_id(self):
+ """
+ Some attributes are passed to Glance as image-properties (ex.
+ instance_id).
+
+ This tests asserts that the ImageService exposes them as if they were
+ first-class attribrutes, but that they are passed to Glance as image
+ properties.
+ """
+ fixture = {'id': 123, 'name': 'test image'}
+ image_id = self.service.create(self.context, fixture)['id']
+
+ expected = {'id': 123, 'name': 'test image', 'properties': {}}
+ self.assertDictMatch(self.sent_to_glance['metadata'], expected)
+
class ImageControllerWithGlanceServiceTest(test.TestCase):