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')
def edit_config(self, command):
for cmd in chain([b'configure'], to_list(command)):
self.send_command(cmd)
for cmd in chain(['configure'], to_list(command)):
self.send_command(to_bytes(cmd))
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)
def commit(self, comment=None):
if comment:
command = b'commit comment "{0}"'.format(comment)
command = 'commit comment "{0}"'.format(comment)
else:
command = b'commit'
self.send_command(command)
command = 'commit'
self.send_command(to_bytes(command))
def discard_changes(self, *args, **kwargs):
self.send_command(b'discard')

View file

@ -4,12 +4,19 @@
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
include: "{{ test_case_to_run }}"
- 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

View file

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

View file

@ -4,12 +4,19 @@
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
include: "{{ test_case_to_run }}"
- 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

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
vyos_command:
@ -16,4 +16,4 @@
- result.failed == true
- 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
vyos_command:
@ -17,4 +17,4 @@
- result.stdout 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
vyos_command:
@ -19,4 +19,4 @@
- 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
vyos_command:
@ -41,4 +41,4 @@
- result.stdout_lines is defined
- 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
vyos_command:
@ -15,4 +15,4 @@
- result.failed == true
- 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"
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
include: "{{ test_case_to_run }}"
- 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

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
vyos_config:
@ -23,4 +23,4 @@
that:
- "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
vyos_config:
@ -31,4 +31,4 @@
lines: set system host-name {{ inventory_hostname_short }}
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
vyos_config:
@ -51,4 +51,4 @@
match: none
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
vyos_config:
@ -30,4 +30,4 @@
lines: set system host-name {{ inventory_hostname_short }}
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"
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
include: "{{ test_case_to_run }}"
- 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

View file

@ -4,12 +4,19 @@
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
include: "{{ test_case_to_run }}"
- 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

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
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
vyos_command:

View file

@ -4,12 +4,19 @@
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
include: "{{ test_case_to_run }}"
- 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

View file

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

View file

@ -4,12 +4,19 @@
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
include: "{{ test_case_to_run }}"
- 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

View file

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

View file

@ -4,12 +4,19 @@
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
include: "{{ test_case_to_run }}"
- 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

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
vyos_config:
lines: delete service lldp

View file

@ -4,12 +4,19 @@
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
include: "{{ test_case_to_run }}"
- 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

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
vyos_config:
lines: delete service lldp

View file

@ -4,12 +4,19 @@
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
include: "{{ test_case_to_run }}"
- 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

View file

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

View file

@ -4,12 +4,19 @@
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
include: "{{ test_case_to_run }}"
- 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

View file

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

View file

@ -4,12 +4,19 @@
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
include: "{{ test_case_to_run }}"
- 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

View file

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

View file

@ -4,12 +4,19 @@
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
include: "{{ test_case_to_run }}"
- 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

View file

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

View file

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