Repository navigation
feat: support multiple portgroups per NAD in network mapping - #102
albertoflorez wants to merge 7 commits into
Conversation
ReviewSolid PR — real bug fix, well-scoped, backward compatible, good description. Logic is correct for standard cases. A few observations: Suggestions1. Unit tests for New filter with branching logic (namespace filtering, comma splitting, exception handling) on a correctness-critical path — wrong match means VM on wrong network. Ansible filter plugins are straightforward to test with pytest. Would be good to cover at minimum: single portgroup match, multi-portgroup match, namespace filtering, no-match, and malformed input. 2. Extract duplicated Jinja2 conditional in The pod-fallback condition on lines 5 and 25 is ~300 chars of nested boolean logic, duplicated for both vSphere and oVirt paths: {% elif ('network_destination_type' in ... and ... == "pod") or (mtv_management_mtv_network_networkattachmentdefinition | length == 0 and ('network_attachment_definition' not in ... or ... | default('', true) | trim | length == 0)) %}Extracting to a 3. Comma-in-portgroup-name edge case (
4. Minor: When both SummaryNo blockers. The core logic and the pod-fallback fix look correct. Main ask is test coverage for the new filter plugin. |
stevefulme1
left a comment
There was a problem hiding this comment.
just fix the slight thing on my review and we can go ahead and approve.
…ion_migration into feat/network-map-multi-portgroup
|
Thanks for the review — all four points addressed. 1. Unit tests for Added The test loads the plugin by path with 2. Duplicated Jinja2 conditional (0cd53fa) Went a bit further than extracting To confirm the refactor is behaviour-preserving I rendered the old and new templates over 126 combinations (3 providers × 14 override shapes × 3 discovered-NAD states): byte-identical output in every case, including the unrecognised-provider case. 3. Comma-in-portgroup-name edge case (88093a9) Documented in the 4. Rather than documenting the silent precedence, I made it an error. One thing worth flagging, since the main ask was test coverage: CI does not currently run unit tests. That's a change in the shared CI repo, so I'd rather not bundle it here. Happy to open an issue against |
Summary
In VMware environments, the same network can be represented by multiple port groups (e.g., on different distributed switches or different sites). Previously, the network mapping logic had two limitations that prevented this scenario from working correctly:
source-portgroupannotation, so only one port group would match automatically.network_attachment_definitionoverride was silently ignored when the annotation-based lookup returned no results — the template fell back totype: podinstead of using the explicitly configured NAD.Changes
match_portgroupfilter plugin (plugins/filter/match_portgroup.py): New custom Ansible filter that replaces the JMESPath exact-match query. It splits thesource-portgroupannotation by comma and checks if the network name is in the resulting list. Fully backward compatible with single-value annotations.portgroups(list) support (roles/network_mgmt/templates/manual-lb/nad.yaml.j2): The manual NAD template now acceptsportgroups(list) alongside the existingportgroup(string). When a list is provided, values are joined with commas in the annotation.portgroupstakes precedence if both are defined.roles/mtv_management/templates/networkmap_map.yml.j2): The template now checks for an explicitnetwork_attachment_definitionin overrides before falling back totype: pod. This applies to both vSphere and oVirt paths.roles/mtv_management/tasks/_mtv_network_map_process_network.yml): Replacedjson_querywith the newmatch_portgroupfilter for both VMware and oVirt NAD lookups.roles/network_mgmt/defaults/main.yml,roles/mtv_management/defaults/main.yml): Added usage examples forportgroupslist and multi-portgroup override patterns.Why this matters
Without this change, migrating VMs connected to different port groups that represent the same network required manual workarounds and could silently result in VMs being mapped to the pod network instead of the intended multus NAD — potentially breaking network connectivity after migration.
Testing
portgroups(list) generates the correct comma-separatedsource-portgroupannotationportgroup(string) continue to work without changesnetwork_attachment_definitionnow correctly producetype: multuseven when the annotation-based lookup returns no matchesCloses #90