>From ec18386d78940cb7255269a6ef9f99c266f4b4c3 Mon Sep 17 00:00:00 2001 From: Chris Lalancette Date: Tue, 9 Aug 2011 09:58:56 -0400 Subject: [PATCH oz] Ignore destroy failures if the domain went away. There is a race inherent in shutdown_guest, in that between the time that wait_for_guest_shutdown failed, and the time that we go to destroy the domain, the domain may have already gone away. Handle that race here by only raising an error if the domain is still there if libvirt_dom.destroy fails. Signed-off-by: Chris Lalancette --- oz/OpenSUSE.py | 13 ++++++++++++- oz/RedHat.py | 13 ++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/oz/OpenSUSE.py b/oz/OpenSUSE.py index ab8c209..cebd9fd 100644 --- a/oz/OpenSUSE.py +++ b/oz/OpenSUSE.py @@ -22,6 +22,7 @@ import re import shutil import os import libxml2 +import libvirt import oz.Guest import oz.ozutil @@ -130,7 +131,17 @@ class OpenSUSEGuest(oz.Guest.CDGuest): self.log.warn("Failed shutting down guest, forcibly killing") if libvirt_dom is not None: - libvirt_dom.destroy() + try: + libvirt_dom.destroy() + except libvirt.libvirtError: + # the destroy failed for some reason. This can happen if + # _wait_for_guest_shutdown times out, but the domain shuts + # down before we get to destroy. Check to make sure that the + # domain is gone from the list of running domains; if so, just + # continue on; if not, re-raise the error. + for domid in self.libvirt_conn.listDomainsID(): + if domid == libvirt_dom.ID(): + raise def guest_execute_command(self, guestaddr, command, timeout=10): """ diff --git a/oz/RedHat.py b/oz/RedHat.py index e5e17e7..ef2a873 100644 --- a/oz/RedHat.py +++ b/oz/RedHat.py @@ -22,6 +22,7 @@ import re import os import shutil import urllib2 +import libvirt import oz.Guest import oz.ozutil @@ -494,7 +495,17 @@ Subsystem sftp /usr/libexec/openssh/sftp-server self.log.warn("Failed shutting down guest, forcibly killing") if libvirt_dom is not None: - libvirt_dom.destroy() + try: + libvirt_dom.destroy() + except libvirt.libvirtError: + # the destroy failed for some reason. This can happen if + # _wait_for_guest_shutdown times out, but the domain shuts + # down before we get to destroy. Check to make sure that the + # domain is gone from the list of running domains; if so, just + # continue on; if not, re-raise the error. + for domid in self.libvirt_conn.listDomainsID(): + if domid == libvirt_dom.ID(): + raise def generate_install_media(self, force_download=False): """ -- 1.7.4.4