Update the describe_image_attribute and modify_image_attribute functions
in the EC2 API so they use the top level 'is_public' attribute of image objects. This brings these functions in line with the base image service. Added missing EC2 API unit tests for describing and modifying image attributes.
This commit is contained in:
commit
a1452132e8
|
@ -984,7 +984,7 @@ class CloudController(object):
|
|||
except exception.NotFound:
|
||||
raise exception.NotFound(_('Image %s not found') % image_id)
|
||||
result = {'imageId': image_id, 'launchPermission': []}
|
||||
if image['properties']['is_public']:
|
||||
if image['is_public']:
|
||||
result['launchPermission'].append({'group': 'all'})
|
||||
return result
|
||||
|
||||
|
@ -1009,7 +1009,7 @@ class CloudController(object):
|
|||
internal_id = image['id']
|
||||
del(image['id'])
|
||||
|
||||
image['properties']['is_public'] = (operation_type == 'add')
|
||||
image['is_public'] = (operation_type == 'add')
|
||||
return self.image_service.update(context, internal_id, image)
|
||||
|
||||
def update_image(self, context, image_id, **kwargs):
|
||||
|
|
|
@ -247,6 +247,37 @@ class CloudTestCase(test.TestCase):
|
|||
self.assertRaises(NotFound, describe_images,
|
||||
self.context, ['ami-fake'])
|
||||
|
||||
def test_describe_image_attribute(self):
|
||||
describe_image_attribute = self.cloud.describe_image_attribute
|
||||
|
||||
def fake_show(meh, context, id):
|
||||
return {'id': 1, 'properties': {'kernel_id': 1, 'ramdisk_id': 1,
|
||||
'type': 'machine'}, 'is_public': True}
|
||||
|
||||
self.stubs.Set(local.LocalImageService, 'show', fake_show)
|
||||
self.stubs.Set(local.LocalImageService, 'show_by_name', fake_show)
|
||||
result = describe_image_attribute(self.context, 'ami-00000001',
|
||||
'launchPermission')
|
||||
self.assertEqual([{'group': 'all'}], result['launchPermission'])
|
||||
|
||||
def test_modify_image_attribute(self):
|
||||
modify_image_attribute = self.cloud.modify_image_attribute
|
||||
|
||||
def fake_show(meh, context, id):
|
||||
return {'id': 1, 'properties': {'kernel_id': 1, 'ramdisk_id': 1,
|
||||
'type': 'machine'}, 'is_public': False}
|
||||
|
||||
def fake_update(meh, context, image_id, metadata, data=None):
|
||||
return metadata
|
||||
|
||||
self.stubs.Set(local.LocalImageService, 'show', fake_show)
|
||||
self.stubs.Set(local.LocalImageService, 'show_by_name', fake_show)
|
||||
self.stubs.Set(local.LocalImageService, 'update', fake_update)
|
||||
result = modify_image_attribute(self.context, 'ami-00000001',
|
||||
'launchPermission', 'add',
|
||||
user_group=['all'])
|
||||
self.assertEqual(True, result['is_public'])
|
||||
|
||||
def test_console_output(self):
|
||||
instance_type = FLAGS.default_instance_type
|
||||
max_count = 1
|
||||
|
|
Loading…
Reference in New Issue