Reduce deprecation warnings

This makes several types of changes to get rid of all of the deprecation
warnings that are spewed during our unit test runs.

Context changes:
    The user_domain and project_domain properties have been deprecated
    and user_domain_id and project_domain_id should be used instead. We
    have used the newer correct properties for some time now, but for
    compatibility we were still setting the old properties as well.

Collections.abc:
    Between py2 and py3, some abstract classes were moved from
    collections to collections.abc. We had some compatibility code to
    try to handle this in most cases, but also had a few cases of using
    the classed directly from the old, deprecated location.

assertRaisesRegexp:
    This was deprecated in favor of assertRaisesRegex.

DefusedXML:
    DefusedXML has deprecated several things now that lxml handles
    things correctly. The project now recommends just using lxml.

Change-Id: Ie2e46b45248d6a06edbe6cffc2eb8e2d341cd4c3
Signed-off-by: Sean McGinnis <sean.mcginnis@gmail.com>
This commit is contained in:
Sean McGinnis 2020-04-14 15:35:28 -05:00
parent ad73a1e0f6
commit 070411fbb7
No known key found for this signature in database
GPG Key ID: CE7EE4BFAF8D70C8
17 changed files with 31 additions and 33 deletions

View File

@ -111,13 +111,13 @@ class CinderKeystoneContext(base_wsgi.Middleware):
return webob.exc.HTTPUnauthorized() return webob.exc.HTTPUnauthorized()
if req.environ.get('X_PROJECT_DOMAIN_ID'): if req.environ.get('X_PROJECT_DOMAIN_ID'):
ctx.project_domain = req.environ['X_PROJECT_DOMAIN_ID'] ctx.project_domain_id = req.environ['X_PROJECT_DOMAIN_ID']
if req.environ.get('X_PROJECT_DOMAIN_NAME'): if req.environ.get('X_PROJECT_DOMAIN_NAME'):
ctx.project_domain_name = req.environ['X_PROJECT_DOMAIN_NAME'] ctx.project_domain_name = req.environ['X_PROJECT_DOMAIN_NAME']
if req.environ.get('X_USER_DOMAIN_ID'): if req.environ.get('X_USER_DOMAIN_ID'):
ctx.user_domain = req.environ['X_USER_DOMAIN_ID'] ctx.user_domain_id = req.environ['X_USER_DOMAIN_ID']
if req.environ.get('X_USER_DOMAIN_NAME'): if req.environ.get('X_USER_DOMAIN_NAME'):
ctx.user_domain_name = req.environ['X_USER_DOMAIN_NAME'] ctx.user_domain_name = req.environ['X_USER_DOMAIN_NAME']

View File

@ -180,10 +180,8 @@ class RequestContext(context.RequestContext):
is_admin=values.get('is_admin'), is_admin=values.get('is_admin'),
roles=values.get('roles'), roles=values.get('roles'),
auth_token=values.get('auth_token'), auth_token=values.get('auth_token'),
user_domain_id=values.get('user_domain'), user_domain_id=values.get('user_domain_id'),
project_domain_id=values.get('project_domain'), project_domain_id=values.get('project_domain_id'),
user_domain=values.get('user_domain'),
project_domain=values.get('project_domain'),
) )
def authorize(self, action, target=None, target_obj=None, fatal=True): def authorize(self, action, target=None, target_obj=None, fatal=True):

View File

@ -15,7 +15,7 @@
"""Manage backends in the current zone.""" """Manage backends in the current zone."""
import collections from collections import abc
import random import random
from oslo_config import cfg from oslo_config import cfg
@ -67,7 +67,7 @@ CONF.import_opt('max_over_subscription_ratio', 'cinder.volume.driver')
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
class ReadOnlyDict(collections.Mapping): class ReadOnlyDict(abc.Mapping):
"""A read-only dict.""" """A read-only dict."""
def __init__(self, source=None): def __init__(self, source=None):
if source is not None: if source is not None:

View File

@ -123,11 +123,11 @@ class UnityReplicationDeviceTest(unittest.TestCase):
@ddt.unpack @ddt.unpack
def test_init_raise(self, conf_dict): def test_init_raise(self, conf_dict):
self.driver.configuration.replication_device = conf_dict self.driver.configuration.replication_device = conf_dict
self.assertRaisesRegexp(exception.InvalidConfigurationValue, self.assertRaisesRegex(exception.InvalidConfigurationValue,
'Value .* is not valid for configuration ' 'Value .* is not valid for configuration '
'option "unity-backend.replication_device"', 'option "unity-backend.replication_device"',
replication.ReplicationDevice, replication.ReplicationDevice,
conf_dict, self.driver) conf_dict, self.driver)
@ddt.data( @ddt.data(
{ {

View File

@ -51,7 +51,8 @@ class FusionStorageConfTestCase(test.TestCase):
config.add_section('manager_ip') config.add_section('manager_ip')
config.set('manager_ip', 'fake_host', 'fake_ip') config.set('manager_ip', 'fake_host', 'fake_ip')
config.write(open(self.conf.cinder_fusionstorage_conf_file, 'w')) with open(self.conf.cinder_fusionstorage_conf_file, 'w') as conf_file:
config.write(conf_file)
@mock.patch.object(fs_conf.FusionStorageConf, '_encode_authentication') @mock.patch.object(fs_conf.FusionStorageConf, '_encode_authentication')
@mock.patch.object(fs_conf.FusionStorageConf, '_pools_name') @mock.patch.object(fs_conf.FusionStorageConf, '_pools_name')

View File

@ -19,8 +19,8 @@ from unittest import mock
from ddt import data from ddt import data
from ddt import ddt from ddt import ddt
from ddt import unpack from ddt import unpack
from defusedxml import cElementTree as ET
import eventlet import eventlet
from lxml import etree as ET
from oslo_config import cfg from oslo_config import cfg
from oslo_utils import units from oslo_utils import units
import requests import requests

View File

@ -18,7 +18,7 @@
from unittest import mock from unittest import mock
from defusedxml import lxml as etree from lxml import etree
import requests import requests
from cinder import exception from cinder import exception
@ -215,7 +215,7 @@ class TestSeagateClient(test.TestCase):
RequestException("error")] RequestException("error")]
mock_requests_get.return_value = m mock_requests_get.return_value = m
ret = self.client._api_request('/path') ret = self.client._api_request('/path')
self.assertTrue(type(ret) == etree.RestrictedElement) self.assertTrue(type(ret) == etree._Element)
self.assertRaises(stx_exception.ConnectionError, self.assertRaises(stx_exception.ConnectionError,
self.client._api_request, self.client._api_request,
'/path') '/path')

View File

@ -23,7 +23,7 @@ import base64
import hashlib import hashlib
import time import time
from defusedxml import ElementTree as ET from lxml import etree as ET
from oslo_concurrency import lockutils from oslo_concurrency import lockutils
from oslo_config import cfg from oslo_config import cfg
from oslo_log import log as logging from oslo_log import log as logging

View File

@ -23,7 +23,7 @@ import base64
import os import os
import re import re
from defusedxml import ElementTree as ET from lxml import etree as ET
from oslo_log import log as logging from oslo_log import log as logging
import six import six

View File

@ -19,7 +19,7 @@ import os
import re import re
import traceback import traceback
from defusedxml import ElementTree from lxml import etree
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 excutils from oslo_utils import excutils
@ -291,7 +291,7 @@ class MStorageVolumeCommon(object):
try: try:
with open(product, 'r') as f: with open(product, 'r') as f:
xml = f.read() xml = f.read()
root = ElementTree.fromstring(xml) root = etree.fromstring(xml)
vendor_name = root.findall('./VendorName')[0].text vendor_name = root.findall('./VendorName')[0].text
product_dict = {} product_dict = {}
@ -785,7 +785,7 @@ class MStorageVolumeCommon(object):
return hostports return hostports
def configs(self, xml): def configs(self, xml):
root = ElementTree.fromstring(xml) root = etree.fromstring(xml)
pools = self.get_pool_config(xml, root) pools = self.get_pool_config(xml, root)
lds, used_ldns = self.get_ld_config(xml, root, pools) lds, used_ldns = self.get_ld_config(xml, root, pools)
iscsi_ldsets = self.get_iscsi_ldset_config(xml, root) iscsi_ldsets = self.get_iscsi_ldset_config(xml, root)

View File

@ -23,8 +23,8 @@ import re
import threading import threading
import time import time
from defusedxml import cElementTree as ET
import eventlet import eventlet
from lxml import etree as ET
from oslo_concurrency import lockutils from oslo_concurrency import lockutils
from oslo_config import cfg from oslo_config import cfg
from oslo_log import log as logging from oslo_log import log as logging

View File

@ -649,10 +649,11 @@ class QuobyteDriver(remotefs_drv.RemoteFSSnapDriverDistributed):
def _mount_quobyte(self, quobyte_volume, mount_path, ensure=False): def _mount_quobyte(self, quobyte_volume, mount_path, ensure=False):
"""Mount Quobyte volume to mount path.""" """Mount Quobyte volume to mount path."""
mounted = False mounted = False
for l in QuobyteDriver.read_proc_mount(): with QuobyteDriver.read_proc_mount() as proc_mount:
if l.split()[1] == mount_path: for l in proc_mount:
mounted = True if l.split()[1] == mount_path:
break mounted = True
break
if mounted: if mounted:
try: try:

View File

@ -19,7 +19,7 @@ import hashlib
import math import math
import time import time
from defusedxml import lxml as etree from lxml import etree
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

View File

@ -19,8 +19,8 @@ import ast
import hashlib import hashlib
import json import json
from random import randint from random import randint
from xml.dom import minidom
from defusedxml import minidom
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_service import loopingcall from oslo_service import loopingcall

View File

@ -17,7 +17,7 @@
This driver requires VPSA with API version 15.07 or higher. This driver requires VPSA with API version 15.07 or higher.
""" """
from defusedxml import lxml from lxml import etree
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 strutils from oslo_utils import strutils
@ -287,7 +287,7 @@ class ZadaraVPSAConnection(object):
raise exception.BadHTTPResponseStatus(status=response.status_code) raise exception.BadHTTPResponseStatus(status=response.status_code)
data = response.content data = response.content
xml_tree = lxml.fromstring(data) xml_tree = etree.fromstring(data)
status = xml_tree.findtext('status') status = xml_tree.findtext('status')
if status == '5': if status == '5':
# Invalid Credentials # Invalid Credentials

View File

@ -20,7 +20,6 @@ cursive==0.2.1
ddt==1.2.1 ddt==1.2.1
debtcollector==1.19.0 debtcollector==1.19.0
decorator==3.4.0 decorator==3.4.0
defusedxml==0.5.0
doc8==0.6.0 doc8==0.6.0
docutils==0.14 docutils==0.14
dogpile.cache==0.6.5 dogpile.cache==0.6.5

View File

@ -4,7 +4,6 @@
pbr!=2.1.0,>=2.0.0 # Apache-2.0 pbr!=2.1.0,>=2.0.0 # Apache-2.0
decorator>=3.4.0 # BSD decorator>=3.4.0 # BSD
defusedxml>=0.5.0 # PSF
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.10 # MIT greenlet>=0.4.10 # MIT
httplib2>=0.9.1 # MIT httplib2>=0.9.1 # MIT