add some Tower module integration tests (and fix a bug or two) (#37421)

* add additional test coverage for tower modules

* add test coverage for the tower_credential module

* add test coverage for the tower_user module

* fix a bug in py3 for tower_credential when ssh_key_data is specified

* add test coverage for tower_host, tower_label, and tower_project

* add test coverage for tower_inventory and tower_job_template

* add more test coverage for tower modules

- tower_job_launch
- tower_job_list
- tower_job_wait
- tower_job_cancel

* add a check mode/version assertion for tower module integration tests

* add test coverage for the tower_role module

* add test coverage for the tower_group module

* add more integration test edge cases for various tower modules

* give the job_wait module more time before failing

* randomize passwords in the tower_user and tower_group tests
This commit is contained in:
Ryan Petrello
2018-03-16 13:28:19 -04:00
committed by AlanCoding
parent 0b26297177
commit 65aeb2b68a
4 changed files with 25 additions and 8 deletions

View File

@@ -73,6 +73,14 @@ options:
client: client:
description: description:
- Client or application ID for azure_rm type. - Client or application ID for azure_rm type.
required: False
default: null
security_token:
description:
- STS token for aws type.
required: False
default: null
version_added: "2.6"
secret: secret:
description: description:
- Secret token for azure_rm type. - Secret token for azure_rm type.
@@ -119,6 +127,7 @@ EXAMPLES = '''
import os import os
from ansible.module_utils._text import to_text
from ansible.module_utils.ansible_tower import tower_argument_spec, tower_auth_config, tower_check_mode, HAS_TOWER_CLI from ansible.module_utils.ansible_tower import tower_argument_spec, tower_auth_config, tower_check_mode, HAS_TOWER_CLI
try: try:
@@ -184,6 +193,7 @@ def main():
authorize=dict(type='bool', default=False), authorize=dict(type='bool', default=False),
authorize_password=dict(no_log=True), authorize_password=dict(no_log=True),
client=dict(), client=dict(),
security_token=dict(),
secret=dict(), secret=dict(),
tenant=dict(), tenant=dict(),
subscription=dict(), subscription=dict(),
@@ -254,13 +264,14 @@ def main():
if os.path.isdir(filename): if os.path.isdir(filename):
module.fail_json(msg='attempted to read contents of directory: %s' % filename) module.fail_json(msg='attempted to read contents of directory: %s' % filename)
with open(filename, 'rb') as f: with open(filename, 'rb') as f:
module.params['ssh_key_data'] = f.read() module.params['ssh_key_data'] = to_text(f.read())
for key in ('authorize', 'authorize_password', 'client', 'secret', for key in ('authorize', 'authorize_password', 'client',
'tenant', 'subscription', 'domain', 'become_method', 'security_token', 'secret', 'tenant', 'subscription',
'become_username', 'become_password', 'vault_password', 'domain', 'become_method', 'become_username',
'project', 'host', 'username', 'password', 'become_password', 'vault_password', 'project', 'host',
'ssh_key_data', 'ssh_key_unlock'): 'username', 'password', 'ssh_key_data',
'ssh_key_unlock'):
if 'kind' in params: if 'kind' in params:
params[key] = module.params.get(key) params[key] = module.params.get(key)
elif module.params.get(key): elif module.params.get(key):

View File

@@ -140,7 +140,8 @@ def main():
if variables: if variables:
if variables.startswith('@'): if variables.startswith('@'):
filename = os.path.expanduser(variables[1:]) filename = os.path.expanduser(variables[1:])
variables = module.contents_from_file(filename) with open(filename, 'r') as f:
variables = f.read()
json_output = {'group': name, 'state': state} json_output = {'group': name, 'state': state}

View File

@@ -100,7 +100,8 @@ def main():
if variables: if variables:
if variables.startswith('@'): if variables.startswith('@'):
filename = os.path.expanduser(variables[1:]) filename = os.path.expanduser(variables[1:])
variables = module.contents_from_file(filename) with open(filename, 'r') as f:
variables = f.read()
json_output = {'host': name, 'state': state} json_output = {'host': name, 'state': state}

View File

@@ -87,6 +87,10 @@ def update_resources(module, p):
by name using their unique field (identity) by name using their unique field (identity)
''' '''
params = p.copy() params = p.copy()
for key in p:
if key.startswith('tower_'):
params.pop(key)
params.pop('state', None)
identity_map = { identity_map = {
'user': 'username', 'user': 'username',
'team': 'name', 'team': 'name',