diff --git a/cinder/backup/drivers/gcs.py b/cinder/backup/drivers/gcs.py index 9eb92fa18d6..cc3aa662b84 100644 --- a/cinder/backup/drivers/gcs.py +++ b/cinder/backup/drivers/gcs.py @@ -37,11 +37,6 @@ try: except ImportError: service_account = google_auth_httplib2 = gexceptions = None -try: - from oauth2client import client -except ImportError: - client = None - from googleapiclient import discovery from googleapiclient import errors from googleapiclient import http @@ -176,16 +171,14 @@ class GoogleBackupDriver(chunkeddriver.ChunkedBackupDriver): creds = service_account.Credentials.from_service_account_file( backup_credential) OAUTH_EXCEPTIONS = (gexceptions.RefreshError, - gexceptions.DefaultCredentialsError, - client.Error) - # The (deprecated) client is imported if the oauth2client library is - # available - elif client: - creds = client.GoogleCredentials.from_stream(backup_credential) - OAUTH_EXCEPTIONS = client.Error + gexceptions.DefaultCredentialsError) else: - msg = _('google-auth-httplib2 or oauth2client should be ' - 'installed.') + # NOTE(tkajinam): google-api-python-client is now in requirements + # and google-auth-httplib2 is its dependency. So + # this error should not be raised now. But it's + # kept now in case the client library is moved to + # extra dependencies + msg = _('google-api-python-client not found') raise exception.BackupDriverException(reason=msg) self.conn = discovery.build('storage', diff --git a/cinder/tests/unit/backup/drivers/test_backup_google.py b/cinder/tests/unit/backup/drivers/test_backup_google.py index 66d23cbf5fb..504b84f35f3 100644 --- a/cinder/tests/unit/backup/drivers/test_backup_google.py +++ b/cinder/tests/unit/backup/drivers/test_backup_google.py @@ -66,8 +66,6 @@ class FakeObjectName(object): def gcs_client(func): - @mock.patch.object(google_dr.client, 'GoogleCredentials', - fake_google_client.FakeGoogleCredentials) @mock.patch.object(google_dr.discovery, 'build', fake_google_client.FakeGoogleDiscovery.Build) @mock.patch.object(google_dr, 'GoogleMediaIoBaseDownload', @@ -85,8 +83,6 @@ def gcs_client(func): def gcs_client2(func): - @mock.patch.object(google_dr.client, 'GoogleCredentials', - fake_google_client2.FakeGoogleCredentials) @mock.patch.object(google_dr.discovery, 'build', fake_google_client2.FakeGoogleDiscovery.Build) @mock.patch.object(google_dr, 'GoogleMediaIoBaseDownload', @@ -635,34 +631,15 @@ class GoogleBackupDriverTestCase(test.TestCase): self.assertEqual('none', result[0]) self.assertEqual(already_compressed_data, result[1]) - @mock.patch.object(google_dr.client.GoogleCredentials, 'from_stream') - @mock.patch.object(google_dr.discovery, 'build') - @mock.patch.object(google_dr, 'service_account', None) - def test_no_httplib2_auth(self, build, from_stream): - # Google api client requires google-auth-httplib2 if not present we - # use legacy credentials - google_dr.CONF.set_override('backup_gcs_credential_file', - 'credentials_file') - - google_dr.GoogleBackupDriver(self.ctxt) - - from_stream.assert_called_once_with('credentials_file') - build.assert_called_once_with('storage', 'v1', cache_discovery=False, - credentials=from_stream.return_value) - @mock.patch.object(google_dr, 'gexceptions', mock.Mock()) - @mock.patch.object(google_dr.client.GoogleCredentials, 'from_stream') @mock.patch.object(google_dr.discovery, 'build') @mock.patch.object(google_dr, 'service_account') - def test_google_auth_used(self, account, build, from_stream): - # Google api client requires google-auth-httplib2 if not present we - # use legacy credentials + def test_client_setup(self, account, build): google_dr.CONF.set_override('backup_gcs_credential_file', 'credentials_file') google_dr.GoogleBackupDriver(self.ctxt) - from_stream.assert_not_called() create_creds = account.Credentials.from_service_account_file create_creds.assert_called_once_with('credentials_file') build.assert_called_once_with('storage', 'v1', cache_discovery=False, diff --git a/cinder/tests/unit/backup/fake_google_client.py b/cinder/tests/unit/backup/fake_google_client.py index 5d3c294095b..58ee8371861 100644 --- a/cinder/tests/unit/backup/fake_google_client.py +++ b/cinder/tests/unit/backup/fake_google_client.py @@ -18,8 +18,8 @@ import json import os import zlib +from google.auth import exceptions as gexceptions from googleapiclient import errors -from oauth2client import client from oslo_utils import units @@ -55,7 +55,7 @@ class FakeGoogleBucketListExecute(object): def execute(self, *args, **kwargs): if self.container_name == 'gcs_oauth2_failure': - raise client.Error + raise gexceptions.DefaultCredentialsError return {u'items': [{u'name': u'gcscinderbucket'}, {u'name': u'gcsbucket'}]} diff --git a/requirements.txt b/requirements.txt index 44a810f578b..2e342031fa1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -12,7 +12,6 @@ jsonschema>=3.2.0 # MIT keystoneauth1>=4.2.1 # Apache-2.0 keystonemiddleware>=9.1.0 # Apache-2.0 lxml>=4.5.2 # BSD -oauth2client>=4.1.3 # Apache-2.0 oslo.config>=8.3.2 # Apache-2.0 oslo.concurrency>=4.5.0 # Apache-2.0 oslo.context>=3.4.0 # Apache-2.0