cli_command module (#42916)

* Create cli_command module to do direct cliconf calls

* Update edgeos cliconf signature to match.

* cli_command is cli-only

* Add tests
This commit is contained in:
Nathaniel Case 2018-08-06 10:41:57 -04:00 committed by GitHub
commit ab39481c31
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 480 additions and 6 deletions

View file

@ -0,0 +1,42 @@
---
- debug:
msg: "START cli/cli_command.yaml on connection={{ ansible_connection }}"
- name: command that does require become (should fail)
cli_command:
commands:
- show running-config
become: no
ignore_errors: yes
register: result
- assert:
that:
- 'result.failed == true'
- '"privileged mode required" in result.msg'
- name: get output for single command
cli_command:
commands:
- show version
register: result
- assert:
that:
- "result.changed == false"
- "result.stdout is defined"
- name: get output for multiple commands
cli_command:
commands:
- show version
- show interfaces
register: result
- assert:
that:
- "result.changed == false"
- "result.stdout is defined"
- "result.stdout | length == 2"
- debug: msg="END cli/cli_command.yaml on connection={{ ansible_connection }}"

View file

@ -15,7 +15,7 @@
- assert:
that:
- 'result.failed == true'
- '"privileged mode required" in result.module_stderr'
- '"privileged mode required" in result.msg'
- name: command that doesn't require become
eos_command:

View file

@ -0,0 +1,32 @@
---
- debug:
msg: "START cli/cli_command.yaml on connection={{ ansible_connection }}"
- block:
- name: get output for single command
cli_command:
commands:
- show version
register: result
- assert:
that:
- "result.changed == false"
- "result.stdout is defined"
- name: get output for multiple commands
cli_command:
commands:
- show version
- show interfaces
register: result
- assert:
that:
- "result.changed == false"
- "result.stdout is defined"
- "result.stdout | length == 2"
when: ansible_connection == 'network_cli'
- debug: msg="END cli/cli_command.yaml on connection={{ ansible_connection }}"

View file

@ -34,7 +34,7 @@
- assert:
that:
- 'result.failed == true'
- "'timeout trying to send command' in result.module_stderr"
- "'timeout trying to send command' in result.msg"
when: ansible_connection == 'network_cli'
- debug: msg="END ios_smoke cli/misc_tests.yaml on connection={{ ansible_connection }}"

View file

@ -0,0 +1,32 @@
---
- debug:
msg: "START cli/cli_command.yaml on connection={{ ansible_connection }}"
- block:
- name: get output for single command
cli_command:
commands:
- show version
register: result
- assert:
that:
- "result.changed == false"
- "result.stdout is defined"
- name: get output for multiple commands
cli_command:
commands:
- show version
- show interfaces
register: result
- assert:
that:
- "result.changed == false"
- "result.stdout is defined"
- "result.stdout | length == 2"
when: ansible_connection == 'network_cli'
- debug: msg="END cli/cli_command.yaml on connection={{ ansible_connection }}"

View file

@ -0,0 +1,16 @@
---
- name: collect all cli test cases
find:
paths: "{{ role_path }}/tests/cli"
patterns: "{{ testcase }}.yaml"
register: test_cases
delegate_to: localhost
- name: set test_items
set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}"
- 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

View file

@ -1,2 +1,3 @@
---
- { include: netconf.yaml, tags: ['netconf'] }
- { include: cli.yaml, tags: ['cli'] }

View file

@ -0,0 +1,29 @@
---
- debug:
msg: "START cli/cli_command.yaml on connection={{ ansible_connection }}"
- name: get output for single command
cli_command:
commands:
- show version
register: result
- assert:
that:
- "result.changed == false"
- "result.stdout is defined"
- name: get output for multiple commands
cli_command:
commands:
- show version
- show interfaces
register: result
- assert:
that:
- "result.changed == false"
- "result.stdout is defined"
- "result.stdout | length == 2"
- debug: msg="END cli/cli_command.yaml on connection={{ ansible_connection }}"

View file

@ -0,0 +1,32 @@
---
- debug:
msg: "START cli/cli_command.yaml on connection={{ ansible_connection }}"
- block:
- name: get output for single command
cli_command:
commands:
- show version
register: result
- assert:
that:
- "result.changed == false"
- "result.stdout is defined"
- name: get output for multiple commands
cli_command:
commands:
- show version
- show interface
register: result
- assert:
that:
- "result.changed == false"
- "result.stdout is defined"
- "result.stdout | length == 2"
when: ansible_connection == 'network_cli'
- debug: msg="END cli/cli_command.yaml on connection={{ ansible_connection }}"

View file

@ -0,0 +1,29 @@
---
- debug:
msg: "START cli/cli_command.yaml on connection={{ ansible_connection }}"
- name: get output for single command
cli_command:
commands:
- show version
register: result
- assert:
that:
- "result.changed == false"
- "result.stdout is defined"
- name: get output for multiple commands
cli_command:
commands:
- show version
- show interfaces
register: result
- assert:
that:
- "result.changed == false"
- "result.stdout is defined"
- "result.stdout | length == 2"
- debug: msg="END cli/cli_command.yaml on connection={{ ansible_connection }}"