mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-06 11:13:21 +02:00
Hotfix
This commit is contained in:
parent
1502e7a693
commit
1ca7c51fbb
4 changed files with 34 additions and 16 deletions
|
@ -172,7 +172,7 @@ class EPPLibWrapper:
|
|||
)
|
||||
|
||||
def start_connection_pool(
|
||||
self, restart_pool_if_exists=True, try_start_if_invalid=False
|
||||
self, restart_pool_if_exists=True
|
||||
):
|
||||
"""Starts a connection pool for the registry.
|
||||
|
||||
|
@ -189,9 +189,8 @@ class EPPLibWrapper:
|
|||
# Since we reuse the same creds for each pool, we can test on
|
||||
# one socket, and if successful, then we know we can connect.
|
||||
if (
|
||||
try_start_if_invalid
|
||||
and (settings.DEBUG
|
||||
or not self._test_registry_connection_success())
|
||||
settings.DEBUG
|
||||
or not self._test_registry_connection_success()
|
||||
):
|
||||
logger.warning("Cannot contact the Registry")
|
||||
self.pool_status.connection_success = False
|
||||
|
|
|
@ -14,6 +14,7 @@ import logging
|
|||
|
||||
try:
|
||||
from epplib import commands
|
||||
from epplib.client import Client
|
||||
from epplib.exceptions import TransportError
|
||||
except ImportError:
|
||||
pass
|
||||
|
@ -35,6 +36,15 @@ class TestConnectionPool(TestCase):
|
|||
"keepalive": 60,
|
||||
}
|
||||
|
||||
#self.start_mocks()
|
||||
|
||||
def tearDown(self):
|
||||
#self.mock_send_patch.stop()
|
||||
#self.mock_connect_patch.stop()
|
||||
#self.mockSendPatch.stop()
|
||||
pass
|
||||
|
||||
def start_mocks(self):
|
||||
# Mock a successful connection
|
||||
self.mock_connect_patch = patch("epplib.client.Client.connect")
|
||||
self.mocked_connect_function = self.mock_connect_patch.start()
|
||||
|
@ -50,11 +60,6 @@ class TestConnectionPool(TestCase):
|
|||
self.mockedSendFunction = self.mockSendPatch.start()
|
||||
self.mockedSendFunction.side_effect = self.fake_pool
|
||||
|
||||
def tearDown(self):
|
||||
self.mock_send_patch.stop()
|
||||
self.mock_connect_patch.stop()
|
||||
self.mockSendPatch.stop()
|
||||
|
||||
def mock_connect(self, _request):
|
||||
return None
|
||||
|
||||
|
@ -96,6 +101,22 @@ class TestConnectionPool(TestCase):
|
|||
)
|
||||
return pool
|
||||
|
||||
@patch("djangooidc.views.CLIENT", autospec=True)
|
||||
def fake_socket(self, mock_client):
|
||||
# mock client
|
||||
mock_client.callback.side_effect = self.user_info
|
||||
# Create a mock transport object
|
||||
mock_login = MagicMock()
|
||||
mock_login.transport.cert_file = "path/to/cert_file"
|
||||
mock_login.transport.key_file = "path/to/key_file"
|
||||
return Socket(mock_client, mock_login)
|
||||
|
||||
def test(self, client, login):
|
||||
mock = MagicMock()
|
||||
mock.response.code = 1000
|
||||
mock().return_value = 1000
|
||||
return MagicMock()
|
||||
|
||||
@skip("not implemented yet")
|
||||
def test_pool_timesout(self):
|
||||
"""The pool timesout and restarts"""
|
||||
|
@ -124,7 +145,7 @@ class TestConnectionPool(TestCase):
|
|||
domain, _ = Domain.objects.get_or_create(name="freeman.gov")
|
||||
|
||||
def fake_send(self):
|
||||
return MagicMock(
|
||||
mock = MagicMock(
|
||||
code=1000,
|
||||
msg="Command completed successfully",
|
||||
res_data=None,
|
||||
|
@ -133,12 +154,10 @@ class TestConnectionPool(TestCase):
|
|||
extensions=[],
|
||||
msg_q=None,
|
||||
)
|
||||
return mock
|
||||
|
||||
with ExitStack() as stack:
|
||||
stack.enter_context(patch.object(Socket, "connect", None))
|
||||
stack.enter_context(patch.object(Socket, "send", fake_send))
|
||||
stack.enter_context(patch.object(EPPLibWrapper, "_create_pool", self.fake_pool))
|
||||
#stack.enter_context(patch.object(EPPLibWrapper, "get_pool", self.fake_pool))
|
||||
stack.enter_context(patch.object(EPPConnectionPool, "_create_socket", self.fake_socket))
|
||||
# Pool should be running, and be the right size
|
||||
self.assertEqual(registry.pool_status.pool_running, True)
|
||||
self.assertEqual(registry.pool_status.connection_success, True)
|
||||
|
|
|
@ -34,7 +34,7 @@ class EPPConnectionPool(ConnectionPool):
|
|||
connection = socket.connect()
|
||||
return connection
|
||||
except Exception as err:
|
||||
message = f"Failed to execute due to a registry login error: {err}"
|
||||
message = f"Failed to execute due to a registry error: {err}"
|
||||
logger.error(message, exc_info=True)
|
||||
# We want to raise a pool error rather than a LoginError here
|
||||
# because if this occurs internally, we should handle this
|
||||
|
|
|
@ -26,7 +26,7 @@ class PoolError(Exception):
|
|||
|
||||
# For linter
|
||||
kill_failed = "Could not kill all connections."
|
||||
conn_failed = "Failed to execute due to a registry login error."
|
||||
conn_failed = "Failed to execute due to a registry error."
|
||||
alive_failed = "Failed to keep the connection alive."
|
||||
_error_mapping = {
|
||||
PoolErrorCodes.KILL_ALL_FAILED: kill_failed,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue