Merge "Cleanup nits from container_update_timeout"

This commit is contained in:
Jenkins 2015-08-06 00:27:14 +00:00 committed by Gerrit Code Review
commit 67fcc37b73
2 changed files with 44 additions and 59 deletions

View File

@ -130,7 +130,7 @@ Request timeout to external services. The default is 3 seconds.
.IP \fBconn_timeout\fR .IP \fBconn_timeout\fR
Connection timeout to external services. The default is 0.5 seconds. Connection timeout to external services. The default is 0.5 seconds.
.IP \fBcontainer_update_timeout\fR .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 .RE
.PD .PD

View File

@ -77,7 +77,6 @@ def fake_spawn():
ensure that the method has completed. ensure that the method has completed.
""" """
orig = object_server.spawn
greenlets = [] greenlets = []
def _inner_fake_spawn(func, *a, **kw): def _inner_fake_spawn(func, *a, **kw):
@ -86,16 +85,12 @@ def fake_spawn():
return gt return gt
object_server.spawn = _inner_fake_spawn object_server.spawn = _inner_fake_spawn
with mock.patch('swift.obj.server.spawn', _inner_fake_spawn):
try: try:
yield yield
finally: finally:
for gt in greenlets: for gt in greenlets:
try:
gt.wait() gt.wait()
except: # noqa
pass # real spawn won't do anything but pollute logs
object_server.spawn = orig
@patch_policies(test_policies) @patch_policies(test_policies)
@ -110,7 +105,8 @@ class TestObjectController(unittest.TestCase):
self.testdir = os.path.join(self.tmpdir, self.testdir = os.path.join(self.tmpdir,
'tmp_test_object_server_ObjectController') 'tmp_test_object_server_ObjectController')
mkdirs(os.path.join(self.testdir, 'sda1')) 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.object_controller = object_server.ObjectController(
self.conf, logger=debug_logger()) self.conf, logger=debug_logger())
self.object_controller.bytes_per_sync = 1 self.object_controller.bytes_per_sync = 1
@ -1335,9 +1331,9 @@ class TestObjectController(unittest.TestCase):
'X-Container-Timestamp': '1', 'X-Container-Timestamp': '1',
'Content-Type': 'application/new1', 'Content-Type': 'application/new1',
'Content-Length': '0'}) 'Content-Length': '0'})
with mock.patch.object(object_server, 'http_connect', with fake_spawn(), mock.patch.object(
object_server, 'http_connect',
mock_http_connect(201)): mock_http_connect(201)):
with fake_spawn():
resp = req.get_response(self.object_controller) resp = req.get_response(self.object_controller)
self.assertEquals(resp.status_int, 201) self.assertEquals(resp.status_int, 201)
timestamp = normalize_timestamp(time()) timestamp = normalize_timestamp(time())
@ -1351,9 +1347,9 @@ class TestObjectController(unittest.TestCase):
'X-Container-Timestamp': '1', 'X-Container-Timestamp': '1',
'Content-Type': 'application/new1', 'Content-Type': 'application/new1',
'Content-Length': '0'}) 'Content-Length': '0'})
with mock.patch.object(object_server, 'http_connect', with fake_spawn(), mock.patch.object(
object_server, 'http_connect',
mock_http_connect(500)): mock_http_connect(500)):
with fake_spawn():
resp = req.get_response(self.object_controller) resp = req.get_response(self.object_controller)
self.assertEquals(resp.status_int, 201) self.assertEquals(resp.status_int, 201)
timestamp = normalize_timestamp(time()) timestamp = normalize_timestamp(time())
@ -1367,9 +1363,9 @@ class TestObjectController(unittest.TestCase):
'X-Container-Timestamp': '1', 'X-Container-Timestamp': '1',
'Content-Type': 'application/new1', 'Content-Type': 'application/new1',
'Content-Length': '0'}) 'Content-Length': '0'})
with mock.patch.object(object_server, 'http_connect', with fake_spawn(), mock.patch.object(
object_server, 'http_connect',
mock_http_connect(500, with_exc=True)): mock_http_connect(500, with_exc=True)):
with fake_spawn():
resp = req.get_response(self.object_controller) resp = req.get_response(self.object_controller)
self.assertEquals(resp.status_int, 201) self.assertEquals(resp.status_int, 201)
@ -2510,9 +2506,8 @@ class TestObjectController(unittest.TestCase):
'X-Container-Device': 'sda1', 'X-Container-Device': 'sda1',
'X-Container-Partition': 'p', 'X-Container-Partition': 'p',
'Content-Type': 'text/plain'}) 'Content-Type': 'text/plain'})
with mocked_http_conn( with fake_spawn(), mocked_http_conn(
200, give_connect=capture_updates) as fake_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.assertRaises(StopIteration, fake_conn.code_iter.next)
self.assertEqual(resp.status_int, 201) self.assertEqual(resp.status_int, 201)
@ -2550,9 +2545,8 @@ class TestObjectController(unittest.TestCase):
'X-Container-Device': 'sda1', 'X-Container-Device': 'sda1',
'X-Container-Partition': 'p', 'X-Container-Partition': 'p',
'Content-Type': 'text/html'}) 'Content-Type': 'text/html'})
with mocked_http_conn( with fake_spawn(), mocked_http_conn(
200, give_connect=capture_updates) as fake_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.assertRaises(StopIteration, fake_conn.code_iter.next)
self.assertEqual(resp.status_int, 201) self.assertEqual(resp.status_int, 201)
@ -2589,9 +2583,8 @@ class TestObjectController(unittest.TestCase):
'X-Container-Device': 'sda1', 'X-Container-Device': 'sda1',
'X-Container-Partition': 'p', 'X-Container-Partition': 'p',
'Content-Type': 'text/enriched'}) 'Content-Type': 'text/enriched'})
with mocked_http_conn( with fake_spawn(), mocked_http_conn(
200, give_connect=capture_updates) as fake_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.assertRaises(StopIteration, fake_conn.code_iter.next)
self.assertEqual(resp.status_int, 201) self.assertEqual(resp.status_int, 201)
@ -2628,9 +2621,8 @@ class TestObjectController(unittest.TestCase):
'X-Container-Host': '10.0.0.1:8080', 'X-Container-Host': '10.0.0.1:8080',
'X-Container-Device': 'sda1', 'X-Container-Device': 'sda1',
'X-Container-Partition': 'p'}) 'X-Container-Partition': 'p'})
with mocked_http_conn( with fake_spawn(), mocked_http_conn(
200, give_connect=capture_updates) as fake_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.assertRaises(StopIteration, fake_conn.code_iter.next)
self.assertEqual(resp.status_int, 204) self.assertEqual(resp.status_int, 204)
@ -2660,9 +2652,8 @@ class TestObjectController(unittest.TestCase):
'X-Container-Host': '10.0.0.1:8080', 'X-Container-Host': '10.0.0.1:8080',
'X-Container-Device': 'sda1', 'X-Container-Device': 'sda1',
'X-Container-Partition': 'p'}) 'X-Container-Partition': 'p'})
with mocked_http_conn( with fake_spawn(), mocked_http_conn(
200, give_connect=capture_updates) as fake_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.assertRaises(StopIteration, fake_conn.code_iter.next)
self.assertEqual(resp.status_int, 404) self.assertEqual(resp.status_int, 404)
@ -3130,9 +3121,8 @@ class TestObjectController(unittest.TestCase):
'X-Delete-At-Partition': '6237', 'X-Delete-At-Partition': '6237',
'X-Delete-At-Device': 'sdp,sdq'}) 'X-Delete-At-Device': 'sdp,sdq'})
with mock.patch.object(object_server, 'http_connect', with fake_spawn(), mock.patch.object(
fake_http_connect): object_server, 'http_connect', fake_http_connect):
with fake_spawn():
resp = req.get_response(self.object_controller) resp = req.get_response(self.object_controller)
self.assertEqual(resp.status_int, 201) self.assertEqual(resp.status_int, 201)
@ -3244,9 +3234,8 @@ class TestObjectController(unittest.TestCase):
'X-Container-Host': '1.2.3.4:5, 6.7.8.9:10', 'X-Container-Host': '1.2.3.4:5, 6.7.8.9:10',
'X-Container-Device': 'sdb1, sdf1'}) 'X-Container-Device': 'sdb1, sdf1'})
with mock.patch.object(object_server, 'http_connect', with fake_spawn(), mock.patch.object(
fake_http_connect): object_server, 'http_connect', fake_http_connect):
with fake_spawn():
req.get_response(self.object_controller) req.get_response(self.object_controller)
http_connect_args.sort(key=operator.itemgetter('ipaddr')) http_connect_args.sort(key=operator.itemgetter('ipaddr'))
@ -3322,9 +3311,8 @@ class TestObjectController(unittest.TestCase):
headers['X-Object-Sysmeta-Ec-Frag-Index'] = '2' headers['X-Object-Sysmeta-Ec-Frag-Index'] = '2'
req = Request.blank( req = Request.blank(
'/sda1/p/a/c/o', method='PUT', body='', headers=headers) '/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: 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.assertRaises(StopIteration, fake_conn.code_iter.next)
self.assertEqual(resp.status_int, 201) self.assertEqual(resp.status_int, 201)
@ -3559,9 +3547,8 @@ class TestObjectController(unittest.TestCase):
'X-Container-Partition': 'cpartition', 'X-Container-Partition': 'cpartition',
'X-Container-Device': 'cdevice', 'X-Container-Device': 'cdevice',
'Content-Type': 'text/plain'}, body='') 'Content-Type': 'text/plain'}, body='')
with mocked_http_conn( with fake_spawn(), mocked_http_conn(
200, give_connect=capture_updates) as fake_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.assertRaises(StopIteration, fake_conn.code_iter.next)
self.assertEqual(resp.status_int, 201) self.assertEqual(resp.status_int, 201)
@ -3601,9 +3588,8 @@ class TestObjectController(unittest.TestCase):
} }
req = Request.blank('/sda1/0/a/c/o', environ={'REQUEST_METHOD': 'PUT'}, req = Request.blank('/sda1/0/a/c/o', environ={'REQUEST_METHOD': 'PUT'},
headers=headers, body='') headers=headers, body='')
with mocked_http_conn( with fake_spawn(), mocked_http_conn(
200, give_connect=capture_updates) as fake_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.assertRaises(StopIteration, fake_conn.code_iter.next)
self.assertEqual(resp.status_int, 201) self.assertEqual(resp.status_int, 201)
@ -3643,8 +3629,7 @@ class TestObjectController(unittest.TestCase):
given_args[:] = args given_args[:] = args
diskfile_mgr = self.object_controller._diskfile_router[policy] diskfile_mgr = self.object_controller._diskfile_router[policy]
diskfile_mgr.pickle_async_update = fake_pickle_async_update diskfile_mgr.pickle_async_update = fake_pickle_async_update
with mocked_http_conn(500) as fake_conn: with fake_spawn(), mocked_http_conn(500) 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.assertRaises(StopIteration, fake_conn.code_iter.next)
self.assertEqual(resp.status_int, 201) self.assertEqual(resp.status_int, 201)