Merge lp:~retr0h/nova/lp705131 into lp:~hudson-openstack/nova/trunk

Proposed by John Dewey
Status: Merged
Approved by: Devin Carlen
Approved revision: 615
Merged at revision: 629
Proposed branch: lp:~retr0h/nova/lp705131
Merge into: lp:~hudson-openstack/nova/trunk
Diff against target: 80 lines (+17/-14)
2 files modified
nova/image/local.py (+16/-14)
nova/tests/api/openstack/test_images.py (+1/-0)
To merge this branch: bzr merge lp:~retr0h/nova/lp705131
Reviewer Review Type Date Requested Status
Devin Carlen (community) Approve
Soren Hansen (community) Approve
Rick Harris (community) Approve
Vish Ishaya Pending
Review via email: mp+47494@code.launchpad.net

This proposal supersedes a proposal from 2011-01-26.

Commit message

Make unit tests clean up their mess in /tmp after themselves.

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

lgtm

review: Approve
Revision history for this message
Vish Ishaya (vishvananda) wrote : Posted in a previous version of this proposal

Although the old code wasn't doing this, I feel like the directory (and any leftover files) should be cleaned up after they are used. I don't like the tests leaving around random tmp dirs.

review: Needs Fixing
Revision history for this message
Vish Ishaya (vishvananda) wrote : Posted in a previous version of this proposal

Nice. In general we prefer no space before the """ comments, so
"""This comment is better."""
"""
   Than this one
"""

On Jan 25, 2011, at 5:27 PM, John Dewey wrote:

> John Dewey has proposed merging lp:~retr0h/nova/lp705131 into lp:nova.
>
> Requested reviews:
> Devin Carlen (devcamcar)
> Vish Ishaya (vishvananda)
> Related bugs:
> #705131 LocalImageService tests fail for user "B" if user "A" has previously run test on same machine
> https://bugs.launchpad.net/bugs/705131
>
> For more details, see:
> https://code.launchpad.net/~retr0h/nova/lp705131/+merge/47491
> --
> https://code.launchpad.net/~retr0h/nova/lp705131/+merge/47491
> You are requested to review the proposed merge of lp:~retr0h/nova/lp705131 into lp:nova.
> === modified file 'nova/image/local.py'
> --- nova/image/local.py 2010-12-03 21:50:30 +0000
> +++ nova/image/local.py 2011-01-26 01:27:27 +0000
> @@ -18,6 +18,7 @@
> import cPickle as pickle
> import os.path
> import random
> +import tempfile
>
> from nova import exception
> from nova.image import service
> @@ -30,11 +31,7 @@
> It assumes that image_ids are integers."""
>
> def __init__(self):
> - self._path = "/tmp/nova/images"
> - try:
> - os.makedirs(self._path)
> - except OSError: # Exists
> - pass
> + self._path = tempfile.mkdtemp()
>
> def _path_to(self, image_id):
> return os.path.join(self._path, str(image_id))
> @@ -65,7 +62,9 @@
> return id
>
> def update(self, context, image_id, data):
> - """Replace the contents of the given image with the new data."""
> + """
> + Replace the contents of the given image with the new data.
> + """
> try:
> pickle.dump(data, open(self._path_to(image_id), 'w'))
> except IOError:
> @@ -82,7 +81,13 @@
>
> def delete_all(self):
> """
> - Clears out all images in local directory
> + Clears out all images in local directory.
> """
> for id in self._ids():
> os.unlink(self._path_to(id))
> +
> + def delete_imagedir(self):
> + """
> + Deletes the local directory. Raises OSError if directory is not empty.
> + """
> + os.rmdir(self._path)
>
> === modified file 'nova/tests/api/openstack/test_images.py'
> --- nova/tests/api/openstack/test_images.py 2011-01-12 19:20:05 +0000
> +++ nova/tests/api/openstack/test_images.py 2011-01-26 01:27:27 +0000
> @@ -143,6 +143,7 @@
>
> def tearDown(self):
> self.service.delete_all()
> + self.service.delete_imagedir()
> self.stubs.UnsetAll()
>
>
>

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

lgtm

review: Approve
Revision history for this message
Soren Hansen (soren) wrote :

lgtm, although I took the liberty of adding a commit message. Can't merge stuff without it.

review: Approve
Revision history for this message
Devin Carlen (devcamcar) wrote :

lgtm

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'nova/image/local.py'
2--- nova/image/local.py 2010-12-03 21:50:30 +0000
3+++ nova/image/local.py 2011-01-26 02:21:46 +0000
4@@ -18,6 +18,7 @@
5 import cPickle as pickle
6 import os.path
7 import random
8+import tempfile
9
10 from nova import exception
11 from nova.image import service
12@@ -26,15 +27,12 @@
13 class LocalImageService(service.BaseImageService):
14
15 """Image service storing images to local disk.
16+ It assumes that image_ids are integers.
17
18- It assumes that image_ids are integers."""
19+ """
20
21 def __init__(self):
22- self._path = "/tmp/nova/images"
23- try:
24- os.makedirs(self._path)
25- except OSError: # Exists
26- pass
27+ self._path = tempfile.mkdtemp()
28
29 def _path_to(self, image_id):
30 return os.path.join(self._path, str(image_id))
31@@ -56,9 +54,7 @@
32 raise exception.NotFound
33
34 def create(self, context, data):
35- """
36- Store the image data and return the new image id.
37- """
38+ """Store the image data and return the new image id."""
39 id = random.randint(0, 2 ** 31 - 1)
40 data['id'] = id
41 self.update(context, id, data)
42@@ -72,8 +68,9 @@
43 raise exception.NotFound
44
45 def delete(self, context, image_id):
46- """
47- Delete the given image. Raises OSError if the image does not exist.
48+ """Delete the given image.
49+ Raises OSError if the image does not exist.
50+
51 """
52 try:
53 os.unlink(self._path_to(image_id))
54@@ -81,8 +78,13 @@
55 raise exception.NotFound
56
57 def delete_all(self):
58- """
59- Clears out all images in local directory
60- """
61+ """Clears out all images in local directory."""
62 for id in self._ids():
63 os.unlink(self._path_to(id))
64+
65+ def delete_imagedir(self):
66+ """Deletes the local directory.
67+ Raises OSError if directory is not empty.
68+
69+ """
70+ os.rmdir(self._path)
71
72=== modified file 'nova/tests/api/openstack/test_images.py'
73--- nova/tests/api/openstack/test_images.py 2011-01-12 19:20:05 +0000
74+++ nova/tests/api/openstack/test_images.py 2011-01-26 02:21:46 +0000
75@@ -143,6 +143,7 @@
76
77 def tearDown(self):
78 self.service.delete_all()
79+ self.service.delete_imagedir()
80 self.stubs.UnsetAll()
81
82