Patches from tinkering with tests and default to devel version (#8)

This causes make install_collection to avoid templating the version
  so that it can still be used as-is in development
This commit is contained in:
Alan Rominger
2020-05-18 08:51:39 -04:00
committed by GitHub
parent b904ad68a6
commit 22cdc129ad
9 changed files with 43 additions and 25 deletions

View File

@@ -393,7 +393,7 @@ symlink_collection:
ln -s $(shell pwd)/awx_collection $(COLLECTION_INSTALL) ln -s $(shell pwd)/awx_collection $(COLLECTION_INSTALL)
build_collection: build_collection:
ansible-playbook -i localhost, awx_collection/tools/template_galaxy.yml -e collection_package=$(COLLECTION_PACKAGE) -e collection_namespace=$(COLLECTION_NAMESPACE) -e collection_version=$(VERSION) ansible-playbook -i localhost, awx_collection/tools/template_galaxy.yml -e collection_package=$(COLLECTION_PACKAGE) -e collection_namespace=$(COLLECTION_NAMESPACE) -e collection_version=$(VERSION) -e '{"awx_template_version":false}'
ansible-galaxy collection build awx_collection --force --output-path=awx_collection ansible-galaxy collection build awx_collection --force --output-path=awx_collection
install_collection: build_collection install_collection: build_collection

View File

@@ -39,6 +39,7 @@ options:
tower_config_file: tower_config_file:
description: description:
- Path to the Tower or AWX config file. - Path to the Tower or AWX config file.
- If provided, the other locations for config files will not be considered.
type: path type: path
notes: notes:

View File

@@ -33,7 +33,7 @@ class ItemNotDefined(Exception):
class TowerModule(AnsibleModule): class TowerModule(AnsibleModule):
# This gets set by the make process so whatever is in here is irrelevant # This gets set by the make process so whatever is in here is irrelevant
_COLLECTION_VERSION = "11.1.0" _COLLECTION_VERSION = "devel"
_COLLECTION_TYPE = "awx" _COLLECTION_TYPE = "awx"
# This maps the collections type (awx/tower) to the values returned by the API # This maps the collections type (awx/tower) to the values returned by the API
# Those values can be found in awx/api/generics.py line 204 # Those values can be found in awx/api/generics.py line 204
@@ -114,14 +114,6 @@ class TowerModule(AnsibleModule):
local_dir = split(local_dir)[0] local_dir = split(local_dir)[0]
config_files.insert(2, join(local_dir, ".{0}".format(self.config_name))) config_files.insert(2, join(local_dir, ".{0}".format(self.config_name)))
for config_file in config_files:
if exists(config_file) and not isdir(config_file):
# Only throw a formatting error if the file exists and is not a directory
try:
self.load_config(config_file)
except ConfigFileException:
self.fail_json('The config file {0} is not properly formatted'.format(config_file))
# If we have a specified tower config, load it # If we have a specified tower config, load it
if self.params.get('tower_config_file'): if self.params.get('tower_config_file'):
duplicated_params = [] duplicated_params = []
@@ -139,6 +131,14 @@ class TowerModule(AnsibleModule):
except ConfigFileException as cfe: except ConfigFileException as cfe:
# Since we were told specifically to load this we want it to fail if we have an error # Since we were told specifically to load this we want it to fail if we have an error
self.fail_json(msg=cfe) self.fail_json(msg=cfe)
else:
for config_file in config_files:
if exists(config_file) and not isdir(config_file):
# Only throw a formatting error if the file exists and is not a directory
try:
self.load_config(config_file)
except ConfigFileException:
self.fail_json('The config file {0} is not properly formatted'.format(config_file))
def load_config(self, config_path): def load_config(self, config_path):
# Validate the config file is an actual file # Validate the config file is an actual file

View File

@@ -108,7 +108,7 @@ def run_module(request, collection_import):
sanitize_dict(py_data) sanitize_dict(py_data)
resp._content = bytes(json.dumps(django_response.data), encoding='utf8') resp._content = bytes(json.dumps(django_response.data), encoding='utf8')
resp.status_code = django_response.status_code resp.status_code = django_response.status_code
resp.headers = {'X-API-Product-Name': 'AWX', 'X-API-Product-Version': '11.0.0'} resp.headers = {'X-API-Product-Name': 'AWX', 'X-API-Product-Version': 'devel'}
if request.config.getoption('verbose') > 0: if request.config.getoption('verbose') > 0:
logger.info( logger.info(

View File

@@ -4,7 +4,6 @@ __metaclass__ = type
import pytest import pytest
from awx.main.models import ActivityStream, JobTemplate, Job, NotificationTemplate from awx.main.models import ActivityStream, JobTemplate, Job, NotificationTemplate
from unittest import mock
@pytest.mark.django_db @pytest.mark.django_db
@@ -162,9 +161,9 @@ def test_job_template_with_survey_encrypted_default(run_module, admin_user, proj
assert result.get('changed', False), result # not actually desired, but assert for sanity assert result.get('changed', False), result # not actually desired, but assert for sanity
silence_warning.assert_has_calls( silence_warning.assert_called_once_with(
[mock.call("The field survey_spec of job_template {0} has encrypted data and " "The field survey_spec of job_template {0} has encrypted data and "
"may inaccurately report task is changed.".format(result['id']))]) "may inaccurately report task is changed.".format(result['id']))
@pytest.mark.django_db @pytest.mark.django_db

View File

@@ -91,3 +91,21 @@ def test_duplicate_config(collection_import, silence_warning):
'tower_config_file. Precedence may be unstable, ' 'tower_config_file. Precedence may be unstable, '
'we suggest either using config file or params.' 'we suggest either using config file or params.'
) )
def test_no_templated_values(collection_import):
"""This test corresponds to replacements done by
awx_collection/tools/roles/template_galaxy/tasks/main.yml
Those replacements should happen at build time, so they should not be
checked into source.
"""
TowerModule = collection_import('plugins.module_utils.tower_api').TowerModule
assert TowerModule._COLLECTION_VERSION == "devel", (
'The collection version is templated when the collection is built '
'and the code should retain the placeholder of "devel".'
)
InventoryModule = collection_import('plugins.inventory.tower').InventoryModule
assert InventoryModule.NAME == 'awx.awx.tower', (
'The inventory plugin FQCN is templated when the collection is built '
'and the code should retain the default of awx.awx.'
)

View File

@@ -3,8 +3,6 @@ __metaclass__ = type
import pytest import pytest
from unittest import mock
from awx.main.models import Project from awx.main.models import Project
@@ -18,9 +16,9 @@ def test_create_project(run_module, admin_user, organization, silence_warning):
wait=False, wait=False,
scm_update_cache_timeout=5 scm_update_cache_timeout=5
), admin_user) ), admin_user)
silence_warning.assert_has_calls( silence_warning.assert_called_once_with(
[mock.call('scm_update_cache_timeout will be ignored since scm_update_on_launch ' 'scm_update_cache_timeout will be ignored since scm_update_on_launch '
'was not set to true')]) 'was not set to true')
assert result.pop('changed', None), result assert result.pop('changed', None), result

View File

@@ -41,6 +41,6 @@ def test_password_no_op_warning(run_module, admin_user, mock_auth_stuff, silence
assert result.get('changed') # not actually desired, but assert for sanity assert result.get('changed') # not actually desired, but assert for sanity
silence_warning.assert_has_calls( silence_warning.assert_called_once_with(
[mock.call("The field password of user {0} has encrypted data and " "The field password of user {0} has encrypted data and "
"may inaccurately report task is changed.".format(result['id']))]) "may inaccurately report task is changed.".format(result['id']))

View File

@@ -2,13 +2,15 @@
- name: Set the collection version in the tower_api.py file - name: Set the collection version in the tower_api.py file
replace: replace:
path: "{{ collection_path }}/plugins/module_utils/tower_api.py" path: "{{ collection_path }}/plugins/module_utils/tower_api.py"
regexp: '^ _COLLECTION_VERSION =.*' regexp: '^ _COLLECTION_VERSION = "devel"'
replace: ' _COLLECTION_VERSION = "{{ collection_version }}"' replace: ' _COLLECTION_VERSION = "{{ collection_version }}"'
when:
- "awx_template_version | default(True)"
- name: Set the collection type in the tower_api.py file - name: Set the collection type in the tower_api.py file
replace: replace:
path: "{{ collection_path }}/plugins/module_utils/tower_api.py" path: "{{ collection_path }}/plugins/module_utils/tower_api.py"
regexp: '^ _COLLECTION_TYPE =.*' regexp: '^ _COLLECTION_TYPE = "awx"'
replace: ' _COLLECTION_TYPE = "{{ collection_namespace }}"' replace: ' _COLLECTION_TYPE = "{{ collection_namespace }}"'
- name: Do file content replacements for non-default namespace or package name - name: Do file content replacements for non-default namespace or package name