Exemple #1
0
def create_operation_log(context, checkpoint):
    checkpoint_dict = checkpoint.to_dict()
    extra_info = checkpoint_dict.get('extra_info', None)
    create_by = (extra_info.get('create_by', None) if extra_info else None)
    scheduled_operation_id = None
    if create_by:
        scheduled_operation_id = create_by.get('scheduled_operation_id', None)

    protection_plan = checkpoint_dict['protection_plan']
    plan_id = None
    provider_id = None
    if protection_plan:
        plan_id = protection_plan.get("id")
        provider_id = protection_plan.get("provider_id")
    operation_log_properties = {
        'project_id': checkpoint_dict['project_id'],
        'operation_type': constants.OPERATION_PROTECT,
        'checkpoint_id': checkpoint_dict['id'],
        'plan_id': plan_id,
        'provider_id': provider_id,
        'scheduled_operation_id': scheduled_operation_id,
        'status': checkpoint_dict['status'],
        'started_at': timeutils.utcnow()
    }
    try:
        operation_log = objects.OperationLog(context=context,
                                             **operation_log_properties)
        operation_log.create()
        return operation_log
    except Exception:
        LOG.error('Error creating operation log. checkpoint: %s',
                  checkpoint.id)
        raise
Exemple #2
0
 def test_destroy(self, operation_log_destroy):
     db_operation_log = fake_operation_log.fake_db_operation_log()
     operation_log = objects.OperationLog._from_db_object(
         self.context, objects.OperationLog(), db_operation_log)
     operation_log.destroy()
     self.assertTrue(operation_log_destroy.called)
     admin_context = operation_log_destroy.call_args[0][0]
     self.assertTrue(admin_context.is_admin)
Exemple #3
0
 def test_save(self, operation_log_update):
     db_operation_log = fake_operation_log.fake_db_operation_log()
     operation_log = objects.OperationLog._from_db_object(
         self.context, objects.OperationLog(), db_operation_log)
     operation_log.state = 'finished'
     operation_log.save()
     operation_log_update.assert_called_once_with(self.context,
                                                  operation_log.id,
                                                  {'state': 'finished'})
Exemple #4
0
def create_operation_log_verify(context, verify):
    operation_log_properties = {
        'project_id': verify.get('project_id'),
        'operation_type': constants.OPERATION_VERIFY,
        'checkpoint_id': verify.get('checkpoint_id'),
        'plan_id': verify.get('plan_id', None),
        'provider_id': verify.get('provider_id'),
        'status': verify.get('status'),
        'started_at': timeutils.utcnow()
    }
    try:
        operation_log = objects.OperationLog(context=context,
                                             **operation_log_properties)
        operation_log.create()
        return operation_log
    except Exception:
        LOG.error('Error creating operation log. verify: %s', verify.id)
        raise
Exemple #5
0
def create_operation_log_restore(context, restore):
    operation_log_properties = {
        'project_id': restore.get('project_id'),
        'operation_type': constants.OPERATION_RESTORE,
        'checkpoint_id': restore.get('checkpoint_id'),
        'plan_id': restore.get('plan_id', None),
        'provider_id': restore.get('provider_id'),
        'restore_id': restore.get('id'),
        'status': restore.get('status'),
        'started_at': timeutils.utcnow()
    }
    try:
        operation_log = objects.OperationLog(context=context,
                                             **operation_log_properties)
        operation_log.create()
        return operation_log
    except Exception:
        LOG.error('Error creating operation log. checkpoint: %s', restore.id)
        raise
Exemple #6
0
 def test_obj_field_status(self):
     operation_log = objects.OperationLog(context=self.context,
                                          state='finished')
     self.assertEqual('finished', operation_log.state)
Exemple #7
0
 def test_create(self, operation_log_create):
     db_operation_log = fake_operation_log.fake_db_operation_log()
     operation_log_create.return_value = db_operation_log
     operation_log = objects.OperationLog(context=self.context)
     operation_log.create()
     self.assertEqual(db_operation_log['id'], operation_log.id)