コード例 #1
0
    def create_segment(self, context, segment_data):
        """Create segment"""
        segment = objects.FailoverSegment(context=context)
        # Populate segment object for create
        segment.name = segment_data.get('name')
        segment.description = segment_data.get('description')
        segment.recovery_method = segment_data.get('recovery_method')
        segment.service_type = segment_data.get('service_type')
        segment.enabled = strutils.bool_from_string(segment_data.get(
            'enabled', True),
                                                    strict=True)

        try:
            segment.create()
        except Exception as e:
            with excutils.save_and_reraise_exception():
                tb = traceback.format_exc()
                api_utils.notify_about_segment_api(
                    context,
                    segment,
                    action=fields.EventNotificationAction.SEGMENT_CREATE,
                    phase=fields.EventNotificationPhase.ERROR,
                    exception=e,
                    tb=tb)
        return segment
コード例 #2
0
ファイル: fakes.py プロジェクト: ynwssjx/masakari
def create_fake_failover_segment(name='fake_segment', id=1, description=None,
                                 service_type='COMPUTE',
                                 recovery_method="auto",
                                 uuid=uuidsentinel.fake_segment):
    return objects.FailoverSegment(
        name=name, id=id, description=description, service_type=service_type,
        recovery_method=recovery_method, uuid=uuid)
コード例 #3
0
    def create_segment(self, context, segment_data):
        """Create segment"""
        segment = objects.FailoverSegment(context=context)
        # Populate segment object for create
        segment.name = segment_data.get('name')
        segment.description = segment_data.get('description')
        segment.recovery_method = segment_data.get('recovery_method')
        segment.service_type = segment_data.get('service_type')

        segment.create()

        return segment
コード例 #4
0
ファイル: host.py プロジェクト: iorchard/okidoki
    def _from_db_object(context, host, db_host):

        for key in host.fields:
            db_value = db_host.get(key)
            if key == "failover_segment":
                db_value = objects.FailoverSegment._from_db_object(
                    host._context, objects.FailoverSegment(), db_value)

            setattr(host, key, db_value)

        host.obj_reset_changes()
        host._context = context
        return host
コード例 #5
0
    def test_notify_about_segment_api(
        self, mock_from_exception, mock_SegmentApiPayload,
        mock_SegmentApiNotification, mock_NotificationPublisher,
        mock_EventType):
        mock_fault = mock.Mock()
        mock_from_exception.return_value = mock_fault
        mock_payload = mock.Mock()
        mock_SegmentApiPayload.return_value = mock_payload
        mock_api_notification = mock.Mock()
        mock_SegmentApiNotification.return_value = mock_api_notification
        mock_api_notification.emit.return_value = None
        mock_publisher = mock.Mock()
        mock_NotificationPublisher.return_value = mock_publisher
        mock_event_type = mock.Mock()
        mock_EventType.return_value = mock_event_type

        mock_context = mock.Mock()
        segment = objects.FailoverSegment()
        action = fields.EventNotificationAction.SEGMENT_CREATE
        phase = fields.EventNotificationPhase.ERROR
        e = Exception()

        api_utils.notify_about_segment_api(mock_context, segment,
            action=action, phase=phase, exception=e)

        mock_from_exception.assert_called_once_with(e, None)
        mock_SegmentApiPayload.assert_called_once_with(
            segment=segment, fault=mock_fault)
        mock_SegmentApiNotification.assert_called_once_with(
            context=mock_context,
            priority=fields.EventNotificationPriority.ERROR,
            publisher=mock_publisher,
            event_type=mock_event_type,
            payload=mock_payload)
        mock_NotificationPublisher.assert_called_once_with(
            context=mock_context, host=socket.gethostname(),
            binary='masakari-api')
        mock_EventType.assert_called_once_with(
            action=action, phase=phase)
        mock_api_notification.emit.assert_called_once_with(mock_context)