Further module conversion changes, unit test changes

Multiple module changes

Added on_change callback

Added head_endpoint

Added additional error returns

Respond with a try an ID message if multiple assets found by name via return_none_on_404 kwarg

Diferentiated between login and logout token errors

Added is_job_done method
This commit is contained in:
beeankha
2020-01-24 11:30:16 -05:00
parent 68926dad27
commit 7c0ad461a5
10 changed files with 224 additions and 47 deletions

View File

@@ -130,17 +130,17 @@ def main():
module.default_check_mode()
# These will be passed into the create/updates
credental_type_params = {
credential_type_params = {
'name': new_name if new_name else name,
'kind': kind,
'managed_by_tower': False,
}
if module.params.get('description'):
credental_type_params['description'] = module.params.get('description')
credential_type_params['description'] = module.params.get('description')
if module.params.get('inputs'):
credental_type_params['inputs'] = module.params.get('inputs')
credential_type_params['inputs'] = module.params.get('inputs')
if module.params.get('injectors'):
credental_type_params['injectors'] = module.params.get('injectors')
credential_type_params['injectors'] = module.params.get('injectors')
# Attempt to lookup credential_type based on the provided name and org ID
credential_type = module.get_one('credential_types', **{
@@ -159,12 +159,12 @@ def main():
elif state == 'present' and not credential_type:
# if the state was present and we couldn't find a credential_type we can build one, the module will handle exiting on its own
module.post_endpoint('credential_types', item_type='credential type', item_name=name, **{
'data': credental_type_params
'data': credential_type_params
})
else:
# If the state was present and we had a credential_type we can see if we need to update it
# This will handle existing on its own
module.update_if_needed(credential_type, credental_type_params)
module.update_if_needed(credential_type, credential_type_params)
if __name__ == '__main__':

View File

@@ -1,7 +1,7 @@
#!/usr/bin/python
# coding: utf-8 -*-
# (c) 20189, John Westcott IV <john.westcott.iv@redhat.com>
# (c) 2019, John Westcott IV <john.westcott.iv@redhat.com>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
@@ -65,7 +65,7 @@ def main():
json_output = {'changed': False}
if not module.params.get('eula_accepted'):
module.fail_json(msg='You must accept the EULA by passing in the param eula_acepte as True')
module.fail_json(msg='You must accept the EULA by passing in the param eula_accepted as True')
json_output['old_license'] = module.get_endpoint('settings/system/')['json']['LICENSE']
new_license = module.params.get('data')

View File

@@ -90,18 +90,6 @@ def main():
state=dict(type='str', choices=['present', 'absent'], default='present', required=False),
)
# instance_groups=dict(type='list', required=False, default=[]),
# The above argument_spec fragment is being left in for reference since we may need
# it later when finalizing the changes.
# instance_groups:
# description:
# - The name of instance groups to tie to this organization
# default: []
# required: False
# The above docstring fragment is being left in for reference since we may need
# it later when finalizing the changes.
# Create a module for ourselves
module = TowerModule(argument_spec=argument_spec, supports_check_mode=True)
@@ -134,11 +122,9 @@ def main():
int_max_hosts = 0
try:
int_max_hosts = int(max_hosts)
except Exception as e:
except Exception:
module.fail_json(msg="Unable to convert max_hosts to an integer")
new_org_data['max_hosts'] = int_max_hosts
# if instance_group_objects:
# new_org_data['instance_groups'] = instance_group_objects
if state == 'absent' and not organization:
# If the state was absent and we had no organization, we can just return

View File

@@ -110,7 +110,7 @@ def main():
new_value = value
try:
new_value = loads(value)
except JSONDecodeError as e:
except JSONDecodeError:
# Attempt to deal with old tower_cli array types
if ',' in value:
new_value = re.split(r",\s+", new_value)

View File

@@ -103,7 +103,7 @@ def main():
# Create data to sent to create and update
team_fields = {
'name': name,
'name': new_name if new_name else name,
'description': description,
'organization': org_id
}