mirror of
https://github.com/ansible/awx.git
synced 2026-05-06 17:07:36 -02:30
remove tests that assume health check runs in view
This commit is contained in:
committed by
Jeff Bradberry
parent
eaa4f2483f
commit
dfe6ce1ba8
@@ -1,16 +1,9 @@
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from unittest import mock
|
|
||||||
|
|
||||||
from awx.api.versioning import reverse
|
from awx.api.versioning import reverse
|
||||||
from awx.main.models.activity_stream import ActivityStream
|
from awx.main.models.activity_stream import ActivityStream
|
||||||
from awx.main.models.ha import Instance
|
from awx.main.models.ha import Instance
|
||||||
|
|
||||||
import redis
|
|
||||||
|
|
||||||
# Django
|
|
||||||
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, memory=36000000000, cpu_capacity=6, mem_capacity=42)
|
||||||
|
|
||||||
@@ -50,33 +43,14 @@ def test_enabled_sets_capacity(patch, admin_user):
|
|||||||
def test_auditor_user_health_check(get, post, system_auditor):
|
def test_auditor_user_health_check(get, post, system_auditor):
|
||||||
instance = Instance.objects.create(**INSTANCE_KWARGS)
|
instance = Instance.objects.create(**INSTANCE_KWARGS)
|
||||||
url = reverse('api:instance_health_check', kwargs={'pk': instance.pk})
|
url = reverse('api:instance_health_check', kwargs={'pk': instance.pk})
|
||||||
r = get(url=url, user=system_auditor, expect=200)
|
get(url=url, user=system_auditor, expect=200)
|
||||||
assert r.data['cpu_capacity'] == instance.cpu_capacity
|
|
||||||
post(url=url, user=system_auditor, expect=403)
|
post(url=url, user=system_auditor, expect=403)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_health_check_throws_error(post, admin_user):
|
|
||||||
instance = Instance.objects.create(node_type='execution', **INSTANCE_KWARGS)
|
|
||||||
url = reverse('api:instance_health_check', kwargs={'pk': instance.pk})
|
|
||||||
# we will simulate a receptor error, similar to this one
|
|
||||||
# https://github.com/ansible/receptor/blob/156e6e24a49fbf868734507f9943ac96208ed8f5/receptorctl/receptorctl/socket_interface.py#L204
|
|
||||||
# related to issue https://github.com/ansible/tower/issues/5315
|
|
||||||
with mock.patch('awx.main.tasks.receptor.run_until_complete', side_effect=RuntimeError('Remote error: foobar')):
|
|
||||||
post(url=url, user=admin_user, expect=200)
|
|
||||||
instance.refresh_from_db()
|
|
||||||
assert 'Remote error: foobar' in instance.errors
|
|
||||||
assert instance.capacity == 0
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
|
||||||
@mock.patch.object(redis.client.Redis, 'ping', lambda self: True)
|
|
||||||
def test_health_check_usage(get, post, admin_user):
|
def test_health_check_usage(get, post, admin_user):
|
||||||
instance = Instance.objects.create(**INSTANCE_KWARGS)
|
instance = Instance.objects.create(**INSTANCE_KWARGS)
|
||||||
url = reverse('api:instance_health_check', kwargs={'pk': instance.pk})
|
url = reverse('api:instance_health_check', kwargs={'pk': instance.pk})
|
||||||
r = get(url=url, user=admin_user, expect=200)
|
get(url=url, user=admin_user, expect=200)
|
||||||
assert r.data['cpu_capacity'] == instance.cpu_capacity
|
r = post(url=url, user=admin_user, expect=200)
|
||||||
assert r.data['last_health_check'] is None
|
assert r.data['msg'] == f"Health check is running for {instance.hostname}."
|
||||||
with override_settings(CLUSTER_HOST_ID=instance.hostname): # force direct call of cluster_node_health_check
|
|
||||||
r = post(url=url, user=admin_user, expect=200)
|
|
||||||
assert r.data['last_health_check'] is not None
|
|
||||||
|
|||||||
Reference in New Issue
Block a user