vagrant-libvirt icon indicating copy to clipboard operation
vagrant-libvirt copied to clipboard

VM action fails if vm is in "pmsuspended" state

Open abbbi opened this issue 4 years ago • 4 comments

In case a virtual machine goes in to "pmsuspended" state, and is shown in virsh like:

  Id    Name                              State
------------------------------------------------------
 36    HPnxl_foobar              pmsuspended

(pmsuspended. The domain has been suspended by guest power management) Im not sure how the VM ended up in this state, probably due to high workload on HV, it should however be possible to destroy it.

Destroying the virtual machine will cause traceback ( or any other action attempted ):

vagrant destroy -f

Traceback (most recent call last):
        14: from /opt/vagrant/embedded/gems/2.2.9/gems/vagrant-2.2.9/bin/vagrant:205:in `<main>'
        13: from /opt/vagrant/embedded/gems/2.2.9/gems/vagrant-2.2.9/lib/vagrant/environment.rb:290:in `cli'
        12: from /opt/vagrant/embedded/gems/2.2.9/gems/vagrant-2.2.9/lib/vagrant/cli.rb:67:in `execute'
        11: from /opt/vagrant/embedded/gems/2.2.9/gems/vagrant-2.2.9/plugins/commands/halt/command.rb:30:in `execute'
        10: from /opt/vagrant/embedded/gems/2.2.9/gems/vagrant-2.2.9/lib/vagrant/plugin/v2/command.rb:212:in `with_target_vms'
         9: from /opt/vagrant/embedded/gems/2.2.9/gems/vagrant-2.2.9/lib/vagrant/plugin/v2/command.rb:212:in `map'
         8: from /opt/vagrant/embedded/gems/2.2.9/gems/vagrant-2.2.9/lib/vagrant/plugin/v2/command.rb:213:in `block in with_target_vms'
         7: from /opt/vagrant/embedded/gems/2.2.9/gems/vagrant-2.2.9/lib/vagrant/plugin/v2/command.rb:180:in `block in with_target_vms'
         6: from /opt/vagrant/embedded/gems/2.2.9/gems/vagrant-2.2.9/lib/vagrant/environment.rb:715:in `machine'
         5: from /opt/vagrant/embedded/gems/2.2.9/gems/vagrant-2.2.9/lib/vagrant/vagrantfile.rb:81:in `machine'
         4: from /opt/vagrant/embedded/gems/2.2.9/gems/vagrant-2.2.9/lib/vagrant/vagrantfile.rb:81:in `new'
         3: from /opt/vagrant/embedded/gems/2.2.9/gems/vagrant-2.2.9/lib/vagrant/machine.rb:151:in `initialize'
         2: from /opt/vagrant/embedded/gems/2.2.9/gems/vagrant-2.2.9/lib/vagrant/machine.rb:535:in `state'
         1: from /home/vagrant/.vagrant.d/gems/2.6.6/gems/vagrant-libvirt-0.3.0/lib/vagrant-libvirt/provider.rb:103:in `state'
/home/vagrant/.vagrant.d/gems/2.6.6/gems/vagrant-libvirt-0.3.0/lib/vagrant-libvirt/driver.rb:141:in `state': undefined method `to_sym' for nil:NilClass (NoMethodError)

abbbi avatar Jan 12 '21 14:01 abbbi

@abbbi are you able to reproduce this? I'm wondering if you can capture what the contents of domain are at this point.

The lines in question are: https://github.com/vagrant-libvirt/vagrant-libvirt/blob/1fe5a80516fb940b4232ce4ab8baaf3b98037dc5/lib/vagrant-libvirt/driver.rb#L125-L127

So for some reason when reporting this state domain.state is nil, which is a bit weird, and also incorrect, as virsh was able to determine a state so we should have some way that we can establish what the correct state is here and then perform conversion to a suitable symbol.

electrofelix avatar May 20 '21 13:05 electrofelix

Actually just found how I can do this via virsh so should be possible to replicate and determine what it means.

electrofelix avatar May 20 '21 15:05 electrofelix

Vagrantfile

# -*- mode: ruby -*-
# vi: set ft=ruby :


Vagrant.configure("2") do |config|
  config.vm.box = "alvistack/ubuntu-21.04"
end

steps to replicate (I did the package install and run through the console but should work this way as well):

vagrant up --provider libvirt
vagrant ssh -c "sudo apt-get update && apt-get install pm-utils"
# may need to reboot at this point to fully enable, as I did while experimenting
vagrant ssh -c "sudo pm-suspend"
vagrant status
# error occurs

It looks like the source of the error is that fog-libvirt isn't parsing the pmsuspended state.

https://github.com/fog/fog-libvirt/blob/master/lib/fog/libvirt/requests/compute/list_domains.rb#L68-L70 is missing it, resulting in nil getting returned for the state instead.

electrofelix avatar May 20 '21 15:05 electrofelix

systemctl suspend

does the job too, nowadays :)

abbbi avatar Aug 05 '21 20:08 abbbi

fog-libvirt release 0.10 resolves this, though we are missing a translation for the state.

electrofelix avatar Dec 02 '22 14:12 electrofelix