mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-08 06:12:51 +00:00
Add vyos_vlan DI module (#32072)
* Add vyos_vlan DI module Signed-off-by: Trishna Guha <trishnaguha17@gmail.com> * Add integration tests Signed-off-by: Trishna Guha <trishnaguha17@gmail.com> * Improve logic and add more test Signed-off-by: Trishna Guha <trishnaguha17@gmail.com> * update boilerplate Signed-off-by: Trishna Guha <trishnaguha17@gmail.com>
This commit is contained in:
3
test/integration/targets/vyos_vlan/defaults/main.yaml
Normal file
3
test/integration/targets/vyos_vlan/defaults/main.yaml
Normal file
@@ -0,0 +1,3 @@
|
||||
---
|
||||
testcase: "*"
|
||||
test_items: []
|
||||
15
test/integration/targets/vyos_vlan/tasks/cli.yaml
Normal file
15
test/integration/targets/vyos_vlan/tasks/cli.yaml
Normal file
@@ -0,0 +1,15 @@
|
||||
---
|
||||
- name: collect all cli test cases
|
||||
find:
|
||||
paths: "{{ role_path }}/tests/cli"
|
||||
patterns: "{{ testcase }}.yaml"
|
||||
register: test_cases
|
||||
|
||||
- name: set test_items
|
||||
set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}"
|
||||
|
||||
- name: run test case
|
||||
include: "{{ test_case_to_run }}"
|
||||
with_items: "{{ test_items }}"
|
||||
loop_control:
|
||||
loop_var: test_case_to_run
|
||||
2
test/integration/targets/vyos_vlan/tasks/main.yaml
Normal file
2
test/integration/targets/vyos_vlan/tasks/main.yaml
Normal file
@@ -0,0 +1,2 @@
|
||||
---
|
||||
- { include: cli.yaml, tags: ['cli'] }
|
||||
73
test/integration/targets/vyos_vlan/tests/cli/basic.yaml
Normal file
73
test/integration/targets/vyos_vlan/tests/cli/basic.yaml
Normal file
@@ -0,0 +1,73 @@
|
||||
---
|
||||
- name: setup - remove vlan used in test
|
||||
vyos_config:
|
||||
lines:
|
||||
- delete interfaces ethernet eth1 vif 100
|
||||
- delete interfaces ethernet eth0 vif 5
|
||||
- delete interfaces ethernet eth0 vif 100
|
||||
|
||||
- name: set vlan with name
|
||||
vyos_vlan: &name
|
||||
vlan_id: 100
|
||||
name: vlan-100
|
||||
interfaces: eth1
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "result.changed == true"
|
||||
- "'set interfaces ethernet eth1 vif 100 description vlan-100' in result.commands"
|
||||
|
||||
- name: set vlan with name(idempotence)
|
||||
vyos_vlan: *name
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "result.changed == false"
|
||||
|
||||
- name: set vlan with address
|
||||
vyos_vlan: &address
|
||||
vlan_id: 5
|
||||
address: 172.24.5.0/24
|
||||
interfaces: eth0
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "result.changed == true"
|
||||
- "'set interfaces ethernet eth0 vif 5 address 172.24.5.0/24' in result.commands"
|
||||
|
||||
- name: set vlan with address(idempotence)
|
||||
vyos_vlan: *address
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "result.changed == false"
|
||||
|
||||
- name: delete
|
||||
vyos_vlan: &delete
|
||||
vlan_id: 100
|
||||
interfaces: eth1
|
||||
state: absent
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "result.changed == true"
|
||||
- "'delete interfaces ethernet eth1 vif 100' in result.commands"
|
||||
|
||||
- name: delete(idempotence)
|
||||
vyos_vlan: *delete
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "result.changed == false"
|
||||
|
||||
- name: teardown
|
||||
vyos_config:
|
||||
lines:
|
||||
- delete interfaces ethernet eth1 vif 100
|
||||
- delete interfaces ethernet eth0 vif 5
|
||||
58
test/integration/targets/vyos_vlan/tests/cli/multiple.yaml
Normal file
58
test/integration/targets/vyos_vlan/tests/cli/multiple.yaml
Normal file
@@ -0,0 +1,58 @@
|
||||
---
|
||||
- name: setup - remove vlan used in test
|
||||
vyos_config:
|
||||
lines:
|
||||
- delete interfaces ethernet eth0 vif 5
|
||||
- delete interfaces ethernet eth0 vif 100
|
||||
- delete interfaces ethernet eth1 vif 100
|
||||
|
||||
- name: Add multiple interfaces to vlan
|
||||
vyos_vlan: &multiple
|
||||
vlan_id: 100
|
||||
interfaces:
|
||||
- eth0
|
||||
- eth1
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "result.changed == true"
|
||||
- "'set interfaces ethernet eth0 vif 100' in result.commands"
|
||||
- "'set interfaces ethernet eth1 vif 100' in result.commands"
|
||||
|
||||
- name: Add multiple interfaces to vlan(idempotence)
|
||||
vyos_vlan: *multiple
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "result.changed == false"
|
||||
|
||||
- name: delete vlan with multiple interfaces
|
||||
vyos_vlan: &delete_multiple
|
||||
vlan_id: 100
|
||||
interfaces:
|
||||
- eth0
|
||||
- eth1
|
||||
state: absent
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "result.changed == true"
|
||||
- "'delete interfaces ethernet eth0 vif 100' in result.commands"
|
||||
- "'delete interfaces ethernet eth1 vif 100' in result.commands"
|
||||
|
||||
- name: delete vlan with multiple interfaces(idempotence)
|
||||
vyos_vlan: *delete_multiple
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "result.changed == false"
|
||||
|
||||
- name: teardown
|
||||
vyos_config:
|
||||
lines:
|
||||
- delete interfaces ethernet eth0 vif 100
|
||||
- delete interfaces ethernet eth1 vif 100
|
||||
@@ -123,6 +123,15 @@
|
||||
failed_modules: "{{ failed_modules }} + [ 'vyos_facts' ]"
|
||||
test_failed: true
|
||||
|
||||
- block:
|
||||
- include_role:
|
||||
name: vyos_vlan
|
||||
when: "limit_to in ['*', 'vyos_vlan']"
|
||||
rescue:
|
||||
- set_fact:
|
||||
failed_modules: "{{ failed_modules }} + [ 'vyos_vlan' ]"
|
||||
test_failed: true
|
||||
|
||||
###########
|
||||
- debug: var=failed_modules
|
||||
when: test_failed
|
||||
|
||||
Reference in New Issue
Block a user