Merge pull request #239 from chrismeyersfsu/fix-ha

equate unix socket file to localhost for ha
This commit is contained in:
Chris Meyers 2015-05-23 15:28:47 -05:00
commit 092732550d
3 changed files with 48 additions and 1 deletions

View File

@ -16,7 +16,7 @@ def is_ha_environment():
# If the database is not local, then we are in an HA environment.
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
# We are not in an HA environment.

View File

@ -18,3 +18,4 @@ from awx.main.tests.views import * # noqa
from awx.main.tests.commands import * # noqa
from awx.main.tests.fact import * # noqa
from awx.main.tests.unified_jobs import * # noqa
from awx.main.tests.ha import * # noqa

46
awx/main/tests/ha.py Normal file
View File

@ -0,0 +1,46 @@
# Copyright (c) 2015 Ansible, Inc.
# Python
import mock
# Django
from django.test import SimpleTestCase
# AWX
from awx.main.models import * # noqa
from awx.main.ha import * # noqa
__all__ = ['HAUnitTest',]
TEST_LOCALHOST = {
'HOST': 'localhost'
}
TEST_127_0_0_1 = {
'HOST': '127.0.0.1'
}
TEST_FILE = {
'HOST': '/i/might/be/a/file',
}
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', TEST_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', TEST_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', TEST_FILE)
def test_db_file_socket(self, ignore):
self.assertFalse(is_ha_environment())