From 09654af5180942dc73fe9732331ad9f4aae2d3d2 Mon Sep 17 00:00:00 2001 From: Sean McGinnis Date: Wed, 20 Jun 2018 16:00:16 -0500 Subject: [PATCH] Fix invalid escape sequence warnings There are a lot of DeprecationWarning message emited when running under python 3.6 due mostly to non-raw strings being used for regex expressions. DeprecationWarning: invalid escape sequence \ These had previously been ignored, but starting with python 3.6, and the commit for issue 27364, these are now considered deprecated and will no longer be supported going forward. Per the discussion on that issue, these strings should really be raw strings any way: https://bugs.python.org/issue27364#msg272696 Change-Id: If6ff206e4bbcf10ab52d2895f606dafad2936ddb --- cinder/hacking/checks.py | 2 +- cinder/tests/unit/volume/drivers/test_rbd.py | 2 +- cinder/tests/unit/volume/drivers/test_remotefs.py | 2 +- cinder/tests/unit/volume/drivers/test_storpool.py | 2 +- .../tests/unit/volume/drivers/vmware/test_vmware_datastore.py | 2 +- cinder/volume/driver.py | 2 +- cinder/volume/drivers/dell_emc/vmax/utils.py | 2 +- cinder/volume/drivers/nec/cli.py | 2 +- cinder/volume/drivers/netapp/utils.py | 2 +- cinder/volume/drivers/windows/smbfs.py | 2 +- cinder/volume/utils.py | 4 ++-- 11 files changed, 12 insertions(+), 12 deletions(-) diff --git a/cinder/hacking/checks.py b/cinder/hacking/checks.py index 8b9626fd8af..0443b24ec4d 100644 --- a/cinder/hacking/checks.py +++ b/cinder/hacking/checks.py @@ -38,7 +38,7 @@ UNDERSCORE_IMPORT_FILES = ['cinder/objects/__init__.py', mutable_default_args = re.compile(r"^\s*def .+\((.+=\{\}|.+=\[\])") translated_log = re.compile( r"(.)*LOG\.(audit|debug|error|info|warn|warning|critical|exception)" - "\(\s*_\(\s*('|\")") + r"\(\s*_\(\s*('|\")") string_translation = re.compile(r"(.)*_\(\s*('|\")") vi_header_re = re.compile(r"^#\s+vim?:.+") underscore_import_check = re.compile(r"(.)*i18n\s+import(.)* _$") diff --git a/cinder/tests/unit/volume/drivers/test_rbd.py b/cinder/tests/unit/volume/drivers/test_rbd.py index 35b6ba71e5d..3d9ad79dd15 100644 --- a/cinder/tests/unit/volume/drivers/test_rbd.py +++ b/cinder/tests/unit/volume/drivers/test_rbd.py @@ -587,7 +587,7 @@ class RBDTestCase(test.TestCase): 8 * units.Gi] mock_get_image_status.side_effect = [ {'watchers': []}, - {'watchers': [{"address": "192.168.120.61:0\/3012034728", + {'watchers': [{"address": "192.168.120.61:0/3012034728", "client": 44431941, "cookie": 94077162321152}]}, {'watchers': []}] res = self.driver.get_manageable_volumes( diff --git a/cinder/tests/unit/volume/drivers/test_remotefs.py b/cinder/tests/unit/volume/drivers/test_remotefs.py index 38c5645905c..5031ab25795 100644 --- a/cinder/tests/unit/volume/drivers/test_remotefs.py +++ b/cinder/tests/unit/volume/drivers/test_remotefs.py @@ -1115,7 +1115,7 @@ class RemoteFSManageableVolumesTestCase(test.TestCase): Exception, mock.sentinel.managed_volume] - self._driver._MANAGEABLE_IMAGE_RE = re.compile('.*\.(?:vhdx)$') + self._driver._MANAGEABLE_IMAGE_RE = re.compile(r'.*\.(?:vhdx)$') managed_volumes = {'volume-1': mock.sentinel.vol1} diff --git a/cinder/tests/unit/volume/drivers/test_storpool.py b/cinder/tests/unit/volume/drivers/test_storpool.py index 60373cc6d39..5dc89122666 100644 --- a/cinder/tests/unit/volume/drivers/test_storpool.py +++ b/cinder/tests/unit/volume/drivers/test_storpool.py @@ -238,7 +238,7 @@ class StorPoolTestCase(test.TestCase): self.assertEqual('storpool', stats['storage_protocol']) self.assertListEqual(['default', 'template_hdd', 'template_ssd'], sorted([p['pool_name'] for p in stats['pools']])) - r = re.compile('^template_([A-Za-z0-9_]+)$') + r = re.compile(r'^template_([A-Za-z0-9_]+)$') for pool in stats['pools']: self.assertEqual(21, pool['total_capacity_gb']) self.assertEqual(5, int(pool['free_capacity_gb'])) diff --git a/cinder/tests/unit/volume/drivers/vmware/test_vmware_datastore.py b/cinder/tests/unit/volume/drivers/vmware/test_vmware_datastore.py index 30b455311f9..c001991526b 100644 --- a/cinder/tests/unit/volume/drivers/vmware/test_vmware_datastore.py +++ b/cinder/tests/unit/volume/drivers/vmware/test_vmware_datastore.py @@ -170,7 +170,7 @@ class DatastoreTest(test.TestCase): ds1a: ds1a_props, ds1b: ds1b_props} profile_id = mock.sentinel.profile_id - self._ds_sel._ds_regex = re.compile("ds-[1-9a]{1,2}$") + self._ds_sel._ds_regex = re.compile(r"ds-[1-9a]{1,2}$") datastores = self._ds_sel._filter_datastores( datastores, 512, diff --git a/cinder/volume/driver.py b/cinder/volume/driver.py index 5ef36ad4808..7f73317e314 100644 --- a/cinder/volume/driver.py +++ b/cinder/volume/driver.py @@ -165,7 +165,7 @@ volume_opts = [ 'storage if the driver supports it.'), cfg.StrOpt('max_over_subscription_ratio', default='20.0', - regex='^(auto|\d*\.\d+|\d+)$', + regex=r'^(auto|\d*\.\d+|\d+)$', help='Representation of the over subscription ratio ' 'when thin provisioning is enabled. Default ratio is ' '20.0, meaning provisioned capacity can be 20 times of ' diff --git a/cinder/volume/drivers/dell_emc/vmax/utils.py b/cinder/volume/drivers/dell_emc/vmax/utils.py index f2a39955016..98bf89a8f91 100644 --- a/cinder/volume/drivers/dell_emc/vmax/utils.py +++ b/cinder/volume/drivers/dell_emc/vmax/utils.py @@ -218,7 +218,7 @@ class VMAXUtils(object): """ element_name = volume_id uuid_regex = (re.compile( - '[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}', + r'[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}', re.I)) match = uuid_regex.search(volume_id) if match: diff --git a/cinder/volume/drivers/nec/cli.py b/cinder/volume/drivers/nec/cli.py index 1856eb16160..e457df5480d 100644 --- a/cinder/volume/drivers/nec/cli.py +++ b/cinder/volume/drivers/nec/cli.py @@ -188,7 +188,7 @@ class MStorageISMCLI(object): else: out, err, status = self._execute_nolock(command) - exstats = re.compile("(.*)ExitStatus(.*)\n") + exstats = re.compile(r"(.*)ExitStatus(.*)\n") tmpout = exstats.sub('', out) out = tmpout if conf_ismview_path is not None: diff --git a/cinder/volume/drivers/netapp/utils.py b/cinder/volume/drivers/netapp/utils.py index 38be5df238b..61bb5ed78d3 100644 --- a/cinder/volume/drivers/netapp/utils.py +++ b/cinder/volume/drivers/netapp/utils.py @@ -263,7 +263,7 @@ def get_pool_name_filter_regex(configuration): # If the configuration parameter is specified as an empty string # (interpreted as matching all pools), we replace it here with # (.+) to be explicit with CSV compatibility support implemented below. - pool_patterns = configuration.netapp_pool_name_search_pattern or '(.+)' + pool_patterns = configuration.netapp_pool_name_search_pattern or r'(.+)' # Strip whitespace from start/end and then 'or' all regex patterns pool_patterns = '|'.join(['^' + pool_pattern.strip('^$ \t') + '$' for diff --git a/cinder/volume/drivers/windows/smbfs.py b/cinder/volume/drivers/windows/smbfs.py index ff83a47cef7..e796719029c 100644 --- a/cinder/volume/drivers/windows/smbfs.py +++ b/cinder/volume/drivers/windows/smbfs.py @@ -91,7 +91,7 @@ class WindowsSmbfsDriver(remotefs_drv.RevertToSnapshotMixin, _DISK_FORMAT_VHDX] _VALID_IMAGE_EXTENSIONS = [_DISK_FORMAT_VHD, _DISK_FORMAT_VHDX] _MANAGEABLE_IMAGE_RE = re.compile( - '.*\.(?:%s)$' % '|'.join(_VALID_IMAGE_EXTENSIONS), + r'.*\.(?:%s)$' % '|'.join(_VALID_IMAGE_EXTENSIONS), re.IGNORECASE) _always_use_temp_snap_when_cloning = False diff --git a/cinder/volume/utils.py b/cinder/volume/utils.py index 29c64ef57f6..db5aef628bf 100644 --- a/cinder/volume/utils.py +++ b/cinder/volume/utils.py @@ -790,7 +790,7 @@ def read_proc_mounts(): def extract_id_from_volume_name(vol_name): regex = re.compile( - CONF.volume_name_template.replace('%s', '(?P.+)')) + CONF.volume_name_template.replace('%s', r'(?P.+)')) match = regex.match(vol_name) return match.group('uuid') if match else None @@ -813,7 +813,7 @@ def check_already_managed_volume(vol_id): def extract_id_from_snapshot_name(snap_name): """Return a snapshot's ID from its name on the backend.""" regex = re.compile( - CONF.snapshot_name_template.replace('%s', '(?P.+)')) + CONF.snapshot_name_template.replace('%s', r'(?P.+)')) match = regex.match(snap_name) return match.group('uuid') if match else None