diff options
author | CaptTrews <capttrews@gmail.com> | 2019-08-29 14:21:30 +0000 |
---|---|---|
committer | CaptTrews <capttrews@gmail.com> | 2019-08-29 14:21:30 +0000 |
commit | ae8514ce0289ee2096a3a9f54be6a4654153c880 (patch) | |
tree | 2d9a958c135c5ec4cad86650e8f7d7ef173d33c2 /tests/integration/targets/vyos_command | |
parent | 59af486ab07108815ad1774205959fa8287d6e53 (diff) | |
download | vyos.vyos-ae8514ce0289ee2096a3a9f54be6a4654153c880.tar.gz vyos.vyos-ae8514ce0289ee2096a3a9f54be6a4654153c880.zip |
Updated from network content collector
Signed-off-by: CaptTrews <capttrews@gmail.com>
Diffstat (limited to 'tests/integration/targets/vyos_command')
10 files changed, 192 insertions, 0 deletions
diff --git a/tests/integration/targets/vyos_command/aliases b/tests/integration/targets/vyos_command/aliases new file mode 100644 index 0000000..539d957 --- /dev/null +++ b/tests/integration/targets/vyos_command/aliases @@ -0,0 +1 @@ +shippable/network diff --git a/tests/integration/targets/vyos_command/defaults/main.yaml b/tests/integration/targets/vyos_command/defaults/main.yaml new file mode 100644 index 0000000..9ef5ba5 --- /dev/null +++ b/tests/integration/targets/vyos_command/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "*" +test_items: [] diff --git a/tests/integration/targets/vyos_command/tasks/cli.yaml b/tests/integration/targets/vyos_command/tasks/cli.yaml new file mode 100644 index 0000000..890d3ac --- /dev/null +++ b/tests/integration/targets/vyos_command/tasks/cli.yaml @@ -0,0 +1,22 @@ +--- +- 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 + +- 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/tests/integration/targets/vyos_command/tasks/main.yaml b/tests/integration/targets/vyos_command/tasks/main.yaml new file mode 100644 index 0000000..415c99d --- /dev/null +++ b/tests/integration/targets/vyos_command/tasks/main.yaml @@ -0,0 +1,2 @@ +--- +- { include: cli.yaml, tags: ['cli'] } diff --git a/tests/integration/targets/vyos_command/tests/cli/bad_operator.yaml b/tests/integration/targets/vyos_command/tests/cli/bad_operator.yaml new file mode 100644 index 0000000..bf3334f --- /dev/null +++ b/tests/integration/targets/vyos_command/tests/cli/bad_operator.yaml @@ -0,0 +1,19 @@ +--- +- debug: msg="START cli/bad_operator.yaml on connection={{ ansible_connection }}" + +- name: test bad operator + vyos.vyos.vyos_command: + commands: + - show version + - show interfaces + wait_for: + - result[0] is 'VyOS' + register: result + ignore_errors: yes + +- assert: + that: + - result.failed == true + - result.msg is defined + +- debug: msg="END cli/bad_operator.yaml on connection={{ ansible_connection }}" diff --git a/tests/integration/targets/vyos_command/tests/cli/cli_command.yaml b/tests/integration/targets/vyos_command/tests/cli/cli_command.yaml new file mode 100644 index 0000000..08a7675 --- /dev/null +++ b/tests/integration/targets/vyos_command/tests/cli/cli_command.yaml @@ -0,0 +1,41 @@ +--- +- debug: + msg: "START cli/cli_command.yaml on connection={{ ansible_connection }}" + +- block: + - name: get output for single command + network.cli.cli_command: + command: show version + register: result + + - assert: + that: + - "result.changed == false" + - "result.stdout is defined" + + - name: send invalid command + network.cli.cli_command: + command: 'show foo' + register: result + ignore_errors: yes + + - assert: + that: + - "result.failed == true" + - "result.msg is defined" + when: "ansible_connection == 'network_cli'" + +- block: + - name: test failure for local connection + network.cli.cli_command: + command: show version + register: result + ignore_errors: yes + + - assert: + that: + - 'result.failed == true' + - "'Connection type local is not valid for this module' in result.msg" + when: "ansible_connection == 'local'" + +- debug: msg="END cli/cli_command.yaml on connection={{ ansible_connection }}" diff --git a/tests/integration/targets/vyos_command/tests/cli/contains.yaml b/tests/integration/targets/vyos_command/tests/cli/contains.yaml new file mode 100644 index 0000000..b8665fa --- /dev/null +++ b/tests/integration/targets/vyos_command/tests/cli/contains.yaml @@ -0,0 +1,20 @@ +--- +- debug: msg="START cli/contains.yaml on connection={{ ansible_connection }}" + +- name: test contains operator + vyos.vyos.vyos_command: + commands: + - show version + - show interface + wait_for: + - result[0] contains VyOS + - result[1] contains eth0 + register: result + +- assert: + that: + - result.changed == false + - result.stdout is defined + - result.stdout_lines is defined + +- debug: msg="END cli/contains.yaml on connection={{ ansible_connection }}" diff --git a/tests/integration/targets/vyos_command/tests/cli/invalid.yaml b/tests/integration/targets/vyos_command/tests/cli/invalid.yaml new file mode 100644 index 0000000..672f6e8 --- /dev/null +++ b/tests/integration/targets/vyos_command/tests/cli/invalid.yaml @@ -0,0 +1,22 @@ +--- +- debug: msg="START cli/invalid.yaml on connection={{ ansible_connection }}" + +- name: run invalid command + vyos.vyos.vyos_command: + commands: show foo + register: result + ignore_errors: yes + +- assert: { that: result.failed } + +- name: run commands that include invalid command + vyos.vyos.vyos_command: + commands: + - show version + - show foo + register: result + ignore_errors: yes + +- assert: { that: result.failed } + +- debug: msg="END cli/invalid.yaml on connection={{ ansible_connection }}" diff --git a/tests/integration/targets/vyos_command/tests/cli/output.yaml b/tests/integration/targets/vyos_command/tests/cli/output.yaml new file mode 100644 index 0000000..bdc8b2a --- /dev/null +++ b/tests/integration/targets/vyos_command/tests/cli/output.yaml @@ -0,0 +1,44 @@ +--- +- debug: msg="START cli/output.yaml on connection={{ ansible_connection }}" + +- name: get output for single command + vyos.vyos.vyos_command: + commands: show version + register: result + +- assert: + that: + - result.changed == false + - result.stdout is defined + - result.stdout_lines is defined + +- name: get output for multiple commands + vyos.vyos.vyos_command: + commands: + - show version + - show interfaces + register: result + +- assert: + that: + - result.changed == false + - result.stdout is defined + - result.stdout | length == 2 + +- name: Get output for multiple commands that call less explicitly + vyos.vyos.vyos_command: + commands: + # NOTE: We only test show commands that will output <ANSIBLE_VYOS_TERMINAL_LENGTH + # Otherwise you will get ": "command timeout triggered" + - show hardware cpu detail + - show hardware mem + - show license + register: result + +- assert: + that: + - result.changed == false + - result.stdout_lines is defined + - result.stdout_lines[2] | length >= 20 + +- debug: msg="END cli/output.yaml on connection={{ ansible_connection }}" diff --git a/tests/integration/targets/vyos_command/tests/cli/timeout.yaml b/tests/integration/targets/vyos_command/tests/cli/timeout.yaml new file mode 100644 index 0000000..e4716ed --- /dev/null +++ b/tests/integration/targets/vyos_command/tests/cli/timeout.yaml @@ -0,0 +1,18 @@ +--- +- debug: msg="START cli/timeout.yaml on connection={{ ansible_connection }}" + +- name: test bad condition + vyos.vyos.vyos_command: + commands: + - show version + wait_for: + - result[0] contains bad_value_string + register: result + ignore_errors: yes + +- assert: + that: + - result.failed == true + - result.msg is defined + +- debug: msg="END cli/timeout.yaml on connection={{ ansible_connection }}" |