From 39b26c8f0e5d08ae8dc80b538b00f7e2905bfe4d Mon Sep 17 00:00:00 2001 From: Seth Foster Date: Thu, 6 May 2021 15:04:52 -0400 Subject: [PATCH] Added env variable CONTROLLER_HOST, et al. Add awx.awx namespace to the runtime.yml redirects, and added templating task to change to ansible.controller --- awx_collection/meta/runtime.yml | 82 +++++++++---------- .../plugins/inventory/controller.py | 2 +- .../plugins/lookup/controller_api.py | 2 +- .../plugins/module_utils/controller_api.py | 30 +++---- .../plugins/module_utils/controller_module.py | 10 +-- awx_collection/test/awx/test_module_utils.py | 6 +- .../targets/credential/tasks/main.yml | 2 +- .../targets/organization/tasks/main.yml | 2 +- .../roles/template_galaxy/tasks/main.yml | 6 ++ 9 files changed, 75 insertions(+), 67 deletions(-) diff --git a/awx_collection/meta/runtime.yml b/awx_collection/meta/runtime.yml index ff29c22ba7..b8a868a73e 100644 --- a/awx_collection/meta/runtime.yml +++ b/awx_collection/meta/runtime.yml @@ -39,93 +39,93 @@ plugin_routing: redirect: awx.awx.schedule_rrule modules: tower_job_list: - redirect: job_list + redirect: awx.awx.job_list tower_job_launch: - redirect: job_launch + redirect: awx.awx.job_launch tower_workflow_job_template: - redirect: workflow_job_template + redirect: awx.awx.workflow_job_template tower_team: - redirect: team + redirect: awx.awx.team tower_job_wait: - redirect: job_wait + redirect: awx.awx.job_wait tower_application: - redirect: application + redirect: awx.awx.application tower_ad_hoc_command_wait: - redirect: ad_hoc_command_wait + redirect: awx.awx.ad_hoc_command_wait tower_credential: - redirect: credential + redirect: awx.awx.credential tower_label: - redirect: label + redirect: awx.awx.label tower_group: - redirect: group + redirect: awx.awx.group tower_host: - redirect: host + redirect: awx.awx.host tower_schedule: - redirect: schedule + redirect: awx.awx.schedule tower_role: - redirect: role + redirect: awx.awx.role tower_ad_hoc_command: - redirect: ad_hoc_command + redirect: awx.awx.ad_hoc_command tower_execution_environment: - redirect: execution_environment + redirect: awx.awx.execution_environment tower_inventory_source_update: - redirect: inventory_source_update + redirect: awx.awx.inventory_source_update tower_instance_group: - redirect: instance_group + redirect: awx.awx.instance_group tower_settings: - redirect: settings + redirect: awx.awx.settings tower_meta: - redirect: controller_meta + redirect: awx.awx.controller_meta tower_export: - redirect: export + redirect: awx.awx.export tower_ad_hoc_command_cancel: - redirect: ad_hoc_command_cancel + redirect: awx.awx.ad_hoc_command_cancel tower_inventory_source: - redirect: inventory_source + redirect: awx.awx.inventory_source tower_user: - redirect: user + redirect: awx.awx.user tower_workflow_launch: - redirect: workflow_launch + redirect: awx.awx.workflow_launch tower_project: - redirect: project + redirect: awx.awx.project tower_token: - redirect: token + redirect: awx.awx.token tower_credential_type: - redirect: credential_type + redirect: awx.awx.credential_type tower_license: - redirect: license + redirect: awx.awx.license tower_project_update: - redirect: project_update + redirect: awx.awx.project_update tower_notification_template: - redirect: notification_template + redirect: awx.awx.notification_template tower_organization: - redirect: organization + redirect: awx.awx.organization tower_job_template: - redirect: job_template + redirect: awx.awx.job_template tower_workflow_job_template_node: - redirect: workflow_job_template_node + redirect: awx.awx.workflow_job_template_node tower_job_cancel: - redirect: job_cancel + redirect: awx.awx.job_cancel tower_import: - redirect: import + redirect: awx.awx.import tower_credential_input_source: - redirect: credential_input_source + redirect: awx.awx.credential_input_source tower_inventory: - redirect: inventory + redirect: awx.awx.inventory tower_receive: - redirect: receive + redirect: awx.awx.receive deprecation: removal_date: TBD warning_text: see plugin documentation for details tower_send: - redirect: send + redirect: awx.awx.send deprecation: removal_date: TBD warning_text: see plugin documentation for details tower_workflow_template: - redirect: workflow_template + redirect: awx.awx.workflow_template deprecation: removal_date: TBD warning_text: see plugin documentation for details tower_notification: - redirect: notification_template + redirect: awx.awx.notification_template diff --git a/awx_collection/plugins/inventory/controller.py b/awx_collection/plugins/inventory/controller.py index c3d24cd810..6cbdc8f328 100644 --- a/awx_collection/plugins/inventory/controller.py +++ b/awx_collection/plugins/inventory/controller.py @@ -81,7 +81,7 @@ def handle_error(**kwargs): class InventoryModule(BaseInventoryPlugin): NAME = 'awx.awx.controller' # REPLACE - # Stays backward compatible with tower inventory script. + # Stays backward compatible with the inventory script. # If the user supplies '@tower_inventory' as path, the plugin will read from environment variables. no_config_file_supplied = False diff --git a/awx_collection/plugins/lookup/controller_api.py b/awx_collection/plugins/lookup/controller_api.py index 90dcaebfdf..d959d17b8a 100644 --- a/awx_collection/plugins/lookup/controller_api.py +++ b/awx_collection/plugins/lookup/controller_api.py @@ -75,7 +75,7 @@ EXAMPLES = """ - name: Load the UI settings specifying the connection info set_fact: - controller_settings: "{{ lookup('awx.awx.controller_api', 'settings/ui' host='tower.example.com', username='admin', password=my_pass_var, verify_ssl=False) }}" + controller_settings: "{{ lookup('awx.awx.controller_api', 'settings/ui' host='controller.example.com', username='admin', password=my_pass_var, verify_ssl=False) }}" - name: Report the usernames of all users with admin privs debug: diff --git a/awx_collection/plugins/module_utils/controller_api.py b/awx_collection/plugins/module_utils/controller_api.py index b655c261da..61aad6712c 100644 --- a/awx_collection/plugins/module_utils/controller_api.py +++ b/awx_collection/plugins/module_utils/controller_api.py @@ -254,26 +254,28 @@ class ControllerAPIModule(ControllerModule): # In PY2 we get back an HTTPResponse object but PY2 is returning an addinfourl # First try to get the headers in PY3 format and then drop down to PY2. try: - tower_type = response.getheader('X-API-Product-Name', None) - tower_version = response.getheader('X-API-Product-Version', None) + controller_type = response.getheader('X-API-Product-Name', None) + controller_version = response.getheader('X-API-Product-Version', None) except Exception: - tower_type = response.info().getheader('X-API-Product-Name', None) - tower_version = response.info().getheader('X-API-Product-Version', None) + controller_type = response.info().getheader('X-API-Product-Name', None) + controller_version = response.info().getheader('X-API-Product-Version', None) parsed_collection_version = Version(self._COLLECTION_VERSION).version - parsed_tower_version = Version(tower_version).version - if tower_type == 'AWX': + parsed_controller_version = Version(controller_version).version + if controller_type == 'AWX': collection_compare_ver = parsed_collection_version[0] - tower_compare_ver = parsed_tower_version[0] + controller_compare_ver = parsed_controller_version[0] else: collection_compare_ver = "{0}.{1}".format(parsed_collection_version[0], parsed_collection_version[1]) - tower_compare_ver = '{0}.{1}'.format(parsed_tower_version[0], parsed_tower_version[1]) + controller_compare_ver = '{0}.{1}'.format(parsed_controller_version[0], parsed_controller_version[1]) - if self._COLLECTION_TYPE not in self.collection_to_version or self.collection_to_version[self._COLLECTION_TYPE] != tower_type: - self.warn("You are using the {0} version of this collection but connecting to {1}".format(self._COLLECTION_TYPE, tower_type)) - elif collection_compare_ver != tower_compare_ver: + if self._COLLECTION_TYPE not in self.collection_to_version or self.collection_to_version[self._COLLECTION_TYPE] != controller_type: + self.warn("You are using the {0} version of this collection but connecting to {1}".format(self._COLLECTION_TYPE, controller_type)) + elif collection_compare_ver != controller_compare_ver: self.warn( - "You are running collection version {0} but connecting to {2} version {1}".format(self._COLLECTION_VERSION, tower_version, tower_type) + "You are running collection version {0} but connecting to {2} version {1}".format( + self._COLLECTION_VERSION, controller_version, controller_type + ) ) self.version_checked = True @@ -694,10 +696,10 @@ class ControllerAPIModule(ControllerModule): resp = he.read() except Exception as e: resp = 'unknown {0}'.format(e) - self.warn('Failed to release tower token: {0}, response: {1}'.format(he, resp)) + self.warn('Failed to release token: {0}, response: {1}'.format(he, resp)) except (Exception) as e: # Sanity check: Did the server send back some kind of internal error? - self.warn('Failed to release tower token {0}: {1}'.format(self.oauth_token_id, e)) + self.warn('Failed to release token {0}: {1}'.format(self.oauth_token_id, e)) def is_job_done(self, job_status): if job_status in ['new', 'pending', 'waiting', 'running']: diff --git a/awx_collection/plugins/module_utils/controller_module.py b/awx_collection/plugins/module_utils/controller_module.py index 1f2bed7c33..234f75a43b 100644 --- a/awx_collection/plugins/module_utils/controller_module.py +++ b/awx_collection/plugins/module_utils/controller_module.py @@ -32,11 +32,11 @@ class ItemNotDefined(Exception): class ControllerModule(AnsibleModule): url = None AUTH_ARGSPEC = dict( - tower_host=dict(required=False, fallback=(env_fallback, ['TOWER_HOST'])), - tower_username=dict(required=False, fallback=(env_fallback, ['TOWER_USERNAME'])), - tower_password=dict(no_log=True, required=False, fallback=(env_fallback, ['TOWER_PASSWORD'])), - validate_certs=dict(type='bool', aliases=['tower_verify_ssl'], required=False, fallback=(env_fallback, ['TOWER_VERIFY_SSL'])), - tower_oauthtoken=dict(type='raw', no_log=True, required=False, fallback=(env_fallback, ['TOWER_OAUTH_TOKEN'])), + tower_host=dict(required=False, fallback=(env_fallback, ['CONTROLLER_HOST', 'TOWER_HOST'])), + tower_username=dict(required=False, fallback=(env_fallback, ['CONTROLLER_USERNAME', 'TOWER_USERNAME'])), + tower_password=dict(no_log=True, required=False, fallback=(env_fallback, ['CONTROLLER_PASSWORD', 'TOWER_PASSWORD'])), + validate_certs=dict(type='bool', aliases=['tower_verify_ssl'], required=False, fallback=(env_fallback, ['CONTROLLER_VERIFY_SSL', 'TOWER_VERIFY_SSL'])), + tower_oauthtoken=dict(type='raw', no_log=True, required=False, fallback=(env_fallback, ['CONTROLLER_OAUTH_TOKEN', 'TOWER_OAUTH_TOKEN'])), tower_config_file=dict(type='path', required=False, default=None), ) short_params = { diff --git a/awx_collection/test/awx/test_module_utils.py b/awx_collection/test/awx/test_module_utils.py index 000a5e7809..fdfc382f77 100644 --- a/awx_collection/test/awx/test_module_utils.py +++ b/awx_collection/test/awx/test_module_utils.py @@ -10,12 +10,12 @@ from requests.models import Response from unittest import mock awx_name = 'AWX' -tower_name = 'Red Hat Automation Platform Controller' +controller_name = 'Red Hat Automation Platform Controller' ping_version = '1.2.3' def getTowerheader(self, header_name, default): - mock_headers = {'X-API-Product-Name': tower_name, 'X-API-Product-Version': ping_version} + mock_headers = {'X-API-Product-Name': controller_name, 'X-API-Product-Version': ping_version} return mock_headers.get(header_name, default) @@ -107,7 +107,7 @@ def test_version_warning_strictness_controller(collection_import, silence_warnin my_module._COLLECTION_TYPE = "controller" my_module.get_endpoint('ping') silence_warning.assert_called_once_with( - 'You are running collection version {0} but connecting to {1} version {2}'.format(my_module._COLLECTION_VERSION, tower_name, ping_version) + 'You are running collection version {0} but connecting to {1} version {2}'.format(my_module._COLLECTION_VERSION, controller_name, ping_version) ) diff --git a/awx_collection/tests/integration/targets/credential/tasks/main.yml b/awx_collection/tests/integration/targets/credential/tasks/main.yml index cbd23c0c76..dda9c4d4cf 100644 --- a/awx_collection/tests/integration/targets/credential/tasks/main.yml +++ b/awx_collection/tests/integration/targets/credential/tasks/main.yml @@ -695,7 +695,7 @@ organization: Default state: present kind: tower - host: https://tower.example.org + host: https://controller.example.org username: joe password: secret register: result diff --git a/awx_collection/tests/integration/targets/organization/tasks/main.yml b/awx_collection/tests/integration/targets/organization/tasks/main.yml index 50e6e7b2d1..a27054a072 100644 --- a/awx_collection/tests/integration/targets/organization/tasks/main.yml +++ b/awx_collection/tests/integration/targets/organization/tasks/main.yml @@ -90,7 +90,7 @@ that: - "result is not changed" -# Test behaviour common to all tower modules +# Test behaviour common to all controller modules - name: Check that SSL is available and verify_ssl is enabled (task must fail) organization: name: Default diff --git a/awx_collection/tools/roles/template_galaxy/tasks/main.yml b/awx_collection/tools/roles/template_galaxy/tasks/main.yml index 99f3356a47..0e3f0630a9 100644 --- a/awx_collection/tools/roles/template_galaxy/tasks/main.yml +++ b/awx_collection/tools/roles/template_galaxy/tasks/main.yml @@ -34,6 +34,12 @@ regexp: "^ NAME = 'awx.awx.controller' # REPLACE$" replace: " NAME = '{{ collection_namespace }}.{{ collection_package }}.controller' # REPLACE" + - name: Change runtime.yml redirect destinations + replace: + path: "{{ collection_path}}/meta/runtime.yml" + regexp: "redirect: awx.awx." + replace: "redirect: '{{ collection_namespace }}.{{ collection_package }}." + - name: get list of test files find: paths: "{{ collection_path }}/tests/integration/targets/"