Skip to content

Add unit tests for conductor SONiC BGP/VLAN/Loopback/VRF helpers#2290

Open
berendt wants to merge 1 commit into
mainfrom
gh2223
Open

Add unit tests for conductor SONiC BGP/VLAN/Loopback/VRF helpers#2290
berendt wants to merge 1 commit into
mainfrom
gh2223

Conversation

@berendt
Copy link
Copy Markdown
Member

@berendt berendt commented May 19, 2026

Closes #2223.

Adds tests/unit/tasks/conductor/sonic/test_config_generator_bgp_vlan_vrf.py covering the BGP, VLAN, Loopback and VRF helpers in osism/tasks/conductor/sonic/config_generator.py.

Coverage

  • _add_bgp_configurationsBGP_NEIGHBOR_AF / BGP_NEIGHBOR for connected interfaces and port channels, plus VLAN-SVI BGP: untagged-member exclusion, direct vs. transfer-role IPv4, switch-to-switch / l2vpn_evpn tag handling, non-default VRF, peer-IP local-addr resolution and peer-IP dedup
  • _get_connected_device_for_interface — delegation
  • _determine_peer_type — AS-mapping vs. computed ASN, missing primary_ip4, and exception handling
  • _add_vlan_configuration — members / VLAN_MEMBER / SVI, unmapped-member warning
  • _add_loopback_configurationLoopback0 BGP_GLOBALS_AF_NETWORK (v4/v6), invalid-IP path
  • _get_vrf_info — both naming conventions, per-interface and top-level error paths
  • _add_vrf_configuration — VNI/table_id/neither, BGP_GLOBALS deep copy, VXLAN sections, interface/port-channel VRF assignment

Notes

  • _add_vlan_configuration does not actually sort members by SONiC name (the issue text says it does); tests assert the real behaviour via an order-independent comparison.
  • Log-only branches are asserted via the shared loguru_logs fixture.

Checks

  • flake8, python-black green locally
  • mypy runs as a separate Zuul job; the file follows the annotation-free SimpleNamespace style of the existing, CI-green SONiC test files
  • pytest left to the python-osism-unit-tests Zuul job

🤖 Generated with Claude Code

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="tests/unit/tasks/conductor/sonic/test_config_generator_bgp_vlan_vrf.py" line_range="758-772" />
<code_context>
+# ---------------------------------------------------------------------------
+
+
+@pytest.fixture
+def vrf_config():
+    return {
+        "VRF": {},
+        "VLAN": {},
+        "VLAN_INTERFACE": {},
+        "BGP_GLOBALS_AF": {},
+        "BGP_GLOBALS_ROUTE_ADVERTISE": {},
+        "BGP_GLOBALS": {},
+        "VXLAN_TUNNEL": {},
+        "VXLAN_EVPN_NVO": {},
+        "VXLAN_TUNNEL_MAP": {},
+        "INTERFACE": {},
+        "PORTCHANNEL_INTERFACE": {},
+    }
+
</code_context>
<issue_to_address>
**suggestion (testing):** Initialize ROUTE_REDISTRIBUTE in vrf_config fixture to make the intent explicit

`TestAddVrfConfiguration.test_vrf_with_vni_full_config` asserts that `"vrfStorage|connected|bgp|ipv4" in vrf_config["ROUTE_REDISTRIBUTE"]`, but the fixture doesn’t define `"ROUTE_REDISTRIBUTE"`. The test currently depends on `_add_vrf_configuration` to create this key. Initializing `"ROUTE_REDISTRIBUTE": {}` in the `vrf_config` fixture would make the test more explicit and its failures less dependent on implementation side effects.

```suggestion
@pytest.fixture
def vrf_config():
    return {
        "VRF": {},
        "VLAN": {},
        "VLAN_INTERFACE": {},
        "BGP_GLOBALS_AF": {},
        "BGP_GLOBALS_ROUTE_ADVERTISE": {},
        "BGP_GLOBALS": {},
        "VXLAN_TUNNEL": {},
        "VXLAN_EVPN_NVO": {},
        "VXLAN_TUNNEL_MAP": {},
        "INTERFACE": {},
        "PORTCHANNEL_INTERFACE": {},
        "ROUTE_REDISTRIBUTE": {},
    }
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@berendt berendt force-pushed the gh2223 branch 2 times, most recently from e4ca3a2 to 8aa1b24 Compare May 19, 2026 14:48
Cover the BGP, VLAN, Loopback and VRF helpers in
osism/tasks/conductor/sonic/config_generator.py:

- _add_bgp_configurations: BGP_NEIGHBOR_AF and BGP_NEIGHBOR for
  connected interfaces and port channels, plus VLAN-SVI BGP
  (untagged-member, transfer-role, switch-to-switch / l2vpn_evpn,
  non-default VRF and dedup branches)
- _get_connected_device_for_interface delegation
- _determine_peer_type AS comparison and error handling
- _add_vlan_configuration members / VLAN_MEMBER / SVI
- _add_loopback_configuration including Loopback0 BGP_GLOBALS_AF_NETWORK
- _get_vrf_info naming conventions and error paths
- _add_vrf_configuration VNI/table_id/VXLAN/interface assignment

Closes #2223

AI-assisted: Claude Code
Signed-off-by: Christian Berendt <berendt@osism.tech>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Ready

Development

Successfully merging this pull request may close these issues.

Unit tests for osism/tasks/conductor/sonic/config_generator.py — BGP/VLAN/Loopback/VRF

2 participants