def _capsule_cleanup(self): """make the necessary cleanup in case of a crash""" if self._subscribed: # use try except to unregister the host, in case of host not # reachable (or any other failure), the capsule is not deleted and # this failure will hide any prior failure. try: self.unregister() except Exception as exp: logger.error('Failed to unregister the host: {0}\n{1}'.format( self.hostname, exp.message)) if self._capsule_hostname: # do cleanup as using a static hostname that can be reused by # other tests and organizations try: # try to delete the hostname first Host.delete({'name': self._capsule_hostname}) # try delete the capsule # note: if the host was not registered the capsule does not # exist yet Capsule.delete({'name': self._capsule_hostname}) except Exception as exp: # do nothing, only log the exception # as maybe that the host was not registered or setup does not # reach that stage # or maybe that the capsule was not registered or setup does # not reach that stage logger.error('Failed to cleanup the host: {0}\n{1}'.format( self.hostname, exp.message))
def _capsule_cleanup(self): """make the necessary cleanup in case of a crash""" if self._subscribed: # use try except to unregister the host, in case of host not # reachable (or any other failure), the capsule is not deleted and # this failure will hide any prior failure. try: self.unregister() except Exception as exp: logger.error('Failed to unregister the host: {0}\n{1}'.format( self.hostname, exp)) if self._capsule_hostname: # do cleanup as using a static hostname that can be reused by # other tests and organizations try: # try to delete the hostname first Host.delete({'name': self._capsule_hostname}) # try delete the capsule except Exception as exp: # log the exception # as maybe that the host was not registered or setup does not # reach that stage # or maybe that the capsule was not registered or setup does # not reach that stage # Destroys the Capsule VM on the provisioning server if # exception has 'return_code=70(Error: host not found)' if exp.return_code == 70: super(CapsuleVirtualMachine, self).destroy() if is_open('BZ:1622064'): logger.warn('Failed to cleanup the host: {0}\n{1}'.format( self.hostname, exp)) else: logger.error('Failed to cleanup the host: {0}\n{1}'.format( self.hostname, exp)) raise try: # try to delete the capsule if it was added already Capsule.delete({'name': self._capsule_hostname}) except Exception as exp: logger.error('Failed to cleanup the capsule: {0}\n{1}'.format( self.hostname, exp)) raise