Skip to content

fix: fix reading copying status by rsync - #21

Open
lkleinax wants to merge 1 commit into
intel:mainfrom
lkleinax:fix__fix_reading_copying_status_by_rsync
Open

lkleinax wants to merge 1 commit into
intel:mainfrom
lkleinax:fix__fix_reading_copying_status_by_rsync

Conversation

@lkleinax

@lkleinax lkleinax commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

This pull request enhances the clone_vm_hdd_image functionality in mfd_kvm/hypervisor.py by improving error handling, adding more detailed progress tracking for rsync-based image cloning, and updating the unit tests to reflect these changes. The main improvements are stricter source file validation, more informative logging and progress updates during cloning, and more robust test coverage for both rsync and scp scenarios.

Key changes:

Error Handling and Validation

  • The function now raises a FileNotFoundError immediately if the source image file does not exist, instead of checking later or after a timeout. [1] [2]

Cloning Process Improvements

  • When using rsync, the command now includes -av --info=progress2 --outbuf=N for verbose output and real-time progress, and logs are captured for progress parsing.
  • During the cloning loop, if rsync is used, the code reads the log file to parse and log detailed progress, including percentage completed, and handles possible errors in reading the log.

Test Enhancements

  • All relevant tests are updated to expect the new rsync command parameters and the use of the log_file argument. [1] [2] [3] [4]
  • New tests are added to specifically verify the progress reporting for both scp and rsync cloning, including parsing of rsync output and checking for accurate log messages.
  • Test assertions are updated to check log messages in a more robust way by extracting messages from log records instead of searching raw log text. [1] [2]

Code Quality and Robustness

  • Refactored command execution and logging for better maintainability and clarity, including improved error reporting if reading the rsync log fails.
  • Minor test cleanup for edge cases and improved mocking to ensure correct behavior in all scenarios.

Copilot AI balanced review requested due to automatic review settings October 27, 2026 14:10

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

3 open issues
What changed in this PR

Updates VM disk image cloning to better track rsync copy progress (Fixes #20) by switching to rsync progress output captured in a log file and parsing it to compute cloning status.

Changes:

  • Update the rsync invocation to include progress output and enable logging to a file.
  • Add rsync-specific progress parsing logic in clone_vm_hdd_image() and adjust timeout-loop behavior accordingly.
  • Update/add unit tests to cover rsync vs scp behavior and progress reporting.
File Description
mfd_kvm/​hypervisor.py Switch rsync command to emit progress, capture output to a log file, and parse progress status during the cloning loop.
tests/​unit/​test_mfd_kvm/​test_hypervisor.py Update expectations for the new rsync command/logging behavior and add tests for rsync vs scp “still cloning” progress messages.

Review effort: Lite

Comment thread mfd_kvm/hypervisor.py
elif path_to_destination_image.name in last_line or "sending incremental file list" in last_line:
current_size = 0
else:
current_size = last_line.strip().split()[0].replace(",", "")
Comment thread mfd_kvm/hypervisor.py
Comment on lines +937 to +947
copy_command = "rsync -av" if self._rsync_available else "scp"
params = f" --info=progress2 --outbuf=N " if self._rsync_available else " "
# show 5 column of ls, size of file
target_size = self._conn.execute_command(
f"ls {path_to_source_image} -l | awk '{{print $5}}'",
shell=True,
).stdout
copy_process = self._conn.start_process(
f"{copy_command}{params}{path_to_source_image} {path_to_destination_image}",
log_file=self._rsync_available,
)
Comment thread mfd_kvm/hypervisor.py
Comment on lines +954 to +959
out = self._conn.execute_command(
f"cat -A {copy_process.log_path}",
shell=True,
expected_return_codes={},
skip_logging=True,
)
Fixes intel#20
Signed-off-by: Łukasz Kleina <lukaszx.kleina@intel.com>
@lkleinax
lkleinax force-pushed the fix__fix_reading_copying_status_by_rsync branch from bd2f0b8 to 5142a1f Compare October 27, 2026 14:37
@lkleinax
lkleinax requested a balanced review from Copilot October 27, 2026 14:42

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Comment thread mfd_kvm/hypervisor.py
)
return path_to_destination_image
if not path_to_source_image.is_file():
raise FileNotFoundError(f"Not found {path_to_source_image} in system.")
Comment thread mfd_kvm/hypervisor.py
Comment on lines +954 to +959
out = self._conn.execute_command(
f"cat -A {copy_process.log_path}",
shell=True,
expected_return_codes={},
skip_logging=True,
)
Comment thread mfd_kvm/hypervisor.py
Comment on lines +974 to +977
elif path_to_destination_image.name in last_line or "sending incremental file list" in last_line:
current_size = 0
else:
current_size = last_line.strip().split()[0].replace(",", "")
Comment thread mfd_kvm/hypervisor.py
except (TypeError, ValueError):
current_size = 0
if current_size > 0:
logging.log(

This branch has not been deployed

No deployments
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.

2 participants