Skip to content

utils_test: Check guest disk space before file transfer#4342

Open
hholoubk wants to merge 4 commits intoavocado-framework:masterfrom
hholoubk:check-guest-disk-space-before-transfer
Open

utils_test: Check guest disk space before file transfer#4342
hholoubk wants to merge 4 commits intoavocado-framework:masterfrom
hholoubk:check-guest-disk-space-before-transfer

Conversation

@hholoubk
Copy link
Copy Markdown
Contributor

Verify that the guest has sufficient free space on the target directory before creating and transferring a large file. This prevents a slow 4GB SCP transfer that fails with a cryptic "scp: write remote ... Failure" when the guest filesystem cannot hold the file.

AI assisted code and commit. Human reviewed.
Sign off: Hana Holoubkova hholoubk@redhat.com

Made-with: Cursor

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the 'run_file_transfer' utility by proactively checking for available disk space on the guest system before attempting to transfer large files. This ensures that file transfers only proceed when there is adequate storage, thereby preventing time-consuming and ultimately failing operations caused by insufficient disk space.

Highlights

  • Pre-transfer Disk Space Check: Implemented a check to verify sufficient free disk space on the guest system before initiating large file transfers, preventing failures due to full disks.
  • Improved Error Handling: Introduced an explicit 'TestError' with a clear message when insufficient disk space is detected, replacing cryptic SCP failure messages.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds a useful pre-check to verify sufficient disk space on the guest before a large file transfer, preventing silent failures. The implementation is straightforward. However, I've identified a significant issue in the get_free_disk function it relies on, which could lead to incorrect free space calculation on Windows guests, potentially masking a critical configuration issue. I've also included a minor suggestion to modernize the string formatting in the new error message.

Comment thread virttest/utils_test/__init__.py Outdated
tmp_dir = params.get("tmp_dir", "c:\\")
guest_path = "\\".join([tmp_dir, utils_misc.generate_random_string(8)])
guest_path = "\\".join(filter(None, re.split(r"\\+", guest_path)))
guest_free_mb = utils_misc.get_free_disk(session, tmp_dir)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

The function utils_misc.get_free_disk that is being called here appears to have a bug when running on Windows guests. It incorrectly treats the output of wmic logicaldisk get FreeSpace (which is in bytes) as if it were in kilobytes. This results in the calculated free space being 1024 times larger than the actual free space. This could cause this check to incorrectly pass even when there is not enough disk space, defeating the purpose of this change. I recommend fixing get_free_disk in virttest/utils_misc.py to correctly handle the value as bytes.

References
  1. When a test's intent is to use a specific feature, it should fail explicitly if that feature or its dependencies are unavailable. Do not silently ignore the error or fall back to a different behavior, as this can mask configuration issues and lead to misleading results. The current bug could lead to a misleading result by incorrectly passing a disk space check.

Comment thread virttest/utils_test/__init__.py Outdated
Comment on lines +788 to +789
"Not enough space on guest '%s': %dMB free, "
"%dMB required" % (tmp_dir, guest_free_mb, filesize)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

For better readability and to align with modern Python practices, consider using the str.format() method for constructing this error message instead of the older % formatting.

            "Not enough space on guest '{0}': {1}MB free, {2}MB required".format(tmp_dir, guest_free_mb, filesize)

@hholoubk hholoubk force-pushed the check-guest-disk-space-before-transfer branch 6 times, most recently from 7292909 to 994e632 Compare March 24, 2026 11:21
Move run_file_transfer and run_virtio_serial_file_transfer from
utils_test/__init__.py into new utils_test/file_transfer.py module.
Re-exports in __init__.py preserve backward compatibility.

Convert utils_disk.py to utils_disk/ package. Move get_free_disk
from utils_misc.py to utils_disk/free_space.py and add new
check_free_disk helper. Re-exports in utils_disk/__init__.py and
utils_misc.py preserve backward compatibility.

Add guest disk free space validation in run_file_transfer to fail
early with a clear error when the VM has insufficient space for
the transfer.

Assisted-by: Claude AI (Cursor IDE) human design
Signed-off-by: hholoubk <hholoubk@redhat.com>
Replace legacy %-style string formatting with f-strings across
both run_file_transfer and run_virtio_serial_file_transfer for
better readability and to follow modern Python practices. Use
lazy logging format for LOG.info calls to avoid unnecessary
string interpolation when log level is disabled.

Assisted-by: Claude AI (Cursor) ~40% code generation
Signed-off-by: hholoubk <hholoubk@redhat.com>
Signed-off-by: hholoubk <hholoubk@redhat.com>
Suppress pylint E0401 on avocado.core import in free_space.py
since avocado is an external runtime dependency. Add TODO noting
that wmic returns bytes but value is tagged as kilobytes. Apply
black formatting to file_transfer.py multiline f-strings.

Assisted-by: Claude AI (Cursor) ~30% code generation
Signed-off-by: hholoubk <hholoubk@redhat.com>
Made-with: Cursor
@hholoubk hholoubk force-pushed the check-guest-disk-space-before-transfer branch from 8a6283d to ed1c224 Compare March 24, 2026 15:50
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.

1 participant