Fixing exception import for tower modules (#50447)

* fixing the exception import from tower modules

* Adding tests for checking tower modules are failing with correct msg

* fixed failing tests

* fixed failing test in tower_team
This commit is contained in:
jainnikhil30 2019-01-09 20:01:21 +05:30 committed by René Moser
parent d84e21dfc8
commit cd27982959
27 changed files with 168 additions and 19 deletions

View file

@ -154,7 +154,7 @@ from ansible.module_utils.ansible_tower import TowerModule, tower_auth_config, t
try:
import tower_cli
import tower_cli.utils.exceptions as exc
import tower_cli.exceptions as exc
from tower_cli.conf import settings
except ImportError:

View file

@ -97,7 +97,7 @@ from ansible.module_utils.ansible_tower import TowerModule, tower_auth_config, t
try:
import tower_cli
import tower_cli.utils.exceptions as exc
import tower_cli.exceptions as exc
from tower_cli.conf import settings
except ImportError:

View file

@ -70,7 +70,7 @@ from ansible.module_utils.ansible_tower import TowerModule, tower_auth_config, t
try:
import tower_cli
import tower_cli.utils.exceptions as exc
import tower_cli.exceptions as exc
from tower_cli.conf import settings
except ImportError:

View file

@ -71,7 +71,7 @@ from ansible.module_utils.ansible_tower import TowerModule, tower_auth_config, t
try:
import tower_cli
import tower_cli.utils.exceptions as exc
import tower_cli.exceptions as exc
from tower_cli.conf import settings
except ImportError:

View file

@ -59,7 +59,7 @@ from ansible.module_utils.ansible_tower import TowerModule, tower_auth_config, t
try:
import tower_cli
import tower_cli.utils.exceptions as exc
import tower_cli.exceptions as exc
from tower_cli.conf import settings
except ImportError:

View file

@ -87,7 +87,7 @@ from ansible.module_utils.ansible_tower import TowerModule, tower_auth_config, t
try:
import tower_cli
import tower_cli.utils.exceptions as exc
import tower_cli.exceptions as exc
from tower_cli.conf import settings
except ImportError:

View file

@ -82,7 +82,7 @@ from ansible.module_utils.ansible_tower import TowerModule, tower_auth_config, t
try:
import tower_cli
import tower_cli.utils.exceptions as exc
import tower_cli.exceptions as exc
from tower_cli.conf import settings
except ImportError:

View file

@ -197,7 +197,7 @@ from ansible.module_utils.ansible_tower import TowerModule, tower_auth_config, t
try:
import tower_cli
import tower_cli.utils.exceptions as exc
import tower_cli.exceptions as exc
from tower_cli.conf import settings
except ImportError:

View file

@ -88,7 +88,7 @@ from ansible.module_utils.six.moves import cStringIO as StringIO
try:
import tower_cli
import tower_cli.utils.exceptions as exc
import tower_cli.exceptions as exc
from tower_cli.conf import settings
except ImportError:

View file

@ -53,7 +53,7 @@ from ansible.module_utils.ansible_tower import TowerModule, tower_auth_config, t
try:
import tower_cli
import tower_cli.utils.exceptions as exc
import tower_cli.exceptions as exc
from tower_cli.conf import settings
except ImportError:

View file

@ -52,7 +52,7 @@ from ansible.module_utils.ansible_tower import TowerModule, tower_auth_config, t
try:
import tower_cli
import tower_cli.utils.exceptions as exc
import tower_cli.exceptions as exc
from tower_cli.conf import settings
except ImportError:

View file

@ -88,7 +88,7 @@ from ansible.module_utils.ansible_tower import TowerModule, tower_auth_config, t
try:
import tower_cli
import tower_cli.utils.exceptions as exc
import tower_cli.exceptions as exc
from tower_cli.conf import settings
except ImportError:

View file

@ -75,7 +75,7 @@ from ansible.module_utils.ansible_tower import TowerModule, tower_auth_config, t
try:
import tower_cli
import tower_cli.utils.exceptions as exc
import tower_cli.exceptions as exc
from tower_cli.conf import settings
except ImportError:

View file

@ -58,7 +58,7 @@ from ansible.module_utils.ansible_tower import TowerModule, tower_auth_config, t
try:
import tower_cli
import tower_cli.utils.exceptions as exc
import tower_cli.exceptions as exc
from tower_cli.conf import settings
except ImportError:

View file

@ -54,7 +54,7 @@ from ansible.module_utils.ansible_tower import TowerModule, tower_auth_config, t
try:
import tower_cli
import tower_cli.utils.exceptions as exc
import tower_cli.exceptions as exc
from tower_cli.conf import settings
except ImportError:

View file

@ -75,7 +75,7 @@ from ansible.module_utils.ansible_tower import TowerModule, tower_auth_config, t
try:
import tower_cli
import tower_cli.utils.exceptions as exc
import tower_cli.exceptions as exc
from tower_cli.conf import settings
except ImportError:

View file

@ -111,7 +111,7 @@
- assert:
that:
- "result is failed"
- "'must be set when SSH key is encrypted' in result.module_stderr"
- "'must be set when SSH key is encrypted' in result.msg"
- name: Create an invalid SSH credential (Organization not found)
tower_credential:
@ -126,7 +126,7 @@
- assert:
that:
- "result is failed"
- "'The requested object could not be found' in result.module_stderr"
- "'The requested object could not be found' in result.msg"
- name: Delete an SSH credential
tower_credential:
@ -522,3 +522,17 @@
- assert:
that:
- "result is changed"
- name: Check module fails with correct msg
tower_credential:
name: test-credential
description: Credential Description
kind: ssh
organization: test-non-existing-org
state: present
register: result
ignore_errors: true
- assert:
that:
- "result.msg =='Failed to update credential, organization not found: The requested object could not be found.'"

View file

@ -32,3 +32,16 @@
- assert:
that:
- "result is changed"
- name: Check module fails with correct msg
tower_group:
name: test-group
description: Group Description
inventory: test-non-existing-inventory
state: present
register: result
ignore_errors: true
- assert:
that:
- "result.msg =='Failed to update the group, inventory not found: The requested object could not be found.'"

View file

@ -31,3 +31,16 @@
- assert:
that:
- "result is changed"
- name: Check module fails with correct msg
tower_host:
name: test-host
description: Host Description
inventory: test-non-existing-inventory
state: present
register: result
ignore_errors: true
- assert:
that:
- "result.msg =='Failed to update host, inventory not found: The requested object could not be found.'"

View file

@ -19,3 +19,16 @@
- assert:
that:
- "result is changed"
- name: Check module fails with correct msg
tower_inventory:
name: test-inventory
description: Inventory Description
organization: test-non-existing-org
state: present
register: result
ignore_errors: true
- assert:
that:
- "result.msg =='Failed to update inventory, organization not found: The requested object could not be found.'"

View file

@ -13,3 +13,13 @@
- name: Cancel the job
tower_job_cancel:
job_id: "{{ job.id }}"
- name: Check module fails with correct msg
tower_job_cancel:
job_id: 9999999999
register: result
ignore_errors: true
- assert:
that:
- "result.msg =='Unable to cancel job_id/9999999999: The requested object could not be found.'"

View file

@ -9,3 +9,15 @@
that:
- "result is changed"
- "result.status == 'pending'"
- name: Check module fails with correct msg
tower_job_launch:
job_template: "Non Existing Job Template"
inventory: "Test Inventory"
credential: "Test Credential"
register: result
ignore_errors: true
- assert:
that:
- "result.msg =='Unable to launch job, job_template/Non Existing Job Template was not found: The requested object could not be found.'"

View file

@ -14,3 +14,13 @@
tower_job_wait:
job_id: "{{ job.id }}"
timeout: 60
- name: Check module fails with correct msg
tower_job_wait:
job_id: "99999999"
register: result
ignore_errors: true
- assert:
that:
- "result.msg =='Unable to wait, no job_id 99999999 found: The requested object could not be found.'"

View file

@ -4,4 +4,16 @@
organization: Default
state: present
- name: Check module fails with correct msg
tower_label:
name: "Test Label"
organization: "Non existing org"
state: present
register: result
ignore_errors: true
- assert:
that:
- "result.msg == 'Failed to update label, organization not found: The requested object could not be found.'"
# TODO: Deleting labels doesn't seem to work currently

View file

@ -76,3 +76,31 @@
- assert:
that:
- "multi_org_cred_project is changed"
- name: Check module fails with correct msg
tower_project:
name: TestProject
organization: Non Existing Org
scm_type: git
scm_url: "https://github.com/ansible/ansible"
scm_credential: TestCred1
register: result
ignore_errors: true
- assert:
that:
- "result.msg == 'Failed to update project, organization not found: Non Existing Org'"
- name: Check module fails with correct msg
tower_project:
name: TestProject
organization: TestOrg1
scm_type: git
scm_url: "https://github.com/ansible/ansible"
scm_credential: Non Existing Credential
register: result
ignore_errors: true
- assert:
that:
- "result.msg =='Failed to update project, credential not found: Non Existing Credential'"

View file

@ -9,7 +9,7 @@
- name: Assert a meaningful error was provided for the failed Tower team creation
assert:
that:
- "'The requested object could not be found.' in result.exception"
- "'The requested object could not be found.' in result.msg"
- name: Create a Tower team
tower_team:
@ -31,3 +31,15 @@
- assert:
that:
- "result is changed"
- name: Check module fails with correct msg
tower_team:
name: Test Team
organization: Non Existing Org
state: present
register: result
ignore_errors: true
- assert:
that:
- "result.msg =='Failed to update team, organization not found: The requested object could not be found.'"

View file

@ -91,3 +91,15 @@
- assert:
that:
- "result is changed"
- name: Check module fails with correct msg
tower_workflow_template:
name: my-workflow
organization: Non Existing Organization
schema: '[{"success": [{"job_template": "my-job-1"}], "job_template": "my-job-2"}]'
register: result
ignore_errors: true
- assert:
that:
- "result.msg =='Failed to update organization source,organization not found: The requested object could not be found.'"