Skip to content

[KT VM] Make vm boot and check more resilient - #87

Open
PlaidCat wants to merge 1 commit into
mainlinefrom
{jmaple}_fix_vm_monitoring
Open

[KT VM] Make vm boot and check more resilient#87
PlaidCat wants to merge 1 commit into
mainlinefrom
{jmaple}_fix_vm_monitoring

Conversation

@PlaidCat

@PlaidCat PlaidCat commented Aug 26, 2026

Copy link
Copy Markdown
Collaborator

During Content Release lts-9.2 the VM process was more flakey about its state than during the vm testing for previous updates. This adds a little more failure or state oddities so that it responds better.

Coverage Report

Name Stmts Miss Branch BrPart Cover Missing
check_fips_changes.py 42 42 12 0 0% 8-67
check_kernel_commits.py 179 179 76 0 0% 3-371
ciq-cherry-pick.py 194 194 54 0 0% 1-434
ciq-tag.py 146 146 16 0 0% 3-378
ciq_tag.py 232 232 54 0 0% 1-464
jira_pr_check.py 180 180 80 0 0% 3-381
kt/ktlib/ciq_helpers.py 325 269 152 4 14% 31-51, 74-106, 124, 126->129, 129->136, 136->151, 162-172, 179-183, 187, 191-199, 208-209, 213, 217, 225-229, 240-255, 263-266, 277-314, 327-333, 346-347, 351-353, 359, 363-369, 380-382, 390-395, 404-406, 415-420, 431-444, 455-479, 489-503, 513-518, 527, 557-623, 632-642, 646-655, 665-680, 692-709
kt/ktlib/command_runner.py 33 20 6 0 33% 16, 20-33, 37-61, 65-66
kt/ktlib/config.py 59 0 16 0 100%
kt/ktlib/kernel_workspace.py 147 50 28 2 62% 24, 100, 141-143, 148-150, 153-159, 172-183, 194-204, 221-224, 228-263
kt/ktlib/kernels.py 96 13 20 1 86% 77-85, 139, 155-162
kt/ktlib/local.py 5 1 0 0 80% 12
kt/ktlib/repo.py 29 15 2 0 45% 30-31, 34-35, 43-55
kt/ktlib/ssh.py 12 5 2 0 50% 9-12, 16
kt/ktlib/util.py 17 0 0 0 100%
kt/ktlib/virt.py 80 39 10 0 46% 26, 34-37, 51-78, 82-88, 92-93, 97, 101, 105, 109, 119-127, 133-138, 142-147
kt/ktlib/vm.py 313 148 56 3 51% 127-144, 177-186, 194-205, 234-238, 253->264, 281->287, 292-302, 305-306, 319-323, 326, 329-345, 350-367, 370-377, 386-392, 437-448, 451-452, 455, 459-464, 476-489, 502-509, 518, 527-539, 542-549, 552-561, 564
release_config.py 2 2 0 0 0% 7-27
rolling-release-update.py 264 264 106 0 0% 1-412
run_interdiff.py 165 165 56 0 0% 3-244
update_lt_spec.py 219 219 46 0 0% 9-411
TOTAL 2739 2183 792 10 18%

During Content Release lts-9.2 the VM process was more flakey about its
state than during the vm testing for previous updates.  This adds a
little more failure or state oddities so that it responds better.

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.

Pull request overview

Improves robustness of VM boot/cloud-init handling by adding additional wait-and-recover logic when SSH availability is flaky, and extends unit tests to cover reboot/shutoff recovery paths.

Changes:

  • Add VM “start if not running” logic to VmInstance._wait_for_ssh() to better recover when the domain is unexpectedly shut off.
  • Add reboot recovery handling in VmInstance.wait_for_cloud_init() including an explicit reboot wait and conditional VM start.
  • Expand VM-related tests to validate reboot recovery and the new _wait_for_ssh() start/skip-start behaviors.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
kt/ktlib/vm.py Adds resilience logic around SSH polling and cloud-init reboot recovery by conditionally starting the VM.
tests/kt/ktlib/test_vm.py Adds new tests covering reboot recovery and _wait_for_ssh() start behavior under different VM running states.
Suppressed comments (2)

tests/kt/ktlib/test_vm.py:357

  • After removing the start() side_effect above, the test name/docstring should describe what is actually being validated (SSH retry after a transient failure), otherwise it’s misleading for future readers.
def test_wait_for_ssh_start_race_then_retry(mock_ssh_run, mock_sleep, mock_is_running, mock_start):
    """_wait_for_ssh swallows RuntimeError from VmCommand.start (race), retries SSH."""

tests/kt/ktlib/test_vm.py:377

  • This assertion hard-codes "300s" even though the message is derived from Constants. If VM_POLL_MAX_ATTEMPTS / VM_POLL_INTERVAL_SECONDS changes, the test will fail for the wrong reason. Prefer building the expected seconds from Constants (and escape the IP dots since match uses regex).
    with pytest.raises(RuntimeError, match="SSH to testuser@192.168.122.10 not available after 300s"):

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread kt/ktlib/vm.py
Comment on lines +396 to +401
if not VirtHelper.is_running(vm_name=self.name):
try:
VmCommand.start(vm_name=self.name)
except RuntimeError as e:
logging.warning(f"Failed to start VM {self.name}: {e}")
pass
Comment thread tests/kt/ktlib/test_vm.py
mock_start.assert_not_called()


@patch("kt.ktlib.vm.VmCommand.start", side_effect=RuntimeError("Domain is already active"))

@bmastbergen bmastbergen left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🥌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants