def execute_host_failure(self, context, host_name, recovery_method, notification_uuid, reserved_host_list=None): novaclient = nova.API() # get flow for host failure process_what = { 'context': context, 'host_name': host_name } try: if recovery_method == fields.FailoverSegmentRecoveryMethod.AUTO: self._execute_auto_workflow(novaclient, process_what) elif recovery_method == ( fields.FailoverSegmentRecoveryMethod.RESERVED_HOST): self._execute_rh_workflow(novaclient, process_what, reserved_host_list) elif recovery_method == ( fields.FailoverSegmentRecoveryMethod.AUTO_PRIORITY): self._execute_auto_priority_workflow(novaclient, process_what, reserved_host_list) else: self._execute_rh_priority_workflow(novaclient, process_what, reserved_host_list) except Exception as exc: with excutils.save_and_reraise_exception(reraise=False) as ctxt: if isinstance(exc, (exception.SkipHostRecoveryException, exception.HostRecoveryFailureException, exception.ReservedHostsUnavailable)): ctxt.reraise = True return msg = _("Failed to execute host failure flow for " "notification '%s'.") % notification_uuid raise exception.MasakariException(msg)
def execute_process_failure(self, context, process_name, host_name, notification_uuid): novaclient = nova.API() # get flow for process failure process_what = { 'context': context, 'process_name': process_name, 'host_name': host_name } # TODO(abhishekk) We need to create a map for process_name and # respective python-client so that we can pass appropriate client # as a input to the process. if process_name == "nova-compute": recovery_flow = process_failure.get_compute_process_recovery_flow else: LOG.warning("Skipping recovery for process: %s.", process_name) raise exception.SkipProcessRecoveryException() try: flow_engine = recovery_flow(novaclient, process_what) except Exception: msg = (_('Failed to create process failure flow.'), notification_uuid) LOG.exception(msg) raise exception.MasakariException(msg) # Attaching this listener will capture all of the notifications that # taskflow sends out and redirect them to a more useful log for # masakari's debugging (or error reporting) usage. with base.DynamicLogListener(flow_engine, logger=LOG): flow_engine.run()
def register_extension(self, ext): if not self._check_extension(ext): return False alias = ext.alias if alias in self.extensions: raise exception.MasakariException( "Found duplicate extension: %s" % alias) self.extensions[alias] = ext return True
def register(self, ext): # Do nothing if the extension doesn't check out if not self._check_extension(ext): return alias = ext.alias if alias in self.extensions: raise exception.MasakariException("Found duplicate extension: %s" % alias) self.extensions[alias] = ext self.sorted_ext_list = None
def get_notification_recovery_workflow_details(self, context, notification): """Retrieve recovery workflow details of the notification""" try: host_obj = objects.Host.get_by_uuid(context, notification.source_host_uuid) recovery_method = host_obj.failover_segment.recovery_method progress_details = ( self.driver.get_notification_recovery_workflow_details( context, recovery_method, notification)) notification['recovery_workflow_details'] = progress_details except Exception: msg = (_('Failed to fetch notification recovery workflow details ' 'for %s') % notification.notification_uuid) LOG.exception(msg) raise exception.MasakariException(msg) return notification
def wrapper(self, ctx, *args, **kwargs): try: res = method(self, ctx, *args, **kwargs) except (request_exceptions.Timeout, nova_exception.CommandError, keystone_exception.ConnectionError) as exc: err_msg = encodeutils.exception_to_unicode(exc) _reraise(exception.MasakariException(reason=err_msg)) except (keystone_exception.BadRequest, nova_exception.BadRequest) as exc: err_msg = encodeutils.exception_to_unicode(exc) _reraise(exception.InvalidInput(reason=err_msg)) except (keystone_exception.Forbidden, nova_exception.Forbidden) as exc: err_msg = encodeutils.exception_to_unicode(exc) _reraise(exception.Forbidden(err_msg)) except (nova_exception.NotFound) as exc: err_msg = encodeutils.exception_to_unicode(exc) _reraise(exception.NotFound(reason=err_msg)) except nova_exception.Conflict as exc: err_msg = encodeutils.exception_to_unicode(exc) _reraise(exception.Conflict(reason=err_msg)) return res
def execute_instance_failure(self, context, instance_uuid, notification_uuid): novaclient = nova.API() # get flow for instance failure process_what = { 'context': context, 'instance_uuid': instance_uuid } try: flow_engine = instance_failure.get_instance_recovery_flow( novaclient, process_what) except Exception: msg = (_('Failed to create instance failure flow.'), notification_uuid) LOG.exception(msg) raise exception.MasakariException(msg) # Attaching this listener will capture all of the notifications that # taskflow sends out and redirect them to a more useful log for # masakari's debugging (or error reporting) usage. with base.DynamicLogListener(flow_engine, logger=LOG): flow_engine.run()
def test_error_msg(self): self.assertEqual('test', str(exception.MasakariException('test')))
def test_error_msg(self): self.assertEqual('test', six.text_type(exception.MasakariException('test')))