diff --git a/lib/ansible/module_utils/network/iosxr/iosxr.py b/lib/ansible/module_utils/network/iosxr/iosxr.py index 3946c07c07..e40a3662da 100644 --- a/lib/ansible/module_utils/network/iosxr/iosxr.py +++ b/lib/ansible/module_utils/network/iosxr/iosxr.py @@ -374,7 +374,7 @@ def get_config(module, config_filter=None, source='running'): if is_netconf(module): out = to_xml(conn.get_config(source=source, filter=config_filter)) - cfg = to_bytes(out, errors='surrogate_then_replace').strip() + cfg = out.strip() _DEVICE_CONFIGS.update({key: cfg}) return cfg diff --git a/lib/ansible/modules/network/iosxr/iosxr_user.py b/lib/ansible/modules/network/iosxr/iosxr_user.py index b7a01918e9..0d4693166e 100644 --- a/lib/ansible/modules/network/iosxr/iosxr_user.py +++ b/lib/ansible/modules/network/iosxr/iosxr_user.py @@ -328,7 +328,7 @@ def convert_key_to_base64(module): splitfile = key.split()[1] base64key = b64decode(splitfile) - base64file = open('/tmp/publickey_%s.b64' % (name), 'w') + base64file = open('/tmp/publickey_%s.b64' % (name), 'bw') base64file.write(base64key) base64file.close() diff --git a/lib/ansible/plugins/action/iosxr.py b/lib/ansible/plugins/action/iosxr.py index 96140b195a..5f2b2ba3cd 100644 --- a/lib/ansible/plugins/action/iosxr.py +++ b/lib/ansible/plugins/action/iosxr.py @@ -80,7 +80,7 @@ class ActionModule(_ActionModule): # make sure we are in the right cli context which should be # enable mode and not config module - if pc.connection == 'network_cli': + if (self._play_context.connection == 'local' and pc.connection == 'network_cli') or self._play_context.connection == 'network_cli': if socket_path is None: socket_path = self._connection.socket_path diff --git a/lib/ansible/plugins/action/iosxr_config.py b/lib/ansible/plugins/action/iosxr_config.py index 8d7ccaffed..26a3893d35 100644 --- a/lib/ansible/plugins/action/iosxr_config.py +++ b/lib/ansible/plugins/action/iosxr_config.py @@ -40,7 +40,7 @@ class ActionModule(_ActionModule): try: self._handle_template() except ValueError as exc: - return dict(failed=True, msg=exc.message) + return dict(failed=True, msg=to_text(exc)) result = super(ActionModule, self).run(tmp, task_vars) @@ -54,7 +54,7 @@ class ActionModule(_ActionModule): # strip out any keys that have two leading and two trailing # underscore characters - for key in result.keys(): + for key in list(result.keys()): if PRIVATE_KEYS_RE.match(key): del result[key] @@ -74,7 +74,7 @@ class ActionModule(_ActionModule): os.remove(fn) tstamp = time.strftime("%Y-%m-%d@%H:%M:%S", time.localtime(time.time())) filename = '%s/%s_config.%s' % (backup_path, host, tstamp) - open(filename, 'w').write(to_bytes(contents)) + open(filename, 'w').write(contents) return filename def _handle_template(self): diff --git a/lib/ansible/plugins/cliconf/iosxr.py b/lib/ansible/plugins/cliconf/iosxr.py index 0c602fe260..42aa864487 100644 --- a/lib/ansible/plugins/cliconf/iosxr.py +++ b/lib/ansible/plugins/cliconf/iosxr.py @@ -61,9 +61,9 @@ class Cliconf(CliconfBase): if source not in lookup: return self.invalid_params("fetching configuration from %s is not supported" % source) if filter: - cmd = to_bytes(b'show {0} {1}'.format(lookup[source], filter), errors='surrogate_or_strict') + cmd = to_bytes('show {0} {1}'.format(lookup[source], filter), errors='surrogate_or_strict') else: - cmd = to_bytes(b'show {0}'.format(lookup[source]), errors='surrogate_or_strict') + cmd = to_bytes('show {0}'.format(lookup[source]), errors='surrogate_or_strict') return self.send_command(cmd) @@ -76,10 +76,10 @@ class Cliconf(CliconfBase): def commit(self, comment=None): if comment: - command = b'commit comment {0}'.format(comment) + command = 'commit comment {0}'.format(comment) else: - command = b'commit' - self.send_command(command) + command = 'commit' + self.send_command(to_bytes(command)) def discard_changes(self): self.send_command(b'abort') diff --git a/lib/ansible/plugins/terminal/iosxr.py b/lib/ansible/plugins/terminal/iosxr.py index 641d1e8c2e..78f7e2b59e 100644 --- a/lib/ansible/plugins/terminal/iosxr.py +++ b/lib/ansible/plugins/terminal/iosxr.py @@ -37,6 +37,7 @@ class TerminalModule(TerminalBase): terminal_stderr_re = [ re.compile(br"% ?Error"), re.compile(br"% ?Bad secret"), + re.compile(br"% ?This command is not authorized"), re.compile(br"invalid input", re.I), re.compile(br"(?:incomplete|ambiguous) command", re.I), re.compile(br"connection timed out", re.I), diff --git a/test/integration/targets/iosxr_banner/tasks/cli.yaml b/test/integration/targets/iosxr_banner/tasks/cli.yaml index 46d86dd698..890d3acf3e 100644 --- a/test/integration/targets/iosxr_banner/tasks/cli.yaml +++ b/test/integration/targets/iosxr_banner/tasks/cli.yaml @@ -9,8 +9,14 @@ - name: set test_items set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" -- name: run test case - include: "{{ test_case_to_run }}" +- name: run test case (connection=network_cli) + include: "{{ test_case_to_run }} ansible_connection=network_cli" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run + +- name: run test case (connection=local) + include: "{{ test_case_to_run }} ansible_connection=local" + with_first_found: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run diff --git a/test/integration/targets/iosxr_command/tasks/cli.yaml b/test/integration/targets/iosxr_command/tasks/cli.yaml index 46d86dd698..890d3acf3e 100644 --- a/test/integration/targets/iosxr_command/tasks/cli.yaml +++ b/test/integration/targets/iosxr_command/tasks/cli.yaml @@ -9,8 +9,14 @@ - name: set test_items set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" -- name: run test case - include: "{{ test_case_to_run }}" +- name: run test case (connection=network_cli) + include: "{{ test_case_to_run }} ansible_connection=network_cli" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run + +- name: run test case (connection=local) + include: "{{ test_case_to_run }} ansible_connection=local" + with_first_found: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run diff --git a/test/integration/targets/iosxr_command/tests/cli/bad_operator.yaml b/test/integration/targets/iosxr_command/tests/cli/bad_operator.yaml index 84aa658796..28e359ab7c 100644 --- a/test/integration/targets/iosxr_command/tests/cli/bad_operator.yaml +++ b/test/integration/targets/iosxr_command/tests/cli/bad_operator.yaml @@ -1,5 +1,5 @@ --- -- debug: msg="START cli/bad_operator.yaml" +- debug: msg="START cli/bad_operator.yaml on connection={{ ansible_connection }}" - name: test bad operator iosxr_command: @@ -16,4 +16,4 @@ - "result.failed == true" - "result.msg is defined" -- debug: msg="END cli/bad_operator.yaml" +- debug: msg="END cli/bad_operator.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/iosxr_command/tests/cli/contains.yaml b/test/integration/targets/iosxr_command/tests/cli/contains.yaml index b6f7b2f14c..55dd302dc0 100644 --- a/test/integration/targets/iosxr_command/tests/cli/contains.yaml +++ b/test/integration/targets/iosxr_command/tests/cli/contains.yaml @@ -1,5 +1,5 @@ --- -- debug: msg="START cli/contains.yaml" +- debug: msg="START cli/contains.yaml on connection={{ ansible_connection }}" - name: test contains operator iosxr_command: @@ -16,4 +16,4 @@ - "result.changed == false" - "result.stdout is defined" -- debug: msg="END cli/contains.yaml" +- debug: msg="END cli/contains.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/iosxr_command/tests/cli/invalid.yaml b/test/integration/targets/iosxr_command/tests/cli/invalid.yaml index c128c0c100..d26b9ec18f 100644 --- a/test/integration/targets/iosxr_command/tests/cli/invalid.yaml +++ b/test/integration/targets/iosxr_command/tests/cli/invalid.yaml @@ -1,5 +1,5 @@ --- -- debug: msg="START cli/invalid.yaml" +- debug: msg="START cli/invalid.yaml on connection={{ ansible_connection }}" - name: run invalid command iosxr_command: @@ -23,4 +23,4 @@ that: - "result.failed" -- debug: msg="END cli/invalid.yaml" +- debug: msg="END cli/invalid.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/iosxr_command/tests/cli/output.yaml b/test/integration/targets/iosxr_command/tests/cli/output.yaml index 5c803e7fad..3057d58c49 100644 --- a/test/integration/targets/iosxr_command/tests/cli/output.yaml +++ b/test/integration/targets/iosxr_command/tests/cli/output.yaml @@ -1,5 +1,5 @@ --- -- debug: msg="START cli/output.yaml" +- debug: msg="START cli/output.yaml on connection={{ ansible_connection }}" - name: get output for single command iosxr_command: @@ -24,4 +24,4 @@ - "result.stdout is defined" - "result.stdout | length == 2" -- debug: msg="END cli/output.yaml" +- debug: msg="END cli/output.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/iosxr_command/tests/cli/timeout.yaml b/test/integration/targets/iosxr_command/tests/cli/timeout.yaml index 00533d785e..bbad3ecaf5 100644 --- a/test/integration/targets/iosxr_command/tests/cli/timeout.yaml +++ b/test/integration/targets/iosxr_command/tests/cli/timeout.yaml @@ -1,5 +1,5 @@ --- -- debug: msg="START cli/timeout.yaml" +- debug: msg="START cli/timeout.yaml on connection={{ ansible_connection }}" - name: test bad condition iosxr_command: @@ -15,4 +15,4 @@ - "result.failed == true" - "result.msg is defined" -- debug: msg="END cli/timeout.yaml" +- debug: msg="END cli/timeout.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/iosxr_config/tasks/cli.yaml b/test/integration/targets/iosxr_config/tasks/cli.yaml index 46d86dd698..890d3acf3e 100644 --- a/test/integration/targets/iosxr_config/tasks/cli.yaml +++ b/test/integration/targets/iosxr_config/tasks/cli.yaml @@ -9,8 +9,14 @@ - name: set test_items set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" -- name: run test case - include: "{{ test_case_to_run }}" +- name: run test case (connection=network_cli) + include: "{{ test_case_to_run }} ansible_connection=network_cli" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run + +- name: run test case (connection=local) + include: "{{ test_case_to_run }} ansible_connection=local" + with_first_found: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run diff --git a/test/integration/targets/iosxr_config/tests/cli/backup.yaml b/test/integration/targets/iosxr_config/tests/cli/backup.yaml index 4c9056b83a..272063d6c1 100644 --- a/test/integration/targets/iosxr_config/tests/cli/backup.yaml +++ b/test/integration/targets/iosxr_config/tests/cli/backup.yaml @@ -1,5 +1,5 @@ --- -- debug: msg="START cli/backup.yaml" +- debug: msg="START cli/backup.yaml on connection={{ ansible_connection }}" - name: setup iosxr_config: @@ -14,8 +14,8 @@ find: paths: "{{ role_path }}/backup" pattern: "{{ inventory_hostname_short }}_config*" + connection: local register: backup_files - delegate_to: localhost - name: delete backup files file: @@ -38,11 +38,11 @@ find: paths: "{{ role_path }}/backup" pattern: "{{ inventory_hostname_short }}_config*" + connection: local register: backup_files - delegate_to: localhost - assert: that: - "backup_files.files is defined" -- debug: msg="END cli/backup.yaml" +- debug: msg="END cli/backup.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/iosxr_config/tests/cli/comment-too-long.yaml b/test/integration/targets/iosxr_config/tests/cli/comment-too-long.yaml index ebf44f464f..856f9ef386 100644 --- a/test/integration/targets/iosxr_config/tests/cli/comment-too-long.yaml +++ b/test/integration/targets/iosxr_config/tests/cli/comment-too-long.yaml @@ -1,5 +1,5 @@ --- -- debug: msg="START cli/comment-too-long.yaml" +- debug: msg="START cli/comment-too-long.yaml on connection={{ ansible_connection }}" - name: setup iosxr_config: @@ -27,4 +27,4 @@ # Check for the correct error message (and not a generic "Invalid input detected") once fixed -- debug: msg="END cli/comment-too-long.yaml" +- debug: msg="END cli/comment-too-long.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/iosxr_config/tests/cli/comment.yaml b/test/integration/targets/iosxr_config/tests/cli/comment.yaml index e6dc9f0037..38f0dd98cf 100644 --- a/test/integration/targets/iosxr_config/tests/cli/comment.yaml +++ b/test/integration/targets/iosxr_config/tests/cli/comment.yaml @@ -1,5 +1,5 @@ --- -- debug: msg="START cli/comment.yaml" +- debug: msg="START cli/comment.yaml on connection={{ ansible_connection }}" - name: setup iosxr_config: @@ -31,4 +31,4 @@ - "result.changed == false" - "result.updates is not defined" -- debug: msg="END cli/comment.yaml" +- debug: msg="END cli/comment.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/iosxr_config/tests/cli/src_basic.yaml b/test/integration/targets/iosxr_config/tests/cli/src_basic.yaml index cb5f666826..7dae193d66 100644 --- a/test/integration/targets/iosxr_config/tests/cli/src_basic.yaml +++ b/test/integration/targets/iosxr_config/tests/cli/src_basic.yaml @@ -1,5 +1,5 @@ --- -- debug: msg="START cli/src_basic.yaml" +- debug: msg="START cli/src_basic.yaml on connection={{ ansible_connection }}" - name: setup iosxr_config: @@ -32,4 +32,4 @@ # https://github.com/ansible/ansible-modules-core/issues/4807 - "result.updates is not defined" -- debug: msg="END cli/src_basic.yaml" +- debug: msg="END cli/src_basic.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/iosxr_config/tests/cli/src_invalid.yaml b/test/integration/targets/iosxr_config/tests/cli/src_invalid.yaml index 362f22586a..5f7b6f2dd1 100644 --- a/test/integration/targets/iosxr_config/tests/cli/src_invalid.yaml +++ b/test/integration/targets/iosxr_config/tests/cli/src_invalid.yaml @@ -1,5 +1,5 @@ --- -- debug: msg="START cli/src_invalid.yaml" +- debug: msg="START cli/src_invalid.yaml on connection={{ ansible_connection }}" # Defend https://github.com/ansible/ansible-modules-core/issues/4797 @@ -15,4 +15,4 @@ - "result.failed == true" - "result.msg == 'path specified in src not found'" -- debug: msg="END cli/src_invalid.yaml" +- debug: msg="END cli/src_invalid.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/iosxr_config/tests/cli/src_match_none.yaml b/test/integration/targets/iosxr_config/tests/cli/src_match_none.yaml index fd817aa988..dc3b269992 100644 --- a/test/integration/targets/iosxr_config/tests/cli/src_match_none.yaml +++ b/test/integration/targets/iosxr_config/tests/cli/src_match_none.yaml @@ -1,5 +1,5 @@ --- -- debug: msg="START cli/src_match_none.yaml" +- debug: msg="START cli/src_match_none.yaml on connection={{ ansible_connection }}" - name: setup iosxr_config: @@ -34,4 +34,4 @@ - "result.changed == false" - "result.updates is not defined" -- debug: msg="END cli/src_match_none.yaml" +- debug: msg="END cli/src_match_none.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/iosxr_config/tests/cli/sublevel.yaml b/test/integration/targets/iosxr_config/tests/cli/sublevel.yaml index 750c49d459..6d27a23149 100644 --- a/test/integration/targets/iosxr_config/tests/cli/sublevel.yaml +++ b/test/integration/targets/iosxr_config/tests/cli/sublevel.yaml @@ -1,5 +1,5 @@ --- -- debug: msg="START cli/sublevel.yaml" +- debug: msg="START cli/sublevel.yaml on connection={{ ansible_connection }}" - name: setup iosxr_config: @@ -34,4 +34,4 @@ commands: ['no ipv4 access-list test'] match: none -- debug: msg="END cli/sublevel.yaml" +- debug: msg="END cli/sublevel.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/iosxr_config/tests/cli/sublevel_block.yaml b/test/integration/targets/iosxr_config/tests/cli/sublevel_block.yaml index d4d7fc6add..88b5e76e99 100644 --- a/test/integration/targets/iosxr_config/tests/cli/sublevel_block.yaml +++ b/test/integration/targets/iosxr_config/tests/cli/sublevel_block.yaml @@ -1,5 +1,5 @@ --- -- debug: msg="START cli/sublevel_block.yaml" +- debug: msg="START cli/sublevel_block.yaml on connection={{ ansible_connection }}" - name: setup iosxr_config: @@ -9,7 +9,6 @@ - 30 permit ipv4 host 3.3.3.3 any log parents: ['ipv4 access-list test'] before: ['no ipv4 access-list test'] - after: ['exit'] match: none - name: configure sub level command using block resplace @@ -21,7 +20,6 @@ - 40 permit ipv4 host 4.4.4.4 any log parents: ['ipv4 access-list test'] replace: block - after: ['exit'] register: result - assert: @@ -42,7 +40,6 @@ - 40 permit ipv4 host 4.4.4.4 any log parents: ['ipv4 access-list test'] replace: block - after: ['exit'] register: result - assert: @@ -54,4 +51,4 @@ commands: ['no ipv4 access-list test'] match: none -- debug: msg="END cli/sublevel_block.yaml" +- debug: msg="END cli/sublevel_block.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/iosxr_config/tests/cli/sublevel_exact.yaml b/test/integration/targets/iosxr_config/tests/cli/sublevel_exact.yaml index d2b4121aec..8c031b50ec 100644 --- a/test/integration/targets/iosxr_config/tests/cli/sublevel_exact.yaml +++ b/test/integration/targets/iosxr_config/tests/cli/sublevel_exact.yaml @@ -1,5 +1,5 @@ --- -- debug: msg="START cli/sublevel_exact.yaml" +- debug: msg="START cli/sublevel_exact.yaml on connection={{ ansible_connection }}" - name: setup iosxr_config: @@ -11,7 +11,6 @@ - 50 permit ipv4 host 5.5.5.5 any log parents: ['ipv4 access-list test'] before: ['no ipv4 access-list test'] - after: ['exit'] match: none - name: configure sub level command using exact match @@ -22,7 +21,6 @@ - 30 permit ipv4 host 3.3.3.3 any log - 40 permit ipv4 host 4.4.4.4 any log parents: ['ipv4 access-list test'] - after: ['exit'] match: exact register: result @@ -45,7 +43,6 @@ - 40 permit ipv4 host 4.4.4.4 any log - 50 permit ipv4 host 5.5.5.5 any log parents: ['ipv4 access-list test'] - after: ['exit'] match: exact register: result @@ -58,4 +55,4 @@ commands: ['no ipv4 access-list test'] match: none -- debug: msg="END cli/sublevel_exact.yaml" +- debug: msg="END cli/sublevel_exact.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/iosxr_config/tests/cli/sublevel_strict.yaml b/test/integration/targets/iosxr_config/tests/cli/sublevel_strict.yaml index 9d752f409a..801fb60375 100644 --- a/test/integration/targets/iosxr_config/tests/cli/sublevel_strict.yaml +++ b/test/integration/targets/iosxr_config/tests/cli/sublevel_strict.yaml @@ -1,5 +1,5 @@ --- -- debug: msg="START cli/sublevel_strict.yaml" +- debug: msg="START cli/sublevel_strict.yaml on connection={{ ansible_connection }}" - name: setup iosxr_config: @@ -11,7 +11,6 @@ - 50 permit ipv4 host 5.5.5.5 any log parents: ['ipv4 access-list test'] before: ['no ipv4 access-list test'] - after: ['exit'] match: none - name: configure sub level command using strict match @@ -23,7 +22,6 @@ - 40 permit ipv4 host 4.4.4.4 any log parents: ['ipv4 access-list test'] before: ['no ipv4 access-list test'] - after: ['exit'] match: strict replace: block register: result @@ -46,7 +44,6 @@ - 30 permit ipv4 host 3.3.3.3 any log - 40 permit ipv4 host 4.4.4.4 any log parents: ['ipv4 access-list test'] - after: ['exit'] match: strict register: result @@ -59,4 +56,4 @@ commands: ['no ipv4 access-list test'] match: none -- debug: msg="END cli/sublevel_strict.yaml" +- debug: msg="END cli/sublevel_strict.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/iosxr_config/tests/cli/toplevel.yaml b/test/integration/targets/iosxr_config/tests/cli/toplevel.yaml index 6e880c2b93..01f9665fc9 100644 --- a/test/integration/targets/iosxr_config/tests/cli/toplevel.yaml +++ b/test/integration/targets/iosxr_config/tests/cli/toplevel.yaml @@ -1,5 +1,5 @@ --- -- debug: msg="START cli/toplevel.yaml" +- debug: msg="START cli/toplevel.yaml on connection={{ ansible_connection }}" - name: setup iosxr_config: @@ -30,4 +30,4 @@ commands: ['hostname {{ inventory_hostname_short }}'] match: none -- debug: msg="END cli/toplevel.yaml" +- debug: msg="END cli/toplevel.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/iosxr_config/tests/cli/toplevel_after.yaml b/test/integration/targets/iosxr_config/tests/cli/toplevel_after.yaml index 0c8b676ec1..7fcb78a7e3 100644 --- a/test/integration/targets/iosxr_config/tests/cli/toplevel_after.yaml +++ b/test/integration/targets/iosxr_config/tests/cli/toplevel_after.yaml @@ -1,5 +1,5 @@ --- -- debug: msg="START cli/toplevel_after.yaml" +- debug: msg="START cli/toplevel_after.yaml on connection={{ ansible_connection }}" - name: setup iosxr_config: @@ -37,4 +37,4 @@ - "hostname {{ inventory_hostname_short }}" match: none -- debug: msg="END cli/toplevel_after.yaml" +- debug: msg="END cli/toplevel_after.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/iosxr_config/tests/cli/toplevel_before.yaml b/test/integration/targets/iosxr_config/tests/cli/toplevel_before.yaml index 7d7fb41171..4c264269cf 100644 --- a/test/integration/targets/iosxr_config/tests/cli/toplevel_before.yaml +++ b/test/integration/targets/iosxr_config/tests/cli/toplevel_before.yaml @@ -1,5 +1,5 @@ --- -- debug: msg="START cli/toplevel_before.yaml" +- debug: msg="START cli/toplevel_before.yaml on connection={{ ansible_connection }}" - name: setup iosxr_config: @@ -37,4 +37,4 @@ - "hostname {{ inventory_hostname_short }}" match: none -- debug: msg="END cli/toplevel_before.yaml" +- debug: msg="END cli/toplevel_before.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/iosxr_config/tests/cli/toplevel_nonidempotent.yaml b/test/integration/targets/iosxr_config/tests/cli/toplevel_nonidempotent.yaml index 45d2060d85..084a38cc24 100644 --- a/test/integration/targets/iosxr_config/tests/cli/toplevel_nonidempotent.yaml +++ b/test/integration/targets/iosxr_config/tests/cli/toplevel_nonidempotent.yaml @@ -1,5 +1,5 @@ --- -- debug: msg="START cli/toplevel_nonidempotent.yaml" +- debug: msg="START cli/toplevel_nonidempotent.yaml on connection={{ ansible_connection }}" - name: setup iosxr_config: @@ -33,4 +33,4 @@ commands: ['hostname {{ inventory_hostname_short }}'] match: none -- debug: msg="END cli/toplevel_nonidempotent.yaml" +- debug: msg="END cli/toplevel_nonidempotent.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/iosxr_facts/tasks/cli.yaml b/test/integration/targets/iosxr_facts/tasks/cli.yaml index 46d86dd698..890d3acf3e 100644 --- a/test/integration/targets/iosxr_facts/tasks/cli.yaml +++ b/test/integration/targets/iosxr_facts/tasks/cli.yaml @@ -9,8 +9,14 @@ - name: set test_items set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" -- name: run test case - include: "{{ test_case_to_run }}" +- name: run test case (connection=network_cli) + include: "{{ test_case_to_run }} ansible_connection=network_cli" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run + +- name: run test case (connection=local) + include: "{{ test_case_to_run }} ansible_connection=local" + with_first_found: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run diff --git a/test/integration/targets/iosxr_facts/tests/cli/all_facts.yaml b/test/integration/targets/iosxr_facts/tests/cli/all_facts.yaml index 3eeb8c0ed3..2522c49b7b 100644 --- a/test/integration/targets/iosxr_facts/tests/cli/all_facts.yaml +++ b/test/integration/targets/iosxr_facts/tests/cli/all_facts.yaml @@ -1,5 +1,5 @@ --- -- debug: msg="START cli/all_facts.yaml" +- debug: msg="START cli/all_facts.yaml on connection={{ ansible_connection }}" - name: test getting all facts @@ -25,4 +25,4 @@ # Items from those subsets are present - "result.ansible_facts.ansible_net_filesystems is defined" -- debug: msg="END cli/all_facts.yaml" +- debug: msg="END cli/all_facts.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/iosxr_facts/tests/cli/default_facts.yaml b/test/integration/targets/iosxr_facts/tests/cli/default_facts.yaml index ebf9aa2652..d56132b734 100644 --- a/test/integration/targets/iosxr_facts/tests/cli/default_facts.yaml +++ b/test/integration/targets/iosxr_facts/tests/cli/default_facts.yaml @@ -1,5 +1,5 @@ --- -- debug: msg="START cli/default_facts.yaml" +- debug: msg="START cli/default_facts.yaml on connection={{ ansible_connection }}" - name: test getting default facts @@ -27,4 +27,4 @@ # ... and not present - "result.ansible_facts.ansible_net_config is not defined" # config -- debug: msg="END cli/default.yaml" +- debug: msg="END cli/default.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/iosxr_facts/tests/cli/invalid_subset.yaml b/test/integration/targets/iosxr_facts/tests/cli/invalid_subset.yaml index 5bfd68708b..5064a86a68 100644 --- a/test/integration/targets/iosxr_facts/tests/cli/invalid_subset.yaml +++ b/test/integration/targets/iosxr_facts/tests/cli/invalid_subset.yaml @@ -1,5 +1,5 @@ --- -- debug: msg="START cli/invalid_subset.yaml" +- debug: msg="START cli/invalid_subset.yaml on connection={{ ansible_connection }}" - name: test invalid subset (foobar) @@ -45,4 +45,4 @@ -- debug: msg="END cli/invalid_subset.yaml" +- debug: msg="END cli/invalid_subset.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/iosxr_facts/tests/cli/not_hardware.yaml b/test/integration/targets/iosxr_facts/tests/cli/not_hardware.yaml index cd9c60e29c..325d07be99 100644 --- a/test/integration/targets/iosxr_facts/tests/cli/not_hardware.yaml +++ b/test/integration/targets/iosxr_facts/tests/cli/not_hardware.yaml @@ -1,5 +1,5 @@ --- -- debug: msg="START cli/not_hardware_facts.yaml" +- debug: msg="START cli/not_hardware_facts.yaml on connection={{ ansible_connection }}" - name: test not hardware @@ -27,4 +27,4 @@ # ... and not present - "result.ansible_facts.ansible_net_filesystems is not defined" -- debug: msg="END cli/not_hardware_facts.yaml" +- debug: msg="END cli/not_hardware_facts.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/iosxr_interface/tasks/cli.yaml b/test/integration/targets/iosxr_interface/tasks/cli.yaml index 46d86dd698..890d3acf3e 100644 --- a/test/integration/targets/iosxr_interface/tasks/cli.yaml +++ b/test/integration/targets/iosxr_interface/tasks/cli.yaml @@ -9,8 +9,14 @@ - name: set test_items set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" -- name: run test case - include: "{{ test_case_to_run }}" +- name: run test case (connection=network_cli) + include: "{{ test_case_to_run }} ansible_connection=network_cli" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run + +- name: run test case (connection=local) + include: "{{ test_case_to_run }} ansible_connection=local" + with_first_found: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run diff --git a/test/integration/targets/iosxr_interface/tests/cli/basic.yaml b/test/integration/targets/iosxr_interface/tests/cli/basic.yaml index a1cb2b6301..05ca4f2980 100644 --- a/test/integration/targets/iosxr_interface/tests/cli/basic.yaml +++ b/test/integration/targets/iosxr_interface/tests/cli/basic.yaml @@ -1,5 +1,5 @@ --- -- debug: msg="START iosxr_interface cli/basic.yaml" +- debug: msg="START iosxr_interface cli/basic.yaml on connection={{ ansible_connection }}" - name: Setup interface iosxr_interface: @@ -256,4 +256,4 @@ that: - 'result.changed == false' -- debug: msg="END iosxr_interface cli/basic.yaml" +- debug: msg="END iosxr_interface cli/basic.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/iosxr_interface/tests/cli/intent.yaml b/test/integration/targets/iosxr_interface/tests/cli/intent.yaml index c134428b4c..3227bad78c 100644 --- a/test/integration/targets/iosxr_interface/tests/cli/intent.yaml +++ b/test/integration/targets/iosxr_interface/tests/cli/intent.yaml @@ -1,5 +1,5 @@ --- -- debug: msg="START iosxr_interface cli/intent.yaml" +- debug: msg="START iosxr_interface cli/intent.yaml on connection={{ ansible_connection }}" - name: Setup (interface is up) iosxr_interface: diff --git a/test/integration/targets/iosxr_logging/tasks/cli.yaml b/test/integration/targets/iosxr_logging/tasks/cli.yaml index 46d86dd698..890d3acf3e 100644 --- a/test/integration/targets/iosxr_logging/tasks/cli.yaml +++ b/test/integration/targets/iosxr_logging/tasks/cli.yaml @@ -9,8 +9,14 @@ - name: set test_items set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" -- name: run test case - include: "{{ test_case_to_run }}" +- name: run test case (connection=network_cli) + include: "{{ test_case_to_run }} ansible_connection=network_cli" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run + +- name: run test case (connection=local) + include: "{{ test_case_to_run }} ansible_connection=local" + with_first_found: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run diff --git a/test/integration/targets/iosxr_netconf/tasks/cli.yaml b/test/integration/targets/iosxr_netconf/tasks/cli.yaml index 46d86dd698..890d3acf3e 100644 --- a/test/integration/targets/iosxr_netconf/tasks/cli.yaml +++ b/test/integration/targets/iosxr_netconf/tasks/cli.yaml @@ -9,8 +9,14 @@ - name: set test_items set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" -- name: run test case - include: "{{ test_case_to_run }}" +- name: run test case (connection=network_cli) + include: "{{ test_case_to_run }} ansible_connection=network_cli" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run + +- name: run test case (connection=local) + include: "{{ test_case_to_run }} ansible_connection=local" + with_first_found: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run diff --git a/test/integration/targets/iosxr_netconf/tests/cli/basic.yaml b/test/integration/targets/iosxr_netconf/tests/cli/basic.yaml index 43af3aacf8..c1eae2e6d7 100644 --- a/test/integration/targets/iosxr_netconf/tests/cli/basic.yaml +++ b/test/integration/targets/iosxr_netconf/tests/cli/basic.yaml @@ -1,5 +1,5 @@ --- -- debug: msg="START iosxr_netconf cli/basic.yaml" +- debug: msg="START iosxr_netconf cli/basic.yaml on connection={{ ansible_connection }}" - name: Disable NetConf service iosxr_netconf: &disable_netconf @@ -66,4 +66,4 @@ - name: Disable Netconf service iosxr_netconf: *disable_netconf -- debug: msg="END iosxr_netconf cli/basic.yaml" +- debug: msg="END iosxr_netconf cli/basic.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/iosxr_system/tasks/cli.yaml b/test/integration/targets/iosxr_system/tasks/cli.yaml index 46d86dd698..890d3acf3e 100644 --- a/test/integration/targets/iosxr_system/tasks/cli.yaml +++ b/test/integration/targets/iosxr_system/tasks/cli.yaml @@ -9,8 +9,14 @@ - name: set test_items set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" -- name: run test case - include: "{{ test_case_to_run }}" +- name: run test case (connection=network_cli) + include: "{{ test_case_to_run }} ansible_connection=network_cli" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run + +- name: run test case (connection=local) + include: "{{ test_case_to_run }} ansible_connection=local" + with_first_found: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run diff --git a/test/integration/targets/iosxr_system/tests/cli/set_domain_list.yaml b/test/integration/targets/iosxr_system/tests/cli/set_domain_list.yaml index 6b3db147c5..4462b6e4b3 100644 --- a/test/integration/targets/iosxr_system/tests/cli/set_domain_list.yaml +++ b/test/integration/targets/iosxr_system/tests/cli/set_domain_list.yaml @@ -1,5 +1,5 @@ --- -- debug: msg="START cli/set_domain_search.yaml" +- debug: msg="START cli/set_domain_search.yaml on connection={{ ansible_connection }}" - name: setup iosxr_config: @@ -119,4 +119,4 @@ match: none provider: "{{ cli }}" -- debug: msg="END cli/set_domain_search.yaml" +- debug: msg="END cli/set_domain_search.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/iosxr_system/tests/cli/set_domain_name.yaml b/test/integration/targets/iosxr_system/tests/cli/set_domain_name.yaml index fc14aaaa00..abbbcab4f9 100644 --- a/test/integration/targets/iosxr_system/tests/cli/set_domain_name.yaml +++ b/test/integration/targets/iosxr_system/tests/cli/set_domain_name.yaml @@ -1,5 +1,5 @@ --- -- debug: msg="START cli/set_domain_name.yaml" +- debug: msg="START cli/set_domain_name.yaml on connection={{ ansible_connection }}" - name: setup iosxr_config: @@ -33,4 +33,4 @@ match: none provider: "{{ cli }}" -- debug: msg="END cli/set_domain_name.yaml" +- debug: msg="END cli/set_domain_name.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/iosxr_system/tests/cli/set_hostname.yaml b/test/integration/targets/iosxr_system/tests/cli/set_hostname.yaml index d9fd02212b..69f8ee114e 100644 --- a/test/integration/targets/iosxr_system/tests/cli/set_hostname.yaml +++ b/test/integration/targets/iosxr_system/tests/cli/set_hostname.yaml @@ -1,5 +1,5 @@ --- -- debug: msg="START cli/set_hostname.yaml" +- debug: msg="START cli/set_hostname.yaml on connection={{ ansible_connection }}" - name: setup iosxr_config: @@ -33,4 +33,4 @@ match: none provider: "{{ cli }}" -- debug: msg="END cli/set_hostname.yaml" +- debug: msg="END cli/set_hostname.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/iosxr_system/tests/cli/set_lookup_source.yaml b/test/integration/targets/iosxr_system/tests/cli/set_lookup_source.yaml index dffe137358..793d722c9b 100644 --- a/test/integration/targets/iosxr_system/tests/cli/set_lookup_source.yaml +++ b/test/integration/targets/iosxr_system/tests/cli/set_lookup_source.yaml @@ -1,5 +1,5 @@ --- -- debug: msg="START cli/set_lookup_source.yaml" +- debug: msg="START cli/set_lookup_source.yaml on connection={{ ansible_connection }}" - name: setup iosxr_config: @@ -63,4 +63,4 @@ match: none provider: "{{ cli }}" -- debug: msg="END cli/set_lookup_source.yaml" +- debug: msg="END cli/set_lookup_source.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/iosxr_system/tests/cli/set_name_servers.yaml b/test/integration/targets/iosxr_system/tests/cli/set_name_servers.yaml index bed28f6394..22b186e7a5 100644 --- a/test/integration/targets/iosxr_system/tests/cli/set_name_servers.yaml +++ b/test/integration/targets/iosxr_system/tests/cli/set_name_servers.yaml @@ -1,5 +1,5 @@ --- -- debug: msg="START cli/set_name_servers.yaml" +- debug: msg="START cli/set_name_servers.yaml on connection={{ ansible_connection }}" - name: setup iosxr_config: @@ -83,4 +83,4 @@ # FIXME: No teardown # -- debug: msg="END cli/set_name_servers.yaml" +- debug: msg="END cli/set_name_servers.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/iosxr_user/tasks/cli.yaml b/test/integration/targets/iosxr_user/tasks/cli.yaml index 46d86dd698..890d3acf3e 100644 --- a/test/integration/targets/iosxr_user/tasks/cli.yaml +++ b/test/integration/targets/iosxr_user/tasks/cli.yaml @@ -9,8 +9,14 @@ - name: set test_items set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" -- name: run test case - include: "{{ test_case_to_run }}" +- name: run test case (connection=network_cli) + include: "{{ test_case_to_run }} ansible_connection=network_cli" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run + +- name: run test case (connection=local) + include: "{{ test_case_to_run }} ansible_connection=local" + with_first_found: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run diff --git a/test/integration/targets/iosxr_user/tests/cli/auth.yaml b/test/integration/targets/iosxr_user/tests/cli/auth.yaml index 4aa4adfe25..b8c55eadb9 100644 --- a/test/integration/targets/iosxr_user/tests/cli/auth.yaml +++ b/test/integration/targets/iosxr_user/tests/cli/auth.yaml @@ -9,13 +9,13 @@ - name: test login expect: - command: "ssh auth_user@{{ ansible_ssh_host }} -p {{ ansible_ssh_port }} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no show version" + command: "ssh auth_user@{{ ansible_ssh_host }} -p {{ ansible_ssh_port|default(22) }} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no show version" responses: (?i)password: "pass123" - name: test login with invalid password (should fail) expect: - command: "ssh auth_user@{{ ansible_ssh_host }} -p {{ ansible_ssh_port }} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no show version" + command: "ssh auth_user@{{ ansible_ssh_host }} -p {{ ansible_ssh_port|default(22) }} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no show version" responses: (?i)password: "badpass" ignore_errors: yes @@ -35,7 +35,7 @@ - name: test login with private key expect: - command: "ssh auth_user@{{ ansible_ssh_host }} -p {{ ansible_ssh_port }} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i {{ role_path }}/files/private show version" + command: "ssh auth_user@{{ ansible_ssh_host }} -p {{ ansible_ssh_port|default(22) }} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i {{ role_path }}/files/private show version" responses: (?i)password: 'pass123' @@ -47,7 +47,7 @@ - name: test login with private key (should fail, no user) expect: - command: "ssh auth_user@{{ ansible_ssh_host }} -p {{ ansible_ssh_port }} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i {{ role_path }}/files/private show version" + command: "ssh auth_user@{{ ansible_ssh_host }} -p {{ ansible_ssh_port|default(22) }} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i {{ role_path }}/files/private show version" responses: (?i)password: 'pass123' ignore_errors: yes @@ -62,7 +62,7 @@ - name: test login with private key expect: - command: "ssh auth_user@{{ ansible_ssh_host }} -p {{ ansible_ssh_port }} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i {{ role_path }}/files/private show version" + command: "ssh auth_user@{{ ansible_ssh_host }} -p {{ ansible_ssh_port|default(22) }} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i {{ role_path }}/files/private show version" responses: (?i)password: 'pass123' ignore_errors: yes @@ -77,7 +77,7 @@ # FIXME: pexpect fails with OSError: [Errno 5] Input/output error - name: test login with invalid private key (should fail) expect: - command: "ssh auth_user@{{ ansible_ssh_host }} -p {{ ansible_ssh_port }} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i {{ role_path }}/files/private show version" + command: "ssh auth_user@{{ ansible_ssh_host }} -p {{ ansible_ssh_port|default(22) }} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i {{ role_path }}/files/private show version" responses: (?i)password: "pass123" ignore_errors: yes diff --git a/test/integration/targets/prepare_iosxr_tests/tasks/main.yml b/test/integration/targets/prepare_iosxr_tests/tasks/main.yml index 8e47a3db0d..4a57bfe392 100644 --- a/test/integration/targets/prepare_iosxr_tests/tasks/main.yml +++ b/test/integration/targets/prepare_iosxr_tests/tasks/main.yml @@ -3,6 +3,7 @@ - name: Ensure we have loopback 888 for testing iosxr_config: src: config.j2 + connection: network_cli # Some AWS hostnames can be longer than those allowed by the system we are testing # Truncate the hostname