summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjiaopengju <jiaopengju@cmss.chinamobile.com>2018-11-22 22:54:17 +0800
committerjiaopengju <jiaopengju@cmss.chinamobile.com>2018-11-22 22:54:17 +0800
commit093e7dd08fed5efabf5e5cf5d733d7dcf177a813 (patch)
tree01c1b58d2bea1ac7825396581e8e2a89ea0ec0f2
parentb6342feeb6b8f7f8984f10962c3286416100ade8 (diff)
Add verify action for volume backup by glance protection plugin
Notes
Notes (review): Code-Review+1: Gaƫtan Trellu <gaetan.trellu@incloudus.com> Code-Review+2: Jiao Pengju <jiaopengju@cmss.chinamobile.com> Workflow+1: Jiao Pengju <jiaopengju@cmss.chinamobile.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Fri, 23 Nov 2018 01:14:38 +0000 Reviewed-on: https://review.openstack.org/619593 Project: openstack/karbor Branch: refs/heads/master
-rw-r--r--karbor/services/protection/protection_plugins/volume/volume_glance_plugin.py37
-rw-r--r--karbor/services/protection/protection_plugins/volume/volume_glance_plugin_schemas.py6
-rw-r--r--karbor/tests/unit/protection/test_cinder_glance_plugin.py34
3 files changed, 77 insertions, 0 deletions
diff --git a/karbor/services/protection/protection_plugins/volume/volume_glance_plugin.py b/karbor/services/protection/protection_plugins/volume/volume_glance_plugin.py
index 773a1e5..9511516 100644
--- a/karbor/services/protection/protection_plugins/volume/volume_glance_plugin.py
+++ b/karbor/services/protection/protection_plugins/volume/volume_glance_plugin.py
@@ -418,6 +418,36 @@ class RestoreOperation(protection_plugin.Operation):
418 resource_type=constants.VOLUME_RESOURCE_TYPE) 418 resource_type=constants.VOLUME_RESOURCE_TYPE)
419 419
420 420
421class 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
421class DeleteOperation(protection_plugin.Operation): 451class DeleteOperation(protection_plugin.Operation):
422 def on_main(self, checkpoint, resource, context, parameters, **kwargs): 452 def on_main(self, checkpoint, resource, context, parameters, **kwargs):
423 volume_id = resource.id 453 volume_id = resource.id
@@ -474,6 +504,10 @@ class VolumeGlanceProtectionPlugin(protection_plugin.ProtectionPlugin):
474 return volume_schemas.SAVED_INFO_SCHEMA 504 return volume_schemas.SAVED_INFO_SCHEMA
475 505
476 @classmethod 506 @classmethod
507 def get_verify_schema(cls, resource_type):
508 return volume_schemas.VERIFY_SCHEMA
509
510 @classmethod
477 def get_saved_info(cls, metadata_store, resource): 511 def get_saved_info(cls, metadata_store, resource):
478 pass 512 pass
479 513
@@ -487,3 +521,6 @@ class VolumeGlanceProtectionPlugin(protection_plugin.ProtectionPlugin):
487 521
488 def get_delete_operation(self, resource): 522 def get_delete_operation(self, resource):
489 return DeleteOperation() 523 return DeleteOperation()
524
525 def get_verify_operation(self, resource):
526 return VerifyOperation()
diff --git a/karbor/services/protection/protection_plugins/volume/volume_glance_plugin_schemas.py b/karbor/services/protection/protection_plugins/volume/volume_glance_plugin_schemas.py
index 0f3170b..da448f1 100644
--- a/karbor/services/protection/protection_plugins/volume/volume_glance_plugin_schemas.py
+++ b/karbor/services/protection/protection_plugins/volume/volume_glance_plugin_schemas.py
@@ -43,6 +43,12 @@ RESTORE_SCHEMA = {
43 "required": ["restore_name"] 43 "required": ["restore_name"]
44} 44}
45 45
46VERIFY_SCHEMA = {
47 "title": "Volume Glance Protection Verify",
48 "type": "object",
49 "properties": {}
50}
51
46SAVED_INFO_SCHEMA = { 52SAVED_INFO_SCHEMA = {
47 "title": "Volume Glance Protection Saved Info", 53 "title": "Volume Glance Protection Saved Info",
48 "type": "object", 54 "type": "object",
diff --git a/karbor/tests/unit/protection/test_cinder_glance_plugin.py b/karbor/tests/unit/protection/test_cinder_glance_plugin.py
index b3613b6..636ee07 100644
--- a/karbor/tests/unit/protection/test_cinder_glance_plugin.py
+++ b/karbor/tests/unit/protection/test_cinder_glance_plugin.py
@@ -13,6 +13,7 @@
13import collections 13import collections
14from karbor.common import constants 14from karbor.common import constants
15from karbor.context import RequestContext 15from karbor.context import RequestContext
16from karbor import exception
16from karbor.resource import Resource 17from karbor.resource import Resource
17from karbor.services.protection.bank_plugin import Bank 18from karbor.services.protection.bank_plugin import Bank
18from karbor.services.protection.bank_plugin import BankPlugin 19from karbor.services.protection.bank_plugin import BankPlugin
@@ -236,3 +237,36 @@ class VolumeGlanceProtectionPluginTest(base.TestCase):
236 def test_get_supported_resources_types(self): 237 def test_get_supported_resources_types(self):
237 types = self.plugin.get_supported_resources_types() 238 types = self.plugin.get_supported_resources_types()
238 self.assertEqual([constants.VOLUME_RESOURCE_TYPE], types) 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.')