Merge lp:~gholt/swift/autocreatebug into lp:~hudson-openstack/swift/trunk

Proposed by gholt
Status: Merged
Approved by: David Goetz
Approved revision: 309
Merged at revision: 309
Proposed branch: lp:~gholt/swift/autocreatebug
Merge into: lp:~hudson-openstack/swift/trunk
Diff against target: 105 lines (+65/-3)
2 files modified
swift/proxy/server.py (+35/-3)
test/unit/proxy/test_server.py (+30/-0)
To merge this branch: bzr merge lp:~gholt/swift/autocreatebug
Reviewer Review Type Date Requested Status
David Goetz (community) Approve
John Dickinson Approve
Review via email: mp+64274@code.launchpad.net

Description of the change

Fixed so account GETs, HEADs, and POSTs autocreate the account when account_autocreate = true

To post a comment you must log in.
Revision history for this message
John Dickinson (notmyname) wrote :

looks fine

review: Approve
Revision history for this message
David Goetz (david-goetz) wrote :

looks good

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'swift/proxy/server.py'
2--- swift/proxy/server.py 2011-06-10 16:56:53 +0000
3+++ swift/proxy/server.py 2011-06-11 05:00:29 +0000
4@@ -1319,8 +1319,26 @@
5 def GETorHEAD(self, req):
6 """Handler for HTTP GET/HEAD requests."""
7 partition, nodes = self.app.account_ring.get_nodes(self.account_name)
8- return self.GETorHEAD_base(req, _('Account'), partition, nodes,
9- req.path_info.rstrip('/'), self.app.account_ring.replica_count)
10+ resp = self.GETorHEAD_base(req, _('Account'), partition, nodes,
11+ req.path_info.rstrip('/'), self.app.account_ring.replica_count)
12+ if resp.status_int == 404 and self.app.account_autocreate:
13+ if len(self.account_name) > MAX_ACCOUNT_NAME_LENGTH:
14+ resp = HTTPBadRequest(request=req)
15+ resp.body = 'Account name length of %d longer than %d' % \
16+ (len(self.account_name), MAX_ACCOUNT_NAME_LENGTH)
17+ return resp
18+ headers = {'X-Timestamp': normalize_timestamp(time.time()),
19+ 'X-Trans-Id': self.trans_id}
20+ resp = self.make_requests(
21+ Request.blank('/v1/' + self.account_name),
22+ self.app.account_ring, partition, 'PUT',
23+ '/' + self.account_name, [headers] * len(nodes))
24+ if resp.status_int // 100 != 2:
25+ raise Exception('Could not autocreate account %r' %
26+ self.account_name)
27+ resp = self.GETorHEAD_base(req, _('Account'), partition, nodes,
28+ req.path_info.rstrip('/'), self.app.account_ring.replica_count)
29+ return resp
30
31 @public
32 def PUT(self, req):
33@@ -1360,9 +1378,23 @@
34 if value[0].lower().startswith('x-account-meta-'))
35 if self.app.memcache:
36 self.app.memcache.delete('account%s' % req.path_info.rstrip('/'))
37- return self.make_requests(req, self.app.account_ring,
38+ resp = self.make_requests(req, self.app.account_ring,
39 account_partition, 'POST', req.path_info,
40 [headers] * len(accounts))
41+ if resp.status_int == 404 and self.app.account_autocreate:
42+ if len(self.account_name) > MAX_ACCOUNT_NAME_LENGTH:
43+ resp = HTTPBadRequest(request=req)
44+ resp.body = 'Account name length of %d longer than %d' % \
45+ (len(self.account_name), MAX_ACCOUNT_NAME_LENGTH)
46+ return resp
47+ resp = self.make_requests(
48+ Request.blank('/v1/' + self.account_name),
49+ self.app.account_ring, account_partition, 'PUT',
50+ '/' + self.account_name, [headers] * len(accounts))
51+ if resp.status_int // 100 != 2:
52+ raise Exception('Could not autocreate account %r' %
53+ self.account_name)
54+ return resp
55
56 @public
57 def DELETE(self, req):
58
59=== modified file 'test/unit/proxy/test_server.py'
60--- test/unit/proxy/test_server.py 2011-06-10 16:56:53 +0000
61+++ test/unit/proxy/test_server.py 2011-06-11 05:00:29 +0000
62@@ -3171,6 +3171,16 @@
63 self.app.memcache = FakeMemcacheReturnsNone()
64 self.assert_status_map(controller.GET, (404, 404, 404), 404)
65
66+ def test_GET_autocreate(self):
67+ with save_globals():
68+ controller = proxy_server.AccountController(self.app, 'account')
69+ self.app.memcache = FakeMemcacheReturnsNone()
70+ self.assert_status_map(controller.GET,
71+ (404, 404, 404, 201, 201, 201, 204), 404)
72+ controller.app.account_autocreate = True
73+ self.assert_status_map(controller.GET,
74+ (404, 404, 404, 201, 201, 201, 204), 204)
75+
76 def test_HEAD(self):
77 with save_globals():
78 controller = proxy_server.AccountController(self.app, 'account')
79@@ -3189,6 +3199,26 @@
80 self.assert_status_map(controller.HEAD, (404, 503, 503), 503)
81 self.assert_status_map(controller.HEAD, (404, 204, 503), 204)
82
83+ def test_HEAD_autocreate(self):
84+ with save_globals():
85+ controller = proxy_server.AccountController(self.app, 'account')
86+ self.app.memcache = FakeMemcacheReturnsNone()
87+ self.assert_status_map(controller.HEAD,
88+ (404, 404, 404, 201, 201, 201, 204), 404)
89+ controller.app.account_autocreate = True
90+ self.assert_status_map(controller.HEAD,
91+ (404, 404, 404, 201, 201, 201, 204), 204)
92+
93+ def test_POST_autocreate(self):
94+ with save_globals():
95+ controller = proxy_server.AccountController(self.app, 'account')
96+ self.app.memcache = FakeMemcacheReturnsNone()
97+ self.assert_status_map(controller.POST,
98+ (404, 404, 404, 201, 201, 201), 404)
99+ controller.app.account_autocreate = True
100+ self.assert_status_map(controller.POST,
101+ (404, 404, 404, 201, 201, 201), 201)
102+
103 def test_connection_refused(self):
104 self.app.account_ring.get_nodes('account')
105 for dev in self.app.account_ring.devs.values():