Skip to content

Conversation

@miguecor
Copy link
Contributor

@miguecor miguecor commented Dec 3, 2025

This PR fixes an issue when creating a new VRF without specifying a L3VNI.

  • Before this change, this functionality was working on ND 3.1 and 3.2, but not on 4.1.
  • After this change, this will work on all ND versions.

The issue was with the vrfVlanId parameter. When the value wasn't provided in the playbook, a default value of 0 was ussed. Now, if the vrfVlanId parameter is not provided, we transform it to an empty string (""). This default value works accross all 3 versions of ND.

Fix #538

Miguel Corona added 2 commits December 3, 2025 09:58
@miguecor
Copy link
Contributor Author

miguecor commented Dec 3, 2025

@allenrobel / @mikewiebe: This PR is ready for review.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes an issue where creating a new VRF without specifying a L3VNI (vlan_id) fails on ND version 4.1, while working on versions 3.1 and 3.2. The fix ensures compatibility across all three ND versions by transforming the default vrfVlanId value from 0 to an empty string ("") for DCNM version 12+.

Key Changes

  • Fixed a bug in get_next_vrf_id() where the retry loop would continue even after successfully retrieving a vrf_id, potentially overwriting valid values
  • Modified diff_merge_create() to transform vrfVlanId from 0 to "" for DCNM version 12+, ensuring compatibility with ND 4.1

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 2279 to 2280
template_conf.update(
vrfVlanId="" if template_conf["vrfVlanId"] == 0 else template_conf["vrfVlanId"]
Copy link

Copilot AI Dec 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The inline conditional in the update() call is difficult to read and maintain. Consider extracting this logic to a separate variable before the update:

vrf_vlan_id_value = "" if template_conf["vrfVlanId"] == 0 else template_conf["vrfVlanId"]
template_conf.update(vrfVlanId=vrf_vlan_id_value)

This improves readability and makes the transformation logic more explicit.

Suggested change
template_conf.update(
vrfVlanId="" if template_conf["vrfVlanId"] == 0 else template_conf["vrfVlanId"]
vrf_vlan_id_value = "" if template_conf["vrfVlanId"] == 0 else template_conf["vrfVlanId"]
template_conf.update(
vrfVlanId=vrf_vlan_id_value

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented suggestion in ^9608cc6

if self.dcnm_version > 11:
template_conf.update(isRPAbsent=json_to_dict.get("isRPAbsent"))
template_conf.update(
vrfVlanId="" if template_conf["vrfVlanId"] == 0 else template_conf["vrfVlanId"]
Copy link

Copilot AI Dec 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The conditional check template_conf["vrfVlanId"] == 0 doesn't handle the case where vrfVlanId might be None. When json_to_dict.get("vrfVlanId") is called at line 2246 without a default value, it returns None if the key is missing.

Consider using a more defensive check:

template_conf.update(
    vrfVlanId="" if template_conf.get("vrfVlanId") in [0, None] else template_conf["vrfVlanId"]
)

Or alternatively, ensure vrfVlanId has a default value at line 2246:

"vrfVlanId": json_to_dict.get("vrfVlanId", 0),
Suggested change
vrfVlanId="" if template_conf["vrfVlanId"] == 0 else template_conf["vrfVlanId"]
vrfVlanId="" if template_conf.get("vrfVlanId") in [0, None] else template_conf["vrfVlanId"]

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented the defesive check in ^9608cc6

@mikewiebe
Copy link
Collaborator

Thanks @miguecor. We need to get PR #542 merged before we can merge this one since it has all of the changes required to support MCFG for VRFs.

Copy link
Collaborator

@allenrobel allenrobel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Miguel, this looks fine to me. I've also enabled Copilot review which generated a couple comments that look worth considering.

Thanks!

)
template_conf.update(
isRPAbsent=json_to_dict.get("isRPAbsent")
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the update for isRPAbsent related to creating the VRF without VNI or is it a separate issue? It's fine that it's added here, but am rather just curious about it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not related. I just added the newline to standirize the elements inside the update function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dcnm_vrf : Error when creating VRF without vrf_id on ND 4.1

3 participants