diff --git a/cinder/backup/drivers/gcs.py b/cinder/backup/drivers/gcs.py index 11a86f9f230..0fd5f15522c 100644 --- a/cinder/backup/drivers/gcs.py +++ b/cinder/backup/drivers/gcs.py @@ -115,16 +115,29 @@ CONF.register_opts(gcsbackup_service_opts) OAUTH_EXCEPTIONS = None +# Google Cloud Storage(GCS) backup driver +class GCSConnectionFailure(exception.BackupDriverException): + message = _("Google Cloud Storage connection failure: %(reason)s") + + +class GCSApiFailure(exception.BackupDriverException): + message = _("Google Cloud Storage api failure: %(reason)s") + + +class GCSOAuth2Failure(exception.BackupDriverException): + message = _("Google Cloud Storage oauth2 failure: %(reason)s") + + def gcs_logger(func): def func_wrapper(self, *args, **kwargs): try: return func(self, *args, **kwargs) except errors.Error as err: - raise exception.GCSApiFailure(reason=err) + raise GCSApiFailure(reason=err) except OAUTH_EXCEPTIONS as err: - raise exception.GCSOAuth2Failure(reason=err) + raise GCSOAuth2Failure(reason=err) except Exception as err: - raise exception.GCSConnectionFailure(reason=err) + raise GCSConnectionFailure(reason=err) return func_wrapper diff --git a/cinder/exception.py b/cinder/exception.py index 776f2a842f8..6422b372863 100644 --- a/cinder/exception.py +++ b/cinder/exception.py @@ -1301,19 +1301,6 @@ class NexentaException(VolumeDriverException): message = "%(reason)s" -# Google Cloud Storage(GCS) backup driver -class GCSConnectionFailure(BackupDriverException): - message = _("Google Cloud Storage connection failure: %(reason)s") - - -class GCSApiFailure(BackupDriverException): - message = _("Google Cloud Storage api failure: %(reason)s") - - -class GCSOAuth2Failure(BackupDriverException): - message = _("Google Cloud Storage oauth2 failure: %(reason)s") - - # Kaminario K2 class KaminarioCinderDriverException(VolumeDriverException): message = _("KaminarioCinderDriver failure: %(reason)s") diff --git a/cinder/tests/unit/backup/drivers/test_backup_google.py b/cinder/tests/unit/backup/drivers/test_backup_google.py index 61e9fd51817..81fcd7630f3 100644 --- a/cinder/tests/unit/backup/drivers/test_backup_google.py +++ b/cinder/tests/unit/backup/drivers/test_backup_google.py @@ -427,7 +427,7 @@ class GoogleBackupDriverTestCase(test.TestCase): container=container_name) service = google_dr.GoogleBackupDriver(self.ctxt) self.volume_file.seek(0) - self.assertRaises(exception.GCSApiFailure, + self.assertRaises(google_dr.GCSApiFailure, service.backup, backup, self.volume_file) @@ -439,7 +439,7 @@ class GoogleBackupDriverTestCase(test.TestCase): container=container_name) service = google_dr.GoogleBackupDriver(self.ctxt) self.volume_file.seek(0) - self.assertRaises(exception.GCSOAuth2Failure, + self.assertRaises(google_dr.GCSOAuth2Failure, service.backup, backup, self.volume_file) @@ -507,7 +507,7 @@ class GoogleBackupDriverTestCase(test.TestCase): service = google_dr.GoogleBackupDriver(self.ctxt) with tempfile.NamedTemporaryFile() as volume_file: - self.assertRaises(exception.GCSConnectionFailure, + self.assertRaises(google_dr.GCSConnectionFailure, service.restore, backup, volume_id, volume_file)