Merge lp:~soren/nova/image-tests into lp:~hudson-openstack/nova/trunk

Proposed by Soren Hansen
Status: Work in progress
Proposed branch: lp:~soren/nova/image-tests
Merge into: lp:~hudson-openstack/nova/trunk
Diff against target: 81 lines (+27/-1)
3 files modified
nova/image/fake.py (+8/-0)
nova/image/service.py (+1/-1)
nova/tests/test_image.py (+18/-0)
To merge this branch: bzr merge lp:~soren/nova/image-tests
Reviewer Review Type Date Requested Status
Brian Waldon (community) Approve
Brian Lamar (community) Needs Fixing
Review via email: mp+73117@code.launchpad.net

Commit message

Make fake image driver support get() call (with tests)

Description of the change

Make the fake image driver support get() and make it return an empty string for images with no data.

I'm not completely convinced this is what we actually want to happen (the returning an empty string when no blob is present) but as far as I can tell, this is what the Glance backend does as well.

To post a comment you must log in.
Revision history for this message
Brian Lamar (blamar) wrote :

Can you update the docstring on BaseImageService.get? Other than that this looks good to me.

review: Needs Fixing
Revision history for this message
Brian Waldon (bcwaldon) wrote :

Cool stuff. Good to go once you fix that docstring.

I would love to get rid of our several different fake image services at some point. Have you had a chance to look into that?

review: Approve

Unmerged revisions

1439. By Soren Hansen

Make fake image driver return an empty string for images with no data. Add a test for this.

1438. By Soren Hansen

Merge trunk

1437. By Soren Hansen

pep8

1436. By Soren Hansen

Merge trunk

1435. By Soren Hansen

Add a test to make sure we can write image data and read it back again.

1434. By Soren Hansen

Merge trunk

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'nova/image/fake.py'
2--- nova/image/fake.py 2011-08-05 13:37:36 +0000
3+++ nova/image/fake.py 2011-08-26 23:06:25 +0000
4@@ -112,6 +112,7 @@
5 self.create(None, image3)
6 self.create(None, image4)
7 self.create(None, image5)
8+ self._imagedata = {}
9 super(_FakeImageService, self).__init__()
10
11 def index(self, context, filters=None, marker=None, limit=None):
12@@ -126,6 +127,11 @@
13 """Return list of detailed image information."""
14 return copy.deepcopy(self.images.values())
15
16+ def get(self, context, image_id, data):
17+ metadata = self.show(context, image_id)
18+ data.write(self._imagedata.get(image_id, ''))
19+ return metadata
20+
21 def show(self, context, image_id):
22 """Get data about specified image.
23
24@@ -168,6 +174,8 @@
25
26 metadata['id'] = image_id
27 self.images[image_id] = copy.deepcopy(metadata)
28+ if data:
29+ self._imagedata[image_id] = data.read()
30 return self.images[image_id]
31
32 def update(self, context, image_id, metadata, data=None):
33
34=== modified file 'nova/image/service.py'
35--- nova/image/service.py 2011-05-25 21:28:10 +0000
36+++ nova/image/service.py 2011-08-26 23:06:25 +0000
37@@ -97,7 +97,7 @@
38 """
39 raise NotImplementedError
40
41- def get(self, context, data):
42+ def get(self, context, image_id, data):
43 """Get an image.
44
45 :param data: a file-like object to hold binary image data
46
47=== modified file 'nova/tests/test_image.py'
48--- nova/tests/test_image.py 2011-08-05 19:28:22 +0000
49+++ nova/tests/test_image.py 2011-08-26 23:06:25 +0000
50@@ -16,6 +16,7 @@
51 # under the License.
52
53 import datetime
54+import StringIO
55
56 from nova import context
57 from nova import exception
58@@ -127,6 +128,23 @@
59 index = self.image_service.index(self.context)
60 self.assertEquals(len(index), 0)
61
62+ def test_create_then_get(self):
63+ blob = 'some data'
64+ s1 = StringIO.StringIO(blob)
65+ self.image_service.create(self.context,
66+ {'id': '32', 'foo': 'bar'},
67+ data=s1)
68+ s2 = StringIO.StringIO()
69+ self.image_service.get(self.context, '32', data=s2)
70+ self.assertEquals(s2.getvalue(), blob, 'Did not get blob back intact')
71+
72+ def test_get_non_existent_content(self):
73+ self.image_service.create(self.context,
74+ {'id': '32', 'foo': 'bar'})
75+ s2 = StringIO.StringIO()
76+ self.image_service.get(self.context, '32', data=s2)
77+ self.assertEquals(s2.getvalue(), '', 'Did not get empty blob back')
78+
79
80 class FakeImageTestCase(_ImageTestCase):
81 def setUp(self):