Skip to content

Commit

Permalink
added few more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AAYUSH2091 committed Nov 19, 2024
1 parent 4c0545e commit 4a21ac1
Show file tree
Hide file tree
Showing 8 changed files with 391 additions and 27 deletions.
152 changes: 150 additions & 2 deletions plugins/modules/ios_vrf_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,12 +315,160 @@
# vrf_name: "vrf_D"
# - name: "GigabitEthernet3"
# - name: "GigabitEthernet4"
# Using replaced
# Before state:
# -------------
#
# vios#show running-config | section ^interface
# interface Loopback24
# no ip address
# interface GigabitEthernet1
# vrf forwarding vrf_A
# ip address dhcp
# negotiation auto
# interface GigabitEthernet2
# vrf forwarding vrf_B
# no ip address
# shutdown
# negotiation auto
# interface GigabitEthernet3
# no ip address
# negotiation auto
# interface GigabitEthernet4
# vrf forwarding vrf_C
# no ip address
# shutdown
# negotiation auto
- name: Replace device configuration of listed VRF interfaces with provided configuration
cisco.ios.ios_vrf_interfaces:
config:
- name: GigabitEthernet1
vrf_name: vrf_D
- name: GigabitEthernet2
vrf_name: vrf_E
state: replaced
# Task Output:
# ------------
#
# before:
# - name: "Loopback24"
# - name: "GigabitEthernet1"
# vrf_name: "vrf_A"
# - name: "GigabitEthernet2"
# vrf_name: "vrf_B"
# - name: "GigabitEthernet3"
# - name: "GigabitEthernet4"
# vrf_name: "vrf_C"
#
# commands:
# - interface GigabitEthernet1
# - no vrf forwarding vrf_A
# - vrf forwarding vrf_D
# - interface GigabitEthernet2
# - no vrf forwarding vrf_B
# - vrf forwarding vrf_E
#
# after:
# - name: "Loopback24"
# - name: "GigabitEthernet1"
# vrf_name: "vrf_D"
# - name: "GigabitEthernet2"
# vrf_name: "vrf_E"
# - name: "GigabitEthernet3"
# - name: "GigabitEthernet4"
# vrf_name: "vrf_C"
# Using deleted
# Before state:
# -------------
#
# vios#show running-config | section ^interface
# interface Loopback24
# no ip address
# interface GigabitEthernet1
# vrf forwarding vrf_A
# ip address dhcp
# negotiation auto
# interface GigabitEthernet2
# vrf forwarding vrf_B
# no ip address
# shutdown
# negotiation auto
# interface GigabitEthernet3
# no ip address
# negotiation auto
# interface GigabitEthernet4
# vrf forwarding vrf_C
# no ip address
# shutdown
# negotiation auto
- name: Delete VRF configuration of specified interfaces
cisco.ios.ios_vrf_interfaces:
config:
- name: GigabitEthernet1
- name: GigabitEthernet2
state: deleted
# Task Output:
# ------------
#
# before:
# - name: "Loopback24"
# - name: "GigabitEthernet1"
# vrf_name: "vrf_A"
# - name: "GigabitEthernet2"
# vrf_name: "vrf_B"
# - name: "GigabitEthernet3"
# - name: "GigabitEthernet4"
# vrf_name: "vrf_C"
#
# commands:
# - interface GigabitEthernet1
# - no vrf forwarding vrf_A
# - interface GigabitEthernet2
# - no vrf forwarding vrf_B
#
# after:
# - name: "Loopback24"
# - name: "GigabitEthernet1"
# - name: "GigabitEthernet2"
# - name: "GigabitEthernet3"
# - name: "GigabitEthernet4"
# vrf_name: "vrf_C"
# After state:
# ------------
#
# vios#show running-config | section ^interface
# interface Loopback24
# no ip address
# interface GigabitEthernet1
# ip address dhcp
# negotiation auto
# interface GigabitEthernet2
# no ip address
# shutdown
# negotiation auto
# interface GigabitEthernet3
# no ip address
# negotiation auto
# interface GigabitEthernet4
# vrf forwarding vrf_C
# no ip address
# shutdown
# negotiation auto
"""

RETURN = """
before:
description: The configuration prior to the module execution.
returned: when I(state) is C(merged), C(replaced), C(overridden), C(deleted) or C(purged)
returned: when I(state) is C(merged), C(replaced), C(overridden), C(deleted)
type: list
sample: >
[
Expand Down Expand Up @@ -368,7 +516,7 @@
commands:
description: The set of commands pushed to the remote device.
returned: when I(state) is C(merged), C(replaced), C(overridden), C(deleted) or C(purged)
returned: when I(state) is C(merged), C(replaced), C(overridden), C(deleted)
type: list
sample:
- "interface GigabitEthernet2"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
- ansible.builtin.debug:
msg: Start Deleted integration state for ios_vrf_interfaces ansible_connection={{ ansible_connection }}

- ansible.builtin.include_tasks: _remove_config.yaml
- ansible.builtin.include_tasks: _populate_config.yaml

- block:
- name: Delete provided VRF interfaces
register: result
cisco.ios.ios_vrf_interfaces: &id001
config:
- name: GigabitEthernet2
state: deleted

- name: Assert that correct set of commands were generated
ansible.builtin.assert:
that:
- "{{ deleted['commands'] | symmetric_difference(result['commands']) | length == 0 }}"

- name: Delete provided VRF interfaces (idempotent)
register: result
cisco.ios.ios_vrf_interfaces: *id001
- name: Assert that the previous task was idempotent
ansible.builtin.assert:
that:
- result.changed == false

- ansible.builtin.include_tasks: _populate_config.yaml

- name: Delete provided VRF interfaces without any configuration
register: result
cisco.ios.ios_vrf_interfaces: &id002
state: deleted

- name: Assert that correct set of commands were generated
ansible.builtin.assert:
that:
- "{{ deleted['commands'] | symmetric_difference(result['commands']) | length == 0 }}"

- name: Delete provided VRF interfaces without any configuration (idempotent)
register: result
cisco.ios.ios_vrf_interfaces: *id002
- name: Assert that the delete task was idempotent
ansible.builtin.assert:
that:
- result.changed == false

always:
- ansible.builtin.include_tasks: _remove_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@
that:
- result.msg == 'value of config parameter must not be empty for state replaced'

- name: Overridden with empty configuration should give appropriate error message
register: result
ignore_errors: true
cisco.ios.ios_vrf_interfaces:
config:
state: overridden

- ansible.builtin.assert:
that:
- result.msg == 'value of config parameter must not be empty for state overridden'

- name: Rendered with empty configuration should give appropriate error message
register: result
ignore_errors: true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,44 @@
---
- ansible.builtin.debug:
msg: Start ios_vrf_interfaces merged integration tests connection={{ ansible_connection}}
msg: START Merged ios_vrf_interfaces state for integration tests on connection={{ ansible_connection }}

- ansible.builtin.include_tasks: _remove_config.yaml

- block:
- name: Simple merge selective
cisco.ios.ios_vrf_interfaces:
state: merged
- name: Merge provided configuration with device configuration
register: result
cisco.ios.ios_vrf_interfaces: &id001
config:
- name: GigabitEthernet1
- name: GigabitEthernet2
vrf_name: vrf_D
- name: GigabitEthernet3
- name: GigabitEthernet4
state: merged

register: result
- name: Assert that correct set of commands were generated
ansible.builtin.assert:
that:
- "{{ merged['commands'] | symmetric_difference(result['commands']) | length == 0 }}"

- name: Run show running-config | section ^interface
cisco.ios.ios_command:
commands: show running-config | section ^interface
- name: Assert that before dicts are correctly generated
ansible.builtin.assert:
that:
- "{{ merged['before'] | symmetric_difference(result['before']) | length == 0 }}"

- name: Assert that correct set of commands were generated
- name: Assert that after dict is correctly generated
ansible.builtin.assert:
that:
- "{{ merged['commands'] | symmetric_difference(result['commands']) |length == 0 }}"
- "{{ merged['after'] | symmetric_difference(result['after']) | length == 0 }}"

- name: Merge provided configuration with device configuration (idempotent)
register: result
cisco.ios.ios_vrf_interfaces: *id001

- name: Assert that after dicts were correctly generated
- name: Assert that the previous task was idempotent
ansible.builtin.assert:
that:
- merged['after'] == result['after']
- result['changed'] == false

always:
- ansible.builtin.include_tasks: _remove_config.yaml
Original file line number Diff line number Diff line change
@@ -1,39 +1,44 @@
---
- ansible.builtin.debug:
msg: Start ios_vrf_interfaces overridden integration tests connection={{ ansible_connection}}
msg: START Overridden ios_vrf_interfaces state for integration tests on connection={{ ansible_connection }}

- ansible.builtin.include_tasks: _populate_config.yaml

- block:
- name: Override the route-policy configuration
cisco.ios.ios_vrf_interfaces:
state: overridden
- name: Override provided configuration with device configuration
register: result
cisco.ios.ios_vrf_interfaces: &id001
config:
- name: GigabitEthernet1
- name: GigabitEthernet2
- name: GigabitEthernet3
- name: GigabitEthernet4
vrf_name: vrf_C

register: result

- name: Run show running-config | section ^interface
cisco.ios.ios_command:
commands: show running-config | section ^interface
state: overridden

- name: Assert that correct set of commands were generated
ansible.builtin.assert:
that:
- "{{ overridden['commands'] | symmetric_difference(result['commands']) |length == 0 }}"
- "{{ overridden['commands'] | symmetric_difference(result['commands']) | length == 0 }}"

- name: Assert that before dicts are correctly generated
ansible.builtin.assert:
that:
- overridden['before'] == result['before']

- name: Assert that after dict is correctly generated
ansible.builtin.assert:
that:
- overridden['after'] == result['after']

- name: Assert that before dicts are correctly generated
- name: Override provided configuration with device configuration (idempotent)
register: result
cisco.ios.ios_vrf_interfaces: *id001

- name: Assert that the previous task was idempotent
ansible.builtin.assert:
that:
- overridden['before'] == result['before']
- result['changed'] == false

always:
- ansible.builtin.include_tasks: _remove_config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
- ansible.builtin.debug:
msg: START Replaced ios_vrf_interfaces state for integration tests on connection={{ ansible_connection }}

- ansible.builtin.include_tasks: _remove_config.yaml
- ansible.builtin.include_tasks: _populate_config.yaml

- block:
- name: Replace provided VRF interfaces configuration
register: result
cisco.ios.ios_vrf_interfaces: &id001
config:
- name: GigabitEthernet2
vrf_name: vrf_D
state: replaced

- name: Assert that correct set of commands were generated
ansible.builtin.assert:
that:
- "{{ replaced['commands'] | symmetric_difference(result['commands']) | length == 0 }}"

- name: Assert that before dicts are correctly generated
ansible.builtin.assert:
that:
- replaced['before'] == result['before']

- name: Assert that after dict is correctly generated
ansible.builtin.assert:
that:
- replaced['after'] == result['after']

- name: Replace provided VRF interfaces configuration (idempotent)
register: result
cisco.ios.ios_vrf_interfaces: *id001

- name: Assert that task was idempotent
ansible.builtin.assert:
that:
- result['changed'] == false

always:
- ansible.builtin.include_tasks: _remove_config.yaml
Loading

0 comments on commit 4a21ac1

Please sign in to comment.