From fe32529d5dab460fdfcf47b93ab92b0758828e59 Mon Sep 17 00:00:00 2001 From: "Walter A. Boring IV" Date: Tue, 7 May 2019 20:40:05 +0000 Subject: [PATCH] move Google backup exceptions This patch moves the Google backup driver exceptions to the gcs.py file Change-Id: I9f881f88a1574b6b392e71ddf2f68d4aa7313793 --- cinder/backup/drivers/gcs.py | 19 ++++++++++++++++--- cinder/exception.py | 13 ------------- .../unit/backup/drivers/test_backup_google.py | 6 +++--- 3 files changed, 19 insertions(+), 19 deletions(-) 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 0232e26c2e3..52b65c11b94 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)