Browse Source

Add verify action for volume backup by glance protection plugin

Change-Id: I5cf2f6d3fddf6f19df9e836cf76be8d3a1d21f47
Implements: blueprint support-verify-the-checkpoint-api
jiaopengju 5 months ago
parent
commit
093e7dd08f

+ 37
- 0
karbor/services/protection/protection_plugins/volume/volume_glance_plugin.py View File

@@ -418,6 +418,36 @@ class RestoreOperation(protection_plugin.Operation):
418 418
                 resource_type=constants.VOLUME_RESOURCE_TYPE)
419 419
 
420 420
 
421
+class VerifyOperation(protection_plugin.Operation):
422
+    def __init__(self):
423
+        super(VerifyOperation, self).__init__()
424
+
425
+    def on_main(self, checkpoint, resource, context, parameters, **kwargs):
426
+        original_volume_id = resource.id
427
+        bank_section = checkpoint.get_resource_bank_section(
428
+            original_volume_id)
429
+        LOG.info('Verifying the volume backup, volume id: %s',
430
+                 original_volume_id)
431
+
432
+        update_method = partial(
433
+            utils.update_resource_verify_result,
434
+            kwargs.get('verify'), resource.type, original_volume_id)
435
+
436
+        backup_status = bank_section.get_object("status")
437
+
438
+        if backup_status == constants.RESOURCE_STATUS_AVAILABLE:
439
+            update_method(constants.RESOURCE_STATUS_AVAILABLE)
440
+        else:
441
+            reason = ('The status of volume backup status is %s.'
442
+                      % backup_status)
443
+            update_method(backup_status, reason)
444
+            raise exception.VerifyResourceFailed(
445
+                name="Volume backup",
446
+                reason=reason,
447
+                resource_id=original_volume_id,
448
+                resource_type=resource.type)
449
+
450
+
421 451
 class DeleteOperation(protection_plugin.Operation):
422 452
     def on_main(self, checkpoint, resource, context, parameters, **kwargs):
423 453
         volume_id = resource.id
@@ -473,6 +503,10 @@ class VolumeGlanceProtectionPlugin(protection_plugin.ProtectionPlugin):
473 503
     def get_saved_info_schema(cls, resources_type):
474 504
         return volume_schemas.SAVED_INFO_SCHEMA
475 505
 
506
+    @classmethod
507
+    def get_verify_schema(cls, resource_type):
508
+        return volume_schemas.VERIFY_SCHEMA
509
+
476 510
     @classmethod
477 511
     def get_saved_info(cls, metadata_store, resource):
478 512
         pass
@@ -487,3 +521,6 @@ class VolumeGlanceProtectionPlugin(protection_plugin.ProtectionPlugin):
487 521
 
488 522
     def get_delete_operation(self, resource):
489 523
         return DeleteOperation()
524
+
525
+    def get_verify_operation(self, resource):
526
+        return VerifyOperation()

+ 6
- 0
karbor/services/protection/protection_plugins/volume/volume_glance_plugin_schemas.py View File

@@ -43,6 +43,12 @@ RESTORE_SCHEMA = {
43 43
     "required": ["restore_name"]
44 44
 }
45 45
 
46
+VERIFY_SCHEMA = {
47
+    "title": "Volume Glance Protection Verify",
48
+    "type": "object",
49
+    "properties": {}
50
+}
51
+
46 52
 SAVED_INFO_SCHEMA = {
47 53
     "title": "Volume Glance Protection Saved Info",
48 54
     "type": "object",

+ 34
- 0
karbor/tests/unit/protection/test_cinder_glance_plugin.py View File

@@ -13,6 +13,7 @@
13 13
 import collections
14 14
 from karbor.common import constants
15 15
 from karbor.context import RequestContext
16
+from karbor import exception
16 17
 from karbor.resource import Resource
17 18
 from karbor.services.protection.bank_plugin import Bank
18 19
 from karbor.services.protection.bank_plugin import BankPlugin
@@ -236,3 +237,36 @@ class VolumeGlanceProtectionPluginTest(base.TestCase):
236 237
     def test_get_supported_resources_types(self):
237 238
         types = self.plugin.get_supported_resources_types()
238 239
         self.assertEqual([constants.VOLUME_RESOURCE_TYPE], types)
240
+
241
+    @mock.patch('karbor.services.protection.protection_plugins.utils.'
242
+                'update_resource_verify_result')
243
+    def test_verify_backup(self, mock_update_verify):
244
+        resource = Resource(id="123",
245
+                            type=constants.VOLUME_RESOURCE_TYPE,
246
+                            name='fake')
247
+
248
+        fake_bank_section.get_object = mock.MagicMock()
249
+        fake_bank_section.get_object.return_value = 'available'
250
+
251
+        verify_operation = self.plugin.get_verify_operation(resource)
252
+        call_hooks(verify_operation, self.checkpoint, resource, self.cntxt,
253
+                   {})
254
+        mock_update_verify.assert_called_with(
255
+            None, resource.type, resource.id, 'available')
256
+
257
+    @mock.patch('karbor.services.protection.protection_plugins.utils.'
258
+                'update_resource_verify_result')
259
+    def test_verify_backup_with_error_status(self, mock_update_verify):
260
+        resource = Resource(id="123",
261
+                            type=constants.VOLUME_RESOURCE_TYPE,
262
+                            name='fake')
263
+        fake_bank_section.get_object = mock.MagicMock()
264
+        fake_bank_section.get_object.return_value = 'error'
265
+
266
+        verify_operation = self.plugin.get_verify_operation(resource)
267
+        self.assertRaises(
268
+            exception.VerifyResourceFailed, call_hooks, verify_operation,
269
+            self.checkpoint, resource, self.cntxt, {})
270
+        mock_update_verify.assert_called_with(
271
+            None, resource.type, resource.id, 'error',
272
+            'The status of volume backup status is error.')

Loading…
Cancel
Save