From cbcfb74132aba4d5834dc9cf33dc4f664b82d39a Mon Sep 17 00:00:00 2001 From: Clay Gerrard Date: Wed, 22 Jul 2015 19:32:46 -0700 Subject: [PATCH] Cleanup nits from container_update_timeout Change-Id: Ib17fc9a027db267350abc5a7db4e3172dfff7913 --- doc/manpages/object-server.conf.5 | 2 +- test/unit/obj/test_server.py | 101 +++++++++++++----------------- 2 files changed, 44 insertions(+), 59 deletions(-) diff --git a/doc/manpages/object-server.conf.5 b/doc/manpages/object-server.conf.5 index 518e72586e..e82a56ffb5 100644 --- a/doc/manpages/object-server.conf.5 +++ b/doc/manpages/object-server.conf.5 @@ -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 diff --git a/test/unit/obj/test_server.py b/test/unit/obj/test_server.py index 1e7a303ea4..8eec9adac6 100755 --- a/test/unit/obj/test_server.py +++ b/test/unit/obj/test_server.py @@ -76,7 +76,6 @@ def fake_spawn(): ensure that the method has completed. """ - orig = object_server.spawn greenlets = [] def _inner_fake_spawn(func, *a, **kw): @@ -85,16 +84,12 @@ def fake_spawn(): 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) @@ -109,7 +104,8 @@ class TestObjectController(unittest.TestCase): 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 @@ -1259,10 +1255,10 @@ class TestObjectController(unittest.TestCase): '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( @@ -1275,10 +1271,10 @@ class TestObjectController(unittest.TestCase): '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( @@ -1291,10 +1287,10 @@ class TestObjectController(unittest.TestCase): '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): @@ -2436,10 +2432,9 @@ class TestObjectController(unittest.TestCase): '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)) @@ -2476,10 +2471,9 @@ class TestObjectController(unittest.TestCase): '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)) @@ -2515,10 +2509,9 @@ class TestObjectController(unittest.TestCase): '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)) @@ -2554,10 +2547,9 @@ class TestObjectController(unittest.TestCase): '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)) @@ -2586,10 +2578,9 @@ class TestObjectController(unittest.TestCase): '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)) @@ -3056,10 +3047,9 @@ class TestObjectController(unittest.TestCase): '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) @@ -3170,10 +3160,9 @@ class TestObjectController(unittest.TestCase): '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')) @@ -3248,10 +3237,9 @@ class TestObjectController(unittest.TestCase): 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)) @@ -3485,10 +3473,9 @@ class TestObjectController(unittest.TestCase): '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) @@ -3527,10 +3514,9 @@ class TestObjectController(unittest.TestCase): } 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) @@ -3569,9 +3555,8 @@ class TestObjectController(unittest.TestCase): 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)