Merge "Add verify action for the database backup protection plugin"
This commit is contained in:
commit
d853f172d6
|
@ -218,6 +218,48 @@ class RestoreOperation(protection_plugin.Operation):
|
|||
"instance_id: %s.", original_instance_id)
|
||||
|
||||
|
||||
class VerifyOperation(protection_plugin.Operation):
|
||||
def __init__(self):
|
||||
super(VerifyOperation, self).__init__()
|
||||
|
||||
def on_main(self, checkpoint, resource, context, parameters, **kwargs):
|
||||
original_instance_id = resource.id
|
||||
bank_section = checkpoint.get_resource_bank_section(
|
||||
original_instance_id)
|
||||
trove_client = ClientFactory.create_client('trove', context)
|
||||
resource_metadata = bank_section.get_object('metadata')
|
||||
LOG.info('Verifying the database instance, instance_id: %s',
|
||||
original_instance_id)
|
||||
|
||||
update_method = partial(
|
||||
utils.update_resource_verify_result,
|
||||
kwargs.get('verify'), resource.type, original_instance_id)
|
||||
|
||||
backup_id = resource_metadata['backup_id']
|
||||
try:
|
||||
instance_backup = trove_client.backups.get(backup_id)
|
||||
backup_status = instance_backup.status
|
||||
except Exception as ex:
|
||||
LOG.error('Getting database backup (backup_id: %(backup_id)s):'
|
||||
'%(reason)s fails',
|
||||
{'backup_id': backup_id, 'reason': ex})
|
||||
reason = 'Getting database backup fails.'
|
||||
update_method(constants.RESOURCE_STATUS_ERROR, reason)
|
||||
raise
|
||||
|
||||
if backup_status == 'COMPLETED':
|
||||
update_method(constants.RESOURCE_STATUS_AVAILABLE)
|
||||
else:
|
||||
reason = ('The status of database backup status is %s.'
|
||||
% backup_status)
|
||||
update_method(backup_status, reason)
|
||||
raise exception.VerifyResourceFailed(
|
||||
name="Database backup",
|
||||
reason=reason,
|
||||
resource_id=original_instance_id,
|
||||
resource_type=resource.type)
|
||||
|
||||
|
||||
class DeleteOperation(protection_plugin.Operation):
|
||||
def __init__(self, poll_interval):
|
||||
super(DeleteOperation, self).__init__()
|
||||
|
@ -287,6 +329,10 @@ class DatabaseBackupProtectionPlugin(protection_plugin.ProtectionPlugin):
|
|||
def get_restore_schema(cls, resources_type):
|
||||
return database_instance_schemas.RESTORE_SCHEMA
|
||||
|
||||
@classmethod
|
||||
def get_verify_schema(cls, resources_type):
|
||||
return database_instance_schemas.VERIFY_SCHEMA
|
||||
|
||||
@classmethod
|
||||
def get_saved_info_schema(cls, resources_type):
|
||||
return database_instance_schemas.SAVED_INFO_SCHEMA
|
||||
|
@ -301,5 +347,8 @@ class DatabaseBackupProtectionPlugin(protection_plugin.ProtectionPlugin):
|
|||
def get_restore_operation(self, resource):
|
||||
return RestoreOperation(self._poll_interval)
|
||||
|
||||
def get_verify_operation(self, resource):
|
||||
return VerifyOperation()
|
||||
|
||||
def get_delete_operation(self, resource):
|
||||
return DeleteOperation(self._poll_interval)
|
||||
|
|
|
@ -43,6 +43,12 @@ RESTORE_SCHEMA = {
|
|||
"required": ["restore_name"]
|
||||
}
|
||||
|
||||
VERIFY_SCHEMA = {
|
||||
"title": "Database backup Verify",
|
||||
"type": "object",
|
||||
"properties": {}
|
||||
}
|
||||
|
||||
SAVED_INFO_SCHEMA = {
|
||||
"title": "Database Instance Protection Saved Info",
|
||||
"type": "object",
|
||||
|
|
|
@ -194,6 +194,30 @@ class TroveProtectionPluginTest(base.TestCase):
|
|||
call_hooks(delete_operation, self.checkpoint, resource, self.cntxt,
|
||||
{})
|
||||
|
||||
@mock.patch('karbor.services.protection.protection_plugins.utils.'
|
||||
'update_resource_verify_result')
|
||||
@mock.patch('karbor.services.protection.clients.trove.create')
|
||||
def test_verify_backup(self, mock_trove_create, mock_update_verify):
|
||||
resource = Resource(id="123",
|
||||
type=constants.DATABASE_RESOURCE_TYPE,
|
||||
name='fake')
|
||||
mock_trove_create.return_value = self.trove_client
|
||||
self.trove_client.backups.get = mock.MagicMock()
|
||||
self.trove_client.backups.get.return_value = Backup(
|
||||
id="1234",
|
||||
status="COMPLETED"
|
||||
)
|
||||
|
||||
fake_bank_section.get_object = mock.MagicMock()
|
||||
fake_bank_section.get_object.return_value = {
|
||||
"backup_id": "1234"}
|
||||
|
||||
verify_operation = self.plugin.get_verify_operation(resource)
|
||||
call_hooks(verify_operation, self.checkpoint, resource, self.cntxt,
|
||||
{})
|
||||
mock_update_verify.assert_called_with(
|
||||
None, resource.type, resource.id, 'available')
|
||||
|
||||
def test_get_supported_resources_types(self):
|
||||
types = self.plugin.get_supported_resources_types()
|
||||
self.assertEqual(types,
|
||||
|
|
Loading…
Reference in New Issue