Пример #1
0
 def event_finish(cls, context, container_uuid, event_name, exc_val=None,
                  exc_tb=None, want_result=None):
     if exc_val:
         exc_val = six.text_type(exc_val)
     if exc_tb and not isinstance(exc_tb, six.string_types):
         exc_tb = ''.join(traceback.format_tb(exc_tb))
     values = cls.pack_action_event_finish(context, container_uuid,
                                           event_name, exc_val=exc_val,
                                           exc_tb=exc_tb)
     db_event = dbapi.action_event_finish(context, values)
     if want_result:
         return cls._from_db_object(context, cls(context), db_event)
Пример #2
0
 def event_finish(cls,
                  context,
                  container_uuid,
                  event_name,
                  exc_val=None,
                  exc_tb=None,
                  want_result=None):
     if exc_val:
         exc_val = six.text_type(exc_val)
     if exc_tb and not isinstance(exc_tb, six.string_types):
         exc_tb = ''.join(traceback.format_tb(exc_tb))
     values = cls.pack_action_event_finish(context,
                                           container_uuid,
                                           event_name,
                                           exc_val=exc_val,
                                           exc_tb=exc_tb)
     db_event = dbapi.action_event_finish(context, values)
     if want_result:
         return cls._from_db_object(context, cls(context), db_event)
Пример #3
0
    def test_container_action_event_finish_success(self):
        """Finish a container action event."""
        uuid = uuidutils.generate_uuid()

        action = dbapi.action_start(self.context,
                                    self._create_action_values(uuid))

        dbapi.action_event_start(self.context, self._create_event_values(uuid))

        event_values = {
            'finish_time': timeutils.utcnow() + datetime.timedelta(seconds=5),
            'result': 'Success'
        }

        event_values = self._create_event_values(uuid, extra=event_values)
        event = dbapi.action_event_finish(self.context, event_values)

        self._assertActionEventSaved(event, action['id'])
        action = dbapi.action_get_by_request_id(self.context, uuid,
                                                self.context.request_id)
        self.assertNotEqual('Error', action['message'])
Пример #4
0
    def test_container_action_event_finish_success(self):
        """Finish a container action event."""
        uuid = uuidutils.generate_uuid()

        action = dbapi.action_start(self.context,
                                    self._create_action_values(uuid))

        dbapi.action_event_start(self.context,
                                 self._create_event_values(uuid))

        event_values = {
            'finish_time': timeutils.utcnow() + timedelta(seconds=5),
            'result': 'Success'
        }

        event_values = self._create_event_values(uuid, extra=event_values)
        event = dbapi.action_event_finish(self.context, event_values)

        self._assertActionEventSaved(event, action['id'])
        action = dbapi.action_get_by_request_id(self.context, uuid,
                                                self.context.request_id)
        self.assertNotEqual('Error', action['message'])
Пример #5
0
    def test_container_action_event_finish_success(
            self, mock_db_inst, mock_get_event_by_name,
            mock__action_get_by_request_id,
            mock_update, mock_write, mock_read):
        """Finish a container action event."""
        mock_db_inst.return_value = etcdapi.get_backend()
        mock_read.side_effect = etcd.EtcdKeyNotFound
        uuid = uuidutils.generate_uuid()

        action = dbapi.action_start(self.context,
                                    self._create_action_values(uuid))

        event_values = self._create_event_values(uuid)
        event_values['action_uuid'] = action['uuid']

        mock__action_get_by_request_id.return_value = action
        mock_read.side_effect = etcd.EtcdKeyNotFound
        event = dbapi.action_event_start(self.context, event_values)

        event_values = {
            'finish_time': timeutils.utcnow() + timedelta(seconds=5),
            'result': 'Success'
        }

        event_values = self._create_event_values(uuid, extra=event_values)

        mock__action_get_by_request_id.return_value = action
        mock_get_event_by_name.return_value = event
        mock_read.side_effect = lambda *args: FakeEtcdResult(event)
        event = dbapi.action_event_finish(self.context, event_values)

        event['start_time'] = datetime.isoformat(event['start_time'])
        mock_read.side_effect = lambda *args: FakeEtcdMultipleResult([event])
        self._assertActionEventSaved(event, action['uuid'])

        mock_read.side_effect = lambda *args: FakeEtcdMultipleResult([action])
        action = dbapi.action_get_by_request_id(self.context, uuid,
                                                self.context.request_id)
        self.assertNotEqual('Error', action['message'])