mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-06 13:22:48 +00:00
ios_l2_interface (#35054)
* Fix sending 'None' to device on ios * Add ios_l2_interface module & tests * Skip l2 tests on non-l2 images * Allow test to continue on non-L2 hosts
This commit is contained in:
@@ -1,39 +1,6 @@
|
||||
---
|
||||
- debug: msg="START ios_interface cli/basic.yaml on connection={{ ansible_connection }}"
|
||||
|
||||
- name: Run show version
|
||||
ios_command:
|
||||
commands: show version
|
||||
authorize: yes
|
||||
register: show_version_result
|
||||
|
||||
- block:
|
||||
- name: Set test interface to GigabitEthernet0/1 as we are on Cisco IOS
|
||||
set_fact: test_interface=GigabitEthernet0/1
|
||||
- name: Set test interface 2 to GigabitEthernet0/2 as we are on Cisco IOS
|
||||
set_fact: test_interface2=GigabitEthernet0/2
|
||||
when: "'Cisco IOS' in show_version_result.stdout[0]"
|
||||
|
||||
- block:
|
||||
- name: Set test interface to GigabitEthernet2 as we are on Cisco IOS-XE
|
||||
set_fact: test_interface=GigabitEthernet2
|
||||
- name: Disable autonegotiation on GigabitEthernet2
|
||||
ios_config:
|
||||
lines:
|
||||
- no negotiation auto
|
||||
parents: int GigabitEthernet2
|
||||
authorize: yes
|
||||
|
||||
- name: Set test interface 2 to GigabitEthernet3 as we are on Cisco IOS-XE
|
||||
set_fact: test_interface2=GigabitEthernet3
|
||||
- name: Disable autonegotiation on GigabitEthernet3
|
||||
ios_config:
|
||||
lines:
|
||||
- no negotiation auto
|
||||
parents: int GigabitEthernet3
|
||||
authorize: yes
|
||||
when: "'Cisco IOS-XE' in show_version_result.stdout[0]"
|
||||
|
||||
- name: Configure interface (setup)
|
||||
ios_interface:
|
||||
name: "{{ test_interface }}"
|
||||
|
||||
@@ -1,21 +1,6 @@
|
||||
---
|
||||
- debug: msg="START ios_interface cli/intent.yaml on connection={{ ansible_connection }}"
|
||||
|
||||
- name: Run show version
|
||||
ios_command:
|
||||
commands: show version
|
||||
authorize: yes
|
||||
register: show_version_result
|
||||
|
||||
- name: Set test interface to GigabitEthernet0/2 if we are on Cisco IOS
|
||||
set_fact: test_interface=GigabitEthernet0/2
|
||||
when: "'Cisco IOS' in show_version_result.stdout[0]"
|
||||
|
||||
- name: Set test interface to GigabitEthernet2 if we are on Cisco IOS-XE
|
||||
set_fact: test_interface=GigabitEthernet2
|
||||
when: "'Cisco IOS-XE' in show_version_result.stdout[0]"
|
||||
|
||||
|
||||
- name: Check intent arguments
|
||||
ios_interface:
|
||||
name: "{{ test_interface }}"
|
||||
|
||||
@@ -4,39 +4,6 @@
|
||||
# Add minimal testcase to check args are passed correctly to
|
||||
# implementation module and module run is successful.
|
||||
|
||||
- name: Run show version
|
||||
ios_command:
|
||||
commands: show version
|
||||
authorize: yes
|
||||
register: show_version_result
|
||||
|
||||
- block:
|
||||
- name: Set test interface to GigabitEthernet0/1 as we are on Cisco IOS
|
||||
set_fact: test_interface=GigabitEthernet0/1
|
||||
- name: Set test interface 2 to GigabitEthernet0/2 as we are on Cisco IOS
|
||||
set_fact: test_interface2=GigabitEthernet0/2
|
||||
when: "'Cisco IOS' in show_version_result.stdout[0]"
|
||||
|
||||
- block:
|
||||
- name: Set test interface to GigabitEthernet2 as we are on Cisco IOS-XE
|
||||
set_fact: test_interface=GigabitEthernet2
|
||||
- name: Disable autonegotiation on GigabitEthernet2
|
||||
ios_config:
|
||||
lines:
|
||||
- no negotiation auto
|
||||
parents: int GigabitEthernet2
|
||||
authorize: yes
|
||||
|
||||
- name: Set test interface 2 to GigabitEthernet3 as we are on Cisco IOS-XE
|
||||
set_fact: test_interface2=GigabitEthernet3
|
||||
- name: Disable autonegotiation on GigabitEthernet3
|
||||
ios_config:
|
||||
lines:
|
||||
- no negotiation auto
|
||||
parents: int GigabitEthernet3
|
||||
authorize: yes
|
||||
when: "'Cisco IOS-XE' in show_version_result.stdout[0]"
|
||||
|
||||
- name: Configure interface (setup)
|
||||
net_interface:
|
||||
name: "{{ test_interface }}"
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
---
|
||||
testcase: "*"
|
||||
2
test/integration/targets/ios_l2_interface/meta/main.yml
Normal file
2
test/integration/targets/ios_l2_interface/meta/main.yml
Normal file
@@ -0,0 +1,2 @@
|
||||
dependencies:
|
||||
- prepare_ios_tests
|
||||
24
test/integration/targets/ios_l2_interface/tasks/cli.yaml
Normal file
24
test/integration/targets/ios_l2_interface/tasks/cli.yaml
Normal file
@@ -0,0 +1,24 @@
|
||||
---
|
||||
- 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 cases (connection=network_cli)
|
||||
include: "{{ test_case_to_run }}"
|
||||
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:
|
||||
- files: "{{ test_items|default([]) }}"
|
||||
skip: true
|
||||
loop_control:
|
||||
loop_var: test_case_to_run
|
||||
@@ -0,0 +1,4 @@
|
||||
---
|
||||
- block:
|
||||
- { include: cli.yaml, tags: ['cli'] }
|
||||
when: 'switch_type == "L2"'
|
||||
81
test/integration/targets/ios_l2_interface/tests/cli/agg.yaml
Normal file
81
test/integration/targets/ios_l2_interface/tests/cli/agg.yaml
Normal file
@@ -0,0 +1,81 @@
|
||||
---
|
||||
- debug: msg="START connection={{ ansible_connection }} ios_l2_interface aggregate test"
|
||||
|
||||
- name: Setup - Ensure interfaces are switchport
|
||||
ios_config:
|
||||
lines:
|
||||
- switchport
|
||||
parents:
|
||||
- "interface {{ item }}"
|
||||
loop:
|
||||
- "{{ test_interface }}"
|
||||
- "{{ test_interface2 }}"
|
||||
|
||||
- name: "Setup vlans"
|
||||
ios_vlan:
|
||||
aggregate:
|
||||
- vlan_id: 6
|
||||
- vlan_id: 15
|
||||
provider: "{{ cli }}"
|
||||
|
||||
- name: Setup - Remove interface aggregate before testing
|
||||
ios_l2_interface:
|
||||
aggregate:
|
||||
- { name: "{{ test_interface }}", mode: access, access_vlan: 6 }
|
||||
- { name: "{{ test_interface2 }}", mode: access, access_vlan: 15 }
|
||||
state: absent
|
||||
provider: "{{ cli }}"
|
||||
|
||||
- block:
|
||||
- name: Configure interface for access_vlan aggregate
|
||||
ios_l2_interface: &conf_agg
|
||||
aggregate:
|
||||
- { name: "{{ test_interface }}", mode: access, access_vlan: 6 }
|
||||
- { name: "{{ test_interface2 }}", mode: access, access_vlan: 15 }
|
||||
provider: "{{ cli }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "result.changed == true"
|
||||
|
||||
- name: Configure interface for access_vlan aggregate(Idempotence)
|
||||
ios_l2_interface: *conf_agg
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "result.changed == false"
|
||||
|
||||
- name: Remove interface aggregate
|
||||
ios_l2_interface: &rm_agg
|
||||
aggregate:
|
||||
- { name: "{{ test_interface }}", mode: access, access_vlan: 6 }
|
||||
- { name: "{{ test_interface2 }}", mode: access, access_vlan: 15 }
|
||||
provider: "{{ cli }}"
|
||||
state: absent
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "result.changed == true"
|
||||
|
||||
- name: Remove interface aggregate(Idempotence)
|
||||
ios_l2_interface: *rm_agg
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "result.changed == false"
|
||||
|
||||
always:
|
||||
- name: "remove vlans"
|
||||
ios_vlan:
|
||||
aggregate:
|
||||
- vlan_id: 6
|
||||
- vlan_id: 15
|
||||
state: absent
|
||||
provider: "{{ cli }}"
|
||||
ignore_errors: yes
|
||||
|
||||
- debug: msg="END connection={{ ansible_connection }} ios_l2_interface aggregate test"
|
||||
139
test/integration/targets/ios_l2_interface/tests/cli/sanity.yaml
Normal file
139
test/integration/targets/ios_l2_interface/tests/cli/sanity.yaml
Normal file
@@ -0,0 +1,139 @@
|
||||
---
|
||||
- debug: msg="START connection={{ ansible_connection }} ios_l2_interface sanity test"
|
||||
|
||||
- name: "Setup interface"
|
||||
ios_config: &default
|
||||
lines:
|
||||
- "default interface {{ test_interface }}"
|
||||
provider: "{{ cli }}"
|
||||
|
||||
- name: set trunk encapsulation type
|
||||
ios_config:
|
||||
lines:
|
||||
- switchport trunk encapsulation dot1q
|
||||
parents:
|
||||
- "interface {{ test_interface }}"
|
||||
provider: "{{ cli }}"
|
||||
|
||||
- name: "Setup vlans"
|
||||
ios_vlan:
|
||||
aggregate:
|
||||
- vlan_id: 5
|
||||
- vlan_id: 6
|
||||
- vlan_id: 7
|
||||
- vlan_id: 8
|
||||
- vlan_id: 9
|
||||
- vlan_id: 10
|
||||
- vlan_id: 20
|
||||
provider: "{{ cli }}"
|
||||
|
||||
- block:
|
||||
- name: Ensure interface is in its default switchport state
|
||||
ios_l2_interface: &def_swi
|
||||
name: "{{ test_interface }}"
|
||||
state: unconfigured
|
||||
provider: "{{ cli }}"
|
||||
|
||||
- name: Ensure interface is configured for access vlan 20
|
||||
ios_l2_interface: &acc_vl
|
||||
name: "{{ test_interface }}"
|
||||
mode: access
|
||||
access_vlan: 20
|
||||
provider: "{{ cli }}"
|
||||
register: result
|
||||
|
||||
- assert: &true
|
||||
that:
|
||||
- "result.changed == true"
|
||||
|
||||
- name: "access vlan Idempotence"
|
||||
ios_l2_interface: *acc_vl
|
||||
register: result
|
||||
|
||||
- assert: &false
|
||||
that:
|
||||
- "result.changed == false"
|
||||
|
||||
- name: Ensure interface only has vlans 5-10 as trunk vlans
|
||||
ios_l2_interface: &tr_vl
|
||||
name: "{{ test_interface }}"
|
||||
mode: trunk
|
||||
native_vlan: 10
|
||||
trunk_allowed_vlans: 5-10
|
||||
provider: "{{ cli }}"
|
||||
register: result
|
||||
|
||||
- assert: *true
|
||||
|
||||
- name: "trunk vlan Idempotence"
|
||||
ios_l2_interface: *tr_vl
|
||||
register: result
|
||||
|
||||
- assert: *false
|
||||
|
||||
- name: Ensure interface is a trunk port and ensure 2-50 are being tagged (doesn't mean others aren't also being tagged)
|
||||
ios_l2_interface: &tag
|
||||
name: "{{ test_interface }}"
|
||||
mode: trunk
|
||||
native_vlan: 10
|
||||
trunk_vlans: 2-50
|
||||
provider: "{{ cli }}"
|
||||
register: result
|
||||
|
||||
- assert: *true
|
||||
|
||||
- name: "tag vlan Idempotence"
|
||||
ios_l2_interface: *tag
|
||||
register: result
|
||||
|
||||
- assert: *false
|
||||
|
||||
- name: Ensure these VLANs are not being tagged on the trunk
|
||||
ios_l2_interface: &no_tag
|
||||
name: "{{ test_interface }}"
|
||||
mode: trunk
|
||||
trunk_vlans: 30-4094
|
||||
state: absent
|
||||
provider: "{{ cli }}"
|
||||
register: result
|
||||
|
||||
- assert: *true
|
||||
|
||||
- name: "no tag vlan Idempotence"
|
||||
ios_l2_interface: *no_tag
|
||||
register: result
|
||||
|
||||
- assert: *false
|
||||
|
||||
- name: put interface default state
|
||||
ios_l2_interface: *def_swi
|
||||
register: result
|
||||
|
||||
- assert: *true
|
||||
|
||||
- name: "default state idempotence"
|
||||
ios_l2_interface: *def_swi
|
||||
register: result
|
||||
|
||||
- assert: *false
|
||||
|
||||
always:
|
||||
- name: "remove vlans"
|
||||
ios_vlan:
|
||||
aggregate:
|
||||
- vlan_id: 5
|
||||
- vlan_id: 6
|
||||
- vlan_id: 7
|
||||
- vlan_id: 8
|
||||
- vlan_id: 9
|
||||
- vlan_id: 10
|
||||
- vlan_id: 20
|
||||
state: absent
|
||||
provider: "{{ cli }}"
|
||||
ignore_errors: yes
|
||||
|
||||
- name: "default interface"
|
||||
ios_config: *default
|
||||
ignore_errors: yes
|
||||
|
||||
- debug: msg="END connection={{ ansible_connection }} ios_l2_interface sanity test"
|
||||
@@ -1,39 +1,6 @@
|
||||
---
|
||||
- debug: msg="START ios_l3_interface cli/basic.yaml on connection={{ ansible_connection }}"
|
||||
|
||||
- name: Run show version
|
||||
ios_command:
|
||||
commands: show version
|
||||
authorize: yes
|
||||
register: show_version_result
|
||||
|
||||
- block:
|
||||
- name: Set test interface to GigabitEthernet0/1 as we are on Cisco IOS
|
||||
set_fact: test_interface=GigabitEthernet0/1
|
||||
- name: Set test interface 2 to GigabitEthernet0/2 as we are on Cisco IOS
|
||||
set_fact: test_interface2=GigabitEthernet0/2
|
||||
when: "'Cisco IOS' in show_version_result.stdout[0]"
|
||||
|
||||
- block:
|
||||
- name: Set test interface to GigabitEthernet2 as we are on Cisco IOS-XE
|
||||
set_fact: test_interface=GigabitEthernet2
|
||||
- name: Disable autonegotiation on GigabitEthernet2
|
||||
ios_config:
|
||||
lines:
|
||||
- no negotiation auto
|
||||
parents: int GigabitEthernet2
|
||||
authorize: yes
|
||||
|
||||
- name: Set test interface 2 to GigabitEthernet3 as we are on Cisco IOS-XE
|
||||
set_fact: test_interface2=GigabitEthernet3
|
||||
- name: Disable autonegotiation on GigabitEthernet3
|
||||
ios_config:
|
||||
lines:
|
||||
- no negotiation auto
|
||||
parents: int GigabitEthernet3
|
||||
authorize: yes
|
||||
when: "'Cisco IOS-XE' in show_version_result.stdout[0]"
|
||||
|
||||
- name: Delete interface ipv4 and ipv6 address(setup)
|
||||
ios_l3_interface:
|
||||
name: "{{ test_interface }}"
|
||||
|
||||
@@ -23,3 +23,30 @@
|
||||
|
||||
- set_fact: switch_type="L2"
|
||||
when: '"l2" in result.stdout[0]'
|
||||
|
||||
- block:
|
||||
- name: Set test interface to GigabitEthernet0/1 as we are on Cisco IOS
|
||||
set_fact: test_interface=GigabitEthernet0/1
|
||||
- name: Set test interface 2 to GigabitEthernet0/2 as we are on Cisco IOS
|
||||
set_fact: test_interface2=GigabitEthernet0/2
|
||||
when: "'Cisco IOS' in result.stdout[0]"
|
||||
|
||||
- block:
|
||||
- name: Set test interface to GigabitEthernet2 as we are on Cisco IOS-XE
|
||||
set_fact: test_interface=GigabitEthernet2
|
||||
- name: Disable autonegotiation on GigabitEthernet2
|
||||
ios_config:
|
||||
lines:
|
||||
- no negotiation auto
|
||||
parents: int GigabitEthernet2
|
||||
authorize: yes
|
||||
|
||||
- name: Set test interface 2 to GigabitEthernet3 as we are on Cisco IOS-XE
|
||||
set_fact: test_interface2=GigabitEthernet3
|
||||
- name: Disable autonegotiation on GigabitEthernet3
|
||||
ios_config:
|
||||
lines:
|
||||
- no negotiation auto
|
||||
parents: int GigabitEthernet3
|
||||
authorize: yes
|
||||
when: "'Cisco IOS-XE' in result.stdout[0]"
|
||||
|
||||
Reference in New Issue
Block a user