diff --git a/awx/main/tasks.py b/awx/main/tasks.py index 6e561dd079..dc4a3b0554 100644 --- a/awx/main/tasks.py +++ b/awx/main/tasks.py @@ -438,6 +438,9 @@ def execution_node_health_check(node): logger.warn(f'Instance record for {node} missing, could not check capacity.') return + if instance.node_type != 'execution': + raise RuntimeError(f'Execution node health check ran against {instance.node_type} node {instance.hostname}') + data = worker_info(node, work_type='ansible-runner' if instance.node_type == 'execution' else 'local') prior_capacity = instance.capacity @@ -3023,7 +3026,7 @@ class AWXReceptorJob: if self.unit_id is not None and settings.RECEPTOR_RELEASE_WORK: receptor_ctl.simple_command(f"work release {self.unit_id}") # If an error occured without the job itself failing, it could be a broken instance - if self.work_type == 'ansible-runner' and res is None or getattr(res, 'rc', None) is None: + if self.work_type == 'ansible-runner' and ((res is None) or (getattr(res, 'rc', None) is None)): execution_node_health_check(self.task.instance.execution_node) def _run_internal(self, receptor_ctl): diff --git a/awx/main/tests/functional/test_tasks.py b/awx/main/tests/functional/test_tasks.py index 850b4709ca..9edf152924 100644 --- a/awx/main/tests/functional/test_tasks.py +++ b/awx/main/tests/functional/test_tasks.py @@ -2,8 +2,8 @@ import pytest from unittest import mock import os -from awx.main.tasks import RunProjectUpdate, RunInventoryUpdate -from awx.main.models import ProjectUpdate, InventoryUpdate, InventorySource +from awx.main.tasks import RunProjectUpdate, RunInventoryUpdate, execution_node_health_check +from awx.main.models import ProjectUpdate, InventoryUpdate, InventorySource, Instance @pytest.fixture @@ -15,6 +15,15 @@ def scm_revision_file(tmpdir_factory): return os.path.join(revision_file.dirname, 'revision.txt') +@pytest.mark.django_db +@pytest.mark.parametrize('node_type', ('control', 'hybrid')) +def test_no_worker_info_on_AWX_nodes(node_type): + hostname = 'us-south-3-compute.invalid' + Instance.objects.create(hostname=hostname, node_type=node_type) + with pytest.raises(RuntimeError): + execution_node_health_check(hostname) + + @pytest.mark.django_db class TestDependentInventoryUpdate: def test_dependent_inventory_updates_is_called(self, scm_inventory_source, scm_revision_file):