From 41fd6ea37f67530d2c50a61e9802987da66a15b2 Mon Sep 17 00:00:00 2001 From: Alex Corey Date: Tue, 11 Oct 2022 16:22:42 -0400 Subject: [PATCH] Prevents health checks on all node types except for Execution nodes --- awx/api/serializers.py | 2 +- awx/api/views/__init__.py | 9 +++++---- awx/main/tests/functional/api/test_instance.py | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/awx/api/serializers.py b/awx/api/serializers.py index b0f56077e9..cf6fa391e9 100644 --- a/awx/api/serializers.py +++ b/awx/api/serializers.py @@ -4952,7 +4952,7 @@ class InstanceSerializer(BaseSerializer): res['install_bundle'] = self.reverse('api:instance_install_bundle', kwargs={'pk': obj.pk}) res['peers'] = self.reverse('api:instance_peers_list', kwargs={"pk": obj.pk}) if self.context['request'].user.is_superuser or self.context['request'].user.is_system_auditor: - if obj.node_type != 'hop': + if obj.node_type == 'execution': res['health_check'] = self.reverse('api:instance_health_check', kwargs={'pk': obj.pk}) return res diff --git a/awx/api/views/__init__.py b/awx/api/views/__init__.py index 15f8359384..14fae507d3 100644 --- a/awx/api/views/__init__.py +++ b/awx/api/views/__init__.py @@ -392,8 +392,8 @@ class InstanceHealthCheck(GenericAPIView): permission_classes = (IsSystemAdminOrAuditor,) def get_queryset(self): + return super().get_queryset().filter(node_type='execution') # FIXME: For now, we don't have a good way of checking the health of a hop node. - return super().get_queryset().exclude(node_type='hop') def get(self, request, *args, **kwargs): obj = self.get_object() @@ -413,9 +413,10 @@ class InstanceHealthCheck(GenericAPIView): execution_node_health_check.apply_async([obj.hostname]) else: - from awx.main.tasks.system import cluster_node_health_check - - cluster_node_health_check.apply_async([obj.hostname], queue=obj.hostname) + return Response( + {"error": f"Cannot run a health check on instances of type {obj.node_type}. Health checks can only be run on execution nodes."}, + status=status.HTTP_400_BAD_REQUEST, + ) return Response({'msg': f"Health check is running for {obj.hostname}."}, status=status.HTTP_200_OK) diff --git a/awx/main/tests/functional/api/test_instance.py b/awx/main/tests/functional/api/test_instance.py index 25ecb78ded..b9ec4d2ab0 100644 --- a/awx/main/tests/functional/api/test_instance.py +++ b/awx/main/tests/functional/api/test_instance.py @@ -7,7 +7,7 @@ from awx.main.models.ha import Instance from django.test.utils import override_settings -INSTANCE_KWARGS = dict(hostname='example-host', cpu=6, memory=36000000000, cpu_capacity=6, mem_capacity=42) +INSTANCE_KWARGS = dict(hostname='example-host', cpu=6, node_type='execution', memory=36000000000, cpu_capacity=6, mem_capacity=42) @pytest.mark.django_db