From ea4a78b2a1b681d2fa16bcee0e672259392635c6 Mon Sep 17 00:00:00 2001 From: Deepak Agrawal Date: Thu, 24 May 2018 13:18:29 +0530 Subject: [PATCH] iosxr_command does not work with prompt and answer arguments (#40475) * mismatch type between function arguments * add testcase for prompt * yamllint issues * remove overwriting response in case of connectionError exception * remove import of ConnectionError as it is not required --- .../module_utils/network/iosxr/iosxr.py | 2 +- .../iosxr_command/tests/cli/prompt.yaml | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 test/integration/targets/iosxr_command/tests/cli/prompt.yaml diff --git a/lib/ansible/module_utils/network/iosxr/iosxr.py b/lib/ansible/module_utils/network/iosxr/iosxr.py index ed64eba456d..50cf3be17e1 100644 --- a/lib/ansible/module_utils/network/iosxr/iosxr.py +++ b/lib/ansible/module_utils/network/iosxr/iosxr.py @@ -454,7 +454,7 @@ def run_command(module, commands): sendonly = False newline = True - out = conn.get(command, prompt=prompt, answer=answer, sendonly=sendonly, newline=newline) + out = conn.get(command=command, prompt=prompt, answer=answer, sendonly=sendonly, newline=newline) try: responses.append(to_text(out, errors='surrogate_or_strict')) diff --git a/test/integration/targets/iosxr_command/tests/cli/prompt.yaml b/test/integration/targets/iosxr_command/tests/cli/prompt.yaml new file mode 100644 index 00000000000..eb64a8a8dda --- /dev/null +++ b/test/integration/targets/iosxr_command/tests/cli/prompt.yaml @@ -0,0 +1,25 @@ +--- +- debug: msg="START cli/prompt.yaml on connection={{ ansible_connection }}" + +- name: delete config file on disk to prevent failure of copy task for duplicate + iosxr_command: + commands: + - command: 'delete harddisk:ansible_tmp.txt' + prompt: 'Delete harddisk\:ansible_tmp\.txt\[confirm\]' + answer: "\r\n" + ignore_errors: yes + +- name: copy + iosxr_command: + commands: + - command: 'copy running-config harddisk:ansible_tmp.txt' + prompt: 'Destination file name \(control-c to abort\)\: \[\/ansible_tmp.txt\]\?' + answer: 'ansible_tmp.txt' + register: result + +- assert: + that: + - "result.stdout is defined" + - "'ansible_tmp' in result.stdout[0]" + +- debug: msg="END cli/prompt.yaml on connection={{ ansible_connection }}"