Merge lp:~rconradharris/glance/lp731684 into lp:~glance-coresec/glance/cactus-trunk

Proposed by Rick Harris
Status: Merged
Approved by: Jay Pipes
Approved revision: 88
Merged at revision: 86
Proposed branch: lp:~rconradharris/glance/lp731684
Merge into: lp:~glance-coresec/glance/cactus-trunk
Diff against target: 109 lines (+14/-11)
2 files modified
glance/store/swift.py (+12/-10)
tests/unit/test_swift_store.py (+2/-1)
To merge this branch: bzr merge lp:~rconradharris/glance/lp731684
Reviewer Review Type Date Requested Status
Jay Pipes (community) Approve
Josh Kearney (community) Approve
Devin Carlen (community) Approve
Review via email: mp+52757@code.launchpad.net

Description of the change

Don't require swift module for unit-tests

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

lgtm

review: Approve
Revision history for this message
Josh Kearney (jk0) wrote :

lgtm

review: Approve
Revision history for this message
Cory Wright (corywright) wrote :

I agree that swift shouldn't be required to use glance, but I don't think its a good idea to skip running the tests if it isn't installed. We don't want to force users to install swift just to use glance, but developers should be required to install it in order to run tests against it and avoid introducing regressions.

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

> but developers should be required to install it in order to run tests against it and avoid introducing regressions.

Well put, you're right.

I'll leave the lazy-import changes so that the code itself doesn't require swift and I'll ax the skip-test workaround.

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

coolness. thx rick.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'glance/store/swift.py'
2--- glance/store/swift.py 2011-03-07 20:11:59 +0000
3+++ glance/store/swift.py 2011-03-09 22:02:23 +0000
4@@ -22,8 +22,6 @@
5 import httplib
6 import logging
7
8-from swift.common.client import Connection, ClientException
9-
10 from glance.common import config
11 from glance.common import exception
12 import glance.store
13@@ -49,18 +47,19 @@
14 swift instance at auth_url and downloads the file. Returns the
15 generator resp_body provided by get_object.
16 """
17+ from swift.common import client as swift_client
18 (user, key, authurl, container, obj) = parse_swift_tokens(parsed_uri)
19
20 # TODO(sirp): snet=False for now, however, if the instance of
21 # swift we're talking to is within our same region, we should set
22 # snet=True
23- swift_conn = Connection(
24+ swift_conn = swift_client.Connection(
25 authurl=authurl, user=user, key=key, snet=False)
26
27 try:
28 (resp_headers, resp_body) = swift_conn.get_object(
29 container=container, obj=obj, resp_chunk_size=cls.CHUNKSIZE)
30- except ClientException, e:
31+ except swift_client.ClientException, e:
32 if e.http_status == httplib.NOT_FOUND:
33 location = format_swift_location(user, key, authurl,
34 container, obj)
35@@ -99,6 +98,7 @@
36 The location that was written,
37 and the size in bytes of the data written
38 """
39+ from swift.common import client as swift_client
40 container = options.get('swift_store_container',
41 DEFAULT_SWIFT_CONTAINER)
42 auth_address = options.get('swift_store_auth_address')
43@@ -132,8 +132,8 @@
44 "options.")
45 raise glance.store.BackendException(msg)
46
47- swift_conn = Connection(authurl=full_auth_address, user=user,
48- key=key, snet=False)
49+ swift_conn = swift_client.Connection(
50+ authurl=full_auth_address, user=user, key=key, snet=False)
51
52 logger.debug("Adding image object to Swift using "
53 "(auth_address=%(auth_address)s, user=%(user)s, "
54@@ -162,7 +162,7 @@
55 if 'content-length' in resp_headers:
56 size = int(resp_headers['content-length'])
57 return (location, size)
58- except ClientException, e:
59+ except swift_client.ClientException, e:
60 if e.http_status == httplib.CONFLICT:
61 raise exception.Duplicate("Swift already has an image at "
62 "location %(location)s" % locals())
63@@ -175,17 +175,18 @@
64 """
65 Deletes the swift object(s) at the parsed_uri location
66 """
67+ from swift.common import client as swift_client
68 (user, key, authurl, container, obj) = parse_swift_tokens(parsed_uri)
69
70 # TODO(sirp): snet=False for now, however, if the instance of
71 # swift we're talking to is within our same region, we should set
72 # snet=True
73- swift_conn = Connection(
74+ swift_conn = swift_client.Connection(
75 authurl=authurl, user=user, key=key, snet=False)
76
77 try:
78 swift_conn.delete_object(container, obj)
79- except ClientException, e:
80+ except swift_client.ClientException, e:
81 if e.http_status == httplib.NOT_FOUND:
82 location = format_swift_location(user, key, authurl,
83 container, obj)
84@@ -253,9 +254,10 @@
85 :param swift_conn: Connection to Swift
86 :param options: Option mapping
87 """
88+ from swift.common import client as swift_client
89 try:
90 swift_conn.head_container(container)
91- except ClientException, e:
92+ except swift_client.ClientException, e:
93 if e.http_status == httplib.NOT_FOUND:
94 add_container = config.get_option(options,
95 'swift_store_create_container_on_put',
96
97=== modified file 'tests/unit/test_swift_store.py'
98--- tests/unit/test_swift_store.py 2011-03-06 16:39:56 +0000
99+++ tests/unit/test_swift_store.py 2011-03-09 22:02:23 +0000
100@@ -294,7 +294,8 @@
101 Test that trying to delete a swift that doesn't exist
102 raises an error
103 """
104- url_pieces = urlparse.urlparse("swift://user:key@auth_address/noexist")
105+ url_pieces = urlparse.urlparse(
106+ "swift://user:key@auth_address/noexist")
107 self.assertRaises(exception.NotFound,
108 SwiftBackend.delete,
109 url_pieces)

Subscribers

People subscribed via source and target branches