Merge lp:~dan-prince/glance/property_delete into lp:~glance-coresec/glance/cactus-trunk

Proposed by Dan Prince
Status: Merged
Approved by: Jay Pipes
Approved revision: 95
Merged at revision: 99
Proposed branch: lp:~dan-prince/glance/property_delete
Merge into: lp:~glance-coresec/glance/cactus-trunk
Diff against target: 62 lines (+36/-0)
2 files modified
glance/registry/db/api.py (+13/-0)
tests/functional/test_curl_api.py (+23/-0)
To merge this branch: bzr merge lp:~dan-prince/glance/property_delete
Reviewer Review Type Date Requested Status
Rick Harris (community) Approve
Jay Pipes (community) Approve
Review via email: mp+54583@code.launchpad.net

Description of the change

Update the glance registry so that it marks properties as deleted if they are no longer exist when images are updated.

To post a comment you must log in.
Revision history for this message
Jay Pipes (jaypipes) wrote :

Hi Dan! Great patch. I'll review thoroughly in a bit, but wanted to say thanks and to say I marked your bug as a duplicate because we already had a bug report about this issue... anyway, I'll link your branch to the original bug report...

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

Looks great, Dan. :)

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

Really clean patch Dan, great work.

I'm little worried by the semantics: a silent delete when a key isn't resubmitted. Though, there really aren't a whole lot of alternatives, and none that I can think of that don't involve some kind of magic, "DELETE ME IF YOU DETECT THIS" value.

So, this seems like the best approach available.

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

Agree that the silent delete if a key isn't present. We can look at possibly doing a DELETE /image/<ID>/prop or POST /image/<ID>/prop call in Diablo?

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

> DELETE /image/<ID>/prop or POST /image/<ID>/prop call in Diablo?

I think you're right, a lot of the current messiness surrounding Image properties would go away if we adopted full REST semantics. To me (not necessarily Roy Fielding ;-), this would mean:

* NOT using headers to store or retrieve image-metadata. Rather, we would use standard GET, POST, PUT, and DELETE operations for each of these.

* Image-properties would be a resource mounted at either /image/1/property/2 or /image-property/2.
 There pros and cons to both, but in terms of routing, the latter approach ends up being much simpler.

Thoughts?

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

Well, the reason that headers are used to return "metadata" (it's not metadata, but whatever.. ;) ) is:

a) for HEAD requests, you have no other choice
b) for GET requests, you have to return the image data as the body, so you have no other choice

Of course, the above is in reference to the API node, not the registry node, which of course does not use headers and in fact returns all the image properties and base attributes in JSON...

Or are you specifically referring to not using headers for the custom properties?

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

Also, FWIW, using headers to return image attributes has worked beautifully for Swift for a long time, which is where the concept came from.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'glance/registry/db/api.py'
--- glance/registry/db/api.py 2011-03-14 19:10:24 +0000
+++ glance/registry/db/api.py 2011-03-23 18:41:13 +0000
@@ -256,6 +256,11 @@
256 else:256 else:
257 image_property_create(context, prop_values, session=session)257 image_property_create(context, prop_values, session=session)
258258
259 for key in orig_properties.keys():
260 if not key in properties:
261 prop_ref = orig_properties[key]
262 image_property_delete(context, prop_ref, session=session)
263
259264
260def image_property_create(context, values, session=None):265def image_property_create(context, values, session=None):
261 """Create an ImageProperty object"""266 """Create an ImageProperty object"""
@@ -277,6 +282,14 @@
277 return prop_ref282 return prop_ref
278283
279284
285def image_property_delete(context, prop_ref, session=None):
286 """Used internally by image_property_create and image_property_update
287 """
288 prop_ref.update(dict(deleted=True))
289 prop_ref.save(session=session)
290 return prop_ref
291
292
280# pylint: disable-msg=C0111293# pylint: disable-msg=C0111
281def _deleted(context):294def _deleted(context):
282 """Calculates whether to include deleted objects based on context.295 """Calculates whether to include deleted objects based on context.
283296
=== modified file 'tests/functional/test_curl_api.py'
--- tests/functional/test_curl_api.py 2011-03-17 21:43:26 +0000
+++ tests/functional/test_curl_api.py 2011-03-23 18:41:13 +0000
@@ -299,4 +299,27 @@
299 expected_value,299 expected_value,
300 image[expected_key]))300 image[expected_key]))
301301
302 # 10. PUT /images/1 and remove a previously existing property.
303 cmd = ("curl -i -X PUT "
304 "-H 'X-Image-Meta-Property-Arch: x86_64' "
305 "http://0.0.0.0:%d/images/1") % api_port
306
307 exitcode, out, err = execute(cmd)
308 self.assertEqual(0, exitcode)
309
310 lines = out.split("\r\n")
311 status_line = lines[0]
312
313 self.assertEqual("HTTP/1.1 200 OK", status_line)
314
315 cmd = "curl -g http://0.0.0.0:%d/images/detail" % api_port
316
317 exitcode, out, err = execute(cmd)
318
319 self.assertEqual(0, exitcode)
320
321 image = json.loads(out.strip())['images'][0]
322 self.assertEqual(1, len(image['properties']))
323 self.assertEqual('x86_64', image['properties']['arch'])
324
302 self.stop_servers()325 self.stop_servers()

Subscribers

People subscribed via source and target branches