Add verify action for the share snapshot protection plugin
Change-Id: I3da9b9f5b53ea7e1ab6ea518fa4d9582f4eeb095 Implements: blueprint support-verify-the-checkpoint-api
This commit is contained in:
parent
ae39095360
commit
d67eb913fb
|
@ -218,6 +218,48 @@ class RestoreOperation(protection_plugin.Operation):
|
|||
original_share_id)
|
||||
|
||||
|
||||
class VerifyOperation(protection_plugin.Operation):
|
||||
def __init__(self):
|
||||
super(VerifyOperation, self).__init__()
|
||||
|
||||
def on_main(self, checkpoint, resource, context, parameters, **kwargs):
|
||||
original_share_id = resource.id
|
||||
bank_section = checkpoint.get_resource_bank_section(original_share_id)
|
||||
manila_client = ClientFactory.create_client('manila', context)
|
||||
resource_metadata = bank_section.get_object('metadata')
|
||||
LOG.info('Verifying the share snapshot, share_id: %s',
|
||||
original_share_id)
|
||||
|
||||
update_method = partial(
|
||||
utils.update_resource_verify_result,
|
||||
kwargs.get('verify'), resource.type, original_share_id)
|
||||
|
||||
snapshot_id = resource_metadata['snapshot_id']
|
||||
try:
|
||||
share_snapshot = manila_client.share_snapshots.get(snapshot_id)
|
||||
snapshot_status = share_snapshot.status
|
||||
except Exception as ex:
|
||||
LOG.error('Getting share snapshot (snapshot_id: %(snapshot_id)s):'
|
||||
'%(reason)s fails',
|
||||
{'snapshot_id': snapshot_id, 'reason': ex})
|
||||
reason = 'Getting share snapshot fails.'
|
||||
update_method(constants.RESOURCE_STATUS_ERROR, reason)
|
||||
raise
|
||||
|
||||
if snapshot_status == 'available':
|
||||
update_method(constants.RESOURCE_STATUS_AVAILABLE)
|
||||
else:
|
||||
reason = ('The status of share snapshot status is %s.'
|
||||
% snapshot_status)
|
||||
update_method(snapshot_status, reason)
|
||||
raise exception.VerifyResourceFailed(
|
||||
name="Share snapshot",
|
||||
reason=reason,
|
||||
resource_id=original_share_id,
|
||||
resource_type=resource.type
|
||||
)
|
||||
|
||||
|
||||
class DeleteOperation(protection_plugin.Operation):
|
||||
def __init__(self, poll_interval):
|
||||
super(DeleteOperation, self).__init__()
|
||||
|
@ -287,6 +329,10 @@ class ManilaSnapshotProtectionPlugin(protection_plugin.ProtectionPlugin):
|
|||
def get_restore_schema(cls, resources_type):
|
||||
return share_schemas.RESTORE_SCHEMA
|
||||
|
||||
@classmethod
|
||||
def get_verify_schema(cls, resources_type):
|
||||
return share_schemas.VERIFY_SCHEMA
|
||||
|
||||
@classmethod
|
||||
def get_saved_info_schema(cls, resources_type):
|
||||
return share_schemas.SAVED_INFO_SCHEMA
|
||||
|
@ -301,5 +347,8 @@ class ManilaSnapshotProtectionPlugin(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)
|
||||
|
|
|
@ -50,6 +50,12 @@ RESTORE_SCHEMA = {
|
|||
"required": ["restore_name"]
|
||||
}
|
||||
|
||||
VERIFY_SCHEMA = {
|
||||
"title": "Share snapshot Verify",
|
||||
"type": "object",
|
||||
"properties": {}
|
||||
}
|
||||
|
||||
SAVED_INFO_SCHEMA = {
|
||||
"title": "Share Protection Saved Info",
|
||||
"type": "object",
|
||||
|
|
|
@ -192,6 +192,30 @@ class ManilaProtectionPluginTest(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.manila.create')
|
||||
def test_verify_snapshot(self, mock_manila_create, mock_update_verify):
|
||||
resource = Resource(id="123",
|
||||
type=constants.SHARE_RESOURCE_TYPE,
|
||||
name='fake')
|
||||
mock_manila_create.return_value = self.manila_client
|
||||
self.manila_client.share_snapshots.get = mock.MagicMock()
|
||||
self.manila_client.share_snapshots.get.return_value = Snapshot(
|
||||
id="1234",
|
||||
status="available"
|
||||
)
|
||||
|
||||
fake_bank_section.get_object = mock.MagicMock()
|
||||
fake_bank_section.get_object.return_value = {
|
||||
"snapshot_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([constants.SHARE_RESOURCE_TYPE], types)
|
||||
|
|
Loading…
Reference in New Issue