Creating metadef object without any properties

Creating a metadef object without any properties associated with it
raises an Internal Server Error. It is easily reproducible by running
following glanceclient command:

glance --os-image-api-version 2 md-object-create --name obj_name
--schema '{"description": "some desc"}' OS::Software::DBMS

The metadef object itself is created successfully, but the notification
is not fired and the response has code 500. Proposed patch fixes it by
making sure that notification system won't iterate over None value.

Change-Id: I591801d80d9cb2738dc3d27d7719fcc53a3d0645
Closes-Bug: 1438154
This commit is contained in:
Kamil Rykowski 2015-03-30 14:16:57 +02:00
parent 02cbb2a17d
commit 374d50a56e
2 changed files with 22 additions and 2 deletions

View File

@ -166,8 +166,9 @@ def format_metadef_namespace_notification(metadef_namespace):
def format_metadef_object_notification(metadef_object):
object_properties = metadef_object.properties or {}
properties = []
for name, prop in six.iteritems(metadef_object.properties):
for name, prop in six.iteritems(object_properties):
object_property = _format_metadef_object_property(name, prop)
properties.append(object_property)

View File

@ -1250,7 +1250,8 @@ class TestMetadefsControllers(base.IsolatedUnitTest):
self.assertEqual({}, object.properties)
self.assertNotificationLog("metadef_object.create",
[{'name': OBJECT2,
'namespace': NAMESPACE1}])
'namespace': NAMESPACE1,
'properties': []}])
object = self.object_controller.show(request, NAMESPACE1, OBJECT2)
self.assertEqual(OBJECT2, object.name)
self.assertEqual([], object.required)
@ -1315,6 +1316,24 @@ class TestMetadefsControllers(base.IsolatedUnitTest):
self.assertEqual([], object.required)
self.assertEqual({}, object.properties)
def test_object_create_missing_properties(self):
request = unit_test_utils.get_fake_request()
object = glance.api.v2.model.metadef_object.MetadefObject()
object.name = OBJECT2
object.required = []
object = self.object_controller.create(request, object, NAMESPACE1)
self.assertEqual(OBJECT2, object.name)
self.assertEqual([], object.required)
self.assertNotificationLog("metadef_object.create",
[{'name': OBJECT2,
'namespace': NAMESPACE1,
'properties': []}])
object = self.object_controller.show(request, NAMESPACE1, OBJECT2)
self.assertEqual(OBJECT2, object.name)
self.assertEqual([], object.required)
self.assertEqual({}, object.properties)
def test_object_update(self):
request = unit_test_utils.get_fake_request(tenant=TENANT3)