From 76a63308f47060e3abcb2998453aed086ef3f4a9 Mon Sep 17 00:00:00 2001 From: Eric Harney Date: Tue, 11 Jul 2017 16:43:44 -0400 Subject: [PATCH] Fix python 3.6 escape char warnings in strings In python 3.6, escape sequences that are not recognized in string literals issue DeprecationWarnings. Convert these to raw strings. Change-Id: I0d20a0dd27415eab0abf08ceb5be415ae1cf0ad0 --- cinder/api/common.py | 2 +- cinder/tests/unit/api/contrib/test_quotas.py | 4 ++-- cinder/tests/unit/test_quota.py | 2 +- .../volume/drivers/infortrend/test_infortrend_cli.py | 2 +- cinder/tests/unit/volume/drivers/nec/test_volume.py | 4 ++-- .../drivers/netapp/dataontap/test_block_cmode.py | 2 +- .../unit/volume/drivers/netapp/eseries/test_library.py | 2 +- cinder/tests/unit/volume/drivers/test_rbd.py | 2 +- cinder/tests/unit/windows/test_smbfs.py | 2 +- cinder/utils.py | 6 +++--- cinder/volume/drivers/dell_emc/scaleio/driver.py | 2 +- cinder/volume/drivers/hitachi/hbsd_common.py | 2 +- cinder/volume/drivers/hitachi/hbsd_snm2.py | 10 +++++----- cinder/volume/drivers/hpe/hpe_lefthand_iscsi.py | 2 +- cinder/volume/drivers/ibm/flashsystem_common.py | 2 +- cinder/volume/drivers/ibm/ibm_storage/ibm_storage.py | 2 +- cinder/volume/drivers/ibm/ibm_storage/xiv_proxy.py | 2 +- cinder/volume/drivers/netapp/dataontap/nfs_base.py | 4 ++-- .../drivers/netapp/dataontap/utils/capabilities.py | 4 ++-- cinder/volume/drivers/tintri.py | 2 +- cinder/volume/drivers/vzstorage.py | 2 +- cinder/volume/drivers/windows/windows.py | 2 +- cinder/volume/targets/iet.py | 4 ++-- .../drivers/brocade/brcd_fc_zone_client_cli.py | 2 +- .../drivers/cisco/cisco_fc_zone_client_cli.py | 4 ++-- 25 files changed, 37 insertions(+), 37 deletions(-) diff --git a/cinder/api/common.py b/cinder/api/common.py index 4065f0940..dcb261652 100644 --- a/cinder/api/common.py +++ b/cinder/api/common.py @@ -248,7 +248,7 @@ def get_request_url(request): forwarded = headers.get('X-Forwarded-Host') if forwarded: url_parts = list(urllib.parse.urlsplit(url)) - url_parts[1] = re.split(',\s?', forwarded)[-1] + url_parts[1] = re.split(r',\s?', forwarded)[-1] url = urllib.parse.urlunsplit(url_parts).rstrip('/') return url diff --git a/cinder/tests/unit/api/contrib/test_quotas.py b/cinder/tests/unit/api/contrib/test_quotas.py index 8753fa476..fcb96c753 100644 --- a/cinder/tests/unit/api/contrib/test_quotas.py +++ b/cinder/tests/unit/api/contrib/test_quotas.py @@ -120,7 +120,7 @@ class QuotaSetsControllerTestBase(test.TestCase): self.fixture.config(auth_uri=self.auth_url, group='keystone_authtoken') def _create_project_hierarchy(self): - """Sets an environment used for nested quotas tests. + r"""Sets an environment used for nested quotas tests. Create a project hierarchy such as follows: +-----------+ @@ -393,7 +393,7 @@ class QuotaSetControllerValidateNestedQuotaSetup(QuotaSetsControllerTestBase): """ def _create_project_hierarchy(self): - """Sets an environment used for nested quotas tests. + r"""Sets an environment used for nested quotas tests. Create a project hierarchy such as follows: +-----------------+ diff --git a/cinder/tests/unit/test_quota.py b/cinder/tests/unit/test_quota.py index 34ea007df..99f91c9c3 100644 --- a/cinder/tests/unit/test_quota.py +++ b/cinder/tests/unit/test_quota.py @@ -1519,7 +1519,7 @@ class NestedDbQuotaDriverTestCase(NestedDbQuotaDriverBaseTestCase): class NestedQuotaValidation(NestedDbQuotaDriverBaseTestCase): def setUp(self): super(NestedQuotaValidation, self).setUp() - """ + r""" Quota hierarchy setup like so +-----------+ | | diff --git a/cinder/tests/unit/volume/drivers/infortrend/test_infortrend_cli.py b/cinder/tests/unit/volume/drivers/infortrend/test_infortrend_cli.py index c5f408077..0a8d6b423 100644 --- a/cinder/tests/unit/volume/drivers/infortrend/test_infortrend_cli.py +++ b/cinder/tests/unit/volume/drivers/infortrend/test_infortrend_cli.py @@ -439,7 +439,7 @@ Return: 0x0000 }]) def get_fake_show_snapshot(self): - msg = """ + msg = r""" CLI: Successful: Device(UID:77124, Name:, Model:DS S12F-G2852-6) selected. Return: 0x0000 \/\/\/- diff --git a/cinder/tests/unit/volume/drivers/nec/test_volume.py b/cinder/tests/unit/volume/drivers/nec/test_volume.py index 0f007d3ec..be8b4aad6 100644 --- a/cinder/tests/unit/volume/drivers/nec/test_volume.py +++ b/cinder/tests/unit/volume/drivers/nec/test_volume.py @@ -923,8 +923,8 @@ class ExportTest(volume_helper.MStorageDSVDriver, unittest.TestCase): self.vol.status = 'downloading' with self.assertRaisesRegexp(exception.VolumeBackendAPIException, - 'Failed to unregister Logical Disk from' - ' Logical Disk Set \(iSM31064\)'): + r'Failed to unregister Logical Disk from' + r' Logical Disk Set \(iSM31064\)'): mock_del = mock.Mock() self._cli.delldsetld = mock_del self._cli.delldsetld.return_value = False, 'iSM31064' diff --git a/cinder/tests/unit/volume/drivers/netapp/dataontap/test_block_cmode.py b/cinder/tests/unit/volume/drivers/netapp/dataontap/test_block_cmode.py index ae9223959..b5ff714fb 100644 --- a/cinder/tests/unit/volume/drivers/netapp/dataontap/test_block_cmode.py +++ b/cinder/tests/unit/volume/drivers/netapp/dataontap/test_block_cmode.py @@ -451,7 +451,7 @@ class NetAppBlockStorageCmodeLibraryTestCase(test.TestCase): self.assertListEqual([], pools) mock_get_ssc.assert_called_once_with() - @ddt.data('open+|demix+', 'open.+', '.+\d', '^((?!mix+).)*$', + @ddt.data(r'open+|demix+', 'open.+', r'.+\d', '^((?!mix+).)*$', 'open123, open321') def test_get_pool_map_match_selected_pools(self, patterns): diff --git a/cinder/tests/unit/volume/drivers/netapp/eseries/test_library.py b/cinder/tests/unit/volume/drivers/netapp/eseries/test_library.py index a793e221d..52789c9e2 100644 --- a/cinder/tests/unit/volume/drivers/netapp/eseries/test_library.py +++ b/cinder/tests/unit/volume/drivers/netapp/eseries/test_library.py @@ -260,7 +260,7 @@ class NetAppEseriesLibraryTestCase(test.TestCase): self.assertEqual(eseries_fake.STORAGE_POOLS, filtered_pools) - @ddt.data(('[\d]+,a', ['1', '2', 'a', 'b'], ['1', '2', 'a']), + @ddt.data((r'[\d]+,a', ['1', '2', 'a', 'b'], ['1', '2', 'a']), ('1 , 3', ['1', '2', '3'], ['1', '3']), ('$,3', ['1', '2', '3'], ['3']), ('[a-zA-Z]+', ['1', 'a', 'B'], ['a', 'B']), diff --git a/cinder/tests/unit/volume/drivers/test_rbd.py b/cinder/tests/unit/volume/drivers/test_rbd.py index c69f41427..cadb9faa9 100644 --- a/cinder/tests/unit/volume/drivers/test_rbd.py +++ b/cinder/tests/unit/volume/drivers/test_rbd.py @@ -106,7 +106,7 @@ def common_mocks(f): return _common_inner_inner1 -CEPH_MON_DUMP = """dumped monmap epoch 1 +CEPH_MON_DUMP = r"""dumped monmap epoch 1 { "epoch": 1, "fsid": "33630410-6d93-4d66-8e42-3b953cf194aa", "modified": "2013-05-22 17:44:56.343618", diff --git a/cinder/tests/unit/windows/test_smbfs.py b/cinder/tests/unit/windows/test_smbfs.py index aedefcf39..23ad206a2 100644 --- a/cinder/tests/unit/windows/test_smbfs.py +++ b/cinder/tests/unit/windows/test_smbfs.py @@ -35,7 +35,7 @@ class WindowsSmbFsTestCase(test.TestCase): _FAKE_SHARE = '//1.2.3.4/share1' _FAKE_SHARE_HASH = 'db0bf952c1734092b83e8990bd321131' - _FAKE_MNT_BASE = 'c:\openstack\mnt' + _FAKE_MNT_BASE = r'c:\openstack\mnt' _FAKE_MNT_POINT = os.path.join(_FAKE_MNT_BASE, _FAKE_SHARE_HASH) _FAKE_VOLUME_ID = '4f711859-4928-4cb7-801a-a50c37ceaccc' _FAKE_VOLUME_NAME = 'volume-%s.vhdx' % _FAKE_VOLUME_ID diff --git a/cinder/utils.py b/cinder/utils.py index c24b1fddf..0b18662fd 100644 --- a/cinder/utils.py +++ b/cinder/utils.py @@ -350,8 +350,8 @@ def sanitize_hostname(hostname): if isinstance(hostname, six.text_type): hostname = hostname.encode('latin-1', 'ignore') - hostname = re.sub('[ _]', '-', hostname) - hostname = re.sub('[^\w.-]+', '', hostname) + hostname = re.sub(r'[ _]', '-', hostname) + hostname = re.sub(r'[^\w.-]+', '', hostname) hostname = hostname.lower() hostname = hostname.strip('.-') @@ -581,7 +581,7 @@ def _get_disk_of_partition(devpath, st=None): for '/dev/disk1p1' ('p' is prepended to the partition number if the disk name ends with numbers). """ - diskpath = re.sub('(?:(?<=\d)p)?\d+$', '', devpath) + diskpath = re.sub(r'(?:(?<=\d)p)?\d+$', '', devpath) if diskpath != devpath: try: st_disk = os.stat(diskpath) diff --git a/cinder/volume/drivers/dell_emc/scaleio/driver.py b/cinder/volume/drivers/dell_emc/scaleio/driver.py index e5ea1660d..a60ee6450 100644 --- a/cinder/volume/drivers/dell_emc/scaleio/driver.py +++ b/cinder/volume/drivers/dell_emc/scaleio/driver.py @@ -694,7 +694,7 @@ class ScaleIODriver(driver.VolumeDriver): raise exception.VolumeBackendAPIException(data=msg) # make sure the response was valid - pattern = re.compile("^\d+(\.\d+)*$") + pattern = re.compile(r"^\d+(\.\d+)*$") if not pattern.match(self.server_api_version): msg = (_("Error calling version api " "response: %s") % r.text) diff --git a/cinder/volume/drivers/hitachi/hbsd_common.py b/cinder/volume/drivers/hitachi/hbsd_common.py index f49886293..95809b784 100644 --- a/cinder/volume/drivers/hitachi/hbsd_common.py +++ b/cinder/volume/drivers/hitachi/hbsd_common.py @@ -228,7 +228,7 @@ class HBSDCommon(object): first_type = 'dig' else: if (first_type == 'dig' - or not re.match('\w\w:\w\w:\w\w', lists[i])): + or not re.match(r'\w\w:\w\w:\w\w', lists[i])): msg = basic_lib.output_err(601, param=param) raise exception.HBSDError(message=msg) try: diff --git a/cinder/volume/drivers/hitachi/hbsd_snm2.py b/cinder/volume/drivers/hitachi/hbsd_snm2.py index e1b54ef04..14a990579 100644 --- a/cinder/volume/drivers/hitachi/hbsd_snm2.py +++ b/cinder/volume/drivers/hitachi/hbsd_snm2.py @@ -116,7 +116,7 @@ class HBSDSNM2(basic_lib.HBSDBasicLib): def get_comm_version(self): ret, stdout, stderr = self.exec_hsnm('auman', '-help') - m = re.search('Version (\d+).(\d+)', stdout) + m = re.search(r'Version (\d+).(\d+)', stdout) if not m: msg = basic_lib.output_err( 600, cmd='auman', ret=ret, out=stdout, err=stderr) @@ -958,8 +958,8 @@ class HBSDSNM2(basic_lib.HBSDBasicLib): lines = stdout.splitlines() for line in lines[2:]: - tc_cc = re.search('\s(\d+\.\d) GB\s+(\d+\.\d) GB\s', line) - pool_tmp = re.match('\s*\d+', line) + tc_cc = re.search(r'\s(\d+\.\d) GB\s+(\d+\.\d) GB\s', line) + pool_tmp = re.match(r'\s*\d+', line) if (pool_tmp and tc_cc and int(pool_tmp.group(0)) == pool_id): total_gb = int(float(tc_cc.group(1))) @@ -1047,10 +1047,10 @@ class HBSDSNM2(basic_lib.HBSDBasicLib): def trans_status_hsnm2raid(self, str): status = None - obj = re.search('Split\((.*)%\)', str) + obj = re.search(r'Split\((.*)%\)', str) if obj: status = basic_lib.PSUS - obj = re.search('Paired\((.*)%\)', str) + obj = re.search(r'Paired\((.*)%\)', str) if obj: status = basic_lib.PAIR return status diff --git a/cinder/volume/drivers/hpe/hpe_lefthand_iscsi.py b/cinder/volume/drivers/hpe/hpe_lefthand_iscsi.py index c76ffd3ea..bd986fef6 100644 --- a/cinder/volume/drivers/hpe/hpe_lefthand_iscsi.py +++ b/cinder/volume/drivers/hpe/hpe_lefthand_iscsi.py @@ -1731,7 +1731,7 @@ class HPELeftHandISCSIDriver(driver.ISCSIDriver): schedule = ''.join(schedule) # We need to check the status of the schedule to make sure # it is not paused. - result = re.search(".*paused\s+(\w+)", schedule) + result = re.search(r".*paused\s+(\w+)", schedule) is_schedule_active = result.group(1) == 'false' volume_info = cl.getVolumeByName(volume['name']) diff --git a/cinder/volume/drivers/ibm/flashsystem_common.py b/cinder/volume/drivers/ibm/flashsystem_common.py index 84b7cc7bb..c37d4d4f5 100644 --- a/cinder/volume/drivers/ibm/flashsystem_common.py +++ b/cinder/volume/drivers/ibm/flashsystem_common.py @@ -304,7 +304,7 @@ class FlashSystemDriver(san.SanDriver, # Ensure that the output is as expected match_obj = re.search( - 'Virtual Disk, id \[([0-9]+)\], successfully created', out) + r'Virtual Disk, id \[([0-9]+)\], successfully created', out) self._driver_assert( match_obj is not None, diff --git a/cinder/volume/drivers/ibm/ibm_storage/ibm_storage.py b/cinder/volume/drivers/ibm/ibm_storage/ibm_storage.py index 89fb7422c..2fb80a582 100644 --- a/cinder/volume/drivers/ibm/ibm_storage/ibm_storage.py +++ b/cinder/volume/drivers/ibm/ibm_storage/ibm_storage.py @@ -75,7 +75,7 @@ class IBMStorageDriver(san.SanDriver, 2.0 - First open source driver version 2.1.0 - Support Consistency groups through Generic volume groups - - Support XIV\A9000 Volume independent QoS + - Support XIV/A9000 Volume independent QoS - Support Consistency groups replication """ diff --git a/cinder/volume/drivers/ibm/ibm_storage/xiv_proxy.py b/cinder/volume/drivers/ibm/ibm_storage/xiv_proxy.py index 88c06ba82..98b7324ca 100644 --- a/cinder/volume/drivers/ibm/ibm_storage/xiv_proxy.py +++ b/cinder/volume/drivers/ibm/ibm_storage/xiv_proxy.py @@ -116,7 +116,7 @@ class XIVProxy(proxy.IBMStorageProxy): 2.0 - First open source driver version 2.1.0 - Support Consistency groups through Generic volume groups - - Support XIV\A9000 Volume independent QoS + - Support XIV/A9000 Volume independent QoS """ async_rates = ( diff --git a/cinder/volume/drivers/netapp/dataontap/nfs_base.py b/cinder/volume/drivers/netapp/dataontap/nfs_base.py index 05970fb6d..4ea22b8c1 100644 --- a/cinder/volume/drivers/netapp/dataontap/nfs_base.py +++ b/cinder/volume/drivers/netapp/dataontap/nfs_base.py @@ -704,8 +704,8 @@ class NetAppNfsDriver(driver.ManageableVD, conn, dr = None, None if image_location: nfs_loc_pattern = \ - ('^nfs://(([\w\-\.]+:{1}[\d]+|[\w\-\.]+)(/[^\/].*)' - '*(/[^\/\\\\]+)$)') + (r'^nfs://(([\w\-\.]+:{1}[\d]+|[\w\-\.]+)(/[^\/].*)' + r'*(/[^\/\\\\]+)$)') matched = re.match(nfs_loc_pattern, image_location, flags=0) if not matched: LOG.debug('Image location not in the' diff --git a/cinder/volume/drivers/netapp/dataontap/utils/capabilities.py b/cinder/volume/drivers/netapp/dataontap/utils/capabilities.py index c13f05cd9..34373cb47 100644 --- a/cinder/volume/drivers/netapp/dataontap/utils/capabilities.py +++ b/cinder/volume/drivers/netapp/dataontap/utils/capabilities.py @@ -279,9 +279,9 @@ class CapabilitiesLibrary(object): for key, value in extra_specs.items(): if isinstance(value, six.string_types): - if re.match('\s+True', value, re.I): + if re.match(r'\s+True', value, re.I): modified_extra_specs[key] = True - elif re.match('\s+False', value, re.I): + elif re.match(r'\s+False', value, re.I): modified_extra_specs[key] = False return modified_extra_specs diff --git a/cinder/volume/drivers/tintri.py b/cinder/volume/drivers/tintri.py index a207042a1..5a00a87d3 100644 --- a/cinder/volume/drivers/tintri.py +++ b/cinder/volume/drivers/tintri.py @@ -592,7 +592,7 @@ class TintriDriver(driver.ManageableVD, conn, dr = None, None if image_location: nfs_loc_pattern = \ - '^nfs://(([\w\-\.]+:[\d]+|[\w\-\.]+)(/[^/].*)*(/[^/\\\\]+))$' + r'^nfs://(([\w\-\.]+:[\d]+|[\w\-\.]+)(/[^/].*)*(/[^/\\\\]+))$' matched = re.match(nfs_loc_pattern, image_location) if not matched: LOG.debug('Image location not in the expected format %s', diff --git a/cinder/volume/drivers/vzstorage.py b/cinder/volume/drivers/vzstorage.py index fecccb7e4..4e628cdf3 100644 --- a/cinder/volume/drivers/vzstorage.py +++ b/cinder/volume/drivers/vzstorage.py @@ -131,7 +131,7 @@ class PloopDevice(object): out, err = self.execute(*cmd, run_as_root=True) - m = re.search('dev=(\S+)', out) + m = re.search(r'dev=(\S+)', out) if not m: raise Exception('Invalid output from ploop mount: %s' % out) diff --git a/cinder/volume/drivers/windows/windows.py b/cinder/volume/drivers/windows/windows.py index 001252e16..08643e4d4 100644 --- a/cinder/volume/drivers/windows/windows.py +++ b/cinder/volume/drivers/windows/windows.py @@ -38,7 +38,7 @@ LOG = logging.getLogger(__name__) windows_opts = [ cfg.StrOpt('windows_iscsi_lun_path', - default='C:\iSCSIVirtualDisks', + default=r'C:\iSCSIVirtualDisks', help='Path to store VHD backed volumes'), ] diff --git a/cinder/volume/targets/iet.py b/cinder/volume/targets/iet.py index 2bff2ac88..b98cffe64 100644 --- a/cinder/volume/targets/iet.py +++ b/cinder/volume/targets/iet.py @@ -55,7 +55,7 @@ class IetAdm(iscsi.ISCSITarget): session_list = re.split('^tid:(?m)', sessions)[1:] for ses in session_list: - m = re.match('(\d+) name:(\S+)\s+', ses) + m = re.match(r'(\d+) name:(\S+)\s+', ses) if m and iqn in m.group(2): return m.group(1) @@ -206,7 +206,7 @@ class IetAdm(iscsi.ISCSITarget): session_list = re.split('^tid:(?m)', sessions)[1:] for ses in session_list: - m = re.match('(\d+) name:(\S+)\s+sid:(\d+).+\s+cid:(\d+)', ses) + m = re.match(r'(\d+) name:(\S+)\s+sid:(\d+).+\s+cid:(\d+)', ses) if m and tid in m.group(1) and name in m.group(2): return m.group(3), m.group(4) diff --git a/cinder/zonemanager/drivers/brocade/brcd_fc_zone_client_cli.py b/cinder/zonemanager/drivers/brocade/brcd_fc_zone_client_cli.py index 884aa509d..14f88f6c3 100644 --- a/cinder/zonemanager/drivers/brocade/brcd_fc_zone_client_cli.py +++ b/cinder/zonemanager/drivers/brocade/brcd_fc_zone_client_cli.py @@ -43,7 +43,7 @@ class BrcdFCZoneClientCLI(object): switch_user = 'admin' switch_pwd = 'none' switch_key = 'none' - patrn = re.compile('[;\s]+') + patrn = re.compile(r'[;\s]+') def __init__(self, ipaddress, username, password, port, key): diff --git a/cinder/zonemanager/drivers/cisco/cisco_fc_zone_client_cli.py b/cinder/zonemanager/drivers/cisco/cisco_fc_zone_client_cli.py index cdde33272..2afecd8b7 100644 --- a/cinder/zonemanager/drivers/cisco/cisco_fc_zone_client_cli.py +++ b/cinder/zonemanager/drivers/cisco/cisco_fc_zone_client_cli.py @@ -95,7 +95,7 @@ class CiscoFCZoneClientCLI(object): try: for line in switch_data: # Split on non-word characters, - line_split = re.split('[\s\[\]]+', line) + line_split = re.split(r'[\s\[\]]+', line) if ZoneConstant.CFG_ZONESET in line_split: # zoneset name [name] vsan [vsan] zone_set_name = \ @@ -291,7 +291,7 @@ class CiscoFCZoneClientCLI(object): try: for line in switch_data: # Split on non-word characters, - line_split = re.split('[\s\[\]]+', line) + line_split = re.split(r'[\s\[\]]+', line) if 'mode:' in line_split: # mode: zone_status['mode'] = line_split[line_split.index('mode:')