mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-10-24 04:54:00 -07:00
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:
parent
086cb0233f
commit
ab39481c31
15 changed files with 480 additions and 6 deletions
|
|
@ -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 }}"
|
||||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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 }}"
|
||||
|
|
@ -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 }}"
|
||||
|
|
|
|||
|
|
@ -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 }}"
|
||||
16
test/integration/targets/junos_smoke/tasks/cli.yaml
Normal file
16
test/integration/targets/junos_smoke/tasks/cli.yaml
Normal 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
|
||||
|
|
@ -1,2 +1,3 @@
|
|||
---
|
||||
- { include: netconf.yaml, tags: ['netconf'] }
|
||||
- { include: cli.yaml, tags: ['cli'] }
|
||||
|
|
|
|||
|
|
@ -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 }}"
|
||||
|
|
@ -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 }}"
|
||||
|
|
@ -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 }}"
|
||||
Loading…
Add table
Add a link
Reference in a new issue