From e52416fd47f48001e3ce448f767dfd94bc992a4c Mon Sep 17 00:00:00 2001 From: Alan Rominger Date: Wed, 6 Oct 2021 10:50:18 -0400 Subject: [PATCH] Report single node clusters as non-ha (#11212) * Report single node clusters as non-ha * Move test file so we can make it use the database * Update unit test to accomidate different node types --- awx/main/ha.py | 2 +- awx/main/tests/functional/test_ha.py | 19 +++++++++++++++++++ awx/main/tests/unit/test_ha.py | 17 ----------------- 3 files changed, 20 insertions(+), 18 deletions(-) create mode 100644 awx/main/tests/functional/test_ha.py delete mode 100644 awx/main/tests/unit/test_ha.py diff --git a/awx/main/ha.py b/awx/main/ha.py index 35ed6f64f0..f5413fdf5b 100644 --- a/awx/main/ha.py +++ b/awx/main/ha.py @@ -10,6 +10,6 @@ def is_ha_environment(): otherwise. """ # If there are two or more instances, then we are in an HA environment. - if Instance.objects.count() > 1: + if Instance.objects.filter(node_type__in=('control', 'hybrid')).count() > 1: return True return False diff --git a/awx/main/tests/functional/test_ha.py b/awx/main/tests/functional/test_ha.py new file mode 100644 index 0000000000..bda4da35a5 --- /dev/null +++ b/awx/main/tests/functional/test_ha.py @@ -0,0 +1,19 @@ +import pytest + +# AWX +from awx.main.ha import is_ha_environment +from awx.main.models.ha import Instance + + +@pytest.mark.django_db +def test_multiple_instances(): + for i in range(2): + Instance.objects.create(hostname=f'foo{i}', node_type='hybrid') + assert is_ha_environment() + + +@pytest.mark.django_db +def test_db_localhost(): + Instance.objects.create(hostname='foo', node_type='hybrd') + Instance.objects.create(hostname='bar', node_type='execution') + assert is_ha_environment() is False diff --git a/awx/main/tests/unit/test_ha.py b/awx/main/tests/unit/test_ha.py deleted file mode 100644 index f88850895c..0000000000 --- a/awx/main/tests/unit/test_ha.py +++ /dev/null @@ -1,17 +0,0 @@ -# Copyright (c) 2016 Ansible, Inc. - -# Python -from unittest import mock - -# AWX -from awx.main.ha import is_ha_environment - - -@mock.patch('awx.main.models.Instance.objects.count', lambda: 2) -def test_multiple_instances(): - assert is_ha_environment() - - -@mock.patch('awx.main.models.Instance.objects.count', lambda: 1) -def test_db_localhost(): - assert is_ha_environment() is False