def test_get_with_gateway_hint_first(self, MockSession): MockSession.return_value.get.return_value = tutil.fake_requests_response( code=200, body='foo', headers={'Content-Length': 3}) self.mock_disks_and_gateways() locator = 'acbd18db4cc2f85cedef654fccc4a4d8+3+K@' + self.gateways[0]['uuid'] self.assertEqual('foo', self.keepClient.get(locator)) self.assertEqual((self.gateway_roots[0]+locator,), MockSession.return_value.get.call_args_list[0][0])
def test_get_with_remote_proxy_hint(self, MockSession): MockSession.return_value.get.return_value = tutil.fake_requests_response( code=200, body='foo', headers={'Content-Length': 3}) self.mock_disks_and_gateways() locator = 'acbd18db4cc2f85cedef654fccc4a4d8+3+K@xyzzy' self.assertEqual('foo', self.keepClient.get(locator)) self.assertEqual(('https://keep.xyzzy.arvadosapi.com/'+locator,), MockSession.return_value.get.call_args_list[0][0])
def test_get_with_remote_proxy_hint(self, MockSession): MockSession.return_value.get.return_value = tutil.fake_requests_response( code=200, body='foo', headers={'Content-Length': 3}) self.mock_disks_and_gateways() locator = 'acbd18db4cc2f85cedef654fccc4a4d8+3+K@xyzzy' self.assertEqual('foo', self.keepClient.get(locator)) self.assertEqual(('https://keep.xyzzy.arvadosapi.com/' + locator, ), MockSession.return_value.get.call_args_list[0][0])
def test_get_with_gateway_hint_first(self, MockSession): MockSession.return_value.get.return_value = tutil.fake_requests_response( code=200, body='foo', headers={'Content-Length': 3}) self.mock_disks_and_gateways() locator = 'acbd18db4cc2f85cedef654fccc4a4d8+3+K@' + self.gateways[0][ 'uuid'] self.assertEqual('foo', self.keepClient.get(locator)) self.assertEqual((self.gateway_roots[0] + locator, ), MockSession.return_value.get.call_args_list[0][0])
def test_get_with_gateway_hints_in_order(self, MockSession): gateways = 4 disks = 3 MockSession.return_value.get.return_value = tutil.fake_requests_response( code=404, body='') self.mock_disks_and_gateways(gateways=gateways, disks=disks) locator = '+'.join(['acbd18db4cc2f85cedef654fccc4a4d8+3'] + ['K@'+gw['uuid'] for gw in self.gateways]) with self.assertRaises(arvados.errors.NotFoundError): self.keepClient.get(locator) # Gateways are tried first, in the order given. for i, root in enumerate(self.gateway_roots): self.assertEqual((root+locator,), MockSession.return_value.get.call_args_list[i][0]) # Disk services are tried next. for i in range(gateways, gateways+disks): self.assertRegexpMatches( MockSession.return_value.get.call_args_list[i][0][0], r'keep0x')
def test_get_with_gateway_hints_in_order(self, MockSession): gateways = 4 disks = 3 MockSession.return_value.get.return_value = tutil.fake_requests_response( code=404, body='') self.mock_disks_and_gateways(gateways=gateways, disks=disks) locator = '+'.join(['acbd18db4cc2f85cedef654fccc4a4d8+3'] + ['K@' + gw['uuid'] for gw in self.gateways]) with self.assertRaises(arvados.errors.NotFoundError): self.keepClient.get(locator) # Gateways are tried first, in the order given. for i, root in enumerate(self.gateway_roots): self.assertEqual((root + locator, ), MockSession.return_value.get.call_args_list[i][0]) # Disk services are tried next. for i in range(gateways, gateways + disks): self.assertRegexpMatches( MockSession.return_value.get.call_args_list[i][0][0], r'keep0x')
def results_map(self, *codes): for code in codes: response = fake_requests_response(code, None) yield code, arv_retry.check_http_response_success(response)
def test_retry_data_with_wrong_checksum(self): with tutil.mock_get((tutil.fake_requests_response(200, s) for s in ['baddata', self.TEST_DATA])): self.check_success(locator=self.HINTED_LOCATOR)
def test_try_next_server_after_timeout(self): with tutil.mock_get([ socket.timeout("timed out"), tutil.fake_requests_response(200, self.DEFAULT_EXPECT)]): self.check_success(locator=self.HINTED_LOCATOR)
def test_try_next_server_after_timeout(self): with tutil.mock_get([ socket.timeout("timed out"), tutil.fake_requests_response(200, self.DEFAULT_EXPECT) ]): self.check_success(locator=self.HINTED_LOCATOR)
class KeepRequestErrorTestCase(unittest.TestCase): REQUEST_ERRORS = [ ('http://keep1.zzzzz.example.org/', IOError("test IOError")), ('http://keep3.zzzzz.example.org/', MemoryError("test MemoryError")), ('http://keep5.zzzzz.example.org/', tutil.fake_requests_response(500, "test 500")), ('http://keep7.zzzzz.example.org/', IOError("second test IOError")), ] def check_get_message(self, *args): test_exc = arv_error.KeepRequestError("test message", *args) self.assertEqual("test message", test_exc.message) def test_get_message_with_request_errors(self): self.check_get_message(self.REQUEST_ERRORS[:]) def test_get_message_without_request_errors(self): self.check_get_message() def check_get_request_errors(self, *args): expected = dict(args[0]) if args else {} test_exc = arv_error.KeepRequestError("test service exceptions", *args) self.assertEqual(expected, test_exc.request_errors()) def test_get_request_errors(self): self.check_get_request_errors(self.REQUEST_ERRORS[:]) def test_get_request_errors_none(self): self.check_get_request_errors({}) def test_empty_exception(self): test_exc = arv_error.KeepRequestError() self.assertFalse(test_exc.message) self.assertEqual({}, test_exc.request_errors()) def traceback_str(self, exc): return traceback.format_exception_only(type(exc), exc)[-1] def test_traceback_str_without_request_errors(self): message = "test plain traceback string" test_exc = arv_error.KeepRequestError(message) exc_report = self.traceback_str(test_exc) self.assertTrue(exc_report.startswith("KeepRequestError: ")) self.assertIn(message, exc_report) def test_traceback_str_with_request_errors(self): message = "test traceback shows Keep services" test_exc = arv_error.KeepRequestError(message, self.REQUEST_ERRORS[:]) exc_report = self.traceback_str(test_exc) self.assertTrue(exc_report.startswith("KeepRequestError: ")) for expect_substr in [ message, "raised IOError", "raised MemoryError", "test MemoryError", "second test IOError", "responded with 500 Internal Server Error" ]: self.assertIn(expect_substr, exc_report) # Assert the report maintains order of listed services. last_index = -1 for service_key, _ in self.REQUEST_ERRORS: service_index = exc_report.find(service_key) self.assertGreater(service_index, last_index) last_index = service_index