From 2693a197ea37490a891c54bbb279937a7b4e897c Mon Sep 17 00:00:00 2001 From: Peter Amstutz Date: Tue, 22 Nov 2022 16:12:20 -0500 Subject: [PATCH] 18842: Use tempdir for cache directory in tests Arvados-DCO-1.1-Signed-off-by: Peter Amstutz --- sdk/python/tests/arvados_testutil.py | 12 +++ sdk/python/tests/test_keep_client.py | 150 ++++++++++++++++++--------- 2 files changed, 111 insertions(+), 51 deletions(-) diff --git a/sdk/python/tests/arvados_testutil.py b/sdk/python/tests/arvados_testutil.py index 3772761b88..0035659796 100644 --- a/sdk/python/tests/arvados_testutil.py +++ b/sdk/python/tests/arvados_testutil.py @@ -295,3 +295,15 @@ def make_block_cache(disk_cache): shutil.rmtree(disk_cache_dir, ignore_errors=True) block_cache = arvados.keep.KeepBlockCache(disk_cache=disk_cache) return block_cache + + +class DiskCacheBase: + def make_block_cache(self, disk_cache): + self.disk_cache_dir = tempfile.mkdtemp() if disk_cache else None + block_cache = arvados.keep.KeepBlockCache(disk_cache=disk_cache, + disk_cache_dir=self.disk_cache_dir) + return block_cache + + def tearDown(self): + if self.disk_cache_dir: + shutil.rmtree(self.disk_cache_dir) diff --git a/sdk/python/tests/test_keep_client.py b/sdk/python/tests/test_keep_client.py index 126116393d..7a227f122f 100644 --- a/sdk/python/tests/test_keep_client.py +++ b/sdk/python/tests/test_keep_client.py @@ -31,22 +31,29 @@ from . import arvados_testutil as tutil from . import keepstub from . import run_test_server -from .arvados_testutil import make_block_cache +from .arvados_testutil import DiskCacheBase @parameterized.parameterized_class([{"disk_cache": True}, {"disk_cache": False}]) -class KeepTestCase(run_test_server.TestCaseWithServers): +class KeepTestCase(run_test_server.TestCaseWithServers, DiskCacheBase): disk_cache = False MAIN_SERVER = {} KEEP_SERVER = {} + block_cache_test = None @classmethod def setUpClass(cls): super(KeepTestCase, cls).setUpClass() run_test_server.authorize_with("admin") cls.api_client = arvados.api('v1') + cls.block_cache_test = DiskCacheBase() cls.keep_client = arvados.KeepClient(api_client=cls.api_client, proxy='', local_store='', - block_cache=make_block_cache(cls.disk_cache)) + block_cache=cls.block_cache_test.make_block_cache(cls.disk_cache)) + + @classmethod + def tearDownClass(cls): + super(KeepTestCase, cls).setUpClass() + cls.block_cache_test.tearDown() def test_KeepBasicRWTest(self): self.assertEqual(0, self.keep_client.upload_counter.get()) @@ -137,14 +144,17 @@ class KeepTestCase(run_test_server.TestCaseWithServers): 'wrong content from Keep.get for "test_head"') @parameterized.parameterized_class([{"disk_cache": True}, {"disk_cache": False}]) -class KeepPermissionTestCase(run_test_server.TestCaseWithServers): +class KeepPermissionTestCase(run_test_server.TestCaseWithServers, DiskCacheBase): disk_cache = False MAIN_SERVER = {} KEEP_SERVER = {'blob_signing': True} + def tearDown(self): + DiskCacheBase.tearDown(self) + def test_KeepBasicRWTest(self): run_test_server.authorize_with('active') - keep_client = arvados.KeepClient(block_cache=make_block_cache(self.disk_cache)) + keep_client = arvados.KeepClient(block_cache=self.make_block_cache(self.disk_cache)) foo_locator = keep_client.put('foo') self.assertRegex( foo_locator, @@ -182,7 +192,7 @@ class KeepPermissionTestCase(run_test_server.TestCaseWithServers): unsigned_bar_locator) @parameterized.parameterized_class([{"disk_cache": True}, {"disk_cache": False}]) -class KeepProxyTestCase(run_test_server.TestCaseWithServers): +class KeepProxyTestCase(run_test_server.TestCaseWithServers, DiskCacheBase): disk_cache = False MAIN_SERVER = {} KEEP_SERVER = {} @@ -196,12 +206,13 @@ class KeepProxyTestCase(run_test_server.TestCaseWithServers): def tearDown(self): super(KeepProxyTestCase, self).tearDown() + DiskCacheBase.tearDown(self) def test_KeepProxyTest1(self): # Will use ARVADOS_KEEP_SERVICES environment variable that # is set by setUpClass(). keep_client = arvados.KeepClient(api_client=self.api_client, - local_store='', block_cache=make_block_cache(self.disk_cache)) + local_store='', block_cache=self.make_block_cache(self.disk_cache)) baz_locator = keep_client.put('baz') self.assertRegex( baz_locator, @@ -218,7 +229,7 @@ class KeepProxyTestCase(run_test_server.TestCaseWithServers): arvados.config.settings()['ARVADOS_KEEP_SERVICES'] = 'http://10.0.0.1 https://foo.example.org:1234/' keep_client = arvados.KeepClient(api_client=self.api_client, local_store='', - block_cache=make_block_cache(self.disk_cache)) + block_cache=self.make_block_cache(self.disk_cache)) uris = [x['_service_root'] for x in keep_client._keep_services] self.assertEqual(uris, ['http://10.0.0.1/', 'https://foo.example.org:1234/']) @@ -228,14 +239,17 @@ class KeepProxyTestCase(run_test_server.TestCaseWithServers): with self.assertRaises(arvados.errors.ArgumentError): keep_client = arvados.KeepClient(api_client=self.api_client, local_store='', - block_cache=make_block_cache(self.disk_cache)) + block_cache=self.make_block_cache(self.disk_cache)) @parameterized.parameterized_class([{"disk_cache": True}, {"disk_cache": False}]) -class KeepClientServiceTestCase(unittest.TestCase, tutil.ApiClientMock): +class KeepClientServiceTestCase(unittest.TestCase, tutil.ApiClientMock, DiskCacheBase): disk_cache = False + def tearDown(self): + DiskCacheBase.tearDown(self) + def get_service_roots(self, api_client): - keep_client = arvados.KeepClient(api_client=api_client, block_cache=make_block_cache(self.disk_cache)) + keep_client = arvados.KeepClient(api_client=api_client, block_cache=self.make_block_cache(self.disk_cache)) services = keep_client.weighted_service_roots(arvados.KeepLocator('0'*32)) return [urllib.parse.urlparse(url) for url in sorted(services)] @@ -255,7 +269,7 @@ class KeepClientServiceTestCase(unittest.TestCase, tutil.ApiClientMock): def test_recognize_proxy_services_in_controller_response(self): keep_client = arvados.KeepClient(api_client=self.mock_keep_services( service_type='proxy', service_host='localhost', service_port=9, count=1), - block_cache=make_block_cache(self.disk_cache)) + block_cache=self.make_block_cache(self.disk_cache)) try: # this will fail, but it ensures we get the service # discovery response @@ -270,7 +284,7 @@ class KeepClientServiceTestCase(unittest.TestCase, tutil.ApiClientMock): api_client.insecure = True with tutil.mock_keep_responses(b'foo', 200) as mock: - keep_client = arvados.KeepClient(api_client=api_client, block_cache=make_block_cache(self.disk_cache)) + keep_client = arvados.KeepClient(api_client=api_client, block_cache=self.make_block_cache(self.disk_cache)) keep_client.get('acbd18db4cc2f85cedef654fccc4a4d8+3') self.assertEqual( mock.responses[0].getopt(pycurl.SSL_VERIFYPEER), @@ -281,7 +295,7 @@ class KeepClientServiceTestCase(unittest.TestCase, tutil.ApiClientMock): api_client.insecure = False with tutil.mock_keep_responses(b'foo', 200) as mock: - keep_client = arvados.KeepClient(api_client=api_client, block_cache=make_block_cache(self.disk_cache)) + keep_client = arvados.KeepClient(api_client=api_client, block_cache=self.make_block_cache(self.disk_cache)) keep_client.get('acbd18db4cc2f85cedef654fccc4a4d8+3') # getopt()==None here means we didn't change the # default. If we were using real pycurl instead of a mock, @@ -302,7 +316,7 @@ class KeepClientServiceTestCase(unittest.TestCase, tutil.ApiClientMock): headers = {'X-Keep-Locator':local_loc} with tutil.mock_keep_responses('', 200, **headers): # Check that the translated locator gets returned - keep_client = arvados.KeepClient(api_client=api_client, block_cache=make_block_cache(self.disk_cache)) + keep_client = arvados.KeepClient(api_client=api_client, block_cache=self.make_block_cache(self.disk_cache)) self.assertEqual(local_loc, keep_client.refresh_signature(remote_loc)) # Check that refresh_signature() uses the correct method and headers keep_client._get_or_head = mock.MagicMock() @@ -321,7 +335,7 @@ class KeepClientServiceTestCase(unittest.TestCase, tutil.ApiClientMock): api_client = self.mock_keep_services(count=1) force_timeout = socket.timeout("timed out") with tutil.mock_keep_responses(force_timeout, 0) as mock: - keep_client = arvados.KeepClient(api_client=api_client, block_cache=make_block_cache(self.disk_cache)) + keep_client = arvados.KeepClient(api_client=api_client, block_cache=self.make_block_cache(self.disk_cache)) with self.assertRaises(arvados.errors.KeepReadError): keep_client.get('ffffffffffffffffffffffffffffffff') self.assertEqual( @@ -338,7 +352,7 @@ class KeepClientServiceTestCase(unittest.TestCase, tutil.ApiClientMock): api_client = self.mock_keep_services(count=1) force_timeout = socket.timeout("timed out") with tutil.mock_keep_responses(force_timeout, 0) as mock: - keep_client = arvados.KeepClient(api_client=api_client, block_cache=make_block_cache(self.disk_cache)) + keep_client = arvados.KeepClient(api_client=api_client, block_cache=self.make_block_cache(self.disk_cache)) with self.assertRaises(arvados.errors.KeepWriteError): keep_client.put(b'foo') self.assertEqual( @@ -355,7 +369,7 @@ class KeepClientServiceTestCase(unittest.TestCase, tutil.ApiClientMock): api_client = self.mock_keep_services(count=1) force_timeout = socket.timeout("timed out") with tutil.mock_keep_responses(force_timeout, 0) as mock: - keep_client = arvados.KeepClient(api_client=api_client, block_cache=make_block_cache(self.disk_cache)) + keep_client = arvados.KeepClient(api_client=api_client, block_cache=self.make_block_cache(self.disk_cache)) with self.assertRaises(arvados.errors.KeepReadError): keep_client.head('ffffffffffffffffffffffffffffffff') self.assertEqual( @@ -372,7 +386,7 @@ class KeepClientServiceTestCase(unittest.TestCase, tutil.ApiClientMock): api_client = self.mock_keep_services(service_type='proxy', count=1) force_timeout = socket.timeout("timed out") with tutil.mock_keep_responses(force_timeout, 0) as mock: - keep_client = arvados.KeepClient(api_client=api_client, block_cache=make_block_cache(self.disk_cache)) + keep_client = arvados.KeepClient(api_client=api_client, block_cache=self.make_block_cache(self.disk_cache)) with self.assertRaises(arvados.errors.KeepReadError): keep_client.get('ffffffffffffffffffffffffffffffff') self.assertEqual( @@ -389,7 +403,7 @@ class KeepClientServiceTestCase(unittest.TestCase, tutil.ApiClientMock): api_client = self.mock_keep_services(service_type='proxy', count=1) force_timeout = socket.timeout("timed out") with tutil.mock_keep_responses(force_timeout, 0) as mock: - keep_client = arvados.KeepClient(api_client=api_client, block_cache=make_block_cache(self.disk_cache)) + keep_client = arvados.KeepClient(api_client=api_client, block_cache=self.make_block_cache(self.disk_cache)) with self.assertRaises(arvados.errors.KeepReadError): keep_client.head('ffffffffffffffffffffffffffffffff') self.assertEqual( @@ -403,6 +417,7 @@ class KeepClientServiceTestCase(unittest.TestCase, tutil.ApiClientMock): None) def test_proxy_put_timeout(self): + self.disk_cache_dir = None api_client = self.mock_keep_services(service_type='proxy', count=1) force_timeout = socket.timeout("timed out") with tutil.mock_keep_responses(force_timeout, 0) as mock: @@ -423,7 +438,7 @@ class KeepClientServiceTestCase(unittest.TestCase, tutil.ApiClientMock): api_client = mock.MagicMock(name='api_client') api_client.keep_services().accessible().execute.side_effect = ( arvados.errors.ApiError) - keep_client = arvados.KeepClient(api_client=api_client, block_cache=make_block_cache(self.disk_cache)) + keep_client = arvados.KeepClient(api_client=api_client, block_cache=self.make_block_cache(self.disk_cache)) with self.assertRaises(exc_class) as err_check: getattr(keep_client, verb)('d41d8cd98f00b204e9800998ecf8427e+0') self.assertEqual(0, len(err_check.exception.request_errors())) @@ -443,7 +458,7 @@ class KeepClientServiceTestCase(unittest.TestCase, tutil.ApiClientMock): "retry error reporting test", 500, 500, 500, 500, 500, 500, 502, 502) with req_mock, tutil.skip_sleep, \ self.assertRaises(exc_class) as err_check: - keep_client = arvados.KeepClient(api_client=api_client, block_cache=make_block_cache(self.disk_cache)) + keep_client = arvados.KeepClient(api_client=api_client, block_cache=self.make_block_cache(self.disk_cache)) getattr(keep_client, verb)('d41d8cd98f00b204e9800998ecf8427e+0', num_retries=3) self.assertEqual([502, 502], [ @@ -466,7 +481,7 @@ class KeepClientServiceTestCase(unittest.TestCase, tutil.ApiClientMock): api_client = self.mock_keep_services(count=3) with tutil.mock_keep_responses(data_loc, 200, 500, 500) as req_mock, \ self.assertRaises(arvados.errors.KeepWriteError) as exc_check: - keep_client = arvados.KeepClient(api_client=api_client, block_cache=make_block_cache(self.disk_cache)) + keep_client = arvados.KeepClient(api_client=api_client, block_cache=self.make_block_cache(self.disk_cache)) keep_client.put(data) self.assertEqual(2, len(exc_check.exception.request_errors())) @@ -476,7 +491,7 @@ class KeepClientServiceTestCase(unittest.TestCase, tutil.ApiClientMock): api_client = self.mock_keep_services(service_type='proxy', read_only=True, count=1) with tutil.mock_keep_responses(data_loc, 200, 500, 500) as req_mock, \ self.assertRaises(arvados.errors.KeepWriteError) as exc_check: - keep_client = arvados.KeepClient(api_client=api_client, block_cache=make_block_cache(self.disk_cache)) + keep_client = arvados.KeepClient(api_client=api_client, block_cache=self.make_block_cache(self.disk_cache)) keep_client.put(data) self.assertEqual(True, ("no Keep services available" in str(exc_check.exception))) self.assertEqual(0, len(exc_check.exception.request_errors())) @@ -485,7 +500,7 @@ class KeepClientServiceTestCase(unittest.TestCase, tutil.ApiClientMock): body = b'oddball service get' api_client = self.mock_keep_services(service_type='fancynewblobstore') with tutil.mock_keep_responses(body, 200): - keep_client = arvados.KeepClient(api_client=api_client, block_cache=make_block_cache(self.disk_cache)) + keep_client = arvados.KeepClient(api_client=api_client, block_cache=self.make_block_cache(self.disk_cache)) actual = keep_client.get(tutil.str_keep_locator(body)) self.assertEqual(body, actual) @@ -494,7 +509,7 @@ class KeepClientServiceTestCase(unittest.TestCase, tutil.ApiClientMock): pdh = tutil.str_keep_locator(body) api_client = self.mock_keep_services(service_type='fancynewblobstore') with tutil.mock_keep_responses(pdh, 200): - keep_client = arvados.KeepClient(api_client=api_client, block_cache=make_block_cache(self.disk_cache)) + keep_client = arvados.KeepClient(api_client=api_client, block_cache=self.make_block_cache(self.disk_cache)) actual = keep_client.put(body, copies=1) self.assertEqual(pdh, actual) @@ -506,22 +521,25 @@ class KeepClientServiceTestCase(unittest.TestCase, tutil.ApiClientMock): headers = {'x-keep-replicas-stored': 3} with tutil.mock_keep_responses(pdh, 200, 418, 418, 418, **headers) as req_mock: - keep_client = arvados.KeepClient(api_client=api_client, block_cache=make_block_cache(self.disk_cache)) + keep_client = arvados.KeepClient(api_client=api_client, block_cache=self.make_block_cache(self.disk_cache)) actual = keep_client.put(body, copies=2) self.assertEqual(pdh, actual) self.assertEqual(1, req_mock.call_count) @tutil.skip_sleep @parameterized.parameterized_class([{"disk_cache": True}, {"disk_cache": False}]) -class KeepClientCacheTestCase(unittest.TestCase, tutil.ApiClientMock): +class KeepClientCacheTestCase(unittest.TestCase, tutil.ApiClientMock, DiskCacheBase): disk_cache = False def setUp(self): self.api_client = self.mock_keep_services(count=2) - self.keep_client = arvados.KeepClient(api_client=self.api_client, block_cache=make_block_cache(self.disk_cache)) + self.keep_client = arvados.KeepClient(api_client=self.api_client, block_cache=self.make_block_cache(self.disk_cache)) self.data = b'xyzzy' self.locator = '1271ed5ef305aadabc605b1609e24c52' + def tearDown(self): + DiskCacheBase.tearDown(self) + @mock.patch('arvados.KeepClient.KeepService.get') def test_get_request_cache(self, get_mock): with tutil.mock_keep_responses(self.data, 200, 200): @@ -552,15 +570,18 @@ class KeepClientCacheTestCase(unittest.TestCase, tutil.ApiClientMock): @tutil.skip_sleep @parameterized.parameterized_class([{"disk_cache": True}, {"disk_cache": False}]) -class KeepStorageClassesTestCase(unittest.TestCase, tutil.ApiClientMock): +class KeepStorageClassesTestCase(unittest.TestCase, tutil.ApiClientMock, DiskCacheBase): disk_cache = False def setUp(self): self.api_client = self.mock_keep_services(count=2) - self.keep_client = arvados.KeepClient(api_client=self.api_client, block_cache=make_block_cache(self.disk_cache)) + self.keep_client = arvados.KeepClient(api_client=self.api_client, block_cache=self.make_block_cache(self.disk_cache)) self.data = b'xyzzy' self.locator = '1271ed5ef305aadabc605b1609e24c52' + def tearDown(self): + DiskCacheBase.tearDown(self) + def test_multiple_default_storage_classes_req_header(self): api_mock = self.api_client_mock() api_mock.config.return_value = { @@ -571,7 +592,7 @@ class KeepStorageClassesTestCase(unittest.TestCase, tutil.ApiClientMock): } } api_client = self.mock_keep_services(api_mock=api_mock, count=2) - keep_client = arvados.KeepClient(api_client=api_client, block_cache=make_block_cache(self.disk_cache)) + keep_client = arvados.KeepClient(api_client=api_client, block_cache=self.make_block_cache(self.disk_cache)) resp_hdr = { 'x-keep-storage-classes-confirmed': 'foo=1, bar=1', 'x-keep-replicas-stored': 1 @@ -666,12 +687,12 @@ class KeepStorageClassesTestCase(unittest.TestCase, tutil.ApiClientMock): @tutil.skip_sleep @parameterized.parameterized_class([{"disk_cache": True}, {"disk_cache": False}]) -class KeepXRequestIdTestCase(unittest.TestCase, tutil.ApiClientMock): +class KeepXRequestIdTestCase(unittest.TestCase, tutil.ApiClientMock, DiskCacheBase): disk_cache = False def setUp(self): self.api_client = self.mock_keep_services(count=2) - self.keep_client = arvados.KeepClient(api_client=self.api_client, block_cache=make_block_cache(self.disk_cache)) + self.keep_client = arvados.KeepClient(api_client=self.api_client, block_cache=self.make_block_cache(self.disk_cache)) self.data = b'xyzzy' self.locator = '1271ed5ef305aadabc605b1609e24c52' self.test_id = arvados.util.new_request_id() @@ -681,6 +702,9 @@ class KeepXRequestIdTestCase(unittest.TestCase, tutil.ApiClientMock): # id='123456789'>: self.api_client.request_id = None + def tearDown(self): + DiskCacheBase.tearDown(self) + def test_default_to_api_client_request_id(self): self.api_client.request_id = self.test_id with tutil.mock_keep_responses(self.locator, 200, 200) as mock: @@ -757,7 +781,7 @@ class KeepXRequestIdTestCase(unittest.TestCase, tutil.ApiClientMock): @tutil.skip_sleep #@parameterized.parameterized_class([{"disk_cache": True}, {"disk_cache": False}]) -class KeepClientRendezvousTestCase(unittest.TestCase, tutil.ApiClientMock): +class KeepClientRendezvousTestCase(unittest.TestCase, tutil.ApiClientMock, DiskCacheBase): disk_cache = False def setUp(self): @@ -781,7 +805,10 @@ class KeepClientRendezvousTestCase(unittest.TestCase, tutil.ApiClientMock): hashlib.md5(self.blocks[x]).hexdigest() for x in range(len(self.expected_order))] self.api_client = self.mock_keep_services(count=self.services) - self.keep_client = arvados.KeepClient(api_client=self.api_client, block_cache=make_block_cache(self.disk_cache)) + self.keep_client = arvados.KeepClient(api_client=self.api_client, block_cache=self.make_block_cache(self.disk_cache)) + + def tearDown(self): + DiskCacheBase.tearDown(self) def test_weighted_service_roots_against_reference_set(self): # Confirm weighted_service_roots() returns the correct order @@ -854,12 +881,12 @@ class KeepClientRendezvousTestCase(unittest.TestCase, tutil.ApiClientMock): hashlib.md5("{:064x}".format(x).encode()).hexdigest() for x in range(100)] initial_services = 12 self.api_client = self.mock_keep_services(count=initial_services) - self.keep_client = arvados.KeepClient(api_client=self.api_client, block_cache=make_block_cache(self.disk_cache)) + self.keep_client = arvados.KeepClient(api_client=self.api_client, block_cache=self.make_block_cache(self.disk_cache)) probes_before = [ self.keep_client.weighted_service_roots(arvados.KeepLocator(hash)) for hash in hashes] for added_services in range(1, 12): api_client = self.mock_keep_services(count=initial_services+added_services) - keep_client = arvados.KeepClient(api_client=api_client, block_cache=make_block_cache(self.disk_cache)) + keep_client = arvados.KeepClient(api_client=api_client, block_cache=self.make_block_cache(self.disk_cache)) total_penalty = 0 for hash_index in range(len(hashes)): probe_after = keep_client.weighted_service_roots( @@ -895,7 +922,7 @@ class KeepClientRendezvousTestCase(unittest.TestCase, tutil.ApiClientMock): # Arbitrary port number: aport = random.randint(1024,65535) api_client = self.mock_keep_services(service_port=aport, count=self.services) - keep_client = arvados.KeepClient(api_client=api_client, block_cache=make_block_cache(self.disk_cache)) + keep_client = arvados.KeepClient(api_client=api_client, block_cache=self.make_block_cache(self.disk_cache)) with mock.patch('pycurl.Curl') as curl_mock, \ self.assertRaises(exc_class) as err_check: curl_mock.return_value = tutil.FakeCurl.make(code=500, body=b'') @@ -912,7 +939,7 @@ class KeepClientRendezvousTestCase(unittest.TestCase, tutil.ApiClientMock): self.check_64_zeros_error_order('put', arvados.errors.KeepWriteError) @parameterized.parameterized_class([{"disk_cache": True}, {"disk_cache": False}]) -class KeepClientTimeout(keepstub.StubKeepServers, unittest.TestCase): +class KeepClientTimeout(keepstub.StubKeepServers, unittest.TestCase, DiskCacheBase): disk_cache = False # BANDWIDTH_LOW_LIM must be less than len(DATA) so we can transfer @@ -922,6 +949,9 @@ class KeepClientTimeout(keepstub.StubKeepServers, unittest.TestCase): BANDWIDTH_LOW_LIM = 1024 TIMEOUT_TIME = 1.0 + def tearDown(self): + DiskCacheBase.tearDown(self) + class assertTakesBetween(unittest.TestCase): def __init__(self, tmin, tmax): self.tmin = tmin @@ -951,7 +981,7 @@ class KeepClientTimeout(keepstub.StubKeepServers, unittest.TestCase): def keepClient(self, timeouts=(0.1, TIMEOUT_TIME, BANDWIDTH_LOW_LIM)): return arvados.KeepClient( api_client=self.api_client, - timeout=timeouts, block_cache=make_block_cache(self.disk_cache)) + timeout=timeouts, block_cache=self.make_block_cache(self.disk_cache)) def test_timeout_slow_connect(self): # Can't simulate TCP delays with our own socket. Leave our @@ -1056,9 +1086,12 @@ class KeepClientTimeout(keepstub.StubKeepServers, unittest.TestCase): kc.put(self.DATA, copies=1, num_retries=0) @parameterized.parameterized_class([{"disk_cache": True}, {"disk_cache": False}]) -class KeepClientGatewayTestCase(unittest.TestCase, tutil.ApiClientMock): +class KeepClientGatewayTestCase(unittest.TestCase, tutil.ApiClientMock, DiskCacheBase): disk_cache = False + def tearDown(self): + DiskCacheBase.tearDown(self) + def mock_disks_and_gateways(self, disks=3, gateways=1): self.gateways = [{ 'uuid': 'zzzzz-bi6l4-gateway{:08d}'.format(i), @@ -1073,7 +1106,7 @@ class KeepClientGatewayTestCase(unittest.TestCase, tutil.ApiClientMock): for gw in self.gateways] self.api_client = self.mock_keep_services( count=disks, additional_services=self.gateways) - self.keepClient = arvados.KeepClient(api_client=self.api_client, block_cache=make_block_cache(self.disk_cache)) + self.keepClient = arvados.KeepClient(api_client=self.api_client, block_cache=self.make_block_cache(self.disk_cache)) @mock.patch('pycurl.Curl') def test_get_with_gateway_hint_first(self, MockCurl): @@ -1181,7 +1214,7 @@ class KeepClientRetryTestMixin(object): def new_client(self, **caller_kwargs): kwargs = self.client_kwargs.copy() kwargs.update(caller_kwargs) - kwargs['block_cache'] = make_block_cache(self.disk_cache) + kwargs['block_cache'] = self.make_block_cache(self.disk_cache) return arvados.KeepClient(**kwargs) def run_method(self, *args, **kwargs): @@ -1232,12 +1265,15 @@ class KeepClientRetryTestMixin(object): @tutil.skip_sleep @parameterized.parameterized_class([{"disk_cache": True}, {"disk_cache": False}]) -class KeepClientRetryGetTestCase(KeepClientRetryTestMixin, unittest.TestCase): +class KeepClientRetryGetTestCase(KeepClientRetryTestMixin, unittest.TestCase, DiskCacheBase): DEFAULT_EXPECT = KeepClientRetryTestMixin.TEST_DATA DEFAULT_EXCEPTION = arvados.errors.KeepReadError HINTED_LOCATOR = KeepClientRetryTestMixin.TEST_LOCATOR + '+K@xyzzy' TEST_PATCHER = staticmethod(tutil.mock_keep_responses) + def tearDown(self): + DiskCacheBase.tearDown(self) + def run_method(self, locator=KeepClientRetryTestMixin.TEST_LOCATOR, *args, **kwargs): return self.new_client().get(locator, *args, **kwargs) @@ -1277,12 +1313,15 @@ class KeepClientRetryGetTestCase(KeepClientRetryTestMixin, unittest.TestCase): @tutil.skip_sleep @parameterized.parameterized_class([{"disk_cache": True}, {"disk_cache": False}]) -class KeepClientRetryHeadTestCase(KeepClientRetryTestMixin, unittest.TestCase): +class KeepClientRetryHeadTestCase(KeepClientRetryTestMixin, unittest.TestCase, DiskCacheBase): DEFAULT_EXPECT = True DEFAULT_EXCEPTION = arvados.errors.KeepReadError HINTED_LOCATOR = KeepClientRetryTestMixin.TEST_LOCATOR + '+K@xyzzy' TEST_PATCHER = staticmethod(tutil.mock_keep_responses) + def tearDown(self): + DiskCacheBase.tearDown(self) + def run_method(self, locator=KeepClientRetryTestMixin.TEST_LOCATOR, *args, **kwargs): return self.new_client().head(locator, *args, **kwargs) @@ -1316,11 +1355,14 @@ class KeepClientRetryHeadTestCase(KeepClientRetryTestMixin, unittest.TestCase): @tutil.skip_sleep @parameterized.parameterized_class([{"disk_cache": True}, {"disk_cache": False}]) -class KeepClientRetryPutTestCase(KeepClientRetryTestMixin, unittest.TestCase): +class KeepClientRetryPutTestCase(KeepClientRetryTestMixin, unittest.TestCase, DiskCacheBase): DEFAULT_EXPECT = KeepClientRetryTestMixin.TEST_LOCATOR DEFAULT_EXCEPTION = arvados.errors.KeepWriteError TEST_PATCHER = staticmethod(tutil.mock_keep_responses) + def tearDown(self): + DiskCacheBase.tearDown(self) + def run_method(self, data=KeepClientRetryTestMixin.TEST_DATA, copies=1, *args, **kwargs): return self.new_client().put(data, copies, *args, **kwargs) @@ -1405,7 +1447,7 @@ class AvoidOverreplication(unittest.TestCase, tutil.ApiClientMock): @tutil.skip_sleep @parameterized.parameterized_class([{"disk_cache": True}, {"disk_cache": False}]) -class RetryNeedsMultipleServices(unittest.TestCase, tutil.ApiClientMock): +class RetryNeedsMultipleServices(unittest.TestCase, tutil.ApiClientMock, DiskCacheBase): block_cache = False # Test put()s that need two distinct servers to succeed, possibly @@ -1413,7 +1455,10 @@ class RetryNeedsMultipleServices(unittest.TestCase, tutil.ApiClientMock): def setUp(self): self.api_client = self.mock_keep_services(count=2) - self.keep_client = arvados.KeepClient(api_client=self.api_client, block_cache=make_block_cache(self.disk_cache)) + self.keep_client = arvados.KeepClient(api_client=self.api_client, block_cache=self.make_block_cache(self.disk_cache)) + + def tearDown(self): + DiskCacheBase.tearDown(self) def test_success_after_exception(self): with tutil.mock_keep_responses( @@ -1441,9 +1486,12 @@ class RetryNeedsMultipleServices(unittest.TestCase, tutil.ApiClientMock): self.assertEqual(2, req_mock.call_count) @parameterized.parameterized_class([{"disk_cache": True}, {"disk_cache": False}]) -class KeepClientAPIErrorTest(unittest.TestCase): +class KeepClientAPIErrorTest(unittest.TestCase, DiskCacheBase): disk_cache = False + def tearDown(self): + DiskCacheBase.tearDown(self) + def test_api_fail(self): class ApiMock(object): def __getattr__(self, r): @@ -1457,7 +1505,7 @@ class KeepClientAPIErrorTest(unittest.TestCase): raise arvados.errors.KeepReadError() keep_client = arvados.KeepClient(api_client=ApiMock(), proxy='', local_store='', - block_cache=make_block_cache(self.disk_cache)) + block_cache=self.make_block_cache(self.disk_cache)) # The bug this is testing for is that if an API (not # keepstore) exception is thrown as part of a get(), the next -- 2.39.5