1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Actually move vyos tests to network_cli (#33710)

* Fix vyos on network_cli on python3

bytes do not have format() in Python3

* Push connection to tasks, with bonus connection=local test

* Run tests without explicit connection set

* Add/update START messages where appropriate
This commit is contained in:
Nathaniel Case 2017-12-13 14:30:24 -05:00 committed by GitHub
parent cfb15b0272
commit 2425374fdd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
37 changed files with 169 additions and 51 deletions

View file

@ -55,18 +55,18 @@ class Cliconf(CliconfBase):
return self.send_command(b'show configuration commands') return self.send_command(b'show configuration commands')
def edit_config(self, command): def edit_config(self, command):
for cmd in chain([b'configure'], to_list(command)): for cmd in chain(['configure'], to_list(command)):
self.send_command(cmd) self.send_command(to_bytes(cmd))
def get(self, command, prompt=None, answer=None, sendonly=False): def get(self, command, prompt=None, answer=None, sendonly=False):
return self.send_command(to_bytes(command), prompt=to_bytes(prompt), answer=to_bytes(answer), sendonly=sendonly) return self.send_command(to_bytes(command), prompt=to_bytes(prompt), answer=to_bytes(answer), sendonly=sendonly)
def commit(self, comment=None): def commit(self, comment=None):
if comment: if comment:
command = b'commit comment "{0}"'.format(comment) command = 'commit comment "{0}"'.format(comment)
else: else:
command = b'commit' command = 'commit'
self.send_command(command) self.send_command(to_bytes(command))
def discard_changes(self, *args, **kwargs): def discard_changes(self, *args, **kwargs):
self.send_command(b'discard') self.send_command(b'discard')

View file

@ -4,12 +4,19 @@
paths: "{{ role_path }}/tests/cli" paths: "{{ role_path }}/tests/cli"
patterns: "{{ testcase }}.yaml" patterns: "{{ testcase }}.yaml"
register: test_cases register: test_cases
delegate_to: localhost
- name: set test_items - name: set test_items
set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}"
- name: run test case - name: run test case (connection=network_cli)
include: "{{ test_case_to_run }}" include: "{{ test_case_to_run }} ansible_connection=network_cli"
with_items: "{{ test_items }}" with_items: "{{ test_items }}"
loop_control: loop_control:
loop_var: test_case_to_run 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

View file

@ -1,4 +1,7 @@
--- ---
- debug:
msg: "cli/basic-no-login.yaml on connection={{ ansible_connection }}"
- name: Setup - name: Setup
vyos_banner: vyos_banner:
banner: pre-login banner: pre-login

View file

@ -1,4 +1,7 @@
--- ---
- debug:
msg: "cli/basic-post-login.yaml on connection={{ ansible_connection }}"
- name: setup - remove post-login - name: setup - remove post-login
vyos_banner: vyos_banner:
banner: post-login banner: post-login

View file

@ -1,4 +1,7 @@
--- ---
- debug:
msg: "cli/basic-pre-login.yaml on connection={{ ansible_connection }}"
- name: setup - remove pre-login - name: setup - remove pre-login
vyos_banner: vyos_banner:
banner: pre-login banner: pre-login

View file

@ -4,12 +4,19 @@
paths: "{{ role_path }}/tests/cli" paths: "{{ role_path }}/tests/cli"
patterns: "{{ testcase }}.yaml" patterns: "{{ testcase }}.yaml"
register: test_cases register: test_cases
delegate_to: localhost
- name: set test_items - name: set test_items
set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}"
- name: run test case - name: run test case (connection=network_cli)
include: "{{ test_case_to_run }}" include: "{{ test_case_to_run }} ansible_connection=network_cli"
with_items: "{{ test_items }}" with_items: "{{ test_items }}"
loop_control: loop_control:
loop_var: test_case_to_run 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

View file

@ -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 - name: test bad operator
vyos_command: vyos_command:
@ -16,4 +16,4 @@
- result.failed == true - result.failed == true
- result.msg is defined - result.msg is defined
- debug: msg="END cli/bad_operator.yaml" - debug: msg="END cli/bad_operator.yaml on connection={{ ansible_connection }}"

View file

@ -1,5 +1,5 @@
--- ---
- debug: msg="START cli/contains.yaml" - debug: msg="START cli/contains.yaml on connection={{ ansible_connection }}"
- name: test contains operator - name: test contains operator
vyos_command: vyos_command:
@ -17,4 +17,4 @@
- result.stdout is defined - result.stdout is defined
- result.stdout_lines is defined - result.stdout_lines is defined
- debug: msg="END cli/contains.yaml" - debug: msg="END cli/contains.yaml on connection={{ ansible_connection }}"

View file

@ -1,5 +1,5 @@
--- ---
- debug: msg="START cli/invalid.yaml" - debug: msg="START cli/invalid.yaml on connection={{ ansible_connection }}"
- name: run invalid command - name: run invalid command
vyos_command: vyos_command:
@ -19,4 +19,4 @@
- assert: { that: result.failed } - assert: { that: result.failed }
- debug: msg="END cli/invalid.yaml" - debug: msg="END cli/invalid.yaml on connection={{ ansible_connection }}"

View file

@ -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 - name: get output for single command
vyos_command: vyos_command:
@ -41,4 +41,4 @@
- result.stdout_lines is defined - result.stdout_lines is defined
- result.stdout_lines[2] | length >= 20 - result.stdout_lines[2] | length >= 20
- debug: msg="END cli/output.yaml" - debug: msg="END cli/output.yaml on connection={{ ansible_connection }}"

View file

@ -1,5 +1,5 @@
--- ---
- debug: msg="START cli/timeout.yaml" - debug: msg="START cli/timeout.yaml on connection={{ ansible_connection }}"
- name: test bad condition - name: test bad condition
vyos_command: vyos_command:
@ -15,4 +15,4 @@
- result.failed == true - result.failed == true
- result.msg is defined - result.msg is defined
- debug: msg="END cli/timeout.yaml" - debug: msg="END cli/timeout.yaml on connection={{ ansible_connection }}"

View file

@ -4,12 +4,19 @@
paths: "{{ role_path }}/tests/cli" paths: "{{ role_path }}/tests/cli"
patterns: "{{ testcase }}.yaml" patterns: "{{ testcase }}.yaml"
register: test_cases register: test_cases
delegate_to: localhost
- name: set test_items - name: set test_items
set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}"
- name: run test case - name: run test case (connection=network_cli)
include: "{{ test_case_to_run }}" include: "{{ test_case_to_run }} ansible_connection=network_cli"
with_items: "{{ test_items }}" with_items: "{{ test_items }}"
loop_control: loop_control:
loop_var: test_case_to_run 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

View file

@ -1,5 +1,5 @@
--- ---
- debug: msg="START cli/config_check.yaml" - debug: msg="START cli/config_check.yaml on connection={{ ansible_connection }}"
- name: setup - name: setup
vyos_config: vyos_config:
@ -23,4 +23,4 @@
that: that:
- "result.changed == false" - "result.changed == false"
- debug: msg="END cli/config_check.yaml" - debug: msg="END cli/config_check.yaml on connection={{ ansible_connection }}"

View file

@ -1,5 +1,5 @@
--- ---
- debug: msg="START cli/comment.yaml" - debug: msg="START cli/comment.yaml on connection={{ ansible_connection }}"
- name: setup - name: setup
vyos_config: vyos_config:
@ -31,4 +31,4 @@
lines: set system host-name {{ inventory_hostname_short }} lines: set system host-name {{ inventory_hostname_short }}
match: none match: none
- debug: msg="END cli/comment.yaml" - debug: msg="END cli/comment.yaml on connection={{ ansible_connection }}"

View file

@ -1,5 +1,5 @@
--- ---
- debug: msg="START cli/save.yaml" - debug: msg="START cli/save.yaml on connection={{ ansible_connection }}"
- name: setup - name: setup
vyos_config: vyos_config:
@ -51,4 +51,4 @@
match: none match: none
save: true save: true
- debug: msg="END cli/simple.yaml" - debug: msg="END cli/simple.yaml on connection={{ ansible_connection }}"

View file

@ -1,5 +1,5 @@
--- ---
- debug: msg="START cli/simple.yaml" - debug: msg="START cli/simple.yaml on connection={{ ansible_connection }}"
- name: setup - name: setup
vyos_config: vyos_config:
@ -30,4 +30,4 @@
lines: set system host-name {{ inventory_hostname_short }} lines: set system host-name {{ inventory_hostname_short }}
match: none match: none
- debug: msg="END cli/simple.yaml" - debug: msg="END cli/simple.yaml on connection={{ ansible_connection }}"

View file

@ -4,12 +4,19 @@
paths: "{{ role_path }}/tests/cli" paths: "{{ role_path }}/tests/cli"
patterns: "{{ testcase }}.yaml" patterns: "{{ testcase }}.yaml"
register: test_cases register: test_cases
delegate_to: localhost
- name: set test_items - name: set test_items
set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}"
- name: run test case - name: run test case (connection=network_cli)
include: "{{ test_case_to_run }}" include: "{{ test_case_to_run }} ansible_connection=network_cli"
with_items: "{{ test_items }}" with_items: "{{ test_items }}"
loop_control: loop_control:
loop_var: test_case_to_run 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

View file

@ -4,12 +4,19 @@
paths: "{{ role_path }}/tests/cli" paths: "{{ role_path }}/tests/cli"
patterns: "{{ testcase }}.yaml" patterns: "{{ testcase }}.yaml"
register: test_cases register: test_cases
delegate_to: localhost
- name: set test_items - name: set test_items
set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}"
- name: run test case - name: run test case (connection=network_cli)
include: "{{ test_case_to_run }}" include: "{{ test_case_to_run }} ansible_connection=network_cli"
with_items: "{{ test_items }}" with_items: "{{ test_items }}"
loop_control: loop_control:
loop_var: test_case_to_run 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

View file

@ -1,5 +1,5 @@
--- ---
- debug: msg="START vyos_interface cli/basic.yaml" - debug: msg="START cli/basic.yaml on connection={{ ansible_connection }}"
- name: Run vyos lsmod command - name: Run vyos lsmod command
vyos_command: vyos_command:

View file

@ -1,5 +1,5 @@
--- ---
- debug: msg="START vyos_interface cli/intent.yaml" - debug: msg="START cli/intent.yaml on connection={{ ansible_connection }}"
- name: Run vyos lsmod command - name: Run vyos lsmod command
vyos_command: vyos_command:

View file

@ -4,12 +4,19 @@
paths: "{{ role_path }}/tests/cli" paths: "{{ role_path }}/tests/cli"
patterns: "{{ testcase }}.yaml" patterns: "{{ testcase }}.yaml"
register: test_cases register: test_cases
delegate_to: localhost
- name: set test_items - name: set test_items
set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}"
- name: run test case - name: run test case (connection=network_cli)
include: "{{ test_case_to_run }}" include: "{{ test_case_to_run }} ansible_connection=network_cli"
with_items: "{{ test_items }}" with_items: "{{ test_items }}"
loop_control: loop_control:
loop_var: test_case_to_run 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

View file

@ -1,4 +1,6 @@
--- ---
- debug: msg="START cli/basic.yaml on connection={{ ansible_connection }}"
- name: Remove IP address - name: Remove IP address
vyos_l3_interface: vyos_l3_interface:
name: eth1 name: eth1

View file

@ -4,12 +4,19 @@
paths: "{{ role_path }}/tests/cli" paths: "{{ role_path }}/tests/cli"
patterns: "{{ testcase }}.yaml" patterns: "{{ testcase }}.yaml"
register: test_cases register: test_cases
delegate_to: localhost
- name: set test_items - name: set test_items
set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}"
- name: run test case - name: run test case (connection=network_cli)
include: "{{ test_case_to_run }}" include: "{{ test_case_to_run }} ansible_connection=network_cli"
with_items: "{{ test_items }}" with_items: "{{ test_items }}"
loop_control: loop_control:
loop_var: test_case_to_run 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

View file

@ -1,4 +1,6 @@
--- ---
- debug: msg="cli/basic.yaml on connection={{ ansible_connection }}"
- name: Remove linkagg - name: Remove linkagg
vyos_linkagg: vyos_linkagg:
name: bond0 name: bond0

View file

@ -4,12 +4,19 @@
paths: "{{ role_path }}/tests/cli" paths: "{{ role_path }}/tests/cli"
patterns: "{{ testcase }}.yaml" patterns: "{{ testcase }}.yaml"
register: test_cases register: test_cases
delegate_to: localhost
- name: set test_items - name: set test_items
set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}"
- name: run test case - name: run test case (connection=network_cli)
include: "{{ test_case_to_run }}" include: "{{ test_case_to_run }} ansible_connection=network_cli"
with_items: "{{ test_items }}" with_items: "{{ test_items }}"
loop_control: loop_control:
loop_var: test_case_to_run 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

View file

@ -1,4 +1,6 @@
--- ---
- debug: msg="START cli/basic.yaml on connection={{ ansible_connection }}"
- name: Make sure LLDP is not running before tests - name: Make sure LLDP is not running before tests
vyos_config: vyos_config:
lines: delete service lldp lines: delete service lldp

View file

@ -4,12 +4,19 @@
paths: "{{ role_path }}/tests/cli" paths: "{{ role_path }}/tests/cli"
patterns: "{{ testcase }}.yaml" patterns: "{{ testcase }}.yaml"
register: test_cases register: test_cases
delegate_to: localhost
- name: set test_items - name: set test_items
set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}"
- name: run test case - name: run test case (connection=network_cli)
include: "{{ test_case_to_run }}" include: "{{ test_case_to_run }} ansible_connection=network_cli"
with_items: "{{ test_items }}" with_items: "{{ test_items }}"
loop_control: loop_control:
loop_var: test_case_to_run 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

View file

@ -1,4 +1,6 @@
--- ---
- debug: msg="START cli/basic.yaml on connection={{ ansible_connection }}"
- name: Make sure LLDP is not running before tests - name: Make sure LLDP is not running before tests
vyos_config: vyos_config:
lines: delete service lldp lines: delete service lldp

View file

@ -4,12 +4,19 @@
paths: "{{ role_path }}/tests/cli" paths: "{{ role_path }}/tests/cli"
patterns: "{{ testcase }}.yaml" patterns: "{{ testcase }}.yaml"
register: test_cases register: test_cases
delegate_to: localhost
- name: set test_items - name: set test_items
set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}"
- name: run test case - name: run test case (connection=network_cli)
include: "{{ test_case_to_run }}" include: "{{ test_case_to_run }} ansible_connection=network_cli"
with_items: "{{ test_items }}" with_items: "{{ test_items }}"
loop_control: loop_control:
loop_var: test_case_to_run 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

View file

@ -1,4 +1,6 @@
--- ---
- debug: msg="START cli/basic.yaml on connection={{ ansible_connection }}"
- name: set-up logging - name: set-up logging
vyos_logging: vyos_logging:
dest: console dest: console

View file

@ -4,12 +4,19 @@
paths: "{{ role_path }}/tests/cli" paths: "{{ role_path }}/tests/cli"
patterns: "{{ testcase }}.yaml" patterns: "{{ testcase }}.yaml"
register: test_cases register: test_cases
delegate_to: localhost
- name: set test_items - name: set test_items
set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}"
- name: run test case - name: run test case (connection=network_cli)
include: "{{ test_case_to_run }}" include: "{{ test_case_to_run }} ansible_connection=network_cli"
with_items: "{{ test_items }}" with_items: "{{ test_items }}"
loop_control: loop_control:
loop_var: test_case_to_run 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

View file

@ -1,4 +1,6 @@
--- ---
- debug: msg="START cli/basic.yaml on connection={{ ansible_connection }}"
- name: create static route - name: create static route
vyos_static_route: vyos_static_route:
prefix: 172.24.0.0/24 prefix: 172.24.0.0/24

View file

@ -4,12 +4,19 @@
paths: "{{ role_path }}/tests/cli" paths: "{{ role_path }}/tests/cli"
patterns: "{{ testcase }}.yaml" patterns: "{{ testcase }}.yaml"
register: test_cases register: test_cases
delegate_to: localhost
- name: set test_items - name: set test_items
set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}"
- name: run test case - name: run test case (connection=network_cli)
include: "{{ test_case_to_run }}" include: "{{ test_case_to_run }} ansible_connection=network_cli"
with_items: "{{ test_items }}" with_items: "{{ test_items }}"
loop_control: loop_control:
loop_var: test_case_to_run 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

View file

@ -1,4 +1,6 @@
--- ---
- debug: msg="START cli/basic.yaml on connection={{ ansible_connection }}"
- name: Setup - name: Setup
vyos_config: vyos_config:
lines: lines:

View file

@ -4,12 +4,19 @@
paths: "{{ role_path }}/tests/cli" paths: "{{ role_path }}/tests/cli"
patterns: "{{ testcase }}.yaml" patterns: "{{ testcase }}.yaml"
register: test_cases register: test_cases
delegate_to: localhost
- name: set test_items - name: set test_items
set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}"
- name: run test case - name: run test case (connection=network_cli)
include: "{{ test_case_to_run }}" include: "{{ test_case_to_run }} ansible_connection=network_cli"
with_items: "{{ test_items }}" with_items: "{{ test_items }}"
loop_control: loop_control:
loop_var: test_case_to_run 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

View file

@ -1,4 +1,6 @@
--- ---
- debug: msg="START cli/basic.yaml on connection={{ ansible_connection }}"
- name: setup - remove vlan used in test - name: setup - remove vlan used in test
vyos_config: vyos_config:
lines: lines:

View file

@ -1,4 +1,6 @@
--- ---
- debug: msg="START cli/multiple.yaml on connection={{ ansible_connection }}"
- name: setup - remove vlan used in test - name: setup - remove vlan used in test
vyos_config: vyos_config:
lines: lines: