Skip to content

virsh_cmd: Change boot time fetching function#6905

Open
aniket-sahu-ibmx wants to merge 1 commit into
autotest:masterfrom
aniket-sahu-ibmx:fixuptime
Open

virsh_cmd: Change boot time fetching function#6905
aniket-sahu-ibmx wants to merge 1 commit into
autotest:masterfrom
aniket-sahu-ibmx:fixuptime

Conversation

@aniket-sahu-ibmx

@aniket-sahu-ibmx aniket-sahu-ibmx commented Jun 22, 2026

Copy link
Copy Markdown

The --since arg for uptime is not part of the basic package shipped with SLES releases. This caused the test to fail silently. This change uses /proc/stat to get boot time which will be present in every linux distro, thus making the test distro-independent

Summary by CodeRabbit

  • Tests
    • Improved boot time detection method in reboot tests for enhanced reliability.

The --since arg for uptime is not part of the basic package
shipped with SLES releases. This caused the test to fail silently.
This change uses /proc/stat to get boot time which will be present
in every linux distro, thus making the test distro-independent
@coderabbitai

coderabbitai Bot commented Jun 22, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e4b27b47-e3ad-48a2-9501-30d67d2f6eb1

📥 Commits

Reviewing files that changed from the base of the PR and between c96ab65 and e0be62b.

📒 Files selected for processing (1)
  • libvirt/tests/src/virsh_cmd/domain/virsh_reboot.py

Walkthrough

In virsh_reboot.py, the nested get_boot_time() helper replaces the uptime --since command with a /proc/stat-based pipeline (grep btime /proc/stat | awk ...) to retrieve the guest boot timestamp. The parsed value is assigned to boot_time. All other reboot flow logic, polling, exception handling, and result verification remain unchanged.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: modifying the boot time fetching function from using uptime --since to parsing /proc/stat.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@aniket-sahu-ibmx

Copy link
Copy Markdown
Author

Before:

08:22:57 INFO : Running: /usr/local/bin/avocado run --vt-type libvirt --vt-config /home/stuff/tests/data/avocado-vt/backends/libvirt/cfg/backuprestore.cfg --force-job-id 4b0f7b7a93c2a59a2d5c34c56c9d17bbef45595a --job-results-dir /home/stuff/tests/results --vt-only-filter "virtio_scsi virtio_net qcow2 SLES.16.1.ppc64le"
/usr/local/lib/python3.13/site-packages/avocado/core/init.py:18: UserWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources package is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81.
import pkg_resources
No python imaging library installed. Screendump and Windows guest BSOD detection are disabled. In order to enable it, please install python-imaging or the equivalent for your distro.
No python imaging library installed. PPM image conversion to JPEG disabled. In order to enable it, please install python-imaging or the equivalent for your distro.
No python imaging library installed. Screendump and Windows guest BSOD detection are disabled. In order to enable it, please install python-imaging or the equivalent for your distro.
No python imaging library installed. PPM image conversion to JPEG disabled. In order to enable it, please install python-imaging or the equivalent for your distro.
JOB ID : 4b0f7b7a93c2a59a2d5c34c56c9d17bbef45595a
JOB LOG : /home/stuff/tests/results/job-2026-06-22T08.22-4b0f7b7/job.log
(1/1) type_specific.io-github-autotest-libvirt.virsh.reboot.normal_test.id_option.no_mode: STARTED
(1/1) type_specific.io-github-autotest-libvirt.virsh.reboot.normal_test.id_option.no_mode: FAIL: Cmd error: Error status: running (booted)\n\n (95.38 s)

RESULTS : PASS 0 | ERROR 0 | FAIL 1 | SKIP 0 | WARN 0 | INTERRUPT 0 | CANCEL 0
JOB HTML : /home/stuff/tests/results/job-2026-06-22T08.22-4b0f7b7/results.html
JOB TIME : 236.22 s

After:
09:32:56 INFO : Running: /usr/local/bin/avocado run --vt-type libvirt --vt-config /home/stuff/tests/data/avocado-vt/backends/libvirt/cfg/backuprestore.cfg --force-job-id 091408353f77c85082e9a4bd4043058564e1cacb --job-results-dir /home/stuff/tests/results --vt-only-filter "virtio_scsi virtio_net qcow2 SLES.16.1.ppc64le"
/usr/local/lib/python3.13/site-packages/avocado/core/init.py:18: UserWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources package is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81.
import pkg_resources
No python imaging library installed. Screendump and Windows guest BSOD detection are disabled. In order to enable it, please install python-imaging or the equivalent for your distro.
No python imaging library installed. PPM image conversion to JPEG disabled. In order to enable it, please install python-imaging or the equivalent for your distro.
No python imaging library installed. Screendump and Windows guest BSOD detection are disabled. In order to enable it, please install python-imaging or the equivalent for your distro.
No python imaging library installed. PPM image conversion to JPEG disabled. In order to enable it, please install python-imaging or the equivalent for your distro.
JOB ID : 091408353f77c85082e9a4bd4043058564e1cacb
JOB LOG : /home/stuff/tests/results/job-2026-06-22T09.32-0914083/job.log
(1/1) type_specific.io-github-autotest-libvirt.virsh.reboot.normal_test.id_option.no_mode: STARTED
(1/1) type_specific.io-github-autotest-libvirt.virsh.reboot.normal_test.id_option.no_mode: PASS (57.32 s)
RESULTS : PASS 1 | ERROR 0 | FAIL 0 | SKIP 0 | WARN 0 | INTERRUPT 0 | CANCEL 0
JOB HTML : /home/stuff/tests/results/job-2026-06-22T09.32-0914083/results.html
JOB TIME : 60.47 s

@hholoubk

Copy link
Copy Markdown
Contributor

The code itself is ok ad make sense. even improving functionality as the returned comparision is beteween timestamp not the datetime string

but when introducing new code it will be better to refactor this 7y old approach.

it would be possible to remove the get_boot_time and reuse vm.uptime() instead.
only please be aware, that the vm.uptime() is returning seconds from boot, so the comparision is vice versa ...
second_boot < first_boot

(and probably would be good to rename in such case variables to [second | first] _uptime

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