summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamil Rykowski <kamil.rykowski@intel.com>2014-09-24 14:15:59 +0200
committerKamil Rykowski <kamil.rykowski@intel.com>2014-10-07 07:12:23 +0000
commit0f3b518028196b5c8c36b378928dae31c2c4a6fa (patch)
tree6e3dc7a6c20fe047541f49fa94c81db67417dbb4
parentd659161db4ff5392dfdd6199a2d43e0e3c48b4fa (diff)
downloadglance-0f3b518028196b5c8c36b378928dae31c2c4a6fa.tar.gz
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 94c05cbdbb3a78b3df4df8d522555f34d2f0a166)
-rw-r--r--glance/api/v2/images.py6
-rw-r--r--glance/tests/unit/v2/test_images_resource.py16
2 files changed, 21 insertions, 1 deletions
diff --git a/glance/api/v2/images.py b/glance/api/v2/images.py
index ffa8e2667..92e1c5c0a 100644
--- a/glance/api/v2/images.py
+++ b/glance/api/v2/images.py
@@ -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
diff --git a/glance/tests/unit/v2/test_images_resource.py b/glance/tests/unit/v2/test_images_resource.py
index 27c767f7d..cfba9b5ff 100644
--- a/glance/tests/unit/v2/test_images_resource.py
+++ b/glance/tests/unit/v2/test_images_resource.py
@@ -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))