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(
|
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.
|
"""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
|
# Since we reuse the same creds for each pool, we can test on
|
||||||
# one socket, and if successful, then we know we can connect.
|
# one socket, and if successful, then we know we can connect.
|
||||||
if (
|
if (
|
||||||
try_start_if_invalid
|
settings.DEBUG
|
||||||
and (settings.DEBUG
|
or not self._test_registry_connection_success()
|
||||||
or not self._test_registry_connection_success())
|
|
||||||
):
|
):
|
||||||
logger.warning("Cannot contact the Registry")
|
logger.warning("Cannot contact the Registry")
|
||||||
self.pool_status.connection_success = False
|
self.pool_status.connection_success = False
|
||||||
|
|
|
@ -14,6 +14,7 @@ import logging
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from epplib import commands
|
from epplib import commands
|
||||||
|
from epplib.client import Client
|
||||||
from epplib.exceptions import TransportError
|
from epplib.exceptions import TransportError
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
|
@ -35,6 +36,15 @@ class TestConnectionPool(TestCase):
|
||||||
"keepalive": 60,
|
"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
|
# Mock a successful connection
|
||||||
self.mock_connect_patch = patch("epplib.client.Client.connect")
|
self.mock_connect_patch = patch("epplib.client.Client.connect")
|
||||||
self.mocked_connect_function = self.mock_connect_patch.start()
|
self.mocked_connect_function = self.mock_connect_patch.start()
|
||||||
|
@ -50,11 +60,6 @@ class TestConnectionPool(TestCase):
|
||||||
self.mockedSendFunction = self.mockSendPatch.start()
|
self.mockedSendFunction = self.mockSendPatch.start()
|
||||||
self.mockedSendFunction.side_effect = self.fake_pool
|
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):
|
def mock_connect(self, _request):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@ -96,6 +101,22 @@ class TestConnectionPool(TestCase):
|
||||||
)
|
)
|
||||||
return pool
|
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")
|
@skip("not implemented yet")
|
||||||
def test_pool_timesout(self):
|
def test_pool_timesout(self):
|
||||||
"""The pool timesout and restarts"""
|
"""The pool timesout and restarts"""
|
||||||
|
@ -124,7 +145,7 @@ class TestConnectionPool(TestCase):
|
||||||
domain, _ = Domain.objects.get_or_create(name="freeman.gov")
|
domain, _ = Domain.objects.get_or_create(name="freeman.gov")
|
||||||
|
|
||||||
def fake_send(self):
|
def fake_send(self):
|
||||||
return MagicMock(
|
mock = MagicMock(
|
||||||
code=1000,
|
code=1000,
|
||||||
msg="Command completed successfully",
|
msg="Command completed successfully",
|
||||||
res_data=None,
|
res_data=None,
|
||||||
|
@ -133,12 +154,10 @@ class TestConnectionPool(TestCase):
|
||||||
extensions=[],
|
extensions=[],
|
||||||
msg_q=None,
|
msg_q=None,
|
||||||
)
|
)
|
||||||
|
return mock
|
||||||
|
|
||||||
with ExitStack() as stack:
|
with ExitStack() as stack:
|
||||||
stack.enter_context(patch.object(Socket, "connect", None))
|
stack.enter_context(patch.object(EPPConnectionPool, "_create_socket", self.fake_socket))
|
||||||
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))
|
|
||||||
# Pool should be running, and be the right size
|
# Pool should be running, and be the right size
|
||||||
self.assertEqual(registry.pool_status.pool_running, True)
|
self.assertEqual(registry.pool_status.pool_running, True)
|
||||||
self.assertEqual(registry.pool_status.connection_success, True)
|
self.assertEqual(registry.pool_status.connection_success, True)
|
||||||
|
|
|
@ -34,7 +34,7 @@ class EPPConnectionPool(ConnectionPool):
|
||||||
connection = socket.connect()
|
connection = socket.connect()
|
||||||
return connection
|
return connection
|
||||||
except Exception as err:
|
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)
|
logger.error(message, exc_info=True)
|
||||||
# We want to raise a pool error rather than a LoginError here
|
# We want to raise a pool error rather than a LoginError here
|
||||||
# because if this occurs internally, we should handle this
|
# because if this occurs internally, we should handle this
|
||||||
|
|
|
@ -26,7 +26,7 @@ class PoolError(Exception):
|
||||||
|
|
||||||
# For linter
|
# For linter
|
||||||
kill_failed = "Could not kill all connections."
|
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."
|
alive_failed = "Failed to keep the connection alive."
|
||||||
_error_mapping = {
|
_error_mapping = {
|
||||||
PoolErrorCodes.KILL_ALL_FAILED: kill_failed,
|
PoolErrorCodes.KILL_ALL_FAILED: kill_failed,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue