more specific retry condition implemented

This commit is contained in:
David Kennedy 2025-03-25 13:23:29 -04:00
parent 6948d6c2d4
commit 7a935d11fc
No known key found for this signature in database
GPG key ID: 6528A5386E66B96B
2 changed files with 12 additions and 4 deletions

View file

@ -1,4 +1,4 @@
from enum import IntEnum from enum import IntEnum, Enum
class ErrorCode(IntEnum): class ErrorCode(IntEnum):
@ -52,6 +52,10 @@ class ErrorCode(IntEnum):
SESSION_LIMIT_EXCEEDED_SERVER_CLOSING_CONNECTION = 2502 SESSION_LIMIT_EXCEEDED_SERVER_CLOSING_CONNECTION = 2502
class RegistryErrorMessage(Enum):
REGISTRAR_NOT_LOGGED_IN = "Registrar is not logged in."
class RegistryError(Exception): class RegistryError(Exception):
""" """
Overview of registry response codes from RFC 5730. See RFC 5730 for full text. Overview of registry response codes from RFC 5730. See RFC 5730 for full text.
@ -72,7 +76,11 @@ class RegistryError(Exception):
def should_retry(self): def should_retry(self):
# COMMAND_USE_ERROR is returning with message, Registrar is not logged in, # COMMAND_USE_ERROR is returning with message, Registrar is not logged in,
# which can be recovered from with a retry # which can be recovered from with a retry
return self.code == ErrorCode.COMMAND_FAILED or self.code == ErrorCode.COMMAND_USE_ERROR return self.code == ErrorCode.COMMAND_FAILED or (
self.code == ErrorCode.COMMAND_USE_ERROR
and self.response
and getattr(self.response, "msg", None) == RegistryErrorMessage.REGISTRAR_NOT_LOGGED_IN.value
)
def is_transport_error(self): def is_transport_error(self):
return self.code == ErrorCode.TRANSPORT_ERROR return self.code == ErrorCode.TRANSPORT_ERROR

View file

@ -280,7 +280,7 @@ class TestClient(TestCase):
mock_close = MagicMock() mock_close = MagicMock()
# create success and failure result messages # create success and failure result messages
send_command_success_result = self.fake_result(1000, "Command completed successfully") send_command_success_result = self.fake_result(1000, "Command completed successfully")
send_command_failure_result = self.fake_result(2002, "Registrar is not logging in.") send_command_failure_result = self.fake_result(2002, "Registrar is not logged in.")
# side_effect for send call, initial send(login) succeeds during initialization, next send(command) # side_effect for send call, initial send(login) succeeds during initialization, next send(command)
# fails, subsequent sends (logout, login, command) all succeed # fails, subsequent sends (logout, login, command) all succeed
send_call_count = 0 send_call_count = 0
@ -312,7 +312,7 @@ class TestClient(TestCase):
self.assertEquals(mock_send.call_count, 5) self.assertEquals(mock_send.call_count, 5)
# Assertion proper logging; note that the # Assertion proper logging; note that the
mock_logger.info.assert_called_once_with( mock_logger.info.assert_called_once_with(
"InfoDomainCommand failed and will be retried Error: Registrar is not logging in.| cltrid is cl_tr_id svtrid is sv_tr_id" "InfoDomainCommand failed and will be retried Error: Registrar is not logged in.| cltrid is cl_tr_id svtrid is sv_tr_id"
) )
@less_console_noise_decorator @less_console_noise_decorator