populate glance 'name' field through ec2-register
For images registered via RegisterImage in the ec2 api, populate glance's 'name' field. If the name is not supplied in the ec2 request, then set it to be the location. This has the added value of 'glance index' now showing ec2 registered images. Previously, they were not listed because of the empty Name field. Additionally, when responding to DescribeImages in the ec2 api, populate the name field. Previously we were not populating this at all. In the case where there is no name, use image_location. Fixes bug 930314 Change-Id: I10bcac9ab298a2bf127b5228c62c3cf4f009abd6
This commit is contained in:
committed by
Vishvananda Ishaya
parent
f0a172ea8b
commit
4a2cf658dc
+17
-5
@@ -1365,11 +1365,18 @@ class CloudController(object):
|
||||
if ramdisk_id:
|
||||
i['ramdiskId'] = ec2utils.image_ec2_id(ramdisk_id, 'ari')
|
||||
i['imageOwnerId'] = image['properties'].get('owner_id')
|
||||
if name:
|
||||
i['imageLocation'] = "%s (%s)" % (image['properties'].
|
||||
get('image_location'), name)
|
||||
|
||||
img_loc = image['properties'].get('image_location')
|
||||
if img_loc:
|
||||
i['imageLocation'] = img_loc
|
||||
else:
|
||||
i['imageLocation'] = image['properties'].get('image_location')
|
||||
i['imageLocation'] = "%s (%s)" % (img_loc, name)
|
||||
|
||||
i['name'] = name
|
||||
if not name and img_loc:
|
||||
# This should only occur for images registered with ec2 api
|
||||
# prior to that api populating the glance name
|
||||
i['name'] = img_loc
|
||||
|
||||
i['imageState'] = self._get_image_state(image)
|
||||
i['description'] = image.get('description')
|
||||
@@ -1425,10 +1432,15 @@ class CloudController(object):
|
||||
return image_id
|
||||
|
||||
def register_image(self, context, image_location=None, **kwargs):
|
||||
if image_location is None and 'name' in kwargs:
|
||||
if image_location is None and kwargs.get('name'):
|
||||
image_location = kwargs['name']
|
||||
metadata = {'properties': {'image_location': image_location}}
|
||||
|
||||
if kwargs.get('name'):
|
||||
metadata['name'] = kwargs['name']
|
||||
else:
|
||||
metadata['name'] = image_location
|
||||
|
||||
if 'root_device_name' in kwargs:
|
||||
metadata['properties']['root_device_name'] = kwargs.get(
|
||||
'root_device_name')
|
||||
|
||||
@@ -33,6 +33,7 @@ from nova import db
|
||||
from nova import exception
|
||||
from nova import flags
|
||||
from nova.image import fake
|
||||
from nova.image import s3
|
||||
from nova import log as logging
|
||||
from nova import rpc
|
||||
from nova import test
|
||||
@@ -1176,6 +1177,63 @@ class CloudTestCase(test.TestCase):
|
||||
user_group=['all'])
|
||||
self.assertEqual(True, result['is_public'])
|
||||
|
||||
def test_register_image_name(self):
|
||||
register_image = self.cloud.register_image
|
||||
|
||||
def fake_create(_self, context, metadata, data=None):
|
||||
self.assertEqual(metadata['name'], self.expected_name)
|
||||
metadata['id'] = 1
|
||||
metadata['container_format'] = 'ami'
|
||||
metadata['is_public'] = False
|
||||
return metadata
|
||||
|
||||
self.stubs.Set(s3.S3ImageService, 'create', fake_create)
|
||||
self.expected_name = 'fake_bucket/fake.img.manifest.xml'
|
||||
result = register_image(self.context,
|
||||
image_location=self.expected_name,
|
||||
name=None)
|
||||
self.expected_name = 'an image name'
|
||||
result = register_image(self.context,
|
||||
image_location='some_location',
|
||||
name=self.expected_name)
|
||||
|
||||
def test_format_image(self):
|
||||
image = {
|
||||
'id': 1,
|
||||
'container_format': 'ami',
|
||||
'name': 'name',
|
||||
'properties': {
|
||||
'image_location': 'location',
|
||||
'kernel_id': 1,
|
||||
'ramdisk_id': 1,
|
||||
'type': 'machine'},
|
||||
'is_public': False}
|
||||
expected = {'name': 'name',
|
||||
'imageOwnerId': None,
|
||||
'isPublic': False,
|
||||
'imageId': 'ami-00000001',
|
||||
'imageState': None,
|
||||
'rootDeviceType': 'instance-store',
|
||||
'architecture': None,
|
||||
'imageLocation': 'location',
|
||||
'kernelId': 'aki-00000001',
|
||||
'ramdiskId': 'ari-00000001',
|
||||
'rootDeviceName': '/dev/sda1',
|
||||
'imageType': 'machine',
|
||||
'description': None}
|
||||
result = self.cloud._format_image(image)
|
||||
self.assertDictMatch(result, expected)
|
||||
image['properties']['image_location'] = None
|
||||
expected['imageLocation'] = 'None (name)'
|
||||
result = self.cloud._format_image(image)
|
||||
self.assertDictMatch(result, expected)
|
||||
image['name'] = None
|
||||
image['properties']['image_location'] = 'location'
|
||||
expected['imageLocation'] = 'location'
|
||||
expected['name'] = 'location'
|
||||
result = self.cloud._format_image(image)
|
||||
self.assertDictMatch(result, expected)
|
||||
|
||||
def test_deregister_image(self):
|
||||
deregister_image = self.cloud.deregister_image
|
||||
|
||||
|
||||
Reference in New Issue
Block a user