Skip to content

Add nd_interface_loopback module with integration tests#220

Open
allenrobel wants to merge 19 commits intond42_integrationfrom
nd_interface_loopback
Open

Add nd_interface_loopback module with integration tests#220
allenrobel wants to merge 19 commits intond42_integrationfrom
nd_interface_loopback

Conversation

@allenrobel
Copy link
Copy Markdown
Collaborator

Summary

  • Adds the nd_interface_loopback Ansible module for managing loopback interfaces on Nexus Dashboard 4.2
  • Fixes state:overridden incorrectly attempting to delete system-provisioned loopback interfaces (Loopback0/Loopback1 with policyType: "underlayLoopback")
  • Adds integration test suite covering all four states (merged, replaced, overridden, deleted)
  • Adds dynamic inventory generator (tests/integration/inventory.py) for running integration tests against live ND testbeds
  • Adds unit tests for manage_interfaces endpoint classes

Details

System loopback filtering fix

query_all() in LoopbackInterfaceOrchestrator previously filtered only by interfaceType == "loopback", which included system-provisioned loopbacks that ND creates during switch role configuration. These interfaces have policyType: "underlayLoopback" and cannot be deleted.

The fix adds a second filter that checks policyType against the set of policy types this module manages (loopback, ipfmLoopback, userDefined). System loopbacks are now excluded from the before collection, ensuring accurate changed flags and no unnecessary API calls.

Integration tests

Test coverage organized into per-state task files:

  • Merged: create single/multiple, idempotency, update, deploy: false
  • Replaced: full replace, idempotency, multi-interface replace
  • Overridden: reduce to single, idempotency, system loopback filtering validation, swap interfaces
  • Deleted: single/multi delete, idempotency, non-existent interface

Dynamic inventory generator

tests/integration/inventory.py reads ND connection params from environment variables and generates a static inventory.networking for ansible-test, which sanitizes the subprocess environment. Also works directly as a dynamic inventory with ansible-playbook -i.

Test plan

  • All 365 unit tests pass (python -m pytest tests/unit/)
  • All integration tests pass against live ND 4.2 testbed via ansible-test network-integration nd_interface_loopback
  • System loopback filtering verified: Loopback0/Loopback1 excluded from before collection in overridden state
  • Peer review

🤖 Generated with Claude Code

allenrobel and others added 13 commits March 31, 2026 07:47
1. Team decided not to allow switch level deploy in resource modules.

- Removed deploy_type parameter and use only interface-level deploy endpoint.
- Updated module documentation

2. Leverage bulk endpoint for interface deletion.

POST …interfaceActions/remove

3. Remove single-interface DELETE endpoint

DELETE …interfaces/{interface_name}

4. Add initial unit tests for nd_interface_loopback
* Update galaxy.yml

* Update galaxy.yml
* update actions jobs to normalize names, steps, and python/ansible matrix

* update job name typo for galaxy-importer

* update on push & pr targets

* fix ansible version var reference name

* update actions package and collection name based on python and ansible versions

* update galaxy-importer-log per python/ansible version

* remove ansible-core 2.15 from actions

* remove scheduler for time being

* update actions package versions

* update unit test name and fix coverage misspelling

* uncomment but disable integration tests

* test ansible partner certification

* test ansible partner certification

* retest partner cert job

* add anisble-lint file

* fix comment for partner cert failure

* address review comment where int tests used global python env but they are disabled for now anyway

* update to leverage ansible anchors
… interfaces

query_all() in LoopbackInterfaceOrchestrator previously filtered interfaces
only by interfaceType == "loopback", which included system-provisioned
loopbacks (Loopback0 routing, Loopback1 VTEP) that ND creates during
initial switch role configuration. These have policyType "underlayLoopback"
and are not deletable.

When state:overridden was used, the module saw these system loopbacks in the
before collection, identified them as "not in proposed", and queued them for
removal. ND silently rejected the delete requests (the interfaces have
deletable: false), but the module incorrectly reported changed=true and
made unnecessary API calls.

The fix adds a second filter stage to query_all() that checks each loopback's
configData.networkOS.policy.policyType against the set of policy types this
module manages (loopback, ipfmLoopback, userDefined). System loopbacks with
policyType "underlayLoopback" are now excluded from the before collection.

This ensures:
- Accurate changed flag (no false positives from undeletable interfaces)
- No unnecessary remove API calls for system-managed interfaces
- The module correctly understands its own management scope

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Integration test suite covering all four states (merged, replaced,
overridden, deleted) for the nd_interface_loopback module. Tests are
organized into separate task files per state for easier debugging and
selective execution.

Test coverage includes:
- Merged: create single/multiple, idempotency, update, deploy=false
- Replaced: full replace, idempotency, multi-interface replace
- Overridden: reduce to single, idempotency, system loopback filtering,
  swap interfaces in one pass
- Deleted: single/multi delete, idempotency, non-existent interface

The overridden tests include a dedicated system loopback filtering test
that verifies Loopback0/Loopback1 (policyType "underlayLoopback") do not
appear in the before collection and are not targeted for deletion.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Python script that serves dual purpose:
- Generator mode (no args): reads ND connection and testbed topology
  from environment variables and writes a static inventory.networking
  file for use with ansible-test network-integration
- Dynamic inventory mode (--list): outputs JSON inventory to stdout
  for direct use with ansible-playbook -i inventory.py

Required env vars: ND_IP4, ND_USERNAME, ND_PASSWORD, ND_DOMAIN
Optional env vars: ND_FABRIC_NAME, ND_SWITCH_IP (with defaults)

The generator approach is needed because ansible-test sanitizes the
subprocess environment, stripping arbitrary env vars at runtime.
Running the generator beforehand bakes values into a static INI file
that ansible-test picks up automatically.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Unit tests for the EpManageInterfaces endpoint classes used by
nd_interface_loopback: Get, ListGet, Post, Put, Deploy, and Remove.
Covers path construction, HTTP verb assignment, and fabric/switch
identifier injection.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@allenrobel allenrobel changed the title Add nd_interface_loopback module with integration tests Add nd_interface_loopback module with integration tests (WIP) Apr 3, 2026
allenrobel and others added 4 commits April 3, 2026 10:39
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Remove shebang from tests/integration/inventory.py (non-module files
  must not have a shebang line per ansible-test sanity rules)
- Fix author format in nd_interface_loopback.py DOCUMENTATION block
  from 'Cisco Systems, Inc.' to 'Allen Robel (@allenrobel)' to match
  the required 'Name (@github_handle)' format

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@allenrobel allenrobel changed the title Add nd_interface_loopback module with integration tests (WIP) Add nd_interface_loopback module with integration tests Apr 3, 2026
1. Ansible sanity requires author to be Name (@github_handle)

Changed all files in this PR to:

# Copyright: (c) 2026, Allen Robel (@allenrobel)

2. Removed the following legacy Python 2.x remnant:

# -*- coding: utf-8 -*-
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.

3 participants