diff --git a/lib/ansible/plugins/action/nxos.py b/lib/ansible/plugins/action/nxos.py index bf97fe14380..d98afa256fe 100644 --- a/lib/ansible/plugins/action/nxos.py +++ b/lib/ansible/plugins/action/nxos.py @@ -43,6 +43,9 @@ class ActionModule(_ActionModule): socket_path = None + if self._task.args.get('provider', {}).get('transport') == 'nxapi' and self._task.action == 'nxos_nxapi': + return {'failed': True, 'msg': "Transport type 'nxapi' is not valid for '%s' module." % (self._task.action)} + if self._play_context.connection == 'network_cli': provider = self._task.args.get('provider', {}) if any(provider.values()): diff --git a/test/integration/targets/nxos_nxapi/tasks/cli.yaml b/test/integration/targets/nxos_nxapi/tasks/cli.yaml index edbff7dfafb..5832987a512 100644 --- a/test/integration/targets/nxos_nxapi/tasks/cli.yaml +++ b/test/integration/targets/nxos_nxapi/tasks/cli.yaml @@ -1,5 +1,5 @@ --- -- name: collect common cli test cases +- name: collect common test cases find: paths: "{{ role_path }}/tests/common" patterns: "{{ testcase }}.yaml" @@ -21,7 +21,7 @@ set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" - name: run test cases (connection=network_cli) - include: "{{ test_case_to_run }} ansible_connection=network_cli connection={}" + include: "{{ test_case_to_run }} ansible_connection=network_cli" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run diff --git a/test/integration/targets/nxos_nxapi/tasks/main.yaml b/test/integration/targets/nxos_nxapi/tasks/main.yaml index 70e67b38dfd..4b0f8c64d90 100644 --- a/test/integration/targets/nxos_nxapi/tasks/main.yaml +++ b/test/integration/targets/nxos_nxapi/tasks/main.yaml @@ -1,4 +1,3 @@ --- -# Only cli tests for this module since cli is used -# to test nxapi - { include: cli.yaml, tags: ['cli'] } +- { include: nxapi.yaml, tags: ['nxapi'] } diff --git a/test/integration/targets/nxos_nxapi/tasks/nxapi.yaml b/test/integration/targets/nxos_nxapi/tasks/nxapi.yaml new file mode 100644 index 00000000000..ab3ad41c472 --- /dev/null +++ b/test/integration/targets/nxos_nxapi/tasks/nxapi.yaml @@ -0,0 +1,27 @@ +--- +- name: collect common test cases + find: + paths: "{{ role_path }}/tests/common" + patterns: "{{ testcase }}.yaml" + connection: local + register: test_cases + +- name: collect nxapi test cases + find: + paths: "{{ role_path }}/tests/nxapi" + patterns: "{{ testcase }}.yaml" + connection: local + register: nxapi_cases + +- set_fact: + test_cases: + files: "{{ test_cases.files }} + {{ nxapi_cases.files }}" + +- name: set test_items + set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + +- name: run test case (connection=local) + include: "{{ test_case_to_run }} ansible_connection=local connection={{ nxapi }}" + with_items: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run diff --git a/test/integration/targets/nxos_nxapi/tests/cli/badtransport.yaml b/test/integration/targets/nxos_nxapi/tests/nxapi/badtransport.yaml similarity index 60% rename from test/integration/targets/nxos_nxapi/tests/cli/badtransport.yaml rename to test/integration/targets/nxos_nxapi/tests/nxapi/badtransport.yaml index 6549aa990be..ebd5bf462cc 100644 --- a/test/integration/targets/nxos_nxapi/tests/cli/badtransport.yaml +++ b/test/integration/targets/nxos_nxapi/tests/nxapi/badtransport.yaml @@ -1,5 +1,5 @@ --- -- debug: msg="START cli/badtransport.yaml" +- debug: msg="START nxapi/badtransport.yaml" - name: Sending transport other than cli should fail nxos_nxapi: @@ -12,6 +12,6 @@ - assert: that: - - result.failed and result.msg is search('transport') + - result.failed and result.msg is search('Transport') -- debug: msg="END cli/badtransport.yaml" +- debug: msg="END nxapi/badtransport.yaml" diff --git a/test/integration/targets/nxos_smoke/tasks/cli.yaml b/test/integration/targets/nxos_smoke/tasks/cli.yaml index edbff7dfafb..f53eac3a477 100644 --- a/test/integration/targets/nxos_smoke/tasks/cli.yaml +++ b/test/integration/targets/nxos_smoke/tasks/cli.yaml @@ -21,7 +21,7 @@ set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" - name: run test cases (connection=network_cli) - include: "{{ test_case_to_run }} ansible_connection=network_cli connection={}" + include: "{{ test_case_to_run }} ansible_connection=network_cli connection={{ cli }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run diff --git a/test/integration/targets/nxos_smoke/tests/common/misc_tests.yaml b/test/integration/targets/nxos_smoke/tests/common/misc_tests.yaml index 27fc07a7cb7..6ae0b003ea7 100644 --- a/test/integration/targets/nxos_smoke/tests/common/misc_tests.yaml +++ b/test/integration/targets/nxos_smoke/tests/common/misc_tests.yaml @@ -22,3 +22,9 @@ - assert: that: - result.stdout|length == 10 + +- name: combine with provider + nxos_command: + commands: + - show hostname + provider: "{{ connection | combine({'timeout': 500}) }}"