From 8fa7e1f9d8209e8cdc447e81e1f2c20129c4a2df Mon Sep 17 00:00:00 2001 From: Julia Kreger Date: Thu, 24 Mar 2022 10:32:40 -0700 Subject: [PATCH] Handle any error from libvirt operations A review of the helper code which wraps libvirtmod's compiled module which implements the libvirt wrapper for Python, which we refer to and call as libvirt or python-libvirt, reveals that it appears possible for AttributeError and KeyError to be raised up to the intermediate library level. While everything else refers to libvirtError, it still seems possible, albeit remote, that the generated code and interactions may still raise exceptions besides libvirtError which previously would result in unexpected behavior. What we sometimes see on the ipmitool side is a generic "Error: Unable to establish IPMI v2 / RMCP+ session" error which is generated in many cases, including when no response is received. So, since libvirtError is based on an Exception class, changes exception handling to just catch and log based upon Exception. Change-Id: I8159f5d1de2acb0678e7c85306413fab6999e615 --- virtualbmc/vbmc.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/virtualbmc/vbmc.py b/virtualbmc/vbmc.py index 5e15192..3dd49b0 100644 --- a/virtualbmc/vbmc.py +++ b/virtualbmc/vbmc.py @@ -115,7 +115,7 @@ class VirtualBMC(bmc.Bmc): boot_element.set('dev', device) conn.defineXML(ET.tostring(tree, encoding="unicode")) - except libvirt.libvirtError: + except Exception: LOG.error('Failed setting the boot device %(bootdev)s for ' 'domain %(domain)s', {'bootdev': device, 'domain': self.domain_name}) @@ -130,7 +130,7 @@ class VirtualBMC(bmc.Bmc): domain = utils.get_libvirt_domain(conn, self.domain_name) if domain.isActive(): return POWERON - except libvirt.libvirtError as e: + except Exception as e: msg = ('Error getting the power state of domain %(domain)s. ' 'Error: %(error)s' % {'domain': self.domain_name, 'error': e}) @@ -147,7 +147,7 @@ class VirtualBMC(bmc.Bmc): domain = utils.get_libvirt_domain(conn, self.domain_name) if domain.isActive(): domain.injectNMI() - except libvirt.libvirtError as e: + except Exception as e: LOG.error('Error powering diag the domain %(domain)s. ' 'Error: %(error)s', {'domain': self.domain_name, 'error': e}) @@ -162,7 +162,7 @@ class VirtualBMC(bmc.Bmc): domain = utils.get_libvirt_domain(conn, self.domain_name) if domain.isActive(): domain.destroy() - except libvirt.libvirtError as e: + except Exception as e: LOG.error('Error powering off the domain %(domain)s. ' 'Error: %(error)s', {'domain': self.domain_name, 'error': e}) @@ -177,7 +177,7 @@ class VirtualBMC(bmc.Bmc): domain = utils.get_libvirt_domain(conn, self.domain_name) if not domain.isActive(): domain.create() - except libvirt.libvirtError as e: + except Exception as e: LOG.error('Error powering on the domain %(domain)s. ' 'Error: %(error)s', {'domain': self.domain_name, 'error': e}) @@ -192,7 +192,7 @@ class VirtualBMC(bmc.Bmc): domain = utils.get_libvirt_domain(conn, self.domain_name) if domain.isActive(): domain.shutdown() - except libvirt.libvirtError as e: + except Exception as e: LOG.error('Error soft powering off the domain %(domain)s. ' 'Error: %(error)s', {'domain': self.domain_name, 'error': e}) @@ -207,7 +207,7 @@ class VirtualBMC(bmc.Bmc): domain = utils.get_libvirt_domain(conn, self.domain_name) if domain.isActive(): domain.reset() - except libvirt.libvirtError as e: + except Exception as e: LOG.error('Error reseting the domain %(domain)s. ' 'Error: %(error)s', {'domain': self.domain_name, 'error': e})