Mark custom properties in image schema as non-base
Currently it is impossible to determine if given image schema property
is base or custom one and knowledge of that can be handy in some
situations. Proposed change appends to every custom property special
key which determiness that it is not a base property.
Change-Id: I49255255df311036d516768afc55475c1f9aad47
Partial-Bug: #1371559
(cherry picked from commit 94c05cbdbb
)
This commit is contained in:
parent
d659161db4
commit
0f3b518028
|
@ -815,7 +815,11 @@ def get_schema(custom_properties=None):
|
|||
schema = glance.schema.PermissiveSchema('image', properties, links)
|
||||
else:
|
||||
schema = glance.schema.Schema('image', properties)
|
||||
schema.merge_properties(custom_properties or {})
|
||||
|
||||
if custom_properties:
|
||||
for property_value in custom_properties.values():
|
||||
property_value['is_base'] = False
|
||||
schema.merge_properties(custom_properties)
|
||||
return schema
|
||||
|
||||
|
||||
|
|
|
@ -3255,3 +3255,19 @@ class TestImageSchemaFormatConfiguration(test_utils.BaseTestCase):
|
|||
expected = ['mark']
|
||||
actual = schema.properties['container_format']['enum']
|
||||
self.assertEqual(expected, actual)
|
||||
|
||||
|
||||
class TestImageSchemaDeterminePropertyBasis(test_utils.BaseTestCase):
|
||||
def test_custom_property_marked_as_non_base(self):
|
||||
self.config(allow_additional_image_properties=False)
|
||||
custom_image_properties = {
|
||||
'pants': {
|
||||
'type': 'string',
|
||||
},
|
||||
}
|
||||
schema = glance.api.v2.images.get_schema(custom_image_properties)
|
||||
self.assertFalse(schema.properties['pants'].get('is_base', True))
|
||||
|
||||
def test_base_property_marked_as_base(self):
|
||||
schema = glance.api.v2.images.get_schema()
|
||||
self.assertTrue(schema.properties['disk_format'].get('is_base', True))
|
||||
|
|
Loading…
Reference in New Issue