Bug 1818089

Summary: virt-install: don't perform post-install VM boot if user 'virsh destroy'd the VM
Product: [Community] Virtualization Tools Reporter: Katerina Koukiou <kkoukiou>
Component: virt-managerAssignee: Cole Robinson <crobinso>
Status: CLOSED NEXTRELEASE QA Contact:
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: unspecifiedCC: berrange, crobinso, gscrivan, juzhou, philip.wyett
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2020-09-11 13:38:54 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Katerina Koukiou 2020-03-27 16:16:08 UTC
Description of problem:

In cockpit we are installing VMs with virt-install and use `--wait -1` option.

If a user tries to `Shut Down` the VM from outside (virsh destroy $VM_NAME) while the installation is running then virt-install restarts the VM and the VM appears running again.
z

Version-Release number of selected component (if applicable):
2.2.1

How reproducible:
Always

Steps to Reproduce:
1: sudo virt-install \
        --connect qemu:///system \
        --name VmTestRestart \
        --wait -1 --noautoconsole \
        --memory memory=300,maxmemory=400 --disk none \
        --cdrom ./Fedora-Server-netinst-x86_64-31-1.9.iso  

WARNING  Requested memory 300 MiB is less than the recommended 1024 MiB for OS fedora31

Starting install...
Domain installation still in progress.
Waiting for installation to complete.
^C



Domain has shutdown. Continuing.
Domain creation completed.
Restarting guest.

Actual results:

While the installation is going on shut off the VM, with `virsh destroy VmTestRestart` and note that virt-install is restarting the guest.

Expected results:

When DESTROY signal was received virt-install should not try to restart the guest.

In other words virt-install should start listening to signals, as well as waiting for the console to exit, so it can judge if the guest requires a restart.

Comment 1 Cole Robinson 2020-03-27 18:47:22 UTC
Thanks for the report. We have similar behavior in virt-manager for when user invokes destroy from there. Wiring up in virt-install is a good thing to do but will definitely take a bit of work to teach virt-install about the event loop, but it's useful to do that anyways. A simpler solution could be to check the VM shutdown reason after noticing the state change, and if it was a user invoked destroy (probably anything besides a graceful VM shutdown) then don't do the reboot.

Comment 2 Cole Robinson 2020-09-11 13:38:54 UTC
Upstream now:

commit 26e6d3b76cebf1902d8c0a9f1568835b4e4f53c6
Author: Cole Robinson <crobinso>
Date:   Fri Sep 11 08:57:08 2020 -0400

    virt-install: Don't reboot VM is user manually stopped it