Merge lp:~jaypipes/glance/bug773388 into lp:~hudson-openstack/glance/trunk

Proposed by Jay Pipes
Status: Merged
Approved by: Vish Ishaya
Approved revision: 129
Merged at revision: 129
Proposed branch: lp:~jaypipes/glance/bug773388
Merge into: lp:~hudson-openstack/glance/trunk
Diff against target: 167 lines (+135/-3)
2 files modified
glance/registry/db/api.py (+1/-1)
tests/functional/test_curl_api.py (+134/-2)
To merge this branch: bzr merge lp:~jaypipes/glance/bug773388
Reviewer Review Type Date Requested Status
Vish Ishaya (community) Approve
Rick Harris (community) Approve
Devin Carlen (community) Approve
Graham Hemingway Pending
Shi Jin Pending
Review via email: mp+59858@code.launchpad.net

Description of the change

Changes glance index to return all public images
in any status other than 'killed'. This should allow
tools like euca-describe-images to show images while
they are in a saving/untarring/decrypting state.

One line fix. 110 line test case. :)

To post a comment you must log in.
Revision history for this message
Devin Carlen (devcamcar) wrote :

nice, lgtm :)

110 to 1 test to fix ratio, I like it!

review: Approve
Revision history for this message
Vish Ishaya (vishvananda) wrote :

9 + filter(models.Image.status != 'active').\

shouldn't that be != 'killed' ??

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

OMG. I can't believe I wrote that big of a test that passes for a wrong conditional. :(

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

Fixed, please re-review.

lp:~jaypipes/glance/bug773388 updated
129. By Jay Pipes

Fix numbering in comment...

Revision history for this message
Rick Harris (rconradharris) wrote :

lgtm

review: Approve
Revision history for this message
Kevin Bringard (kbringard) wrote :

Seems reasonable to me

Revision history for this message
Vish Ishaya (vishvananda) wrote :

lg now

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'glance/registry/db/api.py'
2--- glance/registry/db/api.py 2011-04-22 17:57:19 +0000
3+++ glance/registry/db/api.py 2011-05-04 15:31:35 +0000
4@@ -146,7 +146,7 @@
5 options(joinedload(models.Image.properties)).\
6 filter_by(deleted=_deleted(context)).\
7 filter_by(is_public=True).\
8- filter_by(status='active').\
9+ filter(models.Image.status != 'killed').\
10 all()
11
12
13
14=== modified file 'tests/functional/test_curl_api.py'
15--- tests/functional/test_curl_api.py 2011-04-13 16:44:47 +0000
16+++ tests/functional/test_curl_api.py 2011-05-04 15:31:35 +0000
17@@ -58,9 +58,9 @@
18 - Verify 200 returned
19 9. GET /images/1
20 - Verify updated information about image was stored
21- # 10. PUT /images/1
22+ 10. PUT /images/1
23 - Remove a previously existing property.
24- # 11. PUT /images/1
25+ 11. PUT /images/1
26 - Add a previously deleted property.
27 """
28
29@@ -356,6 +356,138 @@
30
31 self.stop_servers()
32
33+ def test_queued_process_flow(self):
34+ """
35+ We test the process flow where a user registers an image
36+ with Glance but does not immediately upload an image file.
37+ Later, the user uploads an image file using a PUT operation.
38+ We track the changing of image status throughout this process.
39+
40+ 0. GET /images
41+ - Verify no public images
42+ 1. POST /images with public image named Image1 with no location
43+ attribute and no image data.
44+ - Verify 201 returned
45+ 2. GET /images
46+ - Verify one public image
47+ 3. HEAD /images/1
48+ - Verify image now in queued status
49+ 4. PUT /images/1 with image data
50+ - Verify 200 returned
51+ 5. HEAD /images/1
52+ - Verify image now in active status
53+ 6. GET /images
54+ - Verify one public image
55+ """
56+
57+ self.cleanup()
58+ api_port, reg_port, conf_file = self.start_servers()
59+
60+ # 0. GET /images
61+ # Verify no public images
62+ cmd = "curl -g http://0.0.0.0:%d/images" % api_port
63+
64+ exitcode, out, err = execute(cmd)
65+
66+ self.assertEqual(0, exitcode)
67+ self.assertEqual('{"images": []}', out.strip())
68+
69+ # 1. POST /images with public image named Image1
70+ # with no location or image data
71+
72+ cmd = ("curl -i -X POST "
73+ "-H 'Expect: ' " # Necessary otherwise sends 100 Continue
74+ "-H 'X-Image-Meta-Name: Image1' "
75+ "-H 'X-Image-Meta-Is-Public: True' "
76+ "http://0.0.0.0:%d/images") % api_port
77+
78+ exitcode, out, err = execute(cmd)
79+ self.assertEqual(0, exitcode)
80+
81+ lines = out.split("\r\n")
82+ status_line = lines[0]
83+
84+ self.assertEqual("HTTP/1.1 201 Created", status_line)
85+
86+ # 2. GET /images
87+ # Verify 1 public image
88+ cmd = "curl -g http://0.0.0.0:%d/images" % api_port
89+
90+ exitcode, out, err = execute(cmd)
91+
92+ self.assertEqual(0, exitcode)
93+ image = json.loads(out.strip())['images'][0]
94+ expected = {"name": "Image1",
95+ "container_format": None,
96+ "disk_format": None,
97+ "checksum": None,
98+ "id": 1,
99+ "size": 0}
100+ self.assertEqual(expected, image)
101+
102+ # 3. HEAD /images
103+ # Verify status is in queued
104+ cmd = "curl -i -X HEAD http://0.0.0.0:%d/images/1" % api_port
105+
106+ exitcode, out, err = execute(cmd)
107+
108+ self.assertEqual(0, exitcode)
109+
110+ lines = out.split("\r\n")
111+ status_line = lines[0]
112+
113+ self.assertEqual("HTTP/1.1 200 OK", status_line)
114+ self.assertTrue("X-Image-Meta-Name: Image1" in out)
115+ self.assertTrue("X-Image-Meta-Status: queued" in out)
116+
117+ # 4. PUT /images/1 with image data, verify 200 returned
118+ image_data = "*" * FIVE_KB
119+
120+ cmd = ("curl -i -X PUT "
121+ "-H 'Expect: ' " # Necessary otherwise sends 100 Continue
122+ "-H 'Content-Type: application/octet-stream' "
123+ "--data-binary \"%s\" "
124+ "http://0.0.0.0:%d/images/1") % (image_data, api_port)
125+
126+ exitcode, out, err = execute(cmd)
127+ self.assertEqual(0, exitcode)
128+
129+ lines = out.split("\r\n")
130+ status_line = lines[0]
131+
132+ self.assertEqual("HTTP/1.1 200 OK", status_line)
133+
134+ # 5. HEAD /images
135+ # Verify status is in active
136+ cmd = "curl -i -X HEAD http://0.0.0.0:%d/images/1" % api_port
137+
138+ exitcode, out, err = execute(cmd)
139+
140+ self.assertEqual(0, exitcode)
141+
142+ lines = out.split("\r\n")
143+ status_line = lines[0]
144+
145+ self.assertEqual("HTTP/1.1 200 OK", status_line)
146+ self.assertTrue("X-Image-Meta-Name: Image1" in out)
147+ self.assertTrue("X-Image-Meta-Status: active" in out)
148+
149+ # 6. GET /images
150+ # Verify 1 public image still...
151+ cmd = "curl -g http://0.0.0.0:%d/images" % api_port
152+
153+ exitcode, out, err = execute(cmd)
154+
155+ self.assertEqual(0, exitcode)
156+ image = json.loads(out.strip())['images'][0]
157+ expected = {"name": "Image1",
158+ "container_format": None,
159+ "disk_format": None,
160+ "checksum": 'c2e5db72bd7fd153f53ede5da5a06de3',
161+ "id": 1,
162+ "size": 5120}
163+ self.assertEqual(expected, image)
164+
165 def test_size_greater_2G_mysql(self):
166 """
167 A test against the actual datastore backend for the registry

Subscribers

People subscribed via source and target branches