def get_by_operation_id(cls, context, operation_id, expected_attrs=[]):
        columns_to_join = [col for col in expected_attrs
                           if col in cls.INSTANCE_OPTIONAL_JOINED_FIELDS]

        db_state = db.scheduled_operation_state_get(
            context, operation_id, columns_to_join)
        if db_state:
            return cls._from_db_object(context, cls(),
                                       db_state, columns_to_join)
Ejemplo n.º 2
0
    def get_by_operation_id(cls, context, operation_id, expected_attrs=[]):
        columns_to_join = [col for col in expected_attrs
                           if col in cls.INSTANCE_OPTIONAL_JOINED_FIELDS]

        db_state = db.scheduled_operation_state_get(
            context, operation_id, columns_to_join)
        if db_state:
            return cls._from_db_object(context, cls(),
                                       db_state, columns_to_join)
Ejemplo n.º 3
0
    def test_scheduled_operation_state_update(self):
        state_ref = self._create_scheduled_operation_state()
        operation_id = state_ref['operation_id']
        state_ref = db.scheduled_operation_state_update(
            self.ctxt, operation_id, {"state": "success"})
        self.assertEqual('success', state_ref['state'])

        state_ref = db.scheduled_operation_state_get(self.ctxt, operation_id)
        self.assertEqual('success', state_ref['state'])

        self.assertRaises(exception.ScheduledOperationStateNotFound,
                          db.scheduled_operation_state_update, self.ctxt,
                          '100', {"state": "success"})
Ejemplo n.º 4
0
    def test_scheduled_operation_state_update(self):
        state_ref = self._create_scheduled_operation_state()
        operation_id = state_ref['operation_id']
        state_ref = db.scheduled_operation_state_update(self.ctxt,
                                                        operation_id,
                                                        {"state": "success"})
        self.assertEqual('success', state_ref['state'])

        state_ref = db.scheduled_operation_state_get(self.ctxt, operation_id)
        self.assertEqual('success', state_ref['state'])

        self.assertRaises(exception.ScheduledOperationStateNotFound,
                          db.scheduled_operation_state_update,
                          self.ctxt, '100', {"state": "success"})
Ejemplo n.º 5
0
    def test_scheduled_operation_state_get_join_operation(self):
        def _create_scheduled_operation():
            values = {
                'id': '0354ca9ddcd046b693340d78759fd274',
                'name': 'protect vm',
                'operation_type': 'protect',
                'user_id': self.ctxt.user_id,
                'project_id': self.ctxt.tenant,
                'trigger_id': '0354ca9ddcd046b693340d78759fd275',
                'operation_definition': '{}'
            }
            return db.scheduled_operation_create(self.ctxt, values)

        operation_ref = _create_scheduled_operation()
        self._create_scheduled_operation_state()
        state_ref = db.scheduled_operation_state_get(self.ctxt,
                                                     operation_ref['id'],
                                                     ['operation'])
        self.assertEqual(operation_ref['id'], state_ref.operation['id'])
Ejemplo n.º 6
0
    def test_scheduled_operation_state_get_join_operation(self):
        def _create_scheduled_operation():
            values = {
                'id': '0354ca9ddcd046b693340d78759fd274',
                'name': 'protect vm',
                'operation_type': 'protect',
                'user_id': self.ctxt.user_id,
                'project_id': self.ctxt.tenant,
                'trigger_id': '0354ca9ddcd046b693340d78759fd275',
                'operation_definition': '{}'
            }
            return db.scheduled_operation_create(self.ctxt, values)

        operation_ref = _create_scheduled_operation()
        self._create_scheduled_operation_state()
        state_ref = db.scheduled_operation_state_get(
            self.ctxt,
            operation_ref['id'],
            ['operation'])
        self.assertEqual(operation_ref['id'], state_ref.operation['id'])
Ejemplo n.º 7
0
 def test_scheduled_operation_state_get(self):
     state_ref = self._create_scheduled_operation_state()
     state_ref = db.scheduled_operation_state_get(self.ctxt,
                                                  state_ref['operation_id'])
     self.assertEqual('init', state_ref['state'])
Ejemplo n.º 8
0
 def test_scheduled_operation_state_get(self):
     state_ref = self._create_scheduled_operation_state()
     state_ref = db.scheduled_operation_state_get(self.ctxt,
                                                  state_ref['operation_id'])
     self.assertEqual('init', state_ref['state'])