mirror of
https://github.com/ansible/awx.git
synced 2026-03-09 13:39:27 -02:30
equate unix socket file to localhost for ha
This commit is contained in:
@@ -16,7 +16,7 @@ def is_ha_environment():
|
|||||||
|
|
||||||
# If the database is not local, then we are in an HA environment.
|
# If the database is not local, then we are in an HA environment.
|
||||||
host = settings.DATABASES['default'].get('HOST', 'localhost')
|
host = settings.DATABASES['default'].get('HOST', 'localhost')
|
||||||
if host and host.lower() not in ('127.0.0.1', 'localhost'):
|
if host and host.lower() not in ('127.0.0.1', 'localhost') and not host.startswith('/'):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# We are not in an HA environment.
|
# We are not in an HA environment.
|
||||||
|
|||||||
@@ -18,3 +18,4 @@ from awx.main.tests.views import * # noqa
|
|||||||
from awx.main.tests.commands import * # noqa
|
from awx.main.tests.commands import * # noqa
|
||||||
from awx.main.tests.fact import * # noqa
|
from awx.main.tests.fact import * # noqa
|
||||||
from awx.main.tests.unified_jobs import * # noqa
|
from awx.main.tests.unified_jobs import * # noqa
|
||||||
|
from awx.main.tests.ha import * # noqa
|
||||||
|
|||||||
36
awx/main/tests/ha.py
Normal file
36
awx/main/tests/ha.py
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
# Copyright (c) 2015 Ansible, Inc.
|
||||||
|
|
||||||
|
# Python
|
||||||
|
import mock
|
||||||
|
|
||||||
|
# Django
|
||||||
|
from django.test import SimpleTestCase
|
||||||
|
from django.conf import settings
|
||||||
|
|
||||||
|
# AWX
|
||||||
|
from awx.main.models import * # noqa
|
||||||
|
from awx.main.ha import * # noqa
|
||||||
|
from awx.main.tests.base import BaseTest
|
||||||
|
|
||||||
|
__all__ = ['HAUnitTest',]
|
||||||
|
|
||||||
|
class HAUnitTest(SimpleTestCase):
|
||||||
|
|
||||||
|
@mock.patch('awx.main.models.Instance.objects.count', return_value=2)
|
||||||
|
def test_multiple_instances(self, ignore):
|
||||||
|
self.assertTrue(is_ha_environment())
|
||||||
|
|
||||||
|
@mock.patch('awx.main.models.Instance.objects.count', return_value=1)
|
||||||
|
@mock.patch.dict('django.conf.settings.DATABASES', { 'HOST': 'localhost' })
|
||||||
|
def test_db_localhost(self, ignore):
|
||||||
|
self.assertFalse(is_ha_environment())
|
||||||
|
|
||||||
|
@mock.patch('awx.main.models.Instance.objects.count', return_value=1)
|
||||||
|
@mock.patch.dict('django.conf.settings.DATABASES', { 'HOST': '127.0.0.1' })
|
||||||
|
def test_db_127_0_0_1(self, ignore):
|
||||||
|
self.assertFalse(is_ha_environment())
|
||||||
|
|
||||||
|
@mock.patch('awx.main.models.Instance.objects.count', return_value=1)
|
||||||
|
@mock.patch.dict('django.conf.settings.DATABASES', { 'HOST': '/i/might/be/a/file' })
|
||||||
|
def test_db_file_socket(self, ignore):
|
||||||
|
self.assertFalse(is_ha_environment())
|
||||||
Reference in New Issue
Block a user