From 4a97c51329291c218bf713f758cc9fffaf0b9945 Mon Sep 17 00:00:00 2001 From: Daniel Clavijo Coca Date: Thu, 21 Feb 2019 01:48:17 -0600 Subject: [PATCH] F #1684: Fix shutdown timeout handling (#2975) --- src/vmm_mad/remotes/lib/lxd/container.rb | 5 ----- src/vmm_mad/remotes/lxd/shutdown | 25 ++++++++++++++++++------ 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/vmm_mad/remotes/lib/lxd/container.rb b/src/vmm_mad/remotes/lib/lxd/container.rb index 537b9d79b6..9e569c3706 100644 --- a/src/vmm_mad/remotes/lib/lxd/container.rb +++ b/src/vmm_mad/remotes/lib/lxd/container.rb @@ -185,11 +185,6 @@ class Container def stop(options = { :timeout => 120 }) change_state(__method__, options) - rescue StandardError => exception - raise exception unless exception.class == Net::ReadTimeout - - OpenNebula.log_error "Timeout detected\n#{exception}\nForcing shutdown" - stop(:force => true) end def restart(options = {}) diff --git a/src/vmm_mad/remotes/lxd/shutdown b/src/vmm_mad/remotes/lxd/shutdown index f42321ce0d..f9212e05e8 100755 --- a/src/vmm_mad/remotes/lxd/shutdown +++ b/src/vmm_mad/remotes/lxd/shutdown @@ -36,15 +36,28 @@ container = Container.get(vm_name, xml, client) # ------------------------------------------------------------------------------ # Stop the container & unmap devices if not a wild container # ------------------------------------------------------------------------------ -if ARGV[-1] == '-f' - container.stop(:force => true) -else - container.stop +begin + if ARGV[-1] == '-f' + container.stop(:force => true) + else + container.stop + end +rescue => exception + OpenNebula.log_error exception end if !container.wild? - unmapped = container.setup_storage('unmap') - raise 'Failed to dismantle container storage' unless unmapped + # This call may return an operation output instead of a container data + # in case of timeout. The call breaks the container attributes + # it needs to be read again + + container = Container.get(vm_name, xml, client) # :status => "Sucess" + container = Container.get(vm_name, xml, client) unless %w[Running Stopped].include? container.status + + container.stop(:force => true) if container.status == 'Running' + + e = 'Failed to dismantle container storage' + raise "#{e}\n#{container}" unless container.setup_storage('unmap') container.delete end