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
1=== modified file 'glance/registry/db/api.py'
2--- glance/registry/db/api.py 2011-03-14 19:10:24 +0000
3+++ glance/registry/db/api.py 2011-03-23 18:41:13 +0000
4@@ -256,6 +256,11 @@
5 else:
6 image_property_create(context, prop_values, session=session)
7
8+ for key in orig_properties.keys():
9+ if not key in properties:
10+ prop_ref = orig_properties[key]
11+ image_property_delete(context, prop_ref, session=session)
12+
13
14 def image_property_create(context, values, session=None):
15 """Create an ImageProperty object"""
16@@ -277,6 +282,14 @@
17 return prop_ref
18
19
20+def image_property_delete(context, prop_ref, session=None):
21+ """Used internally by image_property_create and image_property_update
22+ """
23+ prop_ref.update(dict(deleted=True))
24+ prop_ref.save(session=session)
25+ return prop_ref
26+
27+
28 # pylint: disable-msg=C0111
29 def _deleted(context):
30 """Calculates whether to include deleted objects based on context.
31
32=== modified file 'tests/functional/test_curl_api.py'
33--- tests/functional/test_curl_api.py 2011-03-17 21:43:26 +0000
34+++ tests/functional/test_curl_api.py 2011-03-23 18:41:13 +0000
35@@ -299,4 +299,27 @@
36 expected_value,
37 image[expected_key]))
38
39+ # 10. PUT /images/1 and remove a previously existing property.
40+ cmd = ("curl -i -X PUT "
41+ "-H 'X-Image-Meta-Property-Arch: x86_64' "
42+ "http://0.0.0.0:%d/images/1") % api_port
43+
44+ exitcode, out, err = execute(cmd)
45+ self.assertEqual(0, exitcode)
46+
47+ lines = out.split("\r\n")
48+ status_line = lines[0]
49+
50+ self.assertEqual("HTTP/1.1 200 OK", status_line)
51+
52+ cmd = "curl -g http://0.0.0.0:%d/images/detail" % api_port
53+
54+ exitcode, out, err = execute(cmd)
55+
56+ self.assertEqual(0, exitcode)
57+
58+ image = json.loads(out.strip())['images'][0]
59+ self.assertEqual(1, len(image['properties']))
60+ self.assertEqual('x86_64', image['properties']['arch'])
61+
62 self.stop_servers()

Subscribers

People subscribed via source and target branches