Merge "Google backup support client 1.8.2"
This commit is contained in:
commit
8e37faa18c
@ -43,13 +43,13 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
client = None
|
client = None
|
||||||
|
|
||||||
import googleapiclient
|
|
||||||
from googleapiclient import discovery
|
from googleapiclient import discovery
|
||||||
from googleapiclient import errors
|
from googleapiclient import errors
|
||||||
from googleapiclient import http
|
from googleapiclient import http
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
from oslo_utils import timeutils
|
from oslo_utils import timeutils
|
||||||
|
import pkg_resources
|
||||||
import six
|
import six
|
||||||
|
|
||||||
from cinder.backup import chunkeddriver
|
from cinder.backup import chunkeddriver
|
||||||
@ -174,8 +174,9 @@ class GoogleBackupDriver(chunkeddriver.ChunkedBackupDriver):
|
|||||||
# If we have google client that support google-auth library
|
# If we have google client that support google-auth library
|
||||||
# (v1.6.0 or higher) and all required libraries are installed use
|
# (v1.6.0 or higher) and all required libraries are installed use
|
||||||
# google-auth for the credentials
|
# google-auth for the credentials
|
||||||
if (version.LooseVersion(googleapiclient.__version__) >=
|
dist = pkg_resources.get_distribution('google-api-python-client')
|
||||||
version.LooseVersion('1.6.0') and service_account):
|
if (version.LooseVersion(dist.version) >= version.LooseVersion('1.6.0')
|
||||||
|
and service_account):
|
||||||
creds = service_account.Credentials.from_service_account_file(
|
creds = service_account.Credentials.from_service_account_file(
|
||||||
backup_credential)
|
backup_credential)
|
||||||
OAUTH_EXCEPTIONS = (gexceptions.RefreshError,
|
OAUTH_EXCEPTIONS = (gexceptions.RefreshError,
|
||||||
|
@ -623,51 +623,59 @@ class GoogleBackupDriverTestCase(test.TestCase):
|
|||||||
self.assertEqual('none', result[0])
|
self.assertEqual('none', result[0])
|
||||||
self.assertEqual(already_compressed_data, result[1])
|
self.assertEqual(already_compressed_data, result[1])
|
||||||
|
|
||||||
@mock.patch('googleapiclient.__version__', '1.5.5')
|
@mock.patch('pkg_resources.get_distribution')
|
||||||
@mock.patch.object(google_dr.client.GoogleCredentials, 'from_stream')
|
@mock.patch.object(google_dr.client.GoogleCredentials, 'from_stream')
|
||||||
@mock.patch.object(google_dr.discovery, 'build')
|
@mock.patch.object(google_dr.discovery, 'build')
|
||||||
@mock.patch.object(google_dr, 'service_account')
|
@mock.patch.object(google_dr, 'service_account')
|
||||||
def test_non_google_auth_version(self, account, build, from_stream):
|
def test_non_google_auth_version(self, account, build, from_stream,
|
||||||
|
get_dist_mock):
|
||||||
# Prior to v1.6.0 Google api client doesn't support google-auth library
|
# Prior to v1.6.0 Google api client doesn't support google-auth library
|
||||||
|
get_dist_mock.return_value.version = '1.5.5'
|
||||||
google_dr.CONF.set_override('backup_gcs_credential_file',
|
google_dr.CONF.set_override('backup_gcs_credential_file',
|
||||||
'credentials_file')
|
'credentials_file')
|
||||||
|
|
||||||
google_dr.GoogleBackupDriver(self.ctxt)
|
google_dr.GoogleBackupDriver(self.ctxt)
|
||||||
|
|
||||||
|
get_dist_mock.assert_called_once_with('google-api-python-client')
|
||||||
from_stream.assert_called_once_with('credentials_file')
|
from_stream.assert_called_once_with('credentials_file')
|
||||||
account.Credentials.from_service_account_file.assert_not_called()
|
account.Credentials.from_service_account_file.assert_not_called()
|
||||||
build.assert_called_once_with('storage', 'v1', cache_discovery=False,
|
build.assert_called_once_with('storage', 'v1', cache_discovery=False,
|
||||||
credentials=from_stream.return_value)
|
credentials=from_stream.return_value)
|
||||||
|
|
||||||
@mock.patch('googleapiclient.__version__', '1.6.6')
|
@mock.patch('pkg_resources.get_distribution')
|
||||||
@mock.patch.object(google_dr.client.GoogleCredentials, 'from_stream')
|
@mock.patch.object(google_dr.client.GoogleCredentials, 'from_stream')
|
||||||
@mock.patch.object(google_dr.discovery, 'build')
|
@mock.patch.object(google_dr.discovery, 'build')
|
||||||
@mock.patch.object(google_dr, 'service_account', None)
|
@mock.patch.object(google_dr, 'service_account', None)
|
||||||
def test_no_httplib2_auth(self, build, from_stream):
|
def test_no_httplib2_auth(self, build, from_stream, get_dist_mock):
|
||||||
# Google api client requires google-auth-httplib2 if not present we
|
# Google api client requires google-auth-httplib2 if not present we
|
||||||
# use legacy credentials
|
# use legacy credentials
|
||||||
|
get_dist_mock.return_value.version = '1.6.6'
|
||||||
google_dr.CONF.set_override('backup_gcs_credential_file',
|
google_dr.CONF.set_override('backup_gcs_credential_file',
|
||||||
'credentials_file')
|
'credentials_file')
|
||||||
|
|
||||||
google_dr.GoogleBackupDriver(self.ctxt)
|
google_dr.GoogleBackupDriver(self.ctxt)
|
||||||
|
|
||||||
|
get_dist_mock.assert_called_once_with('google-api-python-client')
|
||||||
from_stream.assert_called_once_with('credentials_file')
|
from_stream.assert_called_once_with('credentials_file')
|
||||||
build.assert_called_once_with('storage', 'v1', cache_discovery=False,
|
build.assert_called_once_with('storage', 'v1', cache_discovery=False,
|
||||||
credentials=from_stream.return_value)
|
credentials=from_stream.return_value)
|
||||||
|
|
||||||
@mock.patch('googleapiclient.__version__', '1.6.6')
|
@mock.patch('pkg_resources.get_distribution')
|
||||||
@mock.patch.object(google_dr, 'gexceptions', mock.Mock())
|
@mock.patch.object(google_dr, 'gexceptions', mock.Mock())
|
||||||
@mock.patch.object(google_dr.client.GoogleCredentials, 'from_stream')
|
@mock.patch.object(google_dr.client.GoogleCredentials, 'from_stream')
|
||||||
@mock.patch.object(google_dr.discovery, 'build')
|
@mock.patch.object(google_dr.discovery, 'build')
|
||||||
@mock.patch.object(google_dr, 'service_account')
|
@mock.patch.object(google_dr, 'service_account')
|
||||||
def test_google_auth_used(self, account, build, from_stream):
|
def test_google_auth_used(self, account, build, from_stream,
|
||||||
|
get_dist_mock):
|
||||||
# Google api client requires google-auth-httplib2 if not present we
|
# Google api client requires google-auth-httplib2 if not present we
|
||||||
# use legacy credentials
|
# use legacy credentials
|
||||||
|
get_dist_mock.return_value.version = '1.6.6'
|
||||||
google_dr.CONF.set_override('backup_gcs_credential_file',
|
google_dr.CONF.set_override('backup_gcs_credential_file',
|
||||||
'credentials_file')
|
'credentials_file')
|
||||||
|
|
||||||
google_dr.GoogleBackupDriver(self.ctxt)
|
google_dr.GoogleBackupDriver(self.ctxt)
|
||||||
|
|
||||||
|
get_dist_mock.assert_called_once_with('google-api-python-client')
|
||||||
from_stream.assert_not_called()
|
from_stream.assert_not_called()
|
||||||
create_creds = account.Credentials.from_service_account_file
|
create_creds = account.Credentials.from_service_account_file
|
||||||
create_creds.assert_called_once_with('credentials_file')
|
create_creds.assert_called_once_with('credentials_file')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user