mirror of
https://github.com/ansible/awx.git
synced 2026-05-19 23:07:42 -02:30
Adding more through testing of tower_oauthtoken including failure messages
This commit is contained in:
@@ -3,7 +3,7 @@ __metaclass__ = type
|
|||||||
|
|
||||||
from ansible.module_utils.basic import AnsibleModule, env_fallback
|
from ansible.module_utils.basic import AnsibleModule, env_fallback
|
||||||
from ansible.module_utils.urls import Request, SSLValidationError, ConnectionError
|
from ansible.module_utils.urls import Request, SSLValidationError, ConnectionError
|
||||||
from ansible.module_utils.six import PY2
|
from ansible.module_utils.six import PY2, string_types
|
||||||
from ansible.module_utils.six.moves import StringIO
|
from ansible.module_utils.six.moves import StringIO
|
||||||
from ansible.module_utils.six.moves.urllib.parse import urlparse, urlencode
|
from ansible.module_utils.six.moves.urllib.parse import urlparse, urlencode
|
||||||
from ansible.module_utils.six.moves.urllib.error import HTTPError
|
from ansible.module_utils.six.moves.urllib.error import HTTPError
|
||||||
@@ -98,10 +98,16 @@ class TowerModule(AnsibleModule):
|
|||||||
|
|
||||||
# Perform magic depending on whether tower_oauthtoken is a string or a dict
|
# Perform magic depending on whether tower_oauthtoken is a string or a dict
|
||||||
if self.params.get('tower_oauthtoken'):
|
if self.params.get('tower_oauthtoken'):
|
||||||
if type(self.params.get('tower_oauthtoken')) is dict:
|
token_param = self.params.get('tower_oauthtoken')
|
||||||
setattr(self, 'oauth_token', self.params.get('tower_oauthtoken')['token'])
|
if type(token_param) is dict:
|
||||||
elif 'token' in self.params.get('tower_oauthtoken'):
|
if 'token' in token_param:
|
||||||
setattr(self, 'oauth_token', self.params.get('tower_oauthtoken'))
|
self.oauth_token = self.params.get('tower_oauthtoken')['token']
|
||||||
|
else:
|
||||||
|
self.fail_json(msg="The provided dict in tower_oauthtoken did not properly contain the token entry")
|
||||||
|
elif isinstance(token_param, string_types):
|
||||||
|
self.oauth_token = self.params.get('tower_oauthtoken')
|
||||||
|
else:
|
||||||
|
self.fail_json(msg="The provided tower_oauthtoken type was not valid ({0}), please refer to ansible-doc for valid options".format(type(token_param).__name__))
|
||||||
|
|
||||||
# Perform some basic validation
|
# Perform some basic validation
|
||||||
if not re.match('^https{0,1}://', self.host):
|
if not re.match('^https{0,1}://', self.host):
|
||||||
|
|||||||
@@ -3,6 +3,30 @@
|
|||||||
set_fact:
|
set_fact:
|
||||||
token_description: "AWX-Collection-tests-tower_token-description-{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
|
token_description: "AWX-Collection-tests-tower_token-description-{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
|
||||||
|
|
||||||
|
- name: Try to use a token as a dict which is missing the token parameter
|
||||||
|
tower_job_list:
|
||||||
|
tower_oauthtoken:
|
||||||
|
not_token: "This has no token entry"
|
||||||
|
register: results
|
||||||
|
ignore_errors: True
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- results is failed
|
||||||
|
- '"The provided dict in tower_oauthtoken did not properly contain the token entry" == results.msg'
|
||||||
|
|
||||||
|
- name: Try to use a token as a list
|
||||||
|
tower_job_list:
|
||||||
|
tower_oauthtoken:
|
||||||
|
- dummy_token
|
||||||
|
register: results
|
||||||
|
ignore_errors: True
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- results is failed
|
||||||
|
- '"The provided tower_oauthtoken type was not valid (list), please refer to ansible-doc for valid options" == results.msg'
|
||||||
|
|
||||||
- block:
|
- block:
|
||||||
- name: Create a Token
|
- name: Create a Token
|
||||||
tower_token:
|
tower_token:
|
||||||
@@ -14,10 +38,12 @@
|
|||||||
- name: Validate our token works by token
|
- name: Validate our token works by token
|
||||||
tower_job_list:
|
tower_job_list:
|
||||||
tower_oauthtoken: "{{ tower_token.token }}"
|
tower_oauthtoken: "{{ tower_token.token }}"
|
||||||
|
register: job_list
|
||||||
|
|
||||||
- name: Validate out token works by object
|
- name: Validate out token works by object
|
||||||
tower_job_list:
|
tower_job_list:
|
||||||
tower_oauthtoken: "{{ tower_token }}"
|
tower_oauthtoken: "{{ tower_token }}"
|
||||||
|
register: job_list
|
||||||
|
|
||||||
always:
|
always:
|
||||||
- name: Delete our Token with our own token
|
- name: Delete our Token with our own token
|
||||||
|
|||||||
Reference in New Issue
Block a user