Skip to content

Commit 22c0fee

Browse files
Changes from PR comments
1 parent aa35c0b commit 22c0fee

File tree

1 file changed

+23
-32
lines changed

1 file changed

+23
-32
lines changed

plugins/module_utils/network/dcnm/dcnm_vpc_pair_utils.py

Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -395,15 +395,15 @@ def dcnm_vpc_pair_compare_vpc_pair_objects(self, wobj, hobj):
395395

396396
# Special handling for useVirtualPeerlink to treat None and False as equivalent
397397
if key == "useVirtualPeerlink":
398-
hval = hobj.get(key, None)
399-
wval = wobj[key]
400-
if not ((hval is None and wval is False) or (hval is False and wval is None)):
401-
if str(hval).lower() != str(wval).lower():
402-
mismatch_reasons.append(
403-
{key.upper() + "_MISMATCH": [wval, hval]}
404-
)
398+
# Cast to bool to treat None and False equivalently
399+
hval = bool(hobj.get(key, False))
400+
wval = bool(wobj[key])
401+
if hval != wval:
402+
mismatch_reasons.append(
403+
{key.upper() + "_MISMATCH": [wobj[key], hobj.get(key, None)]}
404+
)
405405
elif key != "nvPairs": # Skip nvPairs here as it's handled separately
406-
if str(hobj.get(key, None)).lower() != str(wobj[key]).lower():
406+
if str(hobj.get(key, False)).lower() != str(wobj[key]).lower():
407407
# We found an object that matched all other key values, but differs in one of the params.
408408
mismatch_reasons.append(
409409
{key.upper() + "_MISMATCH": [wobj[key], hobj.get(key, None)]}
@@ -416,30 +416,21 @@ def dcnm_vpc_pair_compare_vpc_pair_objects(self, wobj, hobj):
416416
if "_defaulted" in key:
417417
continue
418418

419-
# Special handling for useVirtualPeerlink in nvPairs to treat None and False as equivalent
420-
if key == "useVirtualPeerlink":
421-
hval = hobj["nvPairs"].get(key, None)
422-
wval = wobj["nvPairs"][key]
423-
if not ((hval is None and wval is False) or (hval is False and wval is None)):
424-
if str(hval).lower() != str(wval).lower():
425-
mismatch_reasons.append(
426-
{key.upper() + "_MISMATCH": [wval, hval]}
427-
)
428-
else:
429-
if (
430-
str(hobj["nvPairs"].get(key, None)).lower()
431-
!= str(wobj["nvPairs"][key]).lower()
432-
):
433-
# We found an object that matched all other key values, but differs in one of the params.
434-
mismatch_reasons.append(
435-
{
436-
key.upper()
437-
+ "_MISMATCH": [
438-
wobj["nvPairs"][key],
439-
hobj["nvPairs"].get(key, None),
440-
]
441-
}
442-
)
419+
# Special handling for useVirtualPeerlink to treat None and False as equivalent
420+
if key == "useVirtualPeerlink":
421+
# Cast to bool to treat None and False equivalently
422+
hval = bool(hobj.get(key, False))
423+
wval = bool(wobj[key])
424+
if hval != wval:
425+
mismatch_reasons.append(
426+
{key.upper() + "_MISMATCH": [wobj[key], hobj.get(key, None)]}
427+
)
428+
elif key != "nvPairs": # Skip nvPairs here as it's handled separately
429+
if str(hobj.get(key, False)).lower() != str(wobj[key]).lower():
430+
# We found an object that matched all other key values, but differs in one of the params.
431+
mismatch_reasons.append(
432+
{key.upper() + "_MISMATCH": [wobj[key], hobj.get(key, None)]}
433+
)
443434

444435
if mismatch_reasons != []:
445436
return "DCNM_VPC_PAIR_MERGE", mismatch_reasons, hobj

0 commit comments

Comments
 (0)