Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance vrf (Add RD Parameter) #59

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
22 changes: 22 additions & 0 deletions plugins/modules/aoscx_vrf.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
description: The name of the VRF
required: true
type: str
rd:
description: The Route Distinguisher (RD) of the VRF (use XXXXX:YYYYY for the format)
required: false
type: str
state:
description: Create or delete the VRF.
required: false
Expand All @@ -44,6 +48,12 @@
name: red
state: create

- name: Create a VRF with RD
aoscx_vrf:
name: red
rd: 100:1
state: create

- name: Delete a VRF
aoscx_vrf:
name: red
Expand All @@ -64,6 +74,11 @@ def get_argument_spec():
"type": "str",
"required": True,
},
"rd": {
"type": "str",
"required": False,
},

"state": {
"type": "str",
"default": "create",
Expand All @@ -85,6 +100,7 @@ def main():
# Get playbook's arguments
vrf_name = ansible_module.params["name"]
state = ansible_module.params["state"]
rd = ansible_module.params["rd"]

result = dict(changed=False)

Expand Down Expand Up @@ -114,6 +130,7 @@ def main():
modified = True

if state == "create":

# Create VRF with incoming attributes
if not vrf_exists:
# Changed
Expand All @@ -124,6 +141,11 @@ def main():
except Exception as e:
ansible_module.fail_json(msg=str(e))

# Configure RD (Route Distinguisher)
if rd:
vrf.rd = rd
modified |= vrf.apply()

result["changed"] = modified
ansible_module.exit_json(**result)

Expand Down
76 changes: 76 additions & 0 deletions tests/integration/targets/aoscx_vrf/tests/api/rd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
---
- debug:
msg: START aoscx_vrf rd (create/modify) integration tests on connection={{ ansible_connection }}

- import_tasks: _remove_config.yaml

- block:

# - import_tasks: _populate.yaml

- name: Create vrf with RD
register: result
aoscx_vrf:
name: ansible_vrf_test_1
rd: "23:23"
state: create

- name: Get vrf facts
register: vrf_facts
aoscx_facts:
gather_network_resources:
- vrfs

- name: Assert if vrf is not created with rd
ansible.builtin.assert:
that:
- "'ansible_vrf_test_1' in vrf_facts.ansible_facts.ansible_network_resources.vrfs"
- vrf_facts.ansible_facts.ansible_network_resources.vrfs.ansible_vrf_test_1.rd == '23:23'

- name: Create vrf with RD (idempotent)
register: result
aoscx_vrf:
name: ansible_vrf_test_1
rd: "23:23"
state: create

- name: Assert that the previous task was idempotent
ansible.builtin.assert:
that:
- not result['changed']

# Modify
- name: Modify vrf with RD
register: result
aoscx_vrf:
name: ansible_vrf_test_1
rd: "44:44"
state: create

- name: Get vrf facts
register: vrf_facts
aoscx_facts:
gather_network_resources:
- vrfs

- name: Assert if vrf is not modifiy with rd
ansible.builtin.assert:
that:
- "'ansible_vrf_test_1' in vrf_facts.ansible_facts.ansible_network_resources.vrfs"
- vrf_facts.ansible_facts.ansible_network_resources.vrfs.ansible_vrf_test_1.rd == '44:44'

- name: Modify vrf with RD (idempotent)
register: result
aoscx_vrf:
name: ansible_vrf_test_1
rd: "44:44"
state: create

- name: Assert that the previous task was idempotent
ansible.builtin.assert:
that:
- not result['changed']

always:

- import_tasks: _remove_config.yaml