Merge "drop use of pkg_resources"
This commit is contained in:
commit
57411ae7c9
@ -27,10 +27,16 @@ Server-centric flow is used for authentication.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import base64
|
import base64
|
||||||
from distutils import version
|
|
||||||
import hashlib
|
import hashlib
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
try:
|
||||||
|
# For python 3.8 and later
|
||||||
|
import importlib.metadata as importlib_metadata
|
||||||
|
except ImportError:
|
||||||
|
# For everyone else
|
||||||
|
import importlib_metadata
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from google.auth import exceptions as gexceptions
|
from google.auth import exceptions as gexceptions
|
||||||
from google.oauth2 import service_account
|
from google.oauth2 import service_account
|
||||||
@ -49,7 +55,7 @@ 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
|
from packaging import version
|
||||||
import six
|
import six
|
||||||
|
|
||||||
from cinder.backup import chunkeddriver
|
from cinder.backup import chunkeddriver
|
||||||
@ -142,6 +148,17 @@ def gcs_logger(func):
|
|||||||
return func_wrapper
|
return func_wrapper
|
||||||
|
|
||||||
|
|
||||||
|
def _get_dist_version(name):
|
||||||
|
"""Mock-able wrapper for importlib_metadata.version()
|
||||||
|
|
||||||
|
The module name where version() is found varies by python
|
||||||
|
version. This function makes it easier for tests to mock the
|
||||||
|
function and change the return value.
|
||||||
|
|
||||||
|
"""
|
||||||
|
return importlib_metadata.version(name)
|
||||||
|
|
||||||
|
|
||||||
@interface.backupdriver
|
@interface.backupdriver
|
||||||
class GoogleBackupDriver(chunkeddriver.ChunkedBackupDriver):
|
class GoogleBackupDriver(chunkeddriver.ChunkedBackupDriver):
|
||||||
"""Provides backup, restore and delete of backup objects within GCS."""
|
"""Provides backup, restore and delete of backup objects within GCS."""
|
||||||
@ -174,8 +191,8 @@ 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
|
||||||
dist = pkg_resources.get_distribution('google-api-python-client')
|
dist_version = _get_dist_version('google-api-python-client')
|
||||||
if (version.LooseVersion(dist.version) >= version.LooseVersion('1.6.0')
|
if (version.parse(dist_version) >= version.parse('1.6.0')
|
||||||
and service_account):
|
and service_account):
|
||||||
creds = service_account.Credentials.from_service_account_file(
|
creds = service_account.Credentials.from_service_account_file(
|
||||||
backup_credential)
|
backup_credential)
|
||||||
|
@ -623,59 +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('pkg_resources.get_distribution')
|
@mock.patch.object(google_dr, '_get_dist_version')
|
||||||
@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):
|
get_dist_version):
|
||||||
# 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'
|
get_dist_version.return_value = '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')
|
get_dist_version.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('pkg_resources.get_distribution')
|
@mock.patch.object(google_dr, '_get_dist_version')
|
||||||
@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, get_dist_mock):
|
def test_no_httplib2_auth(self, build, from_stream, get_dist_version):
|
||||||
# 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'
|
get_dist_version.return_value = '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')
|
get_dist_version.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('pkg_resources.get_distribution')
|
@mock.patch.object(google_dr, '_get_dist_version')
|
||||||
@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):
|
get_dist_version):
|
||||||
# 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'
|
get_dist_version.return_value = '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')
|
get_dist_version.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')
|
||||||
|
@ -21,6 +21,7 @@ import re
|
|||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
from oslo_utils import strutils
|
from oslo_utils import strutils
|
||||||
from oslo_utils import units
|
from oslo_utils import units
|
||||||
|
import packaging.version
|
||||||
import six
|
import six
|
||||||
|
|
||||||
from cinder import exception
|
from cinder import exception
|
||||||
@ -1989,8 +1990,9 @@ class PowerMaxUtils(object):
|
|||||||
:param minimum_version: minimum version allowed
|
:param minimum_version: minimum version allowed
|
||||||
:returns: boolean
|
:returns: boolean
|
||||||
"""
|
"""
|
||||||
from pkg_resources import parse_version
|
checking = packaging.version.parse(version)
|
||||||
return parse_version(version) >= parse_version(minimum_version)
|
minimum = packaging.version.parse(minimum_version)
|
||||||
|
return checking >= minimum
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def parse_specs_from_pool_name(pool_name):
|
def parse_specs_from_pool_name(pool_name):
|
||||||
|
@ -37,6 +37,7 @@ greenlet==0.4.13
|
|||||||
httplib2==0.9.1
|
httplib2==0.9.1
|
||||||
idna==2.5
|
idna==2.5
|
||||||
imagesize==1.0.0
|
imagesize==1.0.0
|
||||||
|
importlib-metadata==1.7.0
|
||||||
iso8601==0.1.12
|
iso8601==0.1.12
|
||||||
Jinja2==2.10
|
Jinja2==2.10
|
||||||
jsonpatch==1.21
|
jsonpatch==1.21
|
||||||
@ -79,6 +80,7 @@ oslo.versionedobjects==1.31.2
|
|||||||
oslo.vmware==2.35.0
|
oslo.vmware==2.35.0
|
||||||
oslotest==3.2.0
|
oslotest==3.2.0
|
||||||
osprofiler==1.4.0
|
osprofiler==1.4.0
|
||||||
|
packaging==20.4
|
||||||
paramiko==2.4.0
|
paramiko==2.4.0
|
||||||
Paste==2.0.2
|
Paste==2.0.2
|
||||||
PasteDeploy==1.5.0
|
PasteDeploy==1.5.0
|
||||||
|
@ -7,6 +7,7 @@ decorator>=4.1.0 # BSD
|
|||||||
eventlet!=0.23.0,!=0.25.0,>=0.22.0 # MIT
|
eventlet!=0.23.0,!=0.25.0,>=0.22.0 # MIT
|
||||||
greenlet>=0.4.13 # MIT
|
greenlet>=0.4.13 # MIT
|
||||||
httplib2>=0.9.1 # MIT
|
httplib2>=0.9.1 # MIT
|
||||||
|
importlib_metadata>=1.7.0;python_version<'3.8' # Apache-2.0
|
||||||
iso8601>=0.1.12 # MIT
|
iso8601>=0.1.12 # MIT
|
||||||
jsonschema>=3.2.0 # MIT
|
jsonschema>=3.2.0 # MIT
|
||||||
keystoneauth1>=3.14.0 # Apache-2.0
|
keystoneauth1>=3.14.0 # Apache-2.0
|
||||||
@ -30,6 +31,7 @@ oslo.upgradecheck>=0.1.0 # Apache-2.0
|
|||||||
oslo.utils>=3.40.2 # Apache-2.0
|
oslo.utils>=3.40.2 # Apache-2.0
|
||||||
oslo.versionedobjects>=1.31.2 # Apache-2.0
|
oslo.versionedobjects>=1.31.2 # Apache-2.0
|
||||||
osprofiler>=1.4.0 # Apache-2.0
|
osprofiler>=1.4.0 # Apache-2.0
|
||||||
|
packaging>=20.4
|
||||||
paramiko>=2.4.0 # LGPLv2.1+
|
paramiko>=2.4.0 # LGPLv2.1+
|
||||||
Paste>=2.0.2 # MIT
|
Paste>=2.0.2 # MIT
|
||||||
PasteDeploy>=1.5.0 # MIT
|
PasteDeploy>=1.5.0 # MIT
|
||||||
|
Loading…
Reference in New Issue
Block a user