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
=== modified file 'swift/proxy/server.py'
--- swift/proxy/server.py 2011-06-10 16:56:53 +0000
+++ swift/proxy/server.py 2011-06-11 05:00:29 +0000
@@ -1319,8 +1319,26 @@
1319 def GETorHEAD(self, req):1319 def GETorHEAD(self, req):
1320 """Handler for HTTP GET/HEAD requests."""1320 """Handler for HTTP GET/HEAD requests."""
1321 partition, nodes = self.app.account_ring.get_nodes(self.account_name)1321 partition, nodes = self.app.account_ring.get_nodes(self.account_name)
1322 return self.GETorHEAD_base(req, _('Account'), partition, nodes,1322 resp = self.GETorHEAD_base(req, _('Account'), partition, nodes,
1323 req.path_info.rstrip('/'), self.app.account_ring.replica_count)1323 req.path_info.rstrip('/'), self.app.account_ring.replica_count)
1324 if resp.status_int == 404 and self.app.account_autocreate:
1325 if len(self.account_name) > MAX_ACCOUNT_NAME_LENGTH:
1326 resp = HTTPBadRequest(request=req)
1327 resp.body = 'Account name length of %d longer than %d' % \
1328 (len(self.account_name), MAX_ACCOUNT_NAME_LENGTH)
1329 return resp
1330 headers = {'X-Timestamp': normalize_timestamp(time.time()),
1331 'X-Trans-Id': self.trans_id}
1332 resp = self.make_requests(
1333 Request.blank('/v1/' + self.account_name),
1334 self.app.account_ring, partition, 'PUT',
1335 '/' + self.account_name, [headers] * len(nodes))
1336 if resp.status_int // 100 != 2:
1337 raise Exception('Could not autocreate account %r' %
1338 self.account_name)
1339 resp = self.GETorHEAD_base(req, _('Account'), partition, nodes,
1340 req.path_info.rstrip('/'), self.app.account_ring.replica_count)
1341 return resp
13241342
1325 @public1343 @public
1326 def PUT(self, req):1344 def PUT(self, req):
@@ -1360,9 +1378,23 @@
1360 if value[0].lower().startswith('x-account-meta-'))1378 if value[0].lower().startswith('x-account-meta-'))
1361 if self.app.memcache:1379 if self.app.memcache:
1362 self.app.memcache.delete('account%s' % req.path_info.rstrip('/'))1380 self.app.memcache.delete('account%s' % req.path_info.rstrip('/'))
1363 return self.make_requests(req, self.app.account_ring,1381 resp = self.make_requests(req, self.app.account_ring,
1364 account_partition, 'POST', req.path_info,1382 account_partition, 'POST', req.path_info,
1365 [headers] * len(accounts))1383 [headers] * len(accounts))
1384 if resp.status_int == 404 and self.app.account_autocreate:
1385 if len(self.account_name) > MAX_ACCOUNT_NAME_LENGTH:
1386 resp = HTTPBadRequest(request=req)
1387 resp.body = 'Account name length of %d longer than %d' % \
1388 (len(self.account_name), MAX_ACCOUNT_NAME_LENGTH)
1389 return resp
1390 resp = self.make_requests(
1391 Request.blank('/v1/' + self.account_name),
1392 self.app.account_ring, account_partition, 'PUT',
1393 '/' + self.account_name, [headers] * len(accounts))
1394 if resp.status_int // 100 != 2:
1395 raise Exception('Could not autocreate account %r' %
1396 self.account_name)
1397 return resp
13661398
1367 @public1399 @public
1368 def DELETE(self, req):1400 def DELETE(self, req):
13691401
=== modified file 'test/unit/proxy/test_server.py'
--- test/unit/proxy/test_server.py 2011-06-10 16:56:53 +0000
+++ test/unit/proxy/test_server.py 2011-06-11 05:00:29 +0000
@@ -3171,6 +3171,16 @@
3171 self.app.memcache = FakeMemcacheReturnsNone()3171 self.app.memcache = FakeMemcacheReturnsNone()
3172 self.assert_status_map(controller.GET, (404, 404, 404), 404)3172 self.assert_status_map(controller.GET, (404, 404, 404), 404)
31733173
3174 def test_GET_autocreate(self):
3175 with save_globals():
3176 controller = proxy_server.AccountController(self.app, 'account')
3177 self.app.memcache = FakeMemcacheReturnsNone()
3178 self.assert_status_map(controller.GET,
3179 (404, 404, 404, 201, 201, 201, 204), 404)
3180 controller.app.account_autocreate = True
3181 self.assert_status_map(controller.GET,
3182 (404, 404, 404, 201, 201, 201, 204), 204)
3183
3174 def test_HEAD(self):3184 def test_HEAD(self):
3175 with save_globals():3185 with save_globals():
3176 controller = proxy_server.AccountController(self.app, 'account')3186 controller = proxy_server.AccountController(self.app, 'account')
@@ -3189,6 +3199,26 @@
3189 self.assert_status_map(controller.HEAD, (404, 503, 503), 503)3199 self.assert_status_map(controller.HEAD, (404, 503, 503), 503)
3190 self.assert_status_map(controller.HEAD, (404, 204, 503), 204)3200 self.assert_status_map(controller.HEAD, (404, 204, 503), 204)
31913201
3202 def test_HEAD_autocreate(self):
3203 with save_globals():
3204 controller = proxy_server.AccountController(self.app, 'account')
3205 self.app.memcache = FakeMemcacheReturnsNone()
3206 self.assert_status_map(controller.HEAD,
3207 (404, 404, 404, 201, 201, 201, 204), 404)
3208 controller.app.account_autocreate = True
3209 self.assert_status_map(controller.HEAD,
3210 (404, 404, 404, 201, 201, 201, 204), 204)
3211
3212 def test_POST_autocreate(self):
3213 with save_globals():
3214 controller = proxy_server.AccountController(self.app, 'account')
3215 self.app.memcache = FakeMemcacheReturnsNone()
3216 self.assert_status_map(controller.POST,
3217 (404, 404, 404, 201, 201, 201), 404)
3218 controller.app.account_autocreate = True
3219 self.assert_status_map(controller.POST,
3220 (404, 404, 404, 201, 201, 201), 201)
3221
3192 def test_connection_refused(self):3222 def test_connection_refused(self):
3193 self.app.account_ring.get_nodes('account')3223 self.app.account_ring.get_nodes('account')
3194 for dev in self.app.account_ring.devs.values():3224 for dev in self.app.account_ring.devs.values():