Merge lp:~dan-prince/nova/fix_euca_describe_img_attr into lp:~hudson-openstack/nova/trunk

Proposed by Dan Prince
Status: Merged
Approved by: Devin Carlen
Approved revision: 962
Merged at revision: 964
Proposed branch: lp:~dan-prince/nova/fix_euca_describe_img_attr
Merge into: lp:~hudson-openstack/nova/trunk
Diff against target: 63 lines (+33/-2)
2 files modified
nova/api/ec2/cloud.py (+2/-2)
nova/tests/test_cloud.py (+31/-0)
To merge this branch: bzr merge lp:~dan-prince/nova/fix_euca_describe_img_attr
Reviewer Review Type Date Requested Status
Devin Carlen (community) Approve
Vish Ishaya (community) Approve
Review via email: mp+56871@code.launchpad.net

Description of the change

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.

To post a comment you must log in.
Revision history for this message
Vish Ishaya (vishvananda) wrote :

another nice catch. LGTM

review: Approve
Revision history for this message
Devin Carlen (devcamcar) wrote :

lgtm

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'nova/api/ec2/cloud.py'
2--- nova/api/ec2/cloud.py 2011-04-07 22:54:14 +0000
3+++ nova/api/ec2/cloud.py 2011-04-08 03:46:24 +0000
4@@ -984,7 +984,7 @@
5 except exception.NotFound:
6 raise exception.NotFound(_('Image %s not found') % image_id)
7 result = {'imageId': image_id, 'launchPermission': []}
8- if image['properties']['is_public']:
9+ if image['is_public']:
10 result['launchPermission'].append({'group': 'all'})
11 return result
12
13@@ -1009,7 +1009,7 @@
14 internal_id = image['id']
15 del(image['id'])
16
17- image['properties']['is_public'] = (operation_type == 'add')
18+ image['is_public'] = (operation_type == 'add')
19 return self.image_service.update(context, internal_id, image)
20
21 def update_image(self, context, image_id, **kwargs):
22
23=== modified file 'nova/tests/test_cloud.py'
24--- nova/tests/test_cloud.py 2011-03-30 00:07:59 +0000
25+++ nova/tests/test_cloud.py 2011-04-08 03:46:24 +0000
26@@ -247,6 +247,37 @@
27 self.assertRaises(NotFound, describe_images,
28 self.context, ['ami-fake'])
29
30+ def test_describe_image_attribute(self):
31+ describe_image_attribute = self.cloud.describe_image_attribute
32+
33+ def fake_show(meh, context, id):
34+ return {'id': 1, 'properties': {'kernel_id': 1, 'ramdisk_id': 1,
35+ 'type': 'machine'}, 'is_public': True}
36+
37+ self.stubs.Set(local.LocalImageService, 'show', fake_show)
38+ self.stubs.Set(local.LocalImageService, 'show_by_name', fake_show)
39+ result = describe_image_attribute(self.context, 'ami-00000001',
40+ 'launchPermission')
41+ self.assertEqual([{'group': 'all'}], result['launchPermission'])
42+
43+ def test_modify_image_attribute(self):
44+ modify_image_attribute = self.cloud.modify_image_attribute
45+
46+ def fake_show(meh, context, id):
47+ return {'id': 1, 'properties': {'kernel_id': 1, 'ramdisk_id': 1,
48+ 'type': 'machine'}, 'is_public': False}
49+
50+ def fake_update(meh, context, image_id, metadata, data=None):
51+ return metadata
52+
53+ self.stubs.Set(local.LocalImageService, 'show', fake_show)
54+ self.stubs.Set(local.LocalImageService, 'show_by_name', fake_show)
55+ self.stubs.Set(local.LocalImageService, 'update', fake_update)
56+ result = modify_image_attribute(self.context, 'ami-00000001',
57+ 'launchPermission', 'add',
58+ user_group=['all'])
59+ self.assertEqual(True, result['is_public'])
60+
61 def test_console_output(self):
62 instance_type = FLAGS.default_instance_type
63 max_count = 1