| 1 |
# Test code for the MSO modules |
| 2 |
# Copyright: (c) 2023, Akini Ross (@akinross) <[email protected]> |
| 3 |
|
| 4 |
# GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 5 |
|
| 6 |
- name: Set vars |
| 7 |
ansible.builtin.set_fact: |
| 8 |
plugin_query: &plugin_query |
| 9 |
state: query |
| 10 |
output_level: debug |
| 11 |
|
| 12 |
- name: Set ansible_connection to ansible.netcommon.httpapi with a wrong domain |
| 13 |
ansible.builtin.set_fact: |
| 14 |
ansible_connection: ansible.netcommon.httpapi |
| 15 |
ansible_httpapi_login_domain: wrong_domain_from_plugin |
| 16 |
|
| 17 |
- name: Reset connection |
| 18 |
ansible.builtin.meta: reset_connection |
| 19 |
|
| 20 |
- name: Query mso_version with domain from ansible_httpapi_login_domain (error with wrong_domain_from_plugin) |
| 21 |
cisco.mso.mso_version: |
| 22 |
<<: *plugin_query |
| 23 |
register: nm_query_test_domain_plugin |
| 24 |
ignore_errors: true |
| 25 |
|
| 26 |
- name: Query mso_version with domain overwrite in task (error with wrong_domain_from_task) |
| 27 |
cisco.mso.mso_version: |
| 28 |
<<: *plugin_query |
| 29 |
login_domain: wrong_domain_from_task |
| 30 |
register: nm_query_wrong_domain_overwrite |
| 31 |
ignore_errors: true |
| 32 |
|
| 33 |
- name: Query mso_version with domain overwrite in task (test) |
| 34 |
cisco.mso.mso_version: |
| 35 |
<<: *plugin_query |
| 36 |
username: '{{ mso_remote_username }}' |
| 37 |
login_domain: test |
| 38 |
register: nm_query_login_domain_overwrite |
| 39 |
|
| 40 |
- name: Unset ansible_httpapi_login_domain |
| 41 |
ansible.builtin.set_fact: |
| 42 |
ansible_httpapi_login_domain: |
| 43 |
|
| 44 |
- name: Query mso_version to trigger new login |
| 45 |
cisco.mso.mso_version: |
| 46 |
<<: *plugin_query |
| 47 |
|
| 48 |
- name: Query mso_version again thus skipping login |
| 49 |
cisco.mso.mso_version: |
| 50 |
<<: *plugin_query |
| 51 |
register: nm_query_skip_login |
| 52 |
|
| 53 |
- name: Query mso_version with username overwrite in task (error with wrong_username/password) |
| 54 |
cisco.mso.mso_version: |
| 55 |
<<: *plugin_query |
| 56 |
username: wrong_username |
| 57 |
password: wrong_password |
| 58 |
register: nm_query_wrong_username_password_overwrite |
| 59 |
ignore_errors: true |
| 60 |
|
| 61 |
- name: Query mso_version and tigger new login because of changed username and password |
| 62 |
cisco.mso.mso_version: &new_plugin_query |
| 63 |
<<: *plugin_query |
| 64 |
register: nm_query_login_new_username_password |
| 65 |
|
| 66 |
- name: Query mso_version again and tigger new login because of changed username and password |
| 67 |
cisco.mso.mso_version: |
| 68 |
<<: *new_plugin_query |
| 69 |
register: nm_query_login_new_username_password_again |
| 70 |
|
| 71 |
- name: Query mso_version again and overwrite timeout |
| 72 |
cisco.mso.mso_version: |
| 73 |
<<: *new_plugin_query |
| 74 |
timeout: 10 |
| 75 |
register: nm_query_login_new_timeout |
| 76 |
|
| 77 |
- name: Query mso_version again and overwrite use_proxy |
| 78 |
cisco.mso.mso_version: |
| 79 |
<<: *new_plugin_query |
| 80 |
use_proxy: False |
| 81 |
register: nm_query_login_new_use_proxy_false |
| 82 |
|
| 83 |
- name: Query mso_version again and overwrite use_ssl (error) |
| 84 |
cisco.mso.mso_version: |
| 85 |
<<: *new_plugin_query |
| 86 |
use_ssl: False |
| 87 |
register: nm_query_login_new_use_ssl_false |
| 88 |
ignore_errors: true |
| 89 |
|
| 90 |
- name: Query mso_version again and validate_certs (error) |
| 91 |
cisco.mso.mso_version: |
| 92 |
<<: *new_plugin_query |
| 93 |
validate_certs: True |
| 94 |
register: nm_query_login_new_validate_certs_true |
| 95 |
ignore_errors: true |
| 96 |
|
| 97 |
- name: Query mso_version again and timeout on with wrong host (error) |
| 98 |
cisco.mso.mso_version: |
| 99 |
<<: *new_plugin_query |
| 100 |
host: '{{ apic_hostname }}' |
| 101 |
register: nm_query_login_new_wrong_host |
| 102 |
ignore_errors: true |
| 103 |
|
| 104 |
- name: Verify httpapi plugin tests |
| 105 |
ansible.builtin.assert: |
| 106 |
that: |
| 107 |
- nm_query_login_new_use_ssl_false.msg is search("Connection refused") |
| 108 |
- nm_query_login_new_validate_certs_true.msg is search("certificate verify failed") |
| 109 |
- nm_query_login_new_wrong_host.current == {} |
| 110 |
|
| 111 |
- name: Set ansible connection search queries and error message for failed authentication |
| 112 |
ansible.builtin.set_fact: |
| 113 |
search_username: "'username': '{{ mso_remote_username }}'" |
| 114 |
search_login_domain: "'login_domain': '{{ mso_login_domain }}'" |
| 115 |
search_proxy_true: "'use_proxy': True" |
| 116 |
search_ssl: "'use_ssl': True" |
| 117 |
search_timeout_300: "'timeout': 300" |
| 118 |
search_validate_certs: "'validate_certs': False" |
| 119 |
search_timeout_10: "'timeout': 10" |
| 120 |
search_proxy_false: "'use_proxy': False" |
| 121 |
|
| 122 |
- name: Verify httpapi plugin tests |
| 123 |
ansible.builtin.assert: |
| 124 |
that: |
| 125 |
- nm_query_test_domain_plugin.msg == "Login domain 'wrong_domain_from_plugin' is not a valid domain name." |
| 126 |
- nm_query_wrong_domain_overwrite.msg == "Login domain 'wrong_domain_from_task' is not a valid domain name." |
| 127 |
- nm_query_login_domain_overwrite.httpapi_logs | length == 8 |
| 128 |
- nm_query_login_domain_overwrite.httpapi_logs.1.1.startswith("set_connection_parameters() - resetting connection due to 'username' change") |
| 129 |
- nm_query_login_domain_overwrite.httpapi_logs.2.1.startswith("set_connection_parameters() - resetting connection due to 'login_domain' change") |
| 130 |
- nm_query_login_domain_overwrite.httpapi_logs.3.1 is search(search_username) |
| 131 |
- nm_query_login_domain_overwrite.httpapi_logs.3.1 is search(search_login_domain) |
| 132 |
- nm_query_login_domain_overwrite.httpapi_logs.3.1 is search(search_proxy_true) |
| 133 |
- nm_query_login_domain_overwrite.httpapi_logs.3.1 is search(search_ssl) |
| 134 |
- nm_query_login_domain_overwrite.httpapi_logs.3.1 is search(search_timeout_300) |
| 135 |
- nm_query_login_domain_overwrite.httpapi_logs.3.1 is search(search_validate_certs) |
| 136 |
- nm_query_skip_login.httpapi_logs | length == 2 |
| 137 |
- nm_query_skip_login.httpapi_logs.1.1.startswith("send_request() - connection.send(/api/v1/platform/version") |
| 138 |
- 'nm_query_wrong_username_password_overwrite.msg == "Authentication failed: Request failed: HTTP Error 401: Unauthorized"' |
| 139 |
- nm_query_login_new_username_password.httpapi_logs | length == 8 |
| 140 |
- nm_query_login_new_username_password.httpapi_logs.1.1.startswith("set_connection_parameters() - resetting connection due to 'username' change") |
| 141 |
- nm_query_login_new_username_password.httpapi_logs.2.1.startswith("set_connection_parameters() - resetting connection due to 'password' change") |
| 142 |
- nm_query_login_new_username_password_again.httpapi_logs | length == 2 |
| 143 |
- nm_query_login_new_username_password_again.httpapi_logs.1.1.startswith("send_request() - connection.send(/api/v1/platform/version") |
| 144 |
- nm_query_login_new_timeout.httpapi_logs | length == 3 |
| 145 |
- nm_query_login_new_timeout.httpapi_logs.1.1 is search(search_timeout_10) |
| 146 |
- nm_query_login_new_use_proxy_false.httpapi_logs.1.1 is search(search_proxy_false) |