Add ASA pre-transfer free-space check (NAPPS-1087)#372
Merged
jeffkala merged 4 commits intonetworktocode:developfrom Apr 22, 2026
Merged
Add ASA pre-transfer free-space check (NAPPS-1087)#372jeffkala merged 4 commits intonetworktocode:developfrom
jeffkala merged 4 commits intonetworktocode:developfrom
Conversation
Implements the fail-open pre-transfer free-space check on Cisco ASA using the seam added in NAPPS-1091 (PR networktocode#370). Image transfers now fail fast when ``disk0:`` lacks room instead of half-writing flash. - ASADevice._get_free_space parses the ``(N bytes free)`` trailer from ``dir`` output (same format EOS exposes). - file_copy calls _check_free_space with os.path.getsize on the local source before any SCP transfer. - remote_file_copy calls _pre_transfer_space_check inside the existing ``not verify_file`` block so the check only fires when a transfer would actually happen; still fail-open when src.file_size_bytes is None. - Unit tests cover the dir-trailer parse, the missing-trailer raise, file_copy raising before SCP, remote_file_copy raising before any copy command, and the fail-open path spying on _check_free_space. - Existing file_copy unit tests updated to mock os.path.getsize and _check_free_space (previously they passed a non-existent path that would now blow up on os.path.getsize). - Integration tests mirror the EOS pattern for manual lab runs. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Real ASA platforms print the dir trailer as ``(<N> bytes free/<pct>% free)`` — the closing paren is not adjacent to ``free``. The previous regex anchored on ``\)`` and so would have failed on live hardware (verified against an ASA 5512 running 9.9.2 at 10.1.100.80, which reports ``4118732800 bytes total (3580170240 bytes free/86% free)``). Drop the trailing ``\)`` anchor and update the mock fixture + tests to cover both the real-device shape and the legacy ``(N bytes free)`` emulator shape. Bumped the ``test_remote_file_copy_raises_not_enough_free_space`` oversize from 2 GB to 10 GB because the mock now reports ~3.3 GB free — 2 GB fits, 10 GB does not. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Contributor
Author
|
mattmiller87
approved these changes
Apr 22, 2026
Contributor
mattmiller87
left a comment
There was a problem hiding this comment.
This matches what we were doing in EOS, IOS, NXOS. ASA seems almost identical with the "dir" command output.
jeffkala
approved these changes
Apr 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
disk0:lacks room instead of half-writing flash.ASADevice._get_free_spaceparses the(N bytes free)trailer fromdiroutput;file_copycalls_check_free_space(os.path.getsize(src))before any SCP transfer;remote_file_copycalls_pre_transfer_space_checkinside the existingnot verify_fileblock so the check only fires when a transfer would actually happen.file_copyraising before SCP,remote_file_copyraising before any copy command, and the fail-open path. Integration tests mirror the EOS pattern for manual lab runs.NAPPS-1087
Test plan
poetry run pytest tests/unit/test_devices/test_asa_device.py— all 143 pass.poetry run pytest tests/unit— all 659 pass.poetry run ruff check pyntc tests— clean.poetry run pytest tests/integration/test_asa_device.py -vwithASA_HOST/ASA_USER/ASA_PASS/ASA_SECRET+ protocol URLs +FILE_CHECKSUM/FILE_SIZE/FILE_SIZE_UNITset — verifies the probe, the oversized reject, and the fail-open path end-to-end.🤖 Generated with Claude Code