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
This commit is contained in:
Julia Kreger 2022-03-24 10:32:40 -07:00 committed by Dmitry Tantsur
parent c1b75e0a25
commit 8fa7e1f9d8
No known key found for this signature in database
GPG Key ID: 315B2AF9FD216C60
1 changed files with 7 additions and 7 deletions

View File

@ -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})