Allow destroy by name only when --keep-mgmt-net is set and topology file is missing #2849
+194
−21
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR addresses the issue where users cannot destroy labs by name when the topology file has been lost, particularly in CI environments where topology files may be accidentally removed.
Problem
Previously, when using
containerlab destroy --name <lab-name>, the command would fail if the topology file referenced in the container labels didn't exist on disk, even when using--keep-mgmt-net. This created issues in scenarios like:Solution
When both
--nameand--keep-mgmt-netflags are used together, containerlab now gracefully handles missing topology files by:Behavior Changes
Before (fails):
$ containerlab destroy --name mylab --keep-mgmt-net ERROR: Topology file '/path/to/missing.yml' not foundAfter (succeeds with warning):
$ containerlab destroy --name mylab --keep-mgmt-net WARN: Topology file '/path/to/missing.yml' not found, proceeding with limited cleanup (--keep-mgmt-net is set) INFO: Destroying lab name=mylab INFO: Deleting 3 containers directly (topology not available) INFO: Removing SSH config ...Backward Compatibility
--keep-mgmt-netis not used--nameand--keep-mgmt-netare specifiedImplementation Details
makeCopyForDestroy()to handle missing topology files gracefully when--keep-mgmt-netis setdeleteContainersDirect()method for container deletion without topology node abstractiondestroy()method to fallback to container listing by lab name when topology parsing failsTesting
Added comprehensive test case that verifies:
--keep-mgmt-netis used--keep-mgmt-netis not usedFixes issue where destroy operations would fail unnecessarily in CI environments and development workflows.
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
myserver.foo/tmp/go-build3271045625/b1249/utils.test -test.paniconexit0 -test.gocoverdir=/tmp/go-build3271045625/b1249/gocoverdir -test.timeout=10m0s -test.v=true -test.gocoverdir=/tmp/clab-tests/coverage(dns block)/tmp/go-build2041016230/b1249/utils.test -test.paniconexit0 -test.gocoverdir=/tmp/go-build2041016230/b1249/gocoverdir -test.timeout=10m0s -test.v=true -test.gocoverdir=/tmp/clab-tests/coverage(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.