equate unix socket file to localhost for ha

This commit is contained in:
Chris Meyers 2015-05-22 12:20:25 -04:00
parent ebdc7a9648
commit b4c0d2b3b3
3 changed files with 38 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

36
awx/main/tests/ha.py Normal file
View 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())