From 818e11dfdc858bedb11e1eb392a392836d0c788b Mon Sep 17 00:00:00 2001 From: Seth Foster Date: Mon, 29 Jan 2024 12:07:16 -0500 Subject: [PATCH] Test inspect_established_receptor_connections Add functional test case for inspecting established receptor connections. InstanceLink starts in ADDING state, and should move to ESTABLISHED state if the connection is detected in the receptor status output. Signed-off-by: Seth Foster --- awx/main/tests/functional/test_linkstate.py | 30 +++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 awx/main/tests/functional/test_linkstate.py diff --git a/awx/main/tests/functional/test_linkstate.py b/awx/main/tests/functional/test_linkstate.py new file mode 100644 index 0000000000..478883870a --- /dev/null +++ b/awx/main/tests/functional/test_linkstate.py @@ -0,0 +1,30 @@ +import pytest + +from awx.main.models import Instance, ReceptorAddress, InstanceLink +from awx.main.tasks.system import inspect_established_receptor_connections + + +@pytest.mark.django_db +class TestLinkState: + @pytest.fixture(autouse=True) + def configure_settings(self, settings): + settings.IS_K8S = True + + def test_inspect_established_receptor_connections(self): + ''' + Change link state from ADDING to ESTABLISHED + if the receptor status KnownConnectionCosts field + has an entry for the source and target node. + ''' + hop1 = Instance.objects.create(hostname='hop1') + hop2 = Instance.objects.create(hostname='hop2') + hop2addr = ReceptorAddress.objects.create(instance=hop2, address='hop2', port=5678) + InstanceLink.objects.create(source=hop1, target=hop2addr, link_state=InstanceLink.States.ADDING) + + # calling with empty KnownConnectionCosts should not change the link state + inspect_established_receptor_connections({"KnownConnectionCosts": {}}) + assert InstanceLink.objects.get(source=hop1, target=hop2addr).link_state == InstanceLink.States.ADDING + + mesh_state = {"KnownConnectionCosts": {"hop1": {"hop2": 1}}} + inspect_established_receptor_connections(mesh_state) + assert InstanceLink.objects.get(source=hop1, target=hop2addr).link_state == InstanceLink.States.ESTABLISHED