mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-05-02 15:21:25 -07:00
Add ios_static_route module (#25527)
* Add ios_static_route module * Add ios_static_route integration tests * Add platform agnostic integration tests for IOS * Replace unicode function to ansible module_utils to_text * Add collections handling logic * Add integration tests for collections * Make collections and prefix mutually exclusive * Add net_static_route integration tests for collections * Do not store load_config return value, as it returns nothing
This commit is contained in:
parent
5242ff1b59
commit
c8ba8bdd6d
14 changed files with 545 additions and 0 deletions
|
@ -15,3 +15,4 @@
|
|||
- { role: ios_template, when: "limit_to in ['*', 'ios_template']" }
|
||||
- { role: ios_system, when: "limit_to in ['*', 'ios_system']" }
|
||||
- { role: ios_user, when: "limit_to in ['*', 'ios_user']" }
|
||||
- { role: ios_static_route, when: "limit_to in ['*', 'ios_static_route']" }
|
||||
|
|
|
@ -15,3 +15,4 @@
|
|||
- { role: net_vlan, when: "limit_to in ['*', 'net_vlan']" }
|
||||
- { role: net_vrf, when: "limit_to in ['*', 'net_vrf']" }
|
||||
- { role: net_interface, when: "limit_to in ['*', 'net_interface']" }
|
||||
- { role: net_static_route, when: "limit_to in ['*', 'net_static_route']" }
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
testcase: "*"
|
2
test/integration/targets/ios_static_route/meta/main.yaml
Normal file
2
test/integration/targets/ios_static_route/meta/main.yaml
Normal file
|
@ -0,0 +1,2 @@
|
|||
dependencies:
|
||||
- prepare_ios_tests
|
15
test/integration/targets/ios_static_route/tasks/cli.yaml
Normal file
15
test/integration/targets/ios_static_route/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
|
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
- { include: cli.yaml, tags: ['cli'] }
|
138
test/integration/targets/ios_static_route/tests/cli/basic.yaml
Normal file
138
test/integration/targets/ios_static_route/tests/cli/basic.yaml
Normal file
|
@ -0,0 +1,138 @@
|
|||
---
|
||||
- name: create static route
|
||||
ios_static_route:
|
||||
prefix: 172.16.31.0
|
||||
mask: 255.255.255.0
|
||||
next_hop: 10.0.0.8
|
||||
state: present
|
||||
authorize: yes
|
||||
provider: "{{ cli }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- 'result.changed == true'
|
||||
- 'result.commands == ["ip route 172.16.31.0 255.255.255.0 10.0.0.8 1"]'
|
||||
|
||||
- name: create static route again (idempotent)
|
||||
ios_static_route:
|
||||
prefix: 172.16.31.0
|
||||
mask: 255.255.255.0
|
||||
next_hop: 10.0.0.8
|
||||
state: present
|
||||
authorize: yes
|
||||
provider: "{{ cli }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- 'result.changed == false'
|
||||
|
||||
- name: modify admin distance of static route
|
||||
ios_static_route:
|
||||
prefix: 172.16.31.0
|
||||
mask: 255.255.255.0
|
||||
next_hop: 10.0.0.8
|
||||
admin_distance: 2
|
||||
state: present
|
||||
authorize: yes
|
||||
provider: "{{ cli }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- 'result.changed == true'
|
||||
- 'result.commands == ["ip route 172.16.31.0 255.255.255.0 10.0.0.8 2"]'
|
||||
|
||||
- name: modify admin distance of static route again (idempotent)
|
||||
ios_static_route:
|
||||
prefix: 172.16.31.0
|
||||
mask: 255.255.255.0
|
||||
next_hop: 10.0.0.8
|
||||
admin_distance: 2
|
||||
state: present
|
||||
authorize: yes
|
||||
provider: "{{ cli }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- 'result.changed == false'
|
||||
|
||||
- name: delete static route
|
||||
ios_static_route:
|
||||
prefix: 172.16.31.0
|
||||
mask: 255.255.255.0
|
||||
next_hop: 10.0.0.8
|
||||
admin_distance: 2
|
||||
state: absent
|
||||
authorize: yes
|
||||
provider: "{{ cli }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- 'result.changed == true'
|
||||
- 'result.commands == ["no ip route 172.16.31.0 255.255.255.0 10.0.0.8"]'
|
||||
|
||||
- name: delete static route again (idempotent)
|
||||
ios_static_route:
|
||||
prefix: 172.16.31.0
|
||||
mask: 255.255.255.0
|
||||
next_hop: 10.0.0.8
|
||||
admin_distance: 2
|
||||
state: absent
|
||||
authorize: yes
|
||||
provider: "{{ cli }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- 'result.changed == false'
|
||||
|
||||
- name: Add static route collections
|
||||
ios_static_route:
|
||||
collection:
|
||||
- { prefix: 172.16.32.0, mask: 255.255.255.0, next_hop: 10.0.0.8 }
|
||||
- { prefix: 172.16.33.0, mask: 255.255.255.0, next_hop: 10.0.0.8 }
|
||||
state: present
|
||||
authorize: yes
|
||||
provider: "{{ cli }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- 'result.changed == true'
|
||||
- 'result.commands == ["ip route 172.16.32.0 255.255.255.0 10.0.0.8 1", "ip route 172.16.33.0 255.255.255.0 10.0.0.8 1"]'
|
||||
|
||||
- name: Add and remove static route collections with overrides
|
||||
ios_static_route:
|
||||
collection:
|
||||
- { prefix: 172.16.32.0, mask: 255.255.255.0, next_hop: 10.0.0.8 }
|
||||
- { prefix: 172.16.33.0, mask: 255.255.255.0, next_hop: 10.0.0.8, state: absent }
|
||||
- { prefix: 172.16.34.0, mask: 255.255.255.0, next_hop: 10.0.0.8 }
|
||||
state: present
|
||||
authorize: yes
|
||||
provider: "{{ cli }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- 'result.changed == true'
|
||||
- 'result.commands == ["no ip route 172.16.33.0 255.255.255.0 10.0.0.8", "ip route 172.16.34.0 255.255.255.0 10.0.0.8 1"]'
|
||||
|
||||
- name: Remove static route collections
|
||||
ios_static_route:
|
||||
collection:
|
||||
- { prefix: 172.16.32.0, mask: 255.255.255.0, next_hop: 10.0.0.8 }
|
||||
- { prefix: 172.16.33.0, mask: 255.255.255.0, next_hop: 10.0.0.8 }
|
||||
- { prefix: 172.16.34.0, mask: 255.255.255.0, next_hop: 10.0.0.8 }
|
||||
state: absent
|
||||
authorize: yes
|
||||
provider: "{{ cli }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- 'result.changed == true'
|
||||
- 'result.commands == ["no ip route 172.16.32.0 255.255.255.0 10.0.0.8", "no ip route 172.16.34.0 255.255.255.0 10.0.0.8"]'
|
0
test/integration/targets/net_static_route/aliases
Normal file
0
test/integration/targets/net_static_route/aliases
Normal file
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
testcase: "*"
|
16
test/integration/targets/net_static_route/tasks/cli.yaml
Normal file
16
test/integration/targets/net_static_route/tasks/cli.yaml
Normal file
|
@ -0,0 +1,16 @@
|
|||
---
|
||||
- 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
|
||||
include: "{{ test_case_to_run }}"
|
||||
with_items: "{{ test_items }}"
|
||||
loop_control:
|
||||
loop_var: test_case_to_run
|
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
- { include: cli.yaml, tags: ['cli'] }
|
|
@ -0,0 +1,3 @@
|
|||
---
|
||||
- include: "{{ role_path }}/tests/ios/basic.yaml"
|
||||
when: hostvars[inventory_hostname]['ansible_network_os'] == 'ios'
|
140
test/integration/targets/net_static_route/tests/ios/basic.yaml
Normal file
140
test/integration/targets/net_static_route/tests/ios/basic.yaml
Normal file
|
@ -0,0 +1,140 @@
|
|||
---
|
||||
- debug: msg="START net_static_route ios/basic.yaml"
|
||||
|
||||
- name: create static route
|
||||
net_static_route:
|
||||
prefix: 172.16.31.0
|
||||
mask: 255.255.255.0
|
||||
next_hop: 10.0.0.8
|
||||
state: present
|
||||
authorize: yes
|
||||
provider: "{{ cli }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- 'result.changed == true'
|
||||
- 'result.commands == ["ip route 172.16.31.0 255.255.255.0 10.0.0.8 1"]'
|
||||
|
||||
- name: create static route again (idempotent)
|
||||
net_static_route:
|
||||
prefix: 172.16.31.0
|
||||
mask: 255.255.255.0
|
||||
next_hop: 10.0.0.8
|
||||
state: present
|
||||
authorize: yes
|
||||
provider: "{{ cli }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- 'result.changed == false'
|
||||
|
||||
- name: modify admin distance of static route
|
||||
net_static_route:
|
||||
prefix: 172.16.31.0
|
||||
mask: 255.255.255.0
|
||||
next_hop: 10.0.0.8
|
||||
admin_distance: 2
|
||||
state: present
|
||||
authorize: yes
|
||||
provider: "{{ cli }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- 'result.changed == true'
|
||||
- 'result.commands == ["ip route 172.16.31.0 255.255.255.0 10.0.0.8 2"]'
|
||||
|
||||
- name: modify admin distance of static route again (idempotent)
|
||||
net_static_route:
|
||||
prefix: 172.16.31.0
|
||||
mask: 255.255.255.0
|
||||
next_hop: 10.0.0.8
|
||||
admin_distance: 2
|
||||
state: present
|
||||
authorize: yes
|
||||
provider: "{{ cli }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- 'result.changed == false'
|
||||
|
||||
- name: delete static route
|
||||
net_static_route:
|
||||
prefix: 172.16.31.0
|
||||
mask: 255.255.255.0
|
||||
next_hop: 10.0.0.8
|
||||
admin_distance: 2
|
||||
state: absent
|
||||
authorize: yes
|
||||
provider: "{{ cli }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- 'result.changed == true'
|
||||
- 'result.commands == ["no ip route 172.16.31.0 255.255.255.0 10.0.0.8"]'
|
||||
|
||||
- name: delete static route again (idempotent)
|
||||
net_static_route:
|
||||
prefix: 172.16.31.0
|
||||
mask: 255.255.255.0
|
||||
next_hop: 10.0.0.8
|
||||
admin_distance: 2
|
||||
state: absent
|
||||
authorize: yes
|
||||
provider: "{{ cli }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- 'result.changed == false'
|
||||
|
||||
- name: Add static route collections
|
||||
net_static_route:
|
||||
collection:
|
||||
- { prefix: 172.16.32.0, mask: 255.255.255.0, next_hop: 10.0.0.8 }
|
||||
- { prefix: 172.16.33.0, mask: 255.255.255.0, next_hop: 10.0.0.8 }
|
||||
state: present
|
||||
authorize: yes
|
||||
provider: "{{ cli }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- 'result.changed == true'
|
||||
- 'result.commands == ["ip route 172.16.32.0 255.255.255.0 10.0.0.8 1", "ip route 172.16.33.0 255.255.255.0 10.0.0.8 1"]'
|
||||
|
||||
- name: Add and remove static route collections with overrides
|
||||
net_static_route:
|
||||
collection:
|
||||
- { prefix: 172.16.32.0, mask: 255.255.255.0, next_hop: 10.0.0.8 }
|
||||
- { prefix: 172.16.33.0, mask: 255.255.255.0, next_hop: 10.0.0.8, state: absent }
|
||||
- { prefix: 172.16.34.0, mask: 255.255.255.0, next_hop: 10.0.0.8 }
|
||||
state: present
|
||||
authorize: yes
|
||||
provider: "{{ cli }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- 'result.changed == true'
|
||||
- 'result.commands == ["no ip route 172.16.33.0 255.255.255.0 10.0.0.8", "ip route 172.16.34.0 255.255.255.0 10.0.0.8 1"]'
|
||||
|
||||
- name: Remove static route collections
|
||||
net_static_route:
|
||||
collection:
|
||||
- { prefix: 172.16.32.0, mask: 255.255.255.0, next_hop: 10.0.0.8 }
|
||||
- { prefix: 172.16.33.0, mask: 255.255.255.0, next_hop: 10.0.0.8 }
|
||||
- { prefix: 172.16.34.0, mask: 255.255.255.0, next_hop: 10.0.0.8 }
|
||||
state: absent
|
||||
authorize: yes
|
||||
provider: "{{ cli }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- 'result.changed == true'
|
||||
- 'result.commands == ["no ip route 172.16.32.0 255.255.255.0 10.0.0.8", "no ip route 172.16.34.0 255.255.255.0 10.0.0.8"]'
|
Loading…
Add table
Add a link
Reference in a new issue