Skip to content

Commit

Permalink
Merge "Cleanup nits from container_update_timeout"
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins authored and openstack-gerrit committed Aug 6, 2015
2 parents 4e92d5e + cbcfb74 commit 67fcc37
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 59 deletions.
2 changes: 1 addition & 1 deletion doc/manpages/object-server.conf.5
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ Request timeout to external services. The default is 3 seconds.
.IP \fBconn_timeout\fR
Connection timeout to external services. The default is 0.5 seconds.
.IP \fBcontainer_update_timeout\fR
Request timeout to do a container update on an object update. The default is 1 second.
Time to wait while sending a container update on object update. The default is 1 second.
.RE
.PD

Expand Down
101 changes: 43 additions & 58 deletions test/unit/obj/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ def fake_spawn():
ensure that the method has completed.
"""

orig = object_server.spawn
greenlets = []

def _inner_fake_spawn(func, *a, **kw):
Expand All @@ -86,16 +85,12 @@ def _inner_fake_spawn(func, *a, **kw):
return gt

object_server.spawn = _inner_fake_spawn

try:
yield
finally:
for gt in greenlets:
try:
with mock.patch('swift.obj.server.spawn', _inner_fake_spawn):
try:
yield
finally:
for gt in greenlets:
gt.wait()
except: # noqa
pass # real spawn won't do anything but pollute logs
object_server.spawn = orig


@patch_policies(test_policies)
Expand All @@ -110,7 +105,8 @@ def setUp(self):
self.testdir = os.path.join(self.tmpdir,
'tmp_test_object_server_ObjectController')
mkdirs(os.path.join(self.testdir, 'sda1'))
self.conf = {'devices': self.testdir, 'mount_check': 'false'}
self.conf = {'devices': self.testdir, 'mount_check': 'false',
'container_update_timeout': 0.0}
self.object_controller = object_server.ObjectController(
self.conf, logger=debug_logger())
self.object_controller.bytes_per_sync = 1
Expand Down Expand Up @@ -1335,10 +1331,10 @@ def read(self, amt=None):
'X-Container-Timestamp': '1',
'Content-Type': 'application/new1',
'Content-Length': '0'})
with mock.patch.object(object_server, 'http_connect',
mock_http_connect(201)):
with fake_spawn():
resp = req.get_response(self.object_controller)
with fake_spawn(), mock.patch.object(
object_server, 'http_connect',
mock_http_connect(201)):
resp = req.get_response(self.object_controller)
self.assertEquals(resp.status_int, 201)
timestamp = normalize_timestamp(time())
req = Request.blank(
Expand All @@ -1351,10 +1347,10 @@ def read(self, amt=None):
'X-Container-Timestamp': '1',
'Content-Type': 'application/new1',
'Content-Length': '0'})
with mock.patch.object(object_server, 'http_connect',
mock_http_connect(500)):
with fake_spawn():
resp = req.get_response(self.object_controller)
with fake_spawn(), mock.patch.object(
object_server, 'http_connect',
mock_http_connect(500)):
resp = req.get_response(self.object_controller)
self.assertEquals(resp.status_int, 201)
timestamp = normalize_timestamp(time())
req = Request.blank(
Expand All @@ -1367,10 +1363,10 @@ def read(self, amt=None):
'X-Container-Timestamp': '1',
'Content-Type': 'application/new1',
'Content-Length': '0'})
with mock.patch.object(object_server, 'http_connect',
mock_http_connect(500, with_exc=True)):
with fake_spawn():
resp = req.get_response(self.object_controller)
with fake_spawn(), mock.patch.object(
object_server, 'http_connect',
mock_http_connect(500, with_exc=True)):
resp = req.get_response(self.object_controller)
self.assertEquals(resp.status_int, 201)

def test_PUT_ssync_multi_frag(self):
Expand Down Expand Up @@ -2510,10 +2506,9 @@ def capture_updates(ip, port, method, path, headers, *args, **kwargs):
'X-Container-Device': 'sda1',
'X-Container-Partition': 'p',
'Content-Type': 'text/plain'})
with mocked_http_conn(
with fake_spawn(), mocked_http_conn(
200, give_connect=capture_updates) as fake_conn:
with fake_spawn():
resp = req.get_response(self.object_controller)
resp = req.get_response(self.object_controller)
self.assertRaises(StopIteration, fake_conn.code_iter.next)
self.assertEqual(resp.status_int, 201)
self.assertEquals(1, len(container_updates))
Expand Down Expand Up @@ -2550,10 +2545,9 @@ def capture_updates(ip, port, method, path, headers, *args, **kwargs):
'X-Container-Device': 'sda1',
'X-Container-Partition': 'p',
'Content-Type': 'text/html'})
with mocked_http_conn(
with fake_spawn(), mocked_http_conn(
200, give_connect=capture_updates) as fake_conn:
with fake_spawn():
resp = req.get_response(self.object_controller)
resp = req.get_response(self.object_controller)
self.assertRaises(StopIteration, fake_conn.code_iter.next)
self.assertEqual(resp.status_int, 201)
self.assertEquals(1, len(container_updates))
Expand Down Expand Up @@ -2589,10 +2583,9 @@ def capture_updates(ip, port, method, path, headers, *args, **kwargs):
'X-Container-Device': 'sda1',
'X-Container-Partition': 'p',
'Content-Type': 'text/enriched'})
with mocked_http_conn(
with fake_spawn(), mocked_http_conn(
200, give_connect=capture_updates) as fake_conn:
with fake_spawn():
resp = req.get_response(self.object_controller)
resp = req.get_response(self.object_controller)
self.assertRaises(StopIteration, fake_conn.code_iter.next)
self.assertEqual(resp.status_int, 201)
self.assertEquals(1, len(container_updates))
Expand Down Expand Up @@ -2628,10 +2621,9 @@ def capture_updates(ip, port, method, path, headers, *args, **kwargs):
'X-Container-Host': '10.0.0.1:8080',
'X-Container-Device': 'sda1',
'X-Container-Partition': 'p'})
with mocked_http_conn(
with fake_spawn(), mocked_http_conn(
200, give_connect=capture_updates) as fake_conn:
with fake_spawn():
resp = req.get_response(self.object_controller)
resp = req.get_response(self.object_controller)
self.assertRaises(StopIteration, fake_conn.code_iter.next)
self.assertEqual(resp.status_int, 204)
self.assertEquals(1, len(container_updates))
Expand Down Expand Up @@ -2660,10 +2652,9 @@ def capture_updates(ip, port, method, path, headers, *args, **kwargs):
'X-Container-Host': '10.0.0.1:8080',
'X-Container-Device': 'sda1',
'X-Container-Partition': 'p'})
with mocked_http_conn(
with fake_spawn(), mocked_http_conn(
200, give_connect=capture_updates) as fake_conn:
with fake_spawn():
resp = req.get_response(self.object_controller)
resp = req.get_response(self.object_controller)
self.assertRaises(StopIteration, fake_conn.code_iter.next)
self.assertEqual(resp.status_int, 404)
self.assertEquals(1, len(container_updates))
Expand Down Expand Up @@ -3130,10 +3121,9 @@ def read(self):
'X-Delete-At-Partition': '6237',
'X-Delete-At-Device': 'sdp,sdq'})

with mock.patch.object(object_server, 'http_connect',
fake_http_connect):
with fake_spawn():
resp = req.get_response(self.object_controller)
with fake_spawn(), mock.patch.object(
object_server, 'http_connect', fake_http_connect):
resp = req.get_response(self.object_controller)

self.assertEqual(resp.status_int, 201)

Expand Down Expand Up @@ -3244,10 +3234,9 @@ def read(self):
'X-Container-Host': '1.2.3.4:5, 6.7.8.9:10',
'X-Container-Device': 'sdb1, sdf1'})

with mock.patch.object(object_server, 'http_connect',
fake_http_connect):
with fake_spawn():
req.get_response(self.object_controller)
with fake_spawn(), mock.patch.object(
object_server, 'http_connect', fake_http_connect):
req.get_response(self.object_controller)

http_connect_args.sort(key=operator.itemgetter('ipaddr'))

Expand Down Expand Up @@ -3322,10 +3311,9 @@ def capture_updates(ip, port, method, path, headers, *args, **kwargs):
headers['X-Object-Sysmeta-Ec-Frag-Index'] = '2'
req = Request.blank(
'/sda1/p/a/c/o', method='PUT', body='', headers=headers)
with mocked_http_conn(
with fake_spawn(), mocked_http_conn(
500, 500, give_connect=capture_updates) as fake_conn:
with fake_spawn():
resp = req.get_response(self.object_controller)
resp = req.get_response(self.object_controller)
self.assertRaises(StopIteration, fake_conn.code_iter.next)
self.assertEqual(resp.status_int, 201)
self.assertEquals(2, len(container_updates))
Expand Down Expand Up @@ -3559,10 +3547,9 @@ def capture_updates(ip, port, method, path, headers, *args, **kwargs):
'X-Container-Partition': 'cpartition',
'X-Container-Device': 'cdevice',
'Content-Type': 'text/plain'}, body='')
with mocked_http_conn(
with fake_spawn(), mocked_http_conn(
200, give_connect=capture_updates) as fake_conn:
with fake_spawn():
resp = req.get_response(self.object_controller)
resp = req.get_response(self.object_controller)
self.assertRaises(StopIteration, fake_conn.code_iter.next)
self.assertEqual(resp.status_int, 201)
self.assertEqual(len(container_updates), 1)
Expand Down Expand Up @@ -3601,10 +3588,9 @@ def capture_updates(ip, port, method, path, headers, *args, **kwargs):
}
req = Request.blank('/sda1/0/a/c/o', environ={'REQUEST_METHOD': 'PUT'},
headers=headers, body='')
with mocked_http_conn(
with fake_spawn(), mocked_http_conn(
200, give_connect=capture_updates) as fake_conn:
with fake_spawn():
resp = req.get_response(self.object_controller)
resp = req.get_response(self.object_controller)
self.assertRaises(StopIteration, fake_conn.code_iter.next)
self.assertEqual(resp.status_int, 201)
self.assertEqual(len(container_updates), 1)
Expand Down Expand Up @@ -3643,9 +3629,8 @@ def fake_pickle_async_update(*args):
given_args[:] = args
diskfile_mgr = self.object_controller._diskfile_router[policy]
diskfile_mgr.pickle_async_update = fake_pickle_async_update
with mocked_http_conn(500) as fake_conn:
with fake_spawn():
resp = req.get_response(self.object_controller)
with fake_spawn(), mocked_http_conn(500) as fake_conn:
resp = req.get_response(self.object_controller)
self.assertRaises(StopIteration, fake_conn.code_iter.next)
self.assertEqual(resp.status_int, 201)
self.assertEqual(len(given_args), 7)
Expand Down

0 comments on commit 67fcc37

Please sign in to comment.