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,10 +1331,10 @@ 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(
mock_http_connect(201)): object_server, 'http_connect',
with fake_spawn(): mock_http_connect(201)):
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())
req = Request.blank( req = Request.blank(
@ -1351,10 +1347,10 @@ 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(
mock_http_connect(500)): object_server, 'http_connect',
with fake_spawn(): mock_http_connect(500)):
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())
req = Request.blank( req = Request.blank(
@ -1367,10 +1363,10 @@ 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(
mock_http_connect(500, with_exc=True)): object_server, 'http_connect',
with fake_spawn(): mock_http_connect(500, with_exc=True)):
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)
def test_PUT_ssync_multi_frag(self): def test_PUT_ssync_multi_frag(self):
@ -2510,10 +2506,9 @@ 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)
self.assertEquals(1, len(container_updates)) self.assertEquals(1, len(container_updates))
@ -2550,10 +2545,9 @@ 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)
self.assertEquals(1, len(container_updates)) self.assertEquals(1, len(container_updates))
@ -2589,10 +2583,9 @@ 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)
self.assertEquals(1, len(container_updates)) self.assertEquals(1, len(container_updates))
@ -2628,10 +2621,9 @@ 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)
self.assertEquals(1, len(container_updates)) self.assertEquals(1, len(container_updates))
@ -2660,10 +2652,9 @@ 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)
self.assertEquals(1, len(container_updates)) self.assertEquals(1, len(container_updates))
@ -3130,10 +3121,9 @@ 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,10 +3234,9 @@ 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,10 +3311,9 @@ 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)
self.assertEquals(2, len(container_updates)) self.assertEquals(2, len(container_updates))
@ -3559,10 +3547,9 @@ 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)
self.assertEqual(len(container_updates), 1) self.assertEqual(len(container_updates), 1)
@ -3601,10 +3588,9 @@ 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)
self.assertEqual(len(container_updates), 1) self.assertEqual(len(container_updates), 1)
@ -3643,9 +3629,8 @@ 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)
self.assertEqual(len(given_args), 7) self.assertEqual(len(given_args), 7)