Remove BackupDriverWithVerify class

It was introduced more then 5 years ago and no backup drivers
implemented this interface. So it looks safe to just remove it.

Change-Id: Ib10f3b8ff55d72a6abd212175e88c8dddedd3466
This commit is contained in:
Ivan Kolodyazhny 2019-05-02 16:42:34 -06:00
parent 6fcb7c6639
commit 7bb731098a
6 changed files with 2 additions and 319 deletions

View File

@ -430,18 +430,3 @@ class BackupDriver(base.Base):
def check_for_setup_error(self):
"""Method for checking if backup backend is successfully installed."""
return
@six.add_metaclass(abc.ABCMeta)
class BackupDriverWithVerify(BackupDriver):
@abc.abstractmethod
def verify(self, backup):
"""Verify that the backup exists on the backend.
Verify that the backup is OK, possibly following an import record
operation.
:param backup: backup id of the backup to verify
:raises InvalidBackup, NotImplementedError:
"""
return

View File

@ -45,7 +45,6 @@ from oslo_utils import importutils
from oslo_utils import timeutils
import six
from cinder.backup import driver
from cinder.backup import rpcapi as backup_rpcapi
from cinder import context
from cinder import exception
@ -930,20 +929,6 @@ class BackupManager(manager.ThreadPoolManager):
backup.update(backup_options)
backup.save()
# Verify backup
try:
if isinstance(backup_service, driver.BackupDriverWithVerify):
backup_service.verify(backup.id)
else:
LOG.warning('Backup service %(service)s does not '
'support verify. Backup id %(id)s is '
'not verified. Skipping verify.',
{'service': self.driver_name,
'id': backup.id})
except exception.InvalidBackup as err:
with excutils.save_and_reraise_exception():
self._update_backup_error(backup, six.text_type(err))
# Update the backup's status
backup.update({"status": fields.BackupStatus.AVAILABLE})
backup.save()
@ -958,7 +943,6 @@ class BackupManager(manager.ThreadPoolManager):
:param backup: The backup object for reset status operation
:param status: The status to be set
:raises InvalidBackup:
:raises BackupVerifyUnsupportedDriver:
:raises AttributeError:
"""
LOG.info('Reset backup status started, backup_id: '
@ -977,56 +961,8 @@ class BackupManager(manager.ThreadPoolManager):
raise exception.InvalidBackup(reason=err)
if backup.service is not None:
# Verify backup
try:
# check whether the backup is ok or not
if (status == fields.BackupStatus.AVAILABLE and
backup['status'] != fields.BackupStatus.RESTORING):
# check whether we could verify the backup is ok or not
backup_service = self.service(context)
if isinstance(backup_service,
driver.BackupDriverWithVerify):
backup_service.verify(backup.id)
backup.status = status
backup.save()
# driver does not support verify function
else:
msg = (_('Backup service %(configured_service)s '
'does not support verify. Backup id'
' %(id)s is not verified. '
'Skipping verify.') %
{'configured_service': self.driver_name,
'id': backup.id})
raise exception.BackupVerifyUnsupportedDriver(
reason=msg)
# reset status to error or from restoring to available
else:
if (status == fields.BackupStatus.ERROR or
(status == fields.BackupStatus.AVAILABLE and
backup.status == fields.BackupStatus.RESTORING)):
backup.status = status
backup.save()
except exception.InvalidBackup:
with excutils.save_and_reraise_exception():
LOG.error("Backup id %s is not invalid. Skipping reset.",
backup.id)
except exception.BackupVerifyUnsupportedDriver:
with excutils.save_and_reraise_exception():
LOG.error('Backup service %(configured_service)s '
'does not support verify. Backup id '
'%(id)s is not verified. '
'Skipping verify.',
{'configured_service': self.driver_name,
'id': backup.id})
except AttributeError:
msg = (_('Backup service %(service)s does not support '
'verify. Backup id %(id)s is not verified. '
'Skipping reset.') %
{'service': self.driver_name,
'id': backup.id})
LOG.error(msg)
raise exception.BackupVerifyUnsupportedDriver(
reason=msg)
backup.status = status
backup.save()
# Needs to clean temporary volumes and snapshots.
try:

View File

@ -777,10 +777,6 @@ class BackupMetadataNotFound(NotFound):
"key %(metadata_key)s.")
class BackupVerifyUnsupportedDriver(BackupDriverException):
message = _("Unsupported backup verify driver")
class VolumeMetadataBackupExists(BackupDriverException):
message = _("Metadata backup already exists for this volume")

View File

@ -1,38 +0,0 @@
# Copyright 2016 Dell Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
"""
Backup driver with verification interface.
Used for backup drivers that support the option to verify the backup after
completion.
"""
from cinder.interface import backup_driver
class BackupDriverWithVerify(backup_driver.BackupDriver):
"""Backup driver that supports the optional verification."""
def verify(self, backup):
"""Verify that the backup exists on the backend.
Verify that the backup is OK, possibly following an import record
operation.
:param backup: Backup id of the backup to verify.
:raises InvalidBackup, NotImplementedError:
"""

View File

@ -1,23 +0,0 @@
# Copyright (C) 2014 Deutsche Telekom AG
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from cinder.backup import driver
from cinder.tests.unit.backup import fake_service
class FakeBackupServiceWithVerify(driver.BackupDriverWithVerify,
fake_service.FakeBackupService):
def verify(self, backup):
pass

View File

@ -1778,179 +1778,6 @@ class BackupTestCase(BaseBackupTest):
self.assertListEqual([], tpool._threads)
class BackupTestCaseWithVerify(BaseBackupTest):
"""Test Case for backups."""
def setUp(self):
self.override_config(
"backup_driver",
"cinder.tests.unit.backup.fake_service_with_verify."
"FakeBackupServiceWithVerify")
super(BackupTestCaseWithVerify, self).setUp()
def test_import_record_with_verify(self):
"""Test normal backup record import.
Test the case when import succeeds for the case that the
driver implements verify.
"""
vol_size = 1
backup_id = uuid.uuid4()
export = self._create_exported_record_entry(
vol_size=vol_size, exported_id=backup_id)
imported_record = self._create_export_record_db_entry(
backup_id=backup_id)
backup_hosts = []
backup_driver = self.backup_mgr.service(self.ctxt)
_mock_backup_verify_class = ('%s.%s.%s' %
(backup_driver.__module__,
backup_driver.__class__.__name__,
'verify'))
def mock_verify(backup_id):
backup = db.backup_get(self.ctxt, backup_id)
self.assertEqual(fields.BackupStatus.CREATING, backup['status'])
with mock.patch(_mock_backup_verify_class) as mock_backup_verify:
mock_backup_verify.side_effect = mock_verify
self.backup_mgr.import_record(self.ctxt,
imported_record,
export['backup_service'],
export['backup_url'],
backup_hosts)
backup = db.backup_get(self.ctxt, imported_record.id)
self.assertEqual(fields.BackupStatus.AVAILABLE, backup['status'])
self.assertEqual(vol_size, backup['size'])
def test_import_record_with_verify_invalid_backup(self):
"""Test error handling.
Test error handling when attempting an import of a backup
record where the backup driver returns an exception.
"""
vol_size = 1
backup_id = uuid.uuid4()
export = self._create_exported_record_entry(
vol_size=vol_size, exported_id=backup_id)
imported_record = self._create_export_record_db_entry(
backup_id=backup_id)
backup_hosts = []
backup_driver = self.backup_mgr.service(self.ctxt)
_mock_backup_verify_class = ('%s.%s.%s' %
(backup_driver.__module__,
backup_driver.__class__.__name__,
'verify'))
with mock.patch(_mock_backup_verify_class) as _mock_record_verify:
_mock_record_verify.side_effect = \
exception.InvalidBackup(reason='fake')
self.assertRaises(exception.InvalidBackup,
self.backup_mgr.import_record,
self.ctxt,
imported_record,
export['backup_service'],
export['backup_url'],
backup_hosts)
self.assertTrue(_mock_record_verify.called)
backup = db.backup_get(self.ctxt, imported_record.id)
self.assertEqual(fields.BackupStatus.ERROR, backup['status'])
@mock.patch.object(manager.BackupManager,
'_cleanup_temp_volumes_snapshots_for_one_backup')
def test_backup_reset_status_from_nonrestoring_to_available(
self, mock_clean_temp):
service_name = ('cinder.tests.unit.backup.'
'fake_service_with_verify.FakeBackupServiceWithVerify')
self.override_config('backup_driver', service_name)
self.backup_mgr.driver_name = service_name
vol_id = self._create_volume_db_entry(status='available',
size=1)
backup = self._create_backup_db_entry(status=fields.BackupStatus.ERROR,
volume_id=vol_id,
service=service_name)
self.backup_mgr.reset_status(self.ctxt,
backup,
fields.BackupStatus.AVAILABLE)
mock_clean_temp.assert_called_once_with(self.ctxt, backup)
new_backup = db.backup_get(self.ctxt, backup.id)
self.assertEqual(fields.BackupStatus.AVAILABLE,
new_backup['status'])
self.backup_mgr.reset_status(self.ctxt,
backup,
fields.BackupStatus.ERROR)
mock_clean_temp.reset_mock()
self.backup_mgr.reset_status(self.ctxt,
backup,
fields.BackupStatus.AVAILABLE)
mock_clean_temp.assert_called_once_with(self.ctxt, backup)
backup = db.backup_get(self.ctxt, backup.id)
self.assertEqual(fields.BackupStatus.AVAILABLE, backup['status'])
def test_backup_reset_status_to_available_invalid_backup(self):
volume = db.volume_create(self.ctxt, {'status': 'available',
'host': 'test',
'provider_location': '',
'size': 1})
backup = self._create_backup_db_entry(status=fields.BackupStatus.ERROR,
volume_id=volume['id'])
backup_driver = self.backup_mgr.service(self.ctxt)
_mock_backup_verify_class = ('%s.%s.%s' %
(backup_driver.__module__,
backup_driver.__class__.__name__,
'verify'))
with mock.patch(_mock_backup_verify_class) as \
_mock_record_verify:
_mock_record_verify.side_effect = \
exception.BackupVerifyUnsupportedDriver(reason='fake')
self.assertRaises(exception.BackupVerifyUnsupportedDriver,
self.backup_mgr.reset_status,
self.ctxt,
backup,
fields.BackupStatus.AVAILABLE)
backup = db.backup_get(self.ctxt, backup.id)
self.assertEqual(fields.BackupStatus.ERROR, backup['status'])
@mock.patch.object(manager.BackupManager,
'_cleanup_temp_volumes_snapshots_for_one_backup')
def test_backup_reset_status_from_restoring_to_available(
self, mock_clean_temp):
volume = db.volume_create(self.ctxt,
{'status': 'available',
'host': 'test',
'provider_location': '',
'size': 1})
backup = self._create_backup_db_entry(
status=fields.BackupStatus.RESTORING,
volume_id=volume['id'])
self.backup_mgr.reset_status(self.ctxt, backup,
fields.BackupStatus.AVAILABLE)
mock_clean_temp.assert_called_once_with(self.ctxt, backup)
backup = db.backup_get(self.ctxt, backup.id)
self.assertEqual(fields.BackupStatus.AVAILABLE, backup['status'])
@mock.patch.object(manager.BackupManager,
'_cleanup_temp_volumes_snapshots_for_one_backup')
def test_backup_reset_status_to_error(self, mock_clean_temp):
volume = db.volume_create(self.ctxt,
{'status': 'available',
'host': 'test',
'provider_location': '',
'size': 1})
backup = self._create_backup_db_entry(
status=fields.BackupStatus.CREATING,
volume_id=volume['id'])
self.backup_mgr.reset_status(self.ctxt, backup,
fields.BackupStatus.ERROR)
mock_clean_temp.assert_called_once_with(self.ctxt, backup)
backup = db.backup_get(self.ctxt, backup['id'])
self.assertEqual(fields.BackupStatus.ERROR, backup['status'])
@ddt.ddt
class BackupAPITestCase(BaseBackupTest):
def setUp(self):