Merge lp:~jaypipes/glance/bug717431 into lp:~glance-coresec/glance/cactus-trunk

Proposed by Jay Pipes
Status: Merged
Approved by: Cory Wright
Approved revision: 91
Merged at revision: 90
Proposed branch: lp:~jaypipes/glance/bug717431
Merge into: lp:~glance-coresec/glance/cactus-trunk
Diff against target: 117 lines (+58/-13)
3 files modified
glance/store/swift.py (+10/-1)
run_tests.py (+10/-11)
tests/unit/test_swift_store.py (+38/-1)
To merge this branch: bzr merge lp:~jaypipes/glance/bug717431
Reviewer Review Type Date Requested Status
Cory Wright (community) Approve
Rick Harris (community) Approve
Review via email: mp+53655@code.launchpad.net

Description of the change

Support account:user:key in Swift URIs. Adds unit tests for various calls to parse_swift_tokens()

To post a comment you must log in.
Revision history for this message
Rick Harris (rconradharris) wrote :

Looks good, thanks Jay!

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

lgtm.

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-09 20:17:37 +0000
3+++ glance/store/swift.py 2011-03-16 16:53:27 +0000
4@@ -215,7 +215,16 @@
5 # see lp659445 and Python issue7904
6 creds, path = path.split('@')
7
8- user, key = creds.split(':')
9+ cred_parts = creds.split(':')
10+
11+ # User can be account:user, in which case cred_parts[0:2] will be
12+ # the account and user. Combine them into a single username of
13+ # account:user
14+ if len(cred_parts) == 3:
15+ user = ':'.join(cred_parts[0:2])
16+ else:
17+ user = cred_parts[0]
18+ key = cred_parts[-1]
19 path_parts = path.split('/')
20 obj = path_parts.pop()
21 container = path_parts.pop()
22
23=== modified file 'run_tests.py'
24--- run_tests.py 2011-03-16 06:43:16 +0000
25+++ run_tests.py 2011-03-16 16:53:27 +0000
26@@ -129,8 +129,7 @@
27 'yellow': red | green | bold,
28 'magenta': red | blue | bold,
29 'cyan': green | blue | bold,
30- 'white': red | green | blue | bold
31- }
32+ 'white': red | green | blue | bold}
33
34 def supported(cls, stream=sys.stdout):
35 try:
36@@ -238,15 +237,15 @@
37 elif self.dots:
38 stream.write(label[:1])
39 return
40- self.errors.append((test, exc_info))
41- test.passed = False
42- if stream is not None:
43- if self.showAll:
44- self.colorizer.write("ERROR", 'red')
45- self.stream.writeln()
46- elif self.dots:
47- stream.write('E')
48-
49+ self.errors.append((test, exc_info))
50+ test.passed = False
51+ if stream is not None:
52+ if self.showAll:
53+ self.colorizer.write("ERROR", 'red')
54+ self.stream.writeln()
55+ elif self.dots:
56+ stream.write('E')
57+
58 def startTest(self, test):
59 unittest.TestResult.startTest(self, test)
60 current_case = test.test.__class__.__name__
61
62=== modified file 'tests/unit/test_swift_store.py'
63--- tests/unit/test_swift_store.py 2011-03-09 21:59:56 +0000
64+++ tests/unit/test_swift_store.py 2011-03-16 16:53:27 +0000
65@@ -29,7 +29,9 @@
66
67 from glance.common import exception
68 from glance.store import BackendException
69-from glance.store.swift import SwiftBackend, format_swift_location
70+from glance.store.swift import (SwiftBackend,
71+ format_swift_location,
72+ parse_swift_tokens)
73
74 FIVE_KB = (5 * 1024)
75 SWIFT_OPTIONS = {'verbose': True,
76@@ -150,6 +152,41 @@
77 """Clear the test environment"""
78 self.stubs.UnsetAll()
79
80+ def test_parse_swift_tokens(self):
81+ """
82+ Test that the parse_swift_tokens function returns
83+ user, key, authurl, container, and objname properly
84+ """
85+ uri = "swift://user:key@localhost/v1.0/container/objname"
86+ url_pieces = urlparse.urlparse(uri)
87+ user, key, authurl, container, objname =\
88+ parse_swift_tokens(url_pieces)
89+ self.assertEqual("user", user)
90+ self.assertEqual("key", key)
91+ self.assertEqual("https://localhost/v1.0", authurl)
92+ self.assertEqual("container", container)
93+ self.assertEqual("objname", objname)
94+
95+ uri = "swift://user:key@localhost:9090/v1.0/container/objname"
96+ url_pieces = urlparse.urlparse(uri)
97+ user, key, authurl, container, objname =\
98+ parse_swift_tokens(url_pieces)
99+ self.assertEqual("user", user)
100+ self.assertEqual("key", key)
101+ self.assertEqual("https://localhost:9090/v1.0", authurl)
102+ self.assertEqual("container", container)
103+ self.assertEqual("objname", objname)
104+
105+ uri = "swift://account:user:key@localhost:9090/v1.0/container/objname"
106+ url_pieces = urlparse.urlparse(uri)
107+ user, key, authurl, container, objname =\
108+ parse_swift_tokens(url_pieces)
109+ self.assertEqual("account:user", user)
110+ self.assertEqual("key", key)
111+ self.assertEqual("https://localhost:9090/v1.0", authurl)
112+ self.assertEqual("container", container)
113+ self.assertEqual("objname", objname)
114+
115 def test_get(self):
116 """Test a "normal" retrieval of an image in chunks"""
117 url_pieces = urlparse.urlparse(

Subscribers

People subscribed via source and target branches