Bug 1460677

Summary: [RFE] Enable dynamic configuration of powercycle event actions
Product: Red Hat Enterprise Linux 7 Reporter: Martin Betak <mbetak>
Component: libvirtAssignee: Pavel Hrdina <phrdina>
Status: CLOSED ERRATA QA Contact: jiyan <jiyan>
Severity: low Docs Contact:
Priority: low    
Version: 7.5CC: dyuan, lmen, mtessun, phrdina, rbalakri, xuzhang
Target Milestone: rcKeywords: FutureFeature
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: libvirt-3.9.0-1.el7 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2018-04-10 10:48:37 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 Martin Betak 2017-06-12 11:56:22 UTC
Description of problem:

when configuring a VM (before run) currently it is possible to specify the actions to be performed on certain power-cycle related events, e.g:

<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>

It would be nice if this behavior was tweakable also for running VMs. The use case is the following

1) start a VM with <on_reboot>restart</on_reboot>
2) while VM is running, be able to change the behavior to <on_reboot>destroy</on_reboot>
3) when triggered reboot from guest, the VM should correctly shut down instead

Comment 2 Pavel Hrdina 2017-10-19 10:03:05 UTC
Upstream commit:

commit d66fc71d3150cb118ead04a7976d9b67d63b000d
Author: Pavel Hrdina <phrdina>
Date:   Wed Oct 11 16:09:49 2017 +0200

    qemu: implement virDomainSetLifecycleAction() API

Comment 4 jiyan 2017-11-06 07:51:08 UTC
Test env components:
qemu-kvm-rhev-2.10.0-4.el7.x86_64
kernel-3.10.0-768.el7.x86_64
libvirt-3.9.0-1.el7.x86_64

Test scenarios:
Scenario-1: Dynamically configure 'on_reboot' from 'restart' to 'destroy' when the guest is started with not all actions set to "destroy"
Scenario-2: Dynamically configure 'on_poweroff' from 'destroy' to 'restart' when the guest is started with not all actions set to "destroy"
Scenario-3: Try to dynamically configure 'on_poweroff' from 'destroy' to 'restart' when the guest is started with all actions set to "destroy"
Scenario-4: when the guest is started with all actions set to "destroy", try to dynamically configure 'on_reboot' from 'destroy' to 'restart'

Detailed steps for test scenarios:
Scenario-1: Dynamically configure 'on_reboot' from 'restart' to 'destroy' when the guest is started with not all actions set to "destroy"
1. prepare a shutdown vm named 'qcow2' with the following inactive configuration
# virsh domstate qcow2
shut off

# virsh dumpxml qcow2 --inactive |grep on_
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>destroy</on_crash>

# virsh start qcow2
Domain qcow2 started

2. Start 'qcow2' vm, then check status of vm and the related configuration
# virsh domstate qcow2
running

# virsh dumpxml qcow2 |grep on_
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>destroy</on_crash>

3. Dynamically configure 'on_reboot' from 'restart' to 'destroy' for vm and check the related configuration
# virsh set-lifecycle-action qcow2 reboot destroy

# virsh dumpxml qcow2 |grep on_
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>destroy</on_reboot>
  <on_crash>destroy</on_crash>

4. Trigger reboot for vm via virsh command and check the state of vm after 1min (ensure the command takes effect)
# virsh reboot qcow2
Domain qcow2 is being rebooted

# virsh domstate qcow2
shut off

Result: The steps above shows configuration 'on_reboot' from 'restart' to 'destroy' for vm takes effect.



Scenario-2: Dynamically configure 'on_poweroff' from 'destroy' to 'restart' when the guest is started with not all actions set to "destroy"
1. prepare a shutdown vm named 'qcow2' with the following inactive configuration
# virsh domstate qcow2
shut off

# virsh dumpxml qcow2 --inactive |grep on_
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>destroy</on_crash>

2. Start 'qcow2' vm, then check status of vm and the related configuration
# virsh start qcow2
Domain qcow2 started

# virsh domstate qcow2
running

# virsh dumpxml qcow2 |grep on_
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>destroy</on_crash>

3. Dynamically configure 'on_poweroff' from 'destroy' to 'restart' for vm and check the related configuration
# virsh set-lifecycle-action qcow2 poweroff restart

# virsh dumpxml qcow2 |grep on_
  <on_poweroff>restart</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>destroy</on_crash>

4. Trigger shutdown for vm via virsh command and check the state of vm after 1min (ensure the command takes effect)
# virsh shutdown qcow2
Domain qcow2 is being shutdown

# virsh domstate qcow2
running

Result: The steps above shows configuration 'on_poweroff' from 'destroy' to 'restart' for vm takes effect.



Scenario-3: Try to dynamically configure 'on_poweroff' from 'destroy' to 'restart' when the guest is started with all actions set to "destroy"
1. prepare a shutdown vm named 'qcow2' with the following inactive configuration
# virsh domstate qcow2
shut off

# virsh dumpxml qcow2 --inactive |grep on_
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>destroy</on_reboot>
  <on_crash>destroy</on_crash>

2. Start 'qcow2' vm, then check status of vm and the related configuration
# virsh start qcow2
Domain qcow2 started

# virsh domstate qcow2
running

# virsh dumpxml qcow2 |grep on_
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>destroy</on_reboot>
  <on_crash>destroy</on_crash>

3. Try to dynamically configure 'on_poweroff' from 'destroy' to 'restart' 
# virsh set-lifecycle-action qcow2 poweroff restart
error: Unable to change lifecycle action.
error: Operation not supported: cannot update lifecycle action because QEMU was started with -no-reboot option

Result: The limitation that virDomainSetLifecycleAction() API cannot be changed when the guest is started with all actions set to "destroy" we put "-no-reboot" on the QEMU command line. 



Scenario-4: when the guest is started with all actions set to "destroy", try to dynamically configure 'on_reboot' from 'destroy' to 'restart'
1. prepare a shutdown vm named 'qcow2' with the following inactive configuration
# virsh domstate qcow2
shut off

# virsh dumpxml qcow2 --inactive |grep on_
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>destroy</on_reboot>
  <on_crash>destroy</on_crash>

2. Start 'qcow2' vm, then check status of vm and the related configuration
# virsh start qcow2
Domain qcow2 started

# virsh domstate qcow2
running

# virsh dumpxml qcow2 |grep on_
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>destroy</on_reboot>
  <on_crash>destroy</on_crash>

3. Try to dynamically configure 'on_reboot' from 'destroy' to 'restart'
# virsh set-lifecycle-action qcow2 reboot restart
error: Unable to change lifecycle action.
error: Operation not supported: cannot update lifecycle action because QEMU was started with -no-reboot option

Result: The limitation that virDomainSetLifecycleAction() API cannot be changed when the guest is started with all actions set to "destroy" we put "-no-reboot" on the QEMU command line. 

All the results are as expected, move this bug to be verified.

Comment 8 errata-xmlrpc 2018-04-10 10:48:37 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHEA-2018:0704