-
Notifications
You must be signed in to change notification settings - Fork 53
Add EOS pre-transfer free-space check (NAPPS-1091) #370
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Added a pre-transfer free-space check to EOS ``file_copy`` and ``remote_file_copy`` that raises ``NotEnoughFreeSpaceError`` when the target filesystem lacks room for the image. | ||
| Added ``file_size_unit`` (``bytes``, ``megabytes``, or ``gigabytes``; default ``bytes``) and a computed ``file_size_bytes`` to ``FileCopyModel`` so ``remote_file_copy`` can verify free space against a caller-supplied size; when ``file_size`` is omitted the pre-transfer check is skipped. |
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like how this simplifies repeated logic in all the test_{device_type}_device.py files. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| """Shared helpers for integration tests that drive ``remote_file_copy``.""" | ||
|
|
||
| import os | ||
| import posixpath | ||
|
|
||
| import pytest | ||
|
|
||
| from pyntc.utils.models import FileCopyModel | ||
|
|
||
| # Every protocol that ``remote_file_copy`` might transfer from. Individual device | ||
| # test modules can narrow this set when they only support a subset. | ||
| PROTOCOL_URL_VARS = { | ||
| "ftp": "FTP_URL", | ||
| "tftp": "TFTP_URL", | ||
| "scp": "SCP_URL", | ||
| "http": "HTTP_URL", | ||
| "https": "HTTPS_URL", | ||
| "sftp": "SFTP_URL", | ||
| } | ||
|
|
||
|
|
||
| def build_file_copy_model(url_env_var): | ||
| """Build a ``FileCopyModel`` from a per-protocol URL env var. | ||
|
|
||
| Calls ``pytest.skip`` if the URL, ``FILE_CHECKSUM``, or ``FILE_SIZE`` env | ||
| vars are not set. | ||
| """ | ||
| url = os.environ.get(url_env_var) | ||
| checksum = os.environ.get("FILE_CHECKSUM") | ||
| file_name = os.environ.get("FILE_NAME") or (posixpath.basename(url.split("?")[0]) if url else None) | ||
| file_size = int(os.environ.get("FILE_SIZE", "0")) | ||
| file_size_unit = os.environ.get("FILE_SIZE_UNIT", "bytes") | ||
|
|
||
| if not all([url, checksum, file_name, file_size]): | ||
| pytest.skip(f"{url_env_var} / FILE_CHECKSUM / FILE_SIZE environment variables not set") | ||
|
|
||
| return FileCopyModel( | ||
| download_url=url, | ||
| checksum=checksum, | ||
| file_name=file_name, | ||
| file_size=file_size, | ||
| file_size_unit=file_size_unit, | ||
| hashing_algorithm="sha512", | ||
| timeout=900, | ||
| ) | ||
|
|
||
|
|
||
| def first_available_url(protocol_url_vars=None): | ||
| """Return ``(scheme, url)`` for the first configured protocol URL. | ||
|
|
||
| ``(None, None)`` when none of the env vars in ``protocol_url_vars`` are set. | ||
| """ | ||
| for scheme, env_var in (protocol_url_vars or PROTOCOL_URL_VARS).items(): | ||
| url = os.environ.get(env_var) | ||
| if url: | ||
| return scheme, url | ||
| return None, None |
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This makes sense for simplifying and sharing the module for pytest. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| """Shared fixtures for pyntc integration tests.""" | ||
|
|
||
| import os | ||
| import posixpath | ||
|
|
||
| import pytest | ||
|
|
||
| from pyntc.utils.models import FileCopyModel | ||
|
|
||
| from ._helpers import PROTOCOL_URL_VARS | ||
|
|
||
|
|
||
| @pytest.fixture(scope="module") | ||
| def any_file_copy_model(): | ||
| """Return a ``FileCopyModel`` using the first available protocol URL. | ||
|
|
||
| Used by tests that only need a file reference (existence checks, checksum | ||
| verification) without caring about the transfer protocol. Skips if no | ||
| protocol URL / ``FILE_CHECKSUM`` / ``FILE_SIZE`` env vars are set. | ||
| """ | ||
| checksum = os.environ.get("FILE_CHECKSUM") | ||
| file_size = int(os.environ.get("FILE_SIZE", "0")) | ||
| file_size_unit = os.environ.get("FILE_SIZE_UNIT", "bytes") | ||
| for env_var in PROTOCOL_URL_VARS.values(): | ||
| url = os.environ.get(env_var) | ||
| if url and checksum and file_size: | ||
| file_name = os.environ.get("FILE_NAME") or posixpath.basename(url.split("?")[0]) | ||
| return FileCopyModel( | ||
| download_url=url, | ||
| checksum=checksum, | ||
| file_name=file_name, | ||
| file_size=file_size, | ||
| file_size_unit=file_size_unit, | ||
| hashing_algorithm="sha512", | ||
| timeout=900, | ||
| ) | ||
| pytest.skip("No protocol URL / FILE_CHECKSUM / FILE_SIZE environment variables not set") |
Uh oh!
There was an error while loading. Please reload this page.