Merge "fix glance metadata layout"

This commit is contained in:
Zuul
2025-03-12 03:36:09 +00:00
committed by Gerrit Code Review
4 changed files with 29 additions and 32 deletions

View File

@@ -38,14 +38,26 @@ LOG = log.getLogger(__name__)
def _extract_attributes(image):
output = {}
# copies attributes from the openstacksdk Image object
# to a dictionary
for attr in _IMAGE_ATTRIBUTES:
output[attr] = getattr(image, attr, None)
output['properties'] = {}
# copy the properties over to start so that image properties
# are not nested in another properties key
output['properties'] = getattr(image, 'properties', {})
output['schema'] = image.schema
for image_property in set(image) - set(_IMAGE_ATTRIBUTES):
output['properties'][image_property] = image[image_property]
# attributes already copied so we copy the rest into properties
copied = set(_IMAGE_ATTRIBUTES)
copied.add('properties')
for image_property in set(image) - copied:
# previously with glanceclient only set things
# were on the object that came back but the SDK
# defines every possible attribute so we need to filter
if image[image_property]:
output['properties'][image_property] = image[image_property]
return output

View File

@@ -100,9 +100,11 @@ class TestGlanceImageService(base.TestCase):
@staticmethod
def _make_fixture(**kwargs):
fixture = {'name': None,
'owner': None,
'properties': {},
'status': "active"}
fixture.update(kwargs)
return stubs.FakeImage(fixture)
return openstack.image.v2.image.Image.new(**fixture)
@property
def endpoint(self):
@@ -142,7 +144,7 @@ class TestGlanceImageService(base.TestCase):
'schema': None,
'size': None,
'status': "active",
'tags': None,
'tags': [],
'updated_at': None,
'visibility': None,
'os_hash_algo': None,

View File

@@ -51,33 +51,6 @@ class FakeImageDownload(object):
self.content = content
class FakeImage(dict):
def __init__(self, metadata):
IMAGE_ATTRIBUTES = ['size', 'disk_format', 'owner',
'container_format', 'checksum', 'id',
'name', 'deleted', 'status',
'min_disk', 'min_ram', 'tags', 'visibility',
'protected', 'file', 'schema', 'os_hash_algo',
'os_hash_value']
raw = dict.fromkeys(IMAGE_ATTRIBUTES)
raw.update(metadata)
# raw['created_at'] = NOW_GLANCE_FORMAT
# raw['updated_at'] = NOW_GLANCE_FORMAT
super(FakeImage, self).__init__(raw)
def __getattr__(self, key):
try:
return self[key]
except KeyError:
raise AttributeError(key)
def __setattr__(self, key, value):
if key in self:
self[key] = value
else:
raise AttributeError(key)
class FakeNeutronPort(dict):
def __init__(self, **attrs):
PORT_ATTRS = ['admin_state_up',

View File

@@ -0,0 +1,10 @@
---
fixes:
- |
When changing from glanceclient to OpenStack SDK to communicate with
Glance, a bug was introduced reading image properties causing the
Anaconda deploy interface to be unable to use Glance images. Other
deploy interfaces continued to function but could have resulted in
some properties not taking affect.
See `bug 2099275 <https://bugs.launchpad.net/ironic/+bug/2099953>`_ for
more details.