Add verify action for the network backup protection plugin

Change-Id: Ib2e4890d3fbef9e233237cefedfba49ba6fa1bfc
Implements: blueprint support-verify-the-checkpoint-api
This commit is contained in:
chenying 2017-10-25 18:04:55 +08:00
parent 7b2cb7c405
commit fff8e49ef6
3 changed files with 60 additions and 0 deletions

View File

@ -30,6 +30,12 @@ RESTORE_SCHEMA = {
"required": ["restore_name"]
}
VERIFY_SCHEMA = {
"title": "Network Protection Verify",
"type": "object",
"properties": {}
}
SAVED_INFO_SCHEMA = {
"title": "Network Protection Saved Info",
"type": "object",

View File

@ -10,6 +10,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import copy
from functools import partial
from neutronclient.common import exceptions
from oslo_config import cfg
from oslo_log import log as logging
@ -255,6 +256,36 @@ class ProtectOperation(protection_plugin.Operation):
resource_type=self._SUPPORT_RESOURCE_TYPES)
class VerifyOperation(protection_plugin.Operation):
def __init__(self):
super(VerifyOperation, self).__init__()
def on_main(self, checkpoint, resource, context, parameters, **kwargs):
network_id = get_network_id(context)
bank_section = checkpoint.get_resource_bank_section(
network_id)
LOG.info('Verifying the network backup, network_id: %s.',
network_id)
update_method = partial(
utils.update_resource_verify_result,
kwargs.get('verify'), resource.type, network_id)
backup_status = bank_section.get_object("status")
if backup_status == constants.RESOURCE_STATUS_AVAILABLE:
update_method(constants.RESOURCE_STATUS_AVAILABLE)
else:
reason = ('The status of network backup status is %s.'
% backup_status)
update_method(backup_status, reason)
raise exception.VerifyResourceFailed(
name="Network backup",
reason=reason,
resource_id=network_id,
resource_type=resource.type)
class RestoreOperation(protection_plugin.Operation):
def __init__(self, poll_interval):
@ -693,6 +724,10 @@ class NeutronProtectionPlugin(protection_plugin.ProtectionPlugin):
def get_restore_schema(self, resources_type):
return network_plugin_schemas.RESTORE_SCHEMA
@classmethod
def get_verify_schema(cls, resources_type):
return network_plugin_schemas.VERIFY_SCHEMA
@classmethod
def get_saved_info_schema(self, resources_type):
return network_plugin_schemas.SAVED_INFO_SCHEMA
@ -708,6 +743,9 @@ class NeutronProtectionPlugin(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):
# TODO(chenhuayi)
pass

View File

@ -388,3 +388,19 @@ class NeutronProtectionPluginTest(base.TestCase):
call_hooks(delete_operation, self.checkpoint, resource, self.cntxt,
{})
@mock.patch('karbor.services.protection.protection_plugins.utils.'
'update_resource_verify_result')
def test_verify_backup(self, mock_update_verify):
resource = Resource(id="abcd",
type=constants.NETWORK_RESOURCE_TYPE,
name="test")
fake_bank_section.get_object = mock.MagicMock()
fake_bank_section.get_object.return_value = 'available'
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')