From 043f97fe35e6ddfbefdcd99dba7b7b522ed74de8 Mon Sep 17 00:00:00 2001 From: Chris Meyers Date: Wed, 13 Apr 2016 17:28:38 -0400 Subject: [PATCH] fixes config endpoint performance issue --- .../tests/unit/settings/test_development.py | 6 ++++++ awx/main/tests/unit/test_utils.py | 20 +++++++++++++++++++ awx/main/utils.py | 3 +++ awx/settings/development.py | 4 ++++ 4 files changed, 33 insertions(+) create mode 100644 awx/main/tests/unit/settings/test_development.py create mode 100644 awx/main/tests/unit/test_utils.py diff --git a/awx/main/tests/unit/settings/test_development.py b/awx/main/tests/unit/settings/test_development.py new file mode 100644 index 0000000000..9367a3db85 --- /dev/null +++ b/awx/main/tests/unit/settings/test_development.py @@ -0,0 +1,6 @@ +import pytest + +def test_ANSILE_VERSION(mocker): + from django.conf import settings + assert hasattr(settings, 'ANSIBLE_VERSION') + diff --git a/awx/main/tests/unit/test_utils.py b/awx/main/tests/unit/test_utils.py new file mode 100644 index 0000000000..231a1ec7c5 --- /dev/null +++ b/awx/main/tests/unit/test_utils.py @@ -0,0 +1,20 @@ +import pytest +import subprocess + +from awx.main.utils import get_ansible_version + +def test_dev(mocker, settings): + settings.ANSIBLE_VERSION = mocker.Mock() + + res = get_ansible_version() + + assert res == settings.ANSIBLE_VERSION + +def test_production(mocker, settings): + mock_Popen = mocker.MagicMock() + mocker.patch.object(subprocess, 'Popen', mock_Popen) + del settings.ANSIBLE_VERSION + + get_ansible_version() + + mock_Popen.assert_called_with(['ansible', '--version'], stdout=subprocess.PIPE) diff --git a/awx/main/utils.py b/awx/main/utils.py index f1d85f72b2..4a7ce90f54 100644 --- a/awx/main/utils.py +++ b/awx/main/utils.py @@ -97,6 +97,9 @@ def get_ansible_version(): ''' Return Ansible version installed. ''' + from django.conf import settings + if hasattr(settings, 'ANSIBLE_VERSION'): + return settings.ANSIBLE_VERSION try: proc = subprocess.Popen(['ansible', '--version'], stdout=subprocess.PIPE) diff --git a/awx/settings/development.py b/awx/settings/development.py index cc4febdbae..a9ae83b242 100644 --- a/awx/settings/development.py +++ b/awx/settings/development.py @@ -10,6 +10,8 @@ import traceback # Django Split Settings from split_settings.tools import optional, include +from awx.main.utils import get_ansible_version + # Load default settings. from defaults import * # NOQA @@ -33,6 +35,8 @@ AWX_PROOT_ENABLED = True PENDO_TRACKING_STATE = "off" +ANSIBLE_VERSION = get_ansible_version() + # Use Django-Jenkins if installed. Only run tests for awx.main app. try: import django_jenkins