Skip to content

Commit

Permalink
Fix for interface module, Issues 276 and 278
Browse files Browse the repository at this point in the history
  • Loading branch information
mmudigon committed Mar 29, 2024
1 parent 0b0dc30 commit b93b71c
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 48 deletions.
90 changes: 64 additions & 26 deletions plugins/modules/dcnm_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,6 @@
description:
- Speed of the interface.
type: str
choices: ['Auto', '100Mb', '1Gb', '10Gb', '25Gb', '40Gb', '100Gb']
default: Auto
int_vrf:
description:
Expand Down Expand Up @@ -1852,6 +1851,21 @@ def dcnm_intf_dump_have_all(self):
)
self.log_msg(f"HAVE ALL = {lhave_all}")

def dcnm_intf_xlate_speed (self, speed):

# Controllers accept speed value in a particular format i.e. 1Gb, 100Gb etc. To make the playbook input
# case insensitive for speed, this routine translates the incoming speed to appropriate format.

if speed == "":
return ""

if speed.lower() == "auto":
return "auto".capitalize()
else:
comp = re.compile("([0-9]+)([a-zA-Z]+)")
match = comp.match(speed)
return (str(match.group(1)) + match.group(2).capitalize())

# New Interfaces
def dcnm_intf_get_if_name(self, name, if_type):

Expand Down Expand Up @@ -2005,6 +2019,7 @@ def dcnm_intf_validate_port_channel_input(self, config):
bpdu_guard=dict(type="str", default="true"),
port_type_fast=dict(type="bool", default=True),
mtu=dict(type="str", default="jumbo"),
speed=dict(type="str", default="Auto"),
allowed_vlans=dict(type="str", default="none"),
cmds=dict(type="list", elements="str"),
description=dict(type="str", default=""),
Expand All @@ -2018,6 +2033,7 @@ def dcnm_intf_validate_port_channel_input(self, config):
bpdu_guard=dict(type="str", default="true"),
port_type_fast=dict(type="bool", default=True),
mtu=dict(type="str", default="jumbo"),
speed=dict(type="str", default="Auto"),
access_vlan=dict(type="str", default=""),
cmds=dict(type="list", elements="str"),
description=dict(type="str", default=""),
Expand All @@ -2033,6 +2049,7 @@ def dcnm_intf_validate_port_channel_input(self, config):
ipv4_mask_len=dict(type="int", default=8),
route_tag=dict(type="str", default=""),
mtu=dict(type="int", default=9216, range_min=576, range_max=9216),
speed=dict(type="str", default="Auto"),
cmds=dict(type="list", elements="str"),
description=dict(type="str", default=""),
admin_state=dict(type="bool", default=True),
Expand Down Expand Up @@ -2077,6 +2094,7 @@ def dcnm_intf_validate_virtual_port_channel_input(self, cfg):
bpdu_guard=dict(type="str", default="true"),
port_type_fast=dict(type="bool", default=True),
mtu=dict(type="str", default="jumbo"),
speed=dict(type="str", default="Auto"),
peer1_allowed_vlans=dict(type="str", default="none"),
peer2_allowed_vlans=dict(type="str", default="none"),
peer1_cmds=dict(type="list"),
Expand All @@ -2100,6 +2118,7 @@ def dcnm_intf_validate_virtual_port_channel_input(self, cfg):
bpdu_guard=dict(type="str", default="true"),
port_type_fast=dict(type="bool", default=True),
mtu=dict(type="str", default="jumbo"),
speed=dict(type="str", default="Auto"),
peer1_access_vlan=dict(type="str", default=""),
peer2_access_vlan=dict(type="str", default=""),
peer1_cmds=dict(type="list"),
Expand Down Expand Up @@ -2141,6 +2160,7 @@ def dcnm_intf_validate_sub_interface_input(self, cfg):
type="int", range_min=64, range_max=127, default=64
),
mtu=dict(type="int", range_min=576, range_max=9216, default=9216),
speed=dict(type="str", default="Auto"),
cmds=dict(type="list", elements="str"),
description=dict(type="str", default=""),
admin_state=dict(type="bool", default=True),
Expand All @@ -2165,6 +2185,7 @@ def dcnm_intf_validate_loopback_interface_input(self, cfg):
int_vrf=dict(type="str", default="default"),
ipv6_addr=dict(type="ipv6", default=""),
route_tag=dict(type="str", default=""),
speed=dict(type="str", default="Auto"),
cmds=dict(type="list", elements="str"),
description=dict(type="str", default=""),
admin_state=dict(type="bool", default=True),
Expand Down Expand Up @@ -2572,6 +2593,9 @@ def dcnm_intf_get_pc_payload(self, delem, intf, profile):
intf["interfaces"][0]["nvPairs"]["ADMIN_STATE"] = str(
delem[profile]["admin_state"]
).lower()
intf["interfaces"][0]["nvPairs"]["SPEED"] = self.dcnm_intf_xlate_speed (
str(delem[profile].get("speed", ""))
)

def dcnm_intf_get_vpc_payload(self, delem, intf, profile):

Expand Down Expand Up @@ -2710,6 +2734,9 @@ def dcnm_intf_get_vpc_payload(self, delem, intf, profile):
delem[profile]["admin_state"]
).lower()
intf["interfaces"][0]["nvPairs"]["INTF_NAME"] = ifname
intf["interfaces"][0]["nvPairs"]["SPEED"] = self.dcnm_intf_xlate_speed (
str(delem[profile].get("speed", ""))
)

def dcnm_intf_get_sub_intf_payload(self, delem, intf, profile):

Expand Down Expand Up @@ -2754,6 +2781,9 @@ def dcnm_intf_get_sub_intf_payload(self, delem, intf, profile):
intf["interfaces"][0]["nvPairs"]["ADMIN_STATE"] = str(
delem[profile]["admin_state"]
).lower()
intf["interfaces"][0]["nvPairs"]["SPEED"] = self.dcnm_intf_xlate_speed (
str(delem[profile].get("speed", ""))
)

def dcnm_intf_get_loopback_payload(self, delem, intf, profile):

Expand All @@ -2780,6 +2810,10 @@ def dcnm_intf_get_loopback_payload(self, delem, intf, profile):
delem[profile]["admin_state"]
).lower()

intf["interfaces"][0]["nvPairs"]["SPEED"] = self.dcnm_intf_xlate_speed (
str(delem[profile].get("speed", ""))
)

# Properties for mode 'lo' Loopback Interfaces
if delem[profile]["mode"] == "lo":

Expand Down Expand Up @@ -2835,9 +2869,6 @@ def dcnm_intf_get_eth_payload(self, delem, intf, profile):
intf["interfaces"][0]["nvPairs"]["MTU"] = str(
delem[profile]["mtu"]
)
intf["interfaces"][0]["nvPairs"]["SPEED"] = str(
delem[profile]["speed"]
)
intf["interfaces"][0]["nvPairs"]["ALLOWED_VLANS"] = delem[profile][
"allowed_vlans"
]
Expand All @@ -2852,9 +2883,6 @@ def dcnm_intf_get_eth_payload(self, delem, intf, profile):
intf["interfaces"][0]["nvPairs"]["MTU"] = str(
delem[profile]["mtu"]
)
intf["interfaces"][0]["nvPairs"]["SPEED"] = str(
delem[profile]["speed"]
)
intf["interfaces"][0]["nvPairs"]["ACCESS_VLAN"] = delem[profile][
"access_vlan"
]
Expand All @@ -2878,9 +2906,6 @@ def dcnm_intf_get_eth_payload(self, delem, intf, profile):
intf["interfaces"][0]["nvPairs"]["MTU"] = str(
delem[profile]["mtu"]
)
intf["interfaces"][0]["nvPairs"]["SPEED"] = str(
delem[profile]["speed"]
)
intf["interfaces"][0]["nvPairs"]["INTF_NAME"] = ifname
if delem[profile]["mode"] == "monitor":
intf["interfaces"][0]["nvPairs"]["INTF_NAME"] = ifname
Expand All @@ -2903,9 +2928,6 @@ def dcnm_intf_get_eth_payload(self, delem, intf, profile):
intf["interfaces"][0]["nvPairs"]["MTU"] = str(
delem[profile]["mtu"]
)
intf["interfaces"][0]["nvPairs"]["SPEED"] = str(
delem[profile]["speed"]
)
intf["interfaces"][0]["nvPairs"]["INTF_NAME"] = ifname

if delem[profile]["mode"] != "monitor":
Expand All @@ -2921,6 +2943,9 @@ def dcnm_intf_get_eth_payload(self, delem, intf, profile):
intf["interfaces"][0]["nvPairs"]["ADMIN_STATE"] = str(
delem[profile]["admin_state"]
).lower()
intf["interfaces"][0]["nvPairs"]["SPEED"] = self.dcnm_intf_xlate_speed (
str(delem[profile].get("speed", ""))
)

def dcnm_intf_get_st_fex_payload(self, delem, intf, profile):

Expand Down Expand Up @@ -3560,7 +3585,9 @@ def dcnm_intf_compare_want_and_have(self, state):
if ik == "nvPairs":
nv_keys = list(want[k][0][ik].keys())
if "SPEED" in nv_keys:
nv_keys.remove("SPEED")
# Remove 'SPEED' only if it is not included in 'have'.
if d[k][index][ik].get("SPEED", None) is None:
nv_keys.remove("SPEED")
for nk in nv_keys:
# HAVE may have an entry with a list # of interfaces. Check all the
# interface entries for a match. Even if one entry matches do not
Expand Down Expand Up @@ -4061,12 +4088,19 @@ def dcnm_intf_get_diff_overridden(self, cfg):
del_list.append(have)

if str(deploy).lower() == "true":
self.diff_delete_deploy[
self.int_index[have["ifType"]]
].append(delem)
self.changed_dict[0]["delete_deploy"].append(
copy.deepcopy(delem)
)
if (
have["complianceStatus"]
== "In-Sync"
) or (
have["complianceStatus"]
== "Pending"
):
self.diff_delete_deploy[
self.int_index[have["ifType"]]
].append(delem)
self.changed_dict[0]["delete_deploy"].append(
copy.deepcopy(delem)
)

for intf in defer_list:
# Check if the 'source' for the ethernet interface is one of the interfaces that is already deleted.
Expand Down Expand Up @@ -4224,12 +4258,16 @@ def dcnm_intf_get_diff_deleted(self):
self.changed_dict[0][
"replaced"
].append(copy.deepcopy(uelem))
delem["serialNumber"] = intf[
"serialNumber"
]
delem["ifName"] = if_name
delem["fabricName"] = self.fabric
self.diff_deploy.append(delem)
if (
str(cfg.get("deploy", "true")).lower()
== "true"
):
delem["serialNumber"] = intf[
"serialNumber"
]
delem["ifName"] = if_name
delem["fabricName"] = self.fabric
self.diff_deploy.append(delem)
else:
intf_payload = self.dcnm_intf_get_intf_info_from_dcnm(
intf
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@
"peerOneId": "{{ ansible_cxt_fabric_sno1 }}",
"peerTwoId": "{{ ansible_cxt_fabric_sno2 }}",
"useVirtualPeerlink": false,
"templateName": "vpc_pair",
"nvPairs": {
"DOMAIN_ID": "{{ ansible_cxt_vpc_domain_id }}",
"PEER1_KEEP_ALIVE_LOCAL_IP": "{{ ansible_cxt_fabric_sw1 }}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@
"cmds": [
"no shutdown"
],
"speed": "auto",
"speed": "Auto",
"description": "eth interface acting as routed"
},
"name": "eth1/32",
Expand All @@ -236,7 +236,7 @@
"cmds": [
"no shutdown"
],
"speed": "auto",
"speed": "Auto",
"description": "eth interface acting as routed"
},
"name": "eth1/22",
Expand All @@ -261,7 +261,7 @@
"admin_state": "False",
"ifname": "Ethernet1/13",
"route_tag": "",
"speed": "auto",
"speed": "Auto",
"cmds": [
"no shutdown"
],
Expand Down Expand Up @@ -289,7 +289,7 @@
"admin_state": "False",
"ifname": "Ethernet1/14",
"route_tag": "",
"speed": "auto",
"speed": "Auto",
"cmds": [
"no shutdown"
],
Expand Down
20 changes: 10 additions & 10 deletions tests/unit/modules/dcnm/fixtures/dcnm_intf_eth_configs.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
"cmds": [
"no shutdown"
],
"speed": "auto",
"speed": "Auto",
"ifname": "Ethernet1/30",
"fabric": "test_fabric"
},
Expand All @@ -121,7 +121,7 @@
"cmds": [
"no shutdown"
],
"speed": "auto",
"speed": "Auto",
"fabric": "test_fabric"
},
"name": "eth1/31",
Expand All @@ -147,7 +147,7 @@
"cmds": [
"no shutdown"
],
"speed": "auto",
"speed": "Auto",
"description": "eth interface acting as routed"
},
"name": "eth1/32",
Expand All @@ -172,7 +172,7 @@
"admin_state": "False",
"ifname": "Ethernet1/33",
"route_tag": "",
"speed": "auto",
"speed": "Auto",
"cmds": [
"no shutdown"
],
Expand Down Expand Up @@ -341,7 +341,7 @@
"cmds": [
"no shutdown"
],
"speed": "auto",
"speed": "Auto",
"ifname": "Ethernet1/30",
"fabric": "test_fabric"
},
Expand All @@ -367,7 +367,7 @@
"cmds": [
"no shutdown"
],
"speed": "auto",
"speed": "Auto",
"fabric": "test_fabric"
},
"name": "eth1/31",
Expand All @@ -393,7 +393,7 @@
"cmds": [
"no shutdown"
],
"speed": "auto",
"speed": "Auto",
"description": "eth interface acting as routed"
},
"name": "eth1/32",
Expand All @@ -418,7 +418,7 @@
"admin_state": "False",
"ifname": "Ethernet1/33",
"route_tag": "",
"speed": "auto",
"speed": "Auto",
"cmds": [
"no shutdown"
],
Expand Down Expand Up @@ -463,7 +463,7 @@
"no shutdown",
"no shutdown"
],
"speed": "auto",
"speed": "Auto",
"ifname": "Ethernet1/30",
"fabric": "test_fabric"
},
Expand Down Expand Up @@ -491,7 +491,7 @@
"no shutdown",
"no shutdown"
],
"speed": "auto",
"speed": "Auto",
"ifname": "Ethernet1/2",
"fabric": "test_fabric"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
"cmds": [
"no shutdown"
],
"speed": "auto",
"speed": "Auto",
"ifname": "Ethernet1/30",
"fabric": "test_fabric"
},
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/modules/dcnm/fixtures/dcnm_intf_multi_configs.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
"cmds": [
"no shutdown"
],
"speed": "auto",
"speed": "Auto",
"ifname": "Ethernet1/10",
"fabric": "test_fabric"
},
Expand Down Expand Up @@ -345,7 +345,7 @@
"cmds": [
"no shutdown"
],
"speed": "auto",
"speed": "Auto",
"description": "eth interface acting as routed"
},
"name": "eth1/32",
Expand Down
Loading

0 comments on commit b93b71c

Please sign in to comment.