Skip to content

Commit

Permalink
Fix for peer swap issue
Browse files Browse the repository at this point in the history
  • Loading branch information
mmudigon committed Apr 17, 2024
1 parent 861eea2 commit ef99ac3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
8 changes: 4 additions & 4 deletions plugins/module_utils/network/dcnm/dcnm_vpc_pair_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -873,18 +873,18 @@ def dcnm_vpc_pair_utils_get_all_filtered_vpc_pair_pairs(self):
== self.ip_sn.get(elem["peerOneId"], None)
)
or (
vpc_pair_info["peerOneId"]
== self.ip_sn.get(elem["peerTwoId"], None)
vpc_pair_info["peerTwoId"]
== self.ip_sn.get(elem["peerOneId"], None)
)
) and (
(elem.get("peerTwoId", None) is None)
or (
vpc_pair_info["peerTwoId"]
vpc_pair_info["peerOneId"]
== self.ip_sn.get(elem["peerTwoId"], None)
)
or (
vpc_pair_info["peerTwoId"]
== self.ip_sn.get(elem["peerOneId"], None)
== self.ip_sn.get(elem["peerTwoId"], None)
)
):
if vpc_pair_info not in vpc_pair_list:
Expand Down
22 changes: 18 additions & 4 deletions plugins/modules/dcnm_vpc_pair.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,8 +641,8 @@ def dcnm_vpc_pair_get_diff_deleted(self):
# Check the peering before deleting. Delete only the peering that is requested for.
if (
(have == [])
or (xelem["peerOneId"] != have["peerOneId"])
or (xelem["peerTwoId"] != have["peerTwoId"])
or (xelem["peerOneId"] != have["peerOneId"] and xelem["peerOneId"] != have["peerTwoId"])
or (xelem["peerTwoId"] != have["peerTwoId"] and xelem["peerTwoId"] != have["peerOneId"])
):
continue

Expand Down Expand Up @@ -822,12 +822,26 @@ def dcnm_vpc_pair_get_have(self):
# another peering, say, peer1 and peer3 or peer2 and peer4, then this should be flagged as an error.

if have != [] and (
(elem["peerOneId"] != have["peerOneId"])
or (elem["peerTwoId"] != have["peerTwoId"])
(
elem["peerOneId"] != have["peerOneId"]
and elem["peerOneId"] != have["peerTwoId"]
)
or (
elem["peerTwoId"] != have["peerTwoId"]
and elem["peerTwoId"] != have["peerOneId"]
)
):
mesg = f"Peering {have['peerOneId']}-{have['peerTwoId']} already exists. Cannot create peering for {elem['peerOneId']}-{elem['peerTwoId']}"
self.module.fail_json(msg=mesg)

# In some cases, specifically on VXLAN fabrics, the peerOneId and peerTwoId will get swapped on NDFC server. The peerOneId and peerTwoId selection
# happens based on some internal logic. Users may not be aware of which switch is peer1 and which is peer2.
# To handle such cases transparently, we will swap the peerOneId and peerTwoId fields in WANT, to be consistent with 'have'.
# Otherwise idempotence cases may fail.
if have != []:
elem["peerOneId"] = have["peerOneId"]
elem["peerTwoId"] = have["peerTwoId"]

if (have != []) and (have not in self.have):
self.have.append(have)

Expand Down

0 comments on commit ef99ac3

Please sign in to comment.