From f17ced8f9cd2c8c2a4c1c0a97ac10b2b27f9ccd3 Mon Sep 17 00:00:00 2001 From: John Westcott IV Date: Mon, 27 Apr 2020 14:25:23 -0400 Subject: [PATCH] Fixing integration tests for deprecation warnings --- .../plugins/modules/tower_credential.py | 23 +++++++++++-------- .../plugins/modules/tower_notification.py | 6 ++++- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/awx_collection/plugins/modules/tower_credential.py b/awx_collection/plugins/modules/tower_credential.py index 2fe3ca45c2..5a260f0ef3 100644 --- a/awx_collection/plugins/modules/tower_credential.py +++ b/awx_collection/plugins/modules/tower_credential.py @@ -364,38 +364,41 @@ def main(): # End backwards compatability state = module.params.get('state') - # Attempt to look up the related items the user specified (these will fail the module if not found) - if organization: - org_id = module.resolve_name_to_id('organizations', organization) - if user: - user_id = module.resolve_name_to_id('users', user) - if team: - team_id = module.resolve_name_to_id('teams', team) - + # Deprication warnings + for legacy_input in OLD_INPUT_NAMES: + if module.params.get(legacy_input) is not None: + module.deprecate(msg='{0} parameter has been deprecated, please use inputs instead'.format(legacy_input), version="3.6") if kind: module.deprecate(msg='The kind parameter has been deprecated, please use credential_type instead', version="3.6") cred_type_id = module.resolve_name_to_id('credential_types', credential_type if credential_type else KIND_CHOICES[kind]) + if organization: + org_id = module.resolve_name_to_id('organizations', organization) # Attempt to look up the object based on the provided name, credential type and optional organization lookup_data = { 'name': name, 'credential_type': cred_type_id, } - if organization: lookup_data['organization'] = org_id + credential = module.get_one('credentials', **{'data': lookup_data}) if state == 'absent': # If the state was absent we can let the module delete it if needed, the module will handle exiting from this module.delete_if_needed(credential) + # Attempt to look up the related items the user specified (these will fail the module if not found) + if user: + user_id = module.resolve_name_to_id('users', user) + if team: + team_id = module.resolve_name_to_id('teams', team) + # Create credential input from legacy inputs credential_inputs = {} for legacy_input in OLD_INPUT_NAMES: if module.params.get(legacy_input) is not None: - module.deprecate(msg='{0} parameter has been deprecated, please use inputs instead'.format(legacy_input), version="3.6") credential_inputs[legacy_input] = module.params.get(legacy_input) if inputs: credential_inputs.update(inputs) diff --git a/awx_collection/plugins/modules/tower_notification.py b/awx_collection/plugins/modules/tower_notification.py index 875a912f84..52d9ccaa5f 100644 --- a/awx_collection/plugins/modules/tower_notification.py +++ b/awx_collection/plugins/modules/tower_notification.py @@ -403,6 +403,11 @@ def main(): messages = module.params.get('messages') state = module.params.get('state') + # Deprecation warnings + for legacy_input in OLD_INPUT_NAMES: + if module.params.get(legacy_input) is not None: + module.deprecate(msg='{0} parameter has been deprecated, please use notification_configuration instead.'.format(legacy_input), version="3.6") + # Attempt to look up the related items the user specified (these will fail the module if not found) organization_id = None if organization: @@ -424,7 +429,6 @@ def main(): final_notification_configuration = {} for legacy_input in OLD_INPUT_NAMES: if module.params.get(legacy_input) is not None: - module.deprecate(msg='{0} parameter has been deprecated, please use notification_configuration instead.'.format(legacy_input), version="3.6") final_notification_configuration[legacy_input] = module.params.get(legacy_input) # Give anything in notification_configuration prescedence over the individual inputs if notification_configuration is not None: