Skip to content

Commit

Permalink
[minor_change] Add loopback interface profile as a child class for ac…
Browse files Browse the repository at this point in the history
…i_l3out_logical_node.
  • Loading branch information
gmicol committed Sep 13, 2023
1 parent 0f85fe7 commit 6ee8a5b
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 18 deletions.
23 changes: 22 additions & 1 deletion plugins/modules/aci_l3out_logical_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
type: str
choices: [ 'yes', 'no' ]
default: 'yes'
loopback_address:
description:
- loopback IP of the loopback interface profile.
state:
description:
- Use C(present) or C(absent) for adding or removing.
Expand Down Expand Up @@ -243,6 +246,7 @@ def main():
node_id=dict(type="int"),
router_id=dict(type="str"),
router_id_as_loopback=dict(type="str", default="yes", choices=["yes", "no"]),
loopback_address = dict(type="str"),
state=dict(type="str", default="present", choices=["absent", "present", "query"]),
)

Expand All @@ -262,6 +266,7 @@ def main():
node_id = module.params.get("node_id")
router_id = module.params.get("router_id")
router_id_as_loopback = module.params.get("router_id_as_loopback")
loopback_address = module.params.get("loopback_address")
state = module.params.get("state")

tdn = None
Expand All @@ -270,6 +275,13 @@ def main():

aci = ACIModule(module)

if loopback_address is not None:
child_classes = ["l3extLoopBackIfP"]
child_configs = [dict(l3extLoopBackIfP=dict(attributes=dict(name="", descr="", addr=loopback_address)))]
else:
child_classes = []
child_configs = []

aci.construct_url(
root_class=dict(
aci_class="fvTenant",
Expand All @@ -295,12 +307,21 @@ def main():
module_object=tdn,
target_filter={"name": tdn},
),
child_classes=child_classes,
)

aci.get_existing()

if state == "present":
aci.payload(aci_class="l3extRsNodeL3OutAtt", class_config=dict(rtrId=router_id, rtrIdLoopBack=router_id_as_loopback, tDn=tdn))
aci.payload(
aci_class="l3extRsNodeL3OutAtt",
class_config=dict(
rtrId=router_id,
rtrIdLoopBack=router_id_as_loopback,
tDn=tdn
),
child_configs=child_configs,
)

aci.get_diff(aci_class="l3extRsNodeL3OutAtt")

Expand Down
54 changes: 37 additions & 17 deletions tests/integration/targets/aci_l3out_logical_node/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Author: Marcel Zehnder (@maercu)
# GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)

- name: Test that we have an ACI APIC host, ACI username and ACI password
fail:
msg: 'Please define the following variables: aci_hostname, aci_username and aci_password.'
when: aci_hostname is not defined or aci_username is not defined or aci_password is not defined

# SET VARS
- name: Set vars
set_fact:
Expand All @@ -11,11 +16,11 @@
validate_certs: '{{ aci_validate_certs | default(false) }}'
use_ssl: '{{ aci_use_ssl | default(true) }}'
use_proxy: '{{ aci_use_proxy | default(true) }}'
output_level: '{{ aci_output_level | default("info") }}'
output_level: debug

# CLEAN ENVIRONMENT
- name: Remove test tenant before we kickoff
cisco.aci.aci_tenant: &tenant_absent
aci_tenant: &tenant_absent
<<: *aci_info
tenant: ansible_test
state: absent
Expand All @@ -28,38 +33,38 @@
block: # block specifies execution of tasks within, based on conditions
# SETUP ENVIRONMENT
- name: Create domain
cisco.aci.aci_domain: &domain_present
aci_domain: &domain_present
<<: *aci_info
domain: l3outtest
domain_type: l3dom
state: present

- name: Create tenant
cisco.aci.aci_tenant: &tenant_present
aci_tenant: &tenant_present
<<: *tenant_absent
state: present

- name: Configure VRF
cisco.aci.aci_vrf: &vrf_present
aci_vrf: &vrf_present
<<: *tenant_present
vrf: l3outtest

- name: Create L3Out
cisco.aci.aci_l3out:
aci_l3out:
<<: *vrf_present
l3out: l3outtest
domain: l3outtest
route_control: export

- name: Crete node profile
cisco.aci.aci_l3out_logical_node_profile: &np_present
aci_l3out_logical_node_profile: &np_present
<<: *tenant_present
l3out: l3outtest
node_profile: NODES

# BEGIN WITH TESTS
- name: Add node (check_mode)
cisco.aci.aci_l3out_logical_node: &node_present
aci_l3out_logical_node: &node_present
<<: *np_present
pod_id: 1
node_id: 111
Expand All @@ -69,7 +74,7 @@
register: cm_add_node

- name: Add node (normal mode)
cisco.aci.aci_l3out_logical_node:
aci_l3out_logical_node:
<<: *node_present
register: nm_add_node

Expand All @@ -85,7 +90,7 @@
- nm_add_node.current.0.l3extRsNodeL3OutAtt.attributes.annotation == 'orchestrator:ansible'

- name: Add node again, check if idempotency works
cisco.aci.aci_l3out_logical_node:
aci_l3out_logical_node:
<<: *node_present
register: add_node_again

Expand All @@ -96,28 +101,37 @@

# UPDATE NODE
- name: Change roouter id
cisco.aci.aci_l3out_logical_node: &node_update
aci_l3out_logical_node: &node_update
<<: *node_present
router_id: 11.11.11.11
register: update_node

- name: Add loopback address
aci_l3out_logical_node: &node_add_loopback
<<: *node_update
loopback_address: 11.11.11.12
register: add_loopback_ip

- name: Verify update_node
assert:
that:
- update_node is changed
- update_node.previous != []
- update_node.sent.l3extRsNodeL3OutAtt.attributes.rtrId == '11.11.11.11'
- add_loopback_ip is changed
- add_loopback_ip.previous != []
- add_loopback_ip.current.0.l3extRsNodeL3OutAtt.children.0.l3extLoopBackIfP.attributes.addr == "11.11.11.12"

# ADD ANOTHER NODE
- name: Add another node
cisco.aci.aci_l3out_logical_node:
aci_l3out_logical_node:
<<: *node_present
node_id: 112
router_id: 12.12.12.12

# QUERY ALL NODES
- name: Query all nodes
cisco.aci.aci_l3out_logical_node:
aci_l3out_logical_node:
<<: *aci_info
state: query
register: query_all_nodes
Expand All @@ -130,8 +144,8 @@

# QUERY A SPECIFIC NODE
- name: Query a specific node
cisco.aci.aci_l3out_logical_node:
<<: *node_update
aci_l3out_logical_node:
<<: *node_add_loopback
state: query
register: query_spec_node

Expand All @@ -143,8 +157,8 @@

# REMOVE NODE
- name: Remove node
cisco.aci.aci_l3out_logical_node:
<<: *node_update
aci_l3out_logical_node:
<<: *node_add_loopback
state: absent
register: remove_node

Expand All @@ -153,3 +167,9 @@
that:
- remove_node is changed
- remove_node.current == []

- name: Remove test tenant - clean-up the environment
aci_tenant:
<<: *aci_info
tenant: ansible_test
state: absent

0 comments on commit 6ee8a5b

Please sign in to comment.