Browse Source

Merge "Remove BackupDriverWithVerify class"

changes/55/681655/1
Zuul 1 week ago
parent
commit
06769bd878

+ 0
- 15
cinder/backup/driver.py View File

@@ -430,18 +430,3 @@ class BackupDriver(base.Base):
430 430
     def check_for_setup_error(self):
431 431
         """Method for checking if backup backend is successfully installed."""
432 432
         return
433
-
434
-
435
-@six.add_metaclass(abc.ABCMeta)
436
-class BackupDriverWithVerify(BackupDriver):
437
-    @abc.abstractmethod
438
-    def verify(self, backup):
439
-        """Verify that the backup exists on the backend.
440
-
441
-        Verify that the backup is OK, possibly following an import record
442
-        operation.
443
-
444
-        :param backup: backup id of the backup to verify
445
-        :raises InvalidBackup, NotImplementedError:
446
-        """
447
-        return

+ 2
- 66
cinder/backup/manager.py View File

@@ -45,7 +45,6 @@ from oslo_utils import importutils
45 45
 from oslo_utils import timeutils
46 46
 import six
47 47
 
48
-from cinder.backup import driver
49 48
 from cinder.backup import rpcapi as backup_rpcapi
50 49
 from cinder import context
51 50
 from cinder import exception
@@ -942,20 +941,6 @@ class BackupManager(manager.ThreadPoolManager):
942 941
             backup.update(backup_options)
943 942
             backup.save()
944 943
 
945
-            # Verify backup
946
-            try:
947
-                if isinstance(backup_service, driver.BackupDriverWithVerify):
948
-                    backup_service.verify(backup.id)
949
-                else:
950
-                    LOG.warning('Backup service %(service)s does not '
951
-                                'support verify. Backup id %(id)s is '
952
-                                'not verified. Skipping verify.',
953
-                                {'service': self.driver_name,
954
-                                 'id': backup.id})
955
-            except exception.InvalidBackup as err:
956
-                with excutils.save_and_reraise_exception():
957
-                    self._update_backup_error(backup, six.text_type(err))
958
-
959 944
             # Update the backup's status
960 945
             backup.update({"status": fields.BackupStatus.AVAILABLE})
961 946
             backup.save()
@@ -970,7 +955,6 @@ class BackupManager(manager.ThreadPoolManager):
970 955
         :param backup: The backup object for reset status operation
971 956
         :param status: The status to be set
972 957
         :raises InvalidBackup:
973
-        :raises BackupVerifyUnsupportedDriver:
974 958
         :raises AttributeError:
975 959
         """
976 960
         LOG.info('Reset backup status started, backup_id: '
@@ -989,56 +973,8 @@ class BackupManager(manager.ThreadPoolManager):
989 973
             raise exception.InvalidBackup(reason=err)
990 974
 
991 975
         if backup.service is not None:
992
-            # Verify backup
993
-            try:
994
-                # check whether the backup is ok or not
995
-                if (status == fields.BackupStatus.AVAILABLE and
996
-                        backup['status'] != fields.BackupStatus.RESTORING):
997
-                    # check whether we could verify the backup is ok or not
998
-                    backup_service = self.service(context)
999
-                    if isinstance(backup_service,
1000
-                                  driver.BackupDriverWithVerify):
1001
-                        backup_service.verify(backup.id)
1002
-                        backup.status = status
1003
-                        backup.save()
1004
-                    # driver does not support verify function
1005
-                    else:
1006
-                        msg = (_('Backup service %(configured_service)s '
1007
-                                 'does not support verify. Backup id'
1008
-                                 ' %(id)s is not verified. '
1009
-                                 'Skipping verify.') %
1010
-                               {'configured_service': self.driver_name,
1011
-                                'id': backup.id})
1012
-                        raise exception.BackupVerifyUnsupportedDriver(
1013
-                            reason=msg)
1014
-                # reset status to error or from restoring to available
1015
-                else:
1016
-                    if (status == fields.BackupStatus.ERROR or
1017
-                        (status == fields.BackupStatus.AVAILABLE and
1018
-                            backup.status == fields.BackupStatus.RESTORING)):
1019
-                        backup.status = status
1020
-                        backup.save()
1021
-            except exception.InvalidBackup:
1022
-                with excutils.save_and_reraise_exception():
1023
-                    LOG.error("Backup id %s is not invalid. Skipping reset.",
1024
-                              backup.id)
1025
-            except exception.BackupVerifyUnsupportedDriver:
1026
-                with excutils.save_and_reraise_exception():
1027
-                    LOG.error('Backup service %(configured_service)s '
1028
-                              'does not support verify. Backup id '
1029
-                              '%(id)s is not verified. '
1030
-                              'Skipping verify.',
1031
-                              {'configured_service': self.driver_name,
1032
-                               'id': backup.id})
1033
-            except AttributeError:
1034
-                msg = (_('Backup service %(service)s does not support '
1035
-                         'verify. Backup id %(id)s is not verified. '
1036
-                         'Skipping reset.') %
1037
-                       {'service': self.driver_name,
1038
-                        'id': backup.id})
1039
-                LOG.error(msg)
1040
-                raise exception.BackupVerifyUnsupportedDriver(
1041
-                    reason=msg)
976
+            backup.status = status
977
+            backup.save()
1042 978
 
1043 979
             # Needs to clean temporary volumes and snapshots.
1044 980
             try:

+ 0
- 4
cinder/exception.py View File

@@ -773,10 +773,6 @@ class BackupMetadataNotFound(NotFound):
773 773
                 "key %(metadata_key)s.")
774 774
 
775 775
 
776
-class BackupVerifyUnsupportedDriver(BackupDriverException):
777
-    message = _("Unsupported backup verify driver")
778
-
779
-
780 776
 class VolumeMetadataBackupExists(BackupDriverException):
781 777
     message = _("Metadata backup already exists for this volume")
782 778
 

+ 0
- 38
cinder/interface/backup_verify_driver.py View File

@@ -1,38 +0,0 @@
1
-# Copyright 2016 Dell Inc.
2
-# All Rights Reserved.
3
-#
4
-#    Licensed under the Apache License, Version 2.0 (the "License"); you may
5
-#    not use this file except in compliance with the License. You may obtain
6
-#    a copy of the License at
7
-#
8
-#         http://www.apache.org/licenses/LICENSE-2.0
9
-#
10
-#    Unless required by applicable law or agreed to in writing, software
11
-#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
-#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
-#    License for the specific language governing permissions and limitations
14
-#    under the License.
15
-#
16
-
17
-"""
18
-Backup driver with verification interface.
19
-
20
-Used for backup drivers that support the option to verify the backup after
21
-completion.
22
-"""
23
-
24
-from cinder.interface import backup_driver
25
-
26
-
27
-class BackupDriverWithVerify(backup_driver.BackupDriver):
28
-    """Backup driver that supports the optional verification."""
29
-
30
-    def verify(self, backup):
31
-        """Verify that the backup exists on the backend.
32
-
33
-        Verify that the backup is OK, possibly following an import record
34
-        operation.
35
-
36
-        :param backup: Backup id of the backup to verify.
37
-        :raises InvalidBackup, NotImplementedError:
38
-        """

+ 0
- 23
cinder/tests/unit/backup/fake_service_with_verify.py View File

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

+ 0
- 173
cinder/tests/unit/backup/test_backup.py View File

@@ -1795,179 +1795,6 @@ class BackupTestCase(BaseBackupTest):
1795 1795
         self.assertListEqual([], tpool._threads)
1796 1796
 
1797 1797
 
1798
-class BackupTestCaseWithVerify(BaseBackupTest):
1799
-    """Test Case for backups."""
1800
-
1801
-    def setUp(self):
1802
-        self.override_config(
1803
-            "backup_driver",
1804
-            "cinder.tests.unit.backup.fake_service_with_verify."
1805
-            "FakeBackupServiceWithVerify")
1806
-        super(BackupTestCaseWithVerify, self).setUp()
1807
-
1808
-    def test_import_record_with_verify(self):
1809
-        """Test normal backup record import.
1810
-
1811
-        Test the case when import succeeds for the case that the
1812
-        driver implements verify.
1813
-        """
1814
-        vol_size = 1
1815
-        backup_id = uuid.uuid4()
1816
-        export = self._create_exported_record_entry(
1817
-            vol_size=vol_size, exported_id=backup_id)
1818
-        imported_record = self._create_export_record_db_entry(
1819
-            backup_id=backup_id)
1820
-        backup_hosts = []
1821
-        backup_driver = self.backup_mgr.service(self.ctxt)
1822
-        _mock_backup_verify_class = ('%s.%s.%s' %
1823
-                                     (backup_driver.__module__,
1824
-                                      backup_driver.__class__.__name__,
1825
-                                      'verify'))
1826
-
1827
-        def mock_verify(backup_id):
1828
-            backup = db.backup_get(self.ctxt, backup_id)
1829
-            self.assertEqual(fields.BackupStatus.CREATING, backup['status'])
1830
-
1831
-        with mock.patch(_mock_backup_verify_class) as mock_backup_verify:
1832
-            mock_backup_verify.side_effect = mock_verify
1833
-            self.backup_mgr.import_record(self.ctxt,
1834
-                                          imported_record,
1835
-                                          export['backup_service'],
1836
-                                          export['backup_url'],
1837
-                                          backup_hosts)
1838
-        backup = db.backup_get(self.ctxt, imported_record.id)
1839
-        self.assertEqual(fields.BackupStatus.AVAILABLE, backup['status'])
1840
-        self.assertEqual(vol_size, backup['size'])
1841
-
1842
-    def test_import_record_with_verify_invalid_backup(self):
1843
-        """Test error handling.
1844
-
1845
-        Test error handling when attempting an import of a backup
1846
-        record where the backup driver returns an exception.
1847
-        """
1848
-        vol_size = 1
1849
-        backup_id = uuid.uuid4()
1850
-        export = self._create_exported_record_entry(
1851
-            vol_size=vol_size, exported_id=backup_id)
1852
-        imported_record = self._create_export_record_db_entry(
1853
-            backup_id=backup_id)
1854
-        backup_hosts = []
1855
-        backup_driver = self.backup_mgr.service(self.ctxt)
1856
-        _mock_backup_verify_class = ('%s.%s.%s' %
1857
-                                     (backup_driver.__module__,
1858
-                                      backup_driver.__class__.__name__,
1859
-                                      'verify'))
1860
-        with mock.patch(_mock_backup_verify_class) as _mock_record_verify:
1861
-            _mock_record_verify.side_effect = \
1862
-                exception.InvalidBackup(reason='fake')
1863
-
1864
-            self.assertRaises(exception.InvalidBackup,
1865
-                              self.backup_mgr.import_record,
1866
-                              self.ctxt,
1867
-                              imported_record,
1868
-                              export['backup_service'],
1869
-                              export['backup_url'],
1870
-                              backup_hosts)
1871
-            self.assertTrue(_mock_record_verify.called)
1872
-        backup = db.backup_get(self.ctxt, imported_record.id)
1873
-        self.assertEqual(fields.BackupStatus.ERROR, backup['status'])
1874
-
1875
-    @mock.patch.object(manager.BackupManager,
1876
-                       '_cleanup_temp_volumes_snapshots_for_one_backup')
1877
-    def test_backup_reset_status_from_nonrestoring_to_available(
1878
-            self, mock_clean_temp):
1879
-        service_name = ('cinder.tests.unit.backup.'
1880
-                        'fake_service_with_verify.FakeBackupServiceWithVerify')
1881
-        self.override_config('backup_driver', service_name)
1882
-        self.backup_mgr.driver_name = service_name
1883
-        vol_id = self._create_volume_db_entry(status='available',
1884
-                                              size=1)
1885
-        backup = self._create_backup_db_entry(status=fields.BackupStatus.ERROR,
1886
-                                              volume_id=vol_id,
1887
-                                              service=service_name)
1888
-        self.backup_mgr.reset_status(self.ctxt,
1889
-                                     backup,
1890
-                                     fields.BackupStatus.AVAILABLE)
1891
-        mock_clean_temp.assert_called_once_with(self.ctxt, backup)
1892
-        new_backup = db.backup_get(self.ctxt, backup.id)
1893
-        self.assertEqual(fields.BackupStatus.AVAILABLE,
1894
-                         new_backup['status'])
1895
-
1896
-        self.backup_mgr.reset_status(self.ctxt,
1897
-                                     backup,
1898
-                                     fields.BackupStatus.ERROR)
1899
-        mock_clean_temp.reset_mock()
1900
-
1901
-        self.backup_mgr.reset_status(self.ctxt,
1902
-                                     backup,
1903
-                                     fields.BackupStatus.AVAILABLE)
1904
-        mock_clean_temp.assert_called_once_with(self.ctxt, backup)
1905
-        backup = db.backup_get(self.ctxt, backup.id)
1906
-        self.assertEqual(fields.BackupStatus.AVAILABLE, backup['status'])
1907
-
1908
-    def test_backup_reset_status_to_available_invalid_backup(self):
1909
-        volume = db.volume_create(self.ctxt, {'status': 'available',
1910
-                                              'host': 'test',
1911
-                                              'provider_location': '',
1912
-                                              'size': 1})
1913
-        backup = self._create_backup_db_entry(status=fields.BackupStatus.ERROR,
1914
-                                              volume_id=volume['id'])
1915
-
1916
-        backup_driver = self.backup_mgr.service(self.ctxt)
1917
-        _mock_backup_verify_class = ('%s.%s.%s' %
1918
-                                     (backup_driver.__module__,
1919
-                                      backup_driver.__class__.__name__,
1920
-                                      'verify'))
1921
-        with mock.patch(_mock_backup_verify_class) as \
1922
-                _mock_record_verify:
1923
-            _mock_record_verify.side_effect = \
1924
-                exception.BackupVerifyUnsupportedDriver(reason='fake')
1925
-
1926
-            self.assertRaises(exception.BackupVerifyUnsupportedDriver,
1927
-                              self.backup_mgr.reset_status,
1928
-                              self.ctxt,
1929
-                              backup,
1930
-                              fields.BackupStatus.AVAILABLE)
1931
-            backup = db.backup_get(self.ctxt, backup.id)
1932
-            self.assertEqual(fields.BackupStatus.ERROR, backup['status'])
1933
-
1934
-    @mock.patch.object(manager.BackupManager,
1935
-                       '_cleanup_temp_volumes_snapshots_for_one_backup')
1936
-    def test_backup_reset_status_from_restoring_to_available(
1937
-            self, mock_clean_temp):
1938
-        volume = db.volume_create(self.ctxt,
1939
-                                  {'status': 'available',
1940
-                                   'host': 'test',
1941
-                                   'provider_location': '',
1942
-                                   'size': 1})
1943
-        backup = self._create_backup_db_entry(
1944
-            status=fields.BackupStatus.RESTORING,
1945
-            volume_id=volume['id'])
1946
-
1947
-        self.backup_mgr.reset_status(self.ctxt, backup,
1948
-                                     fields.BackupStatus.AVAILABLE)
1949
-        mock_clean_temp.assert_called_once_with(self.ctxt, backup)
1950
-        backup = db.backup_get(self.ctxt, backup.id)
1951
-        self.assertEqual(fields.BackupStatus.AVAILABLE, backup['status'])
1952
-
1953
-    @mock.patch.object(manager.BackupManager,
1954
-                       '_cleanup_temp_volumes_snapshots_for_one_backup')
1955
-    def test_backup_reset_status_to_error(self, mock_clean_temp):
1956
-        volume = db.volume_create(self.ctxt,
1957
-                                  {'status': 'available',
1958
-                                   'host': 'test',
1959
-                                   'provider_location': '',
1960
-                                   'size': 1})
1961
-        backup = self._create_backup_db_entry(
1962
-            status=fields.BackupStatus.CREATING,
1963
-            volume_id=volume['id'])
1964
-        self.backup_mgr.reset_status(self.ctxt, backup,
1965
-                                     fields.BackupStatus.ERROR)
1966
-        mock_clean_temp.assert_called_once_with(self.ctxt, backup)
1967
-        backup = db.backup_get(self.ctxt, backup['id'])
1968
-        self.assertEqual(fields.BackupStatus.ERROR, backup['status'])
1969
-
1970
-
1971 1798
 @ddt.ddt
1972 1799
 class BackupAPITestCase(BaseBackupTest):
1973 1800
     def setUp(self):

Loading…
Cancel
Save