Merge lp:~rackspace-titan/nova/images-500-lp749972 into lp:~hudson-openstack/nova/trunk

Proposed by Brian Lamar
Status: Merged
Approved by: Josh Kearney
Approved revision: 936
Merged at revision: 936
Proposed branch: lp:~rackspace-titan/nova/images-500-lp749972
Merge into: lp:~hudson-openstack/nova/trunk
Diff against target: 121 lines (+60/-7)
2 files modified
nova/api/openstack/views/images.py (+5/-5)
nova/tests/api/openstack/test_images.py (+55/-2)
To merge this branch: bzr merge lp:~rackspace-titan/nova/images-500-lp749972
Reviewer Review Type Date Requested Status
Jay Pipes (community) Approve
Josh Kearney (community) Approve
Titan Pending
Review via email: mp+56189@code.launchpad.net

Description of the change

Attempt to circumvent errors in the API from improper/malformed responses from image service.

To post a comment you must log in.
Revision history for this message
Josh Kearney (jk0) wrote :

lgtm

review: Approve
Revision history for this message
Jay Pipes (jaypipes) wrote :

w00t for testing.

not sure about images with no names, but if the API supports it, I guess this fixes that issue :)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'nova/api/openstack/views/images.py'
2--- nova/api/openstack/views/images.py 2011-03-29 13:51:02 +0000
3+++ nova/api/openstack/views/images.py 2011-04-04 15:23:32 +0000
4@@ -60,8 +60,8 @@
5 self._format_status(image_obj)
6
7 image = {
8- "id": image_obj["id"],
9- "name": image_obj["name"],
10+ "id": image_obj.get("id"),
11+ "name": image_obj.get("name"),
12 }
13
14 if "instance_id" in properties:
15@@ -72,9 +72,9 @@
16
17 if detail:
18 image.update({
19- "created": image_obj["created_at"],
20- "updated": image_obj["updated_at"],
21- "status": image_obj["status"],
22+ "created": image_obj.get("created_at"),
23+ "updated": image_obj.get("updated_at"),
24+ "status": image_obj.get("status"),
25 })
26
27 if image["status"] == "SAVING":
28
29=== modified file 'nova/tests/api/openstack/test_images.py'
30--- nova/tests/api/openstack/test_images.py 2011-03-29 19:22:28 +0000
31+++ nova/tests/api/openstack/test_images.py 2011-04-04 15:23:32 +0000
32@@ -263,7 +263,8 @@
33 {'id': 124, 'name': 'queued backup'},
34 {'id': 125, 'name': 'saving backup'},
35 {'id': 126, 'name': 'active backup'},
36- {'id': 127, 'name': 'killed backup'}]
37+ {'id': 127, 'name': 'killed backup'},
38+ {'id': 129, 'name': None}]
39
40 self.assertDictListMatch(response_list, expected)
41
42@@ -339,6 +340,24 @@
43
44 self.assertEqual(expected_image.toxml(), actual_image.toxml())
45
46+ def test_get_image_xml_no_name(self):
47+ request = webob.Request.blank('/v1.0/images/129')
48+ request.accept = "application/xml"
49+ response = request.get_response(fakes.wsgi_app())
50+
51+ actual_image = minidom.parseString(response.body.replace(" ", ""))
52+
53+ expected_now = self.NOW_API_FORMAT
54+ expected_image = minidom.parseString("""
55+ <image id="129"
56+ name="None"
57+ updated="%(expected_now)s"
58+ created="%(expected_now)s"
59+ status="ACTIVE" />
60+ """ % (locals()))
61+
62+ self.assertEqual(expected_image.toxml(), actual_image.toxml())
63+
64 def test_get_image_v1_1_xml(self):
65 request = webob.Request.blank('/v1.1/images/123')
66 request.accept = "application/xml"
67@@ -516,6 +535,13 @@
68 'updated': self.NOW_API_FORMAT,
69 'created': self.NOW_API_FORMAT,
70 'status': 'FAILED',
71+ },
72+ {
73+ 'id': 129,
74+ 'name': None,
75+ 'updated': self.NOW_API_FORMAT,
76+ 'created': self.NOW_API_FORMAT,
77+ 'status': 'ACTIVE',
78 }]
79
80 self.assertDictListMatch(expected, response_list)
81@@ -635,7 +661,29 @@
82 "type": "application/xml",
83 "href": "http://localhost/v1.1/images/127",
84 }],
85- }]
86+ },
87+ {
88+ 'id': 129,
89+ 'name': None,
90+ 'updated': self.NOW_API_FORMAT,
91+ 'created': self.NOW_API_FORMAT,
92+ 'status': 'ACTIVE',
93+ "links": [{
94+ "rel": "self",
95+ "href": "http://localhost/v1.1/images/129",
96+ },
97+ {
98+ "rel": "bookmark",
99+ "type": "application/json",
100+ "href": "http://localhost/v1.1/images/129",
101+ },
102+ {
103+ "rel": "bookmark",
104+ "type": "application/xml",
105+ "href": "http://localhost/v1.1/images/129",
106+ }],
107+ },
108+ ]
109
110 self.assertDictListMatch(expected, response_list)
111
112@@ -694,4 +742,9 @@
113 status='active', properties=other_backup_properties)
114 image_id += 1
115
116+ # Image without a name
117+ add_fixture(id=image_id, is_public=True, status='active',
118+ properties={})
119+ image_id += 1
120+
121 return fixtures