Merge "Fix the image name of a shelved server"

This commit is contained in:
Jenkins 2013-10-16 15:45:35 +00:00 committed by Gerrit Code Review
commit 546b30e7b2
2 changed files with 18 additions and 2 deletions
nova
compute
tests/compute

@ -2367,7 +2367,7 @@ class API(base.Base):
image_id = None
if not self.is_volume_backed_instance(context, instance):
name = '%s-shelved' % instance['name']
name = '%s-shelved' % instance['display_name']
image_meta = self._create_image(context, instance, name,
'snapshot')
image_id = image_meta['id']

@ -315,12 +315,28 @@ class ShelveComputeManagerTestCase(test_compute.BaseTestCase):
class ShelveComputeAPITestCase(test_compute.BaseTestCase):
def test_shelve(self):
# Ensure instance can be shelved.
instance = jsonutils.to_primitive(self._create_fake_instance())
fake_instance = self._create_fake_instance({'display_name': 'vm01'})
instance = jsonutils.to_primitive(fake_instance)
instance_uuid = instance['uuid']
self.compute.run_instance(self.context, instance=instance)
self.assertEqual(instance['task_state'], None)
def fake_init(self2):
# In original _FakeImageService.__init__(), some fake images are
# created. To verify the snapshot name of this test only, here
# sets a fake method.
self2.images = {}
def fake_create(self2, ctxt, metadata):
self.assertEqual(metadata['name'], 'vm01-shelved')
metadata['id'] = '8b24ed3f-ee57-43bc-bc2e-fb2e9482bc42'
return metadata
fake_image.stub_out_image_service(self.stubs)
self.stubs.Set(fake_image._FakeImageService, '__init__', fake_init)
self.stubs.Set(fake_image._FakeImageService, 'create', fake_create)
inst_obj = instance_obj.Instance.get_by_uuid(self.context,
instance_uuid)
self.compute_api.shelve(self.context, inst_obj)