diff options
author | jainnikhil30 <jainnikhil30@gmail.com> | 2019-01-09 15:31:21 +0100 |
---|---|---|
committer | René Moser <mail@renemoser.net> | 2019-01-09 15:31:21 +0100 |
commit | cd279829598e83a7bebaaf294253a57db3ad7931 (patch) | |
tree | 48eec050c42531e5732f6bc9c8e45e673f189f0f | |
parent | fix docs for tower modules (#50710) (diff) | |
download | ansible-cd279829598e83a7bebaaf294253a57db3ad7931.tar.xz ansible-cd279829598e83a7bebaaf294253a57db3ad7931.zip |
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
27 files changed, 168 insertions, 19 deletions
diff --git a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py index fe912745ac..2b30355363 100644 --- a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py +++ b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py @@ -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: diff --git a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_group.py b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_group.py index 1e87a408ec..50772891ff 100644 --- a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_group.py +++ b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_group.py @@ -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: diff --git a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_host.py b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_host.py index 16a92b1120..492c4842c0 100644 --- a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_host.py +++ b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_host.py @@ -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: diff --git a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_inventory.py b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_inventory.py index 6da3928928..1be2477321 100644 --- a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_inventory.py +++ b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_inventory.py @@ -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: diff --git a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_job_cancel.py b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_job_cancel.py index 51258a31de..f2f5f8eada 100644 --- a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_job_cancel.py +++ b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_job_cancel.py @@ -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: diff --git a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_job_launch.py b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_job_launch.py index cb997abdb2..c34ec3dd23 100644 --- a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_job_launch.py +++ b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_job_launch.py @@ -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: diff --git a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_job_list.py b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_job_list.py index 47b4ed6b06..51eda5ecdb 100644 --- a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_job_list.py +++ b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_job_list.py @@ -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: diff --git a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_job_template.py b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_job_template.py index fb811d11ce..4f69ec99d5 100644 --- a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_job_template.py +++ b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_job_template.py @@ -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: diff --git a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_job_wait.py b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_job_wait.py index 519adc8403..8974289157 100644 --- a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_job_wait.py +++ b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_job_wait.py @@ -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: diff --git a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_label.py b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_label.py index 836cb1b43f..554d154cb1 100644 --- a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_label.py +++ b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_label.py @@ -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: diff --git a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_organization.py b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_organization.py index 20e5399675..8acbfd5108 100644 --- a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_organization.py +++ b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_organization.py @@ -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: diff --git a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_project.py b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_project.py index 6d6a80260a..c1b4a0c972 100644 --- a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_project.py +++ b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_project.py @@ -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: diff --git a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_role.py b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_role.py index 2279bc925a..38a56514b9 100644 --- a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_role.py +++ b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_role.py @@ -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: diff --git a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_settings.py b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_settings.py index b3d07f99b1..1a2acbfb9e 100644 --- a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_settings.py +++ b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_settings.py @@ -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: diff --git a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_team.py b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_team.py index cd9854f7ee..4c49fd5447 100644 --- a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_team.py +++ b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_team.py @@ -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: diff --git a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_user.py b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_user.py index 00e8c0fcf0..86baf18e90 100644 --- a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_user.py +++ b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_user.py @@ -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: diff --git a/test/integration/targets/tower_credential/tasks/main.yml b/test/integration/targets/tower_credential/tasks/main.yml index 9af78d9577..20631bfdd0 100644 --- a/test/integration/targets/tower_credential/tasks/main.yml +++ b/test/integration/targets/tower_credential/tasks/main.yml @@ -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.'" diff --git a/test/integration/targets/tower_group/tasks/main.yml b/test/integration/targets/tower_group/tasks/main.yml index d559ba6919..a1e2f118af 100644 --- a/test/integration/targets/tower_group/tasks/main.yml +++ b/test/integration/targets/tower_group/tasks/main.yml @@ -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.'" diff --git a/test/integration/targets/tower_host/tasks/main.yml b/test/integration/targets/tower_host/tasks/main.yml index b56553f14e..ad1a5f04e5 100644 --- a/test/integration/targets/tower_host/tasks/main.yml +++ b/test/integration/targets/tower_host/tasks/main.yml @@ -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.'" diff --git a/test/integration/targets/tower_inventory/tasks/main.yml b/test/integration/targets/tower_inventory/tasks/main.yml index 0d45bb8c72..e1af6d6454 100644 --- a/test/integration/targets/tower_inventory/tasks/main.yml +++ b/test/integration/targets/tower_inventory/tasks/main.yml @@ -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.'"
\ No newline at end of file diff --git a/test/integration/targets/tower_job_cancel/tasks/main.yml b/test/integration/targets/tower_job_cancel/tasks/main.yml index 4d795d6096..304e71a84f 100644 --- a/test/integration/targets/tower_job_cancel/tasks/main.yml +++ b/test/integration/targets/tower_job_cancel/tasks/main.yml @@ -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.'"
\ No newline at end of file diff --git a/test/integration/targets/tower_job_launch/tasks/main.yml b/test/integration/targets/tower_job_launch/tasks/main.yml index f619368d23..9bf271c105 100644 --- a/test/integration/targets/tower_job_launch/tasks/main.yml +++ b/test/integration/targets/tower_job_launch/tasks/main.yml @@ -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.'" diff --git a/test/integration/targets/tower_job_wait/tasks/main.yml b/test/integration/targets/tower_job_wait/tasks/main.yml index 904e6a5169..2ffc5bca3a 100644 --- a/test/integration/targets/tower_job_wait/tasks/main.yml +++ b/test/integration/targets/tower_job_wait/tasks/main.yml @@ -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.'"
\ No newline at end of file diff --git a/test/integration/targets/tower_label/tasks/main.yml b/test/integration/targets/tower_label/tasks/main.yml index f580c7c690..f86712b96a 100644 --- a/test/integration/targets/tower_label/tasks/main.yml +++ b/test/integration/targets/tower_label/tasks/main.yml @@ -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 diff --git a/test/integration/targets/tower_project/tasks/main.yml b/test/integration/targets/tower_project/tasks/main.yml index e965709cbb..ba9096c20f 100644 --- a/test/integration/targets/tower_project/tasks/main.yml +++ b/test/integration/targets/tower_project/tasks/main.yml @@ -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'"
\ No newline at end of file diff --git a/test/integration/targets/tower_team/tasks/main.yml b/test/integration/targets/tower_team/tasks/main.yml index 40fa7e05e4..96fb921a81 100644 --- a/test/integration/targets/tower_team/tasks/main.yml +++ b/test/integration/targets/tower_team/tasks/main.yml @@ -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.'" diff --git a/test/integration/targets/tower_workflow_template/tasks/main.yml b/test/integration/targets/tower_workflow_template/tasks/main.yml index 39a03c68d7..c4bc1607d0 100644 --- a/test/integration/targets/tower_workflow_template/tasks/main.yml +++ b/test/integration/targets/tower_workflow_template/tasks/main.yml @@ -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.'"
\ No newline at end of file |