summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Lamar <brian.lamar@rackspace.com>2011-04-04 10:59:44 -0400
committerBrian Lamar <brian.lamar@rackspace.com>2011-04-04 10:59:44 -0400
commitbd64c4f6bebb50528b87bf6e3f64d7d1cba053df (patch)
tree895d39c8c3b03bd5a8ff5691ff848f356301892b
parent0ec4352046939785b3ffa390e6d8264ce4d99f98 (diff)
downloadnova-bd64c4f6bebb50528b87bf6e3f64d7d1cba053df.tar.gz
nova-bd64c4f6bebb50528b87bf6e3f64d7d1cba053df.tar.xz
nova-bd64c4f6bebb50528b87bf6e3f64d7d1cba053df.zip
Fixes error which occurs when no name is specified for an image.
-rw-r--r--nova/api/openstack/views/images.py2
-rw-r--r--nova/tests/api/openstack/test_images.py57
2 files changed, 56 insertions, 3 deletions
diff --git a/nova/api/openstack/views/images.py b/nova/api/openstack/views/images.py
index 3807fa95f..d8578ebdd 100644
--- a/nova/api/openstack/views/images.py
+++ b/nova/api/openstack/views/images.py
@@ -61,7 +61,7 @@ class ViewBuilder(object):
image = {
"id": image_obj["id"],
- "name": image_obj["name"],
+ "name": image_obj.get("name"),
}
if "instance_id" in properties:
diff --git a/nova/tests/api/openstack/test_images.py b/nova/tests/api/openstack/test_images.py
index 57e447dce..69cc3116d 100644
--- a/nova/tests/api/openstack/test_images.py
+++ b/nova/tests/api/openstack/test_images.py
@@ -263,7 +263,8 @@ class ImageControllerWithGlanceServiceTest(test.TestCase):
{'id': 124, 'name': 'queued backup'},
{'id': 125, 'name': 'saving backup'},
{'id': 126, 'name': 'active backup'},
- {'id': 127, 'name': 'killed backup'}]
+ {'id': 127, 'name': 'killed backup'},
+ {'id': 129, 'name': None}]
self.assertDictListMatch(response_list, expected)
@@ -339,6 +340,24 @@ class ImageControllerWithGlanceServiceTest(test.TestCase):
self.assertEqual(expected_image.toxml(), actual_image.toxml())
+ def test_get_image_xml_no_name(self):
+ request = webob.Request.blank('/v1.0/images/129')
+ request.accept = "application/xml"
+ response = request.get_response(fakes.wsgi_app())
+
+ actual_image = minidom.parseString(response.body.replace(" ", ""))
+
+ expected_now = self.NOW_API_FORMAT
+ expected_image = minidom.parseString("""
+ <image id="129"
+ name="None"
+ updated="%(expected_now)s"
+ created="%(expected_now)s"
+ status="ACTIVE" />
+ """ % (locals()))
+
+ self.assertEqual(expected_image.toxml(), actual_image.toxml())
+
def test_get_image_v1_1_xml(self):
request = webob.Request.blank('/v1.1/images/123')
request.accept = "application/xml"
@@ -516,6 +535,13 @@ class ImageControllerWithGlanceServiceTest(test.TestCase):
'updated': self.NOW_API_FORMAT,
'created': self.NOW_API_FORMAT,
'status': 'FAILED',
+ },
+ {
+ 'id': 129,
+ 'name': None,
+ 'updated': self.NOW_API_FORMAT,
+ 'created': self.NOW_API_FORMAT,
+ 'status': 'ACTIVE',
}]
self.assertDictListMatch(expected, response_list)
@@ -635,7 +661,29 @@ class ImageControllerWithGlanceServiceTest(test.TestCase):
"type": "application/xml",
"href": "http://localhost/v1.1/images/127",
}],
- }]
+ },
+ {
+ 'id': 129,
+ 'name': None,
+ 'updated': self.NOW_API_FORMAT,
+ 'created': self.NOW_API_FORMAT,
+ 'status': 'ACTIVE',
+ "links": [{
+ "rel": "self",
+ "href": "http://localhost/v1.1/images/129",
+ },
+ {
+ "rel": "bookmark",
+ "type": "application/json",
+ "href": "http://localhost/v1.1/images/129",
+ },
+ {
+ "rel": "bookmark",
+ "type": "application/xml",
+ "href": "http://localhost/v1.1/images/129",
+ }],
+ },
+ ]
self.assertDictListMatch(expected, response_list)
@@ -694,4 +742,9 @@ class ImageControllerWithGlanceServiceTest(test.TestCase):
status='active', properties=other_backup_properties)
image_id += 1
+ # Image without a name
+ add_fixture(id=image_id, is_public=True, status='active',
+ properties={})
+ image_id += 1
+
return fixtures