示例#1
0
    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)
示例#2
0
    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()
示例#3
0
 def setUp(self):
     super(ProcessFailureTestCase, self).setUp()
     self.ctxt = context.get_admin_context()
     self.process_name = "nova-compute"
     self.service_host = "fake-host"
     self.novaclient = nova.API()
     self.fake_client = fakes.FakeNovaClient()
     # overriding 'wait_period_after_service_update' to 2 seconds
     # to reduce the wait period.
     self.override_config('wait_period_after_service_update', 2)
 def setUp(self):
     super(HostFailureTestCase, self).setUp()
     self.ctxt = context.get_admin_context()
     # overriding 'wait_period_after_evacuation' and
     # 'wait_period_after_service_update' to 2 seconds to
     # reduce the wait period.
     self.override_config("wait_period_after_evacuation", 2)
     self.override_config("wait_period_after_service_update", 2)
     self.override_config("evacuate_all_instances", False, "host_failure")
     self.instance_host = "fake-host"
     self.novaclient = nova.API()
     self.fake_client = fakes.FakeNovaClient()
示例#5
0
 def setUp(self):
     super(InstanceFailureTestCase, self).setUp()
     self.ctxt = context.get_admin_context()
     self.novaclient = nova.API()
     self.fake_client = fakes.FakeNovaClient()
     self.instance_id = "1"
     # overriding 'wait_period_after_power_off' and
     # 'wait_period_after_power_on' to 2 seconds to
     # reduce the wait period.
     self.override_config('wait_period_after_power_off', 2)
     self.override_config('wait_period_after_power_on', 2)
     self.override_config("process_all_instances",
                          False, "instance_failure")
示例#6
0
    def _get_taskflow_sequence(self, context, recovery_method, notification):
        # Get the taskflow sequence based on the recovery method.

        novaclient = nova.API()
        task_list = []

        # Get linear task flow based on notification type
        if notification.type == fields.NotificationType.VM:
            tasks = TASKFLOW_CONF.instance_failure_recovery_tasks
        elif notification.type == fields.NotificationType.PROCESS:
            tasks = TASKFLOW_CONF.process_failure_recovery_tasks
        elif notification.type == fields.NotificationType.COMPUTE_HOST:
            if recovery_method in [
                    fields.FailoverSegmentRecoveryMethod.AUTO,
                    fields.FailoverSegmentRecoveryMethod.AUTO_PRIORITY
            ]:
                tasks = TASKFLOW_CONF.host_auto_failure_recovery_tasks
            elif recovery_method in [
                    fields.FailoverSegmentRecoveryMethod.RESERVED_HOST,
                    fields.FailoverSegmentRecoveryMethod.RH_PRIORITY
            ]:
                tasks = TASKFLOW_CONF.host_rh_failure_recovery_tasks

        for plugin in base.get_recovery_flow(tasks['pre'],
                                             context=context,
                                             novaclient=novaclient,
                                             update_host_method=None):
            task_list.append(plugin.name)

        for plugin in base.get_recovery_flow(tasks['main'],
                                             context=context,
                                             novaclient=novaclient,
                                             update_host_method=None):
            task_list.append(plugin.name)

        for plugin in base.get_recovery_flow(tasks['post'],
                                             context=context,
                                             novaclient=novaclient,
                                             update_host_method=None):
            task_list.append(plugin.name)

        return task_list
示例#7
0
    def create_host(self, context, segment_uuid, host_data):
        """Create host"""
        segment = objects.FailoverSegment.get_by_uuid(context, segment_uuid)
        host = objects.Host(context=context)

        # Populate host object for create
        host.name = host_data.get('name')
        host.failover_segment_id = segment.uuid
        host.type = host_data.get('type')
        host.control_attributes = host_data.get('control_attributes')
        host.on_maintenance = strutils.bool_from_string(host_data.get(
            'on_maintenance', False),
                                                        strict=True)
        host.reserved = strutils.bool_from_string(host_data.get(
            'reserved', False),
                                                  strict=True)

        novaclient = nova.API()
        novaclient.hypervisor_search(context, host.name)
        host.create()
        return host
示例#8
0
    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()
示例#9
0
 def setUp(self):
     super(NovaApiTestCase, self).setUp()
     self.api = nova.API()
     self.ctx = context.get_admin_context()
示例#10
0
 def _is_valid_host_name(self, context, name):
     novaclient = nova.API()
     novaclient.find_compute_service(context, name)
示例#11
0
 def _is_valid_host_name(self, context, name):
     novaclient = nova.API()
     novaclient.hypervisor_search(context, name)