diff --git a/manila/exception.py b/manila/exception.py index 1f2cd20f47..2b0a9cd382 100644 --- a/manila/exception.py +++ b/manila/exception.py @@ -103,7 +103,7 @@ class ManilaException(Exception): elif isinstance(message, Exception): message = six.text_type(message) - if re.match('.*[^\.]\.\.$', message): + if re.match(r'.*[^\.]\.\.$', message): message = message[:-1] self.msg = message super(ManilaException, self).__init__(message) diff --git a/manila/network/linux/ovs_lib.py b/manila/network/linux/ovs_lib.py index a6ee77198a..e64d3fb6d9 100644 --- a/manila/network/linux/ovs_lib.py +++ b/manila/network/linux/ovs_lib.py @@ -28,16 +28,16 @@ class OVSBridge(object): self.re_id = self.re_compile_id() def re_compile_id(self): - external = 'external_ids\s*' - mac = 'attached-mac="(?P([a-fA-F\d]{2}:){5}([a-fA-F\d]{2}))"' - iface = 'iface-id="(?P[^"]+)"' - name = 'name\s*:\s"(?P[^"]*)"' - port = 'ofport\s*:\s(?P-?\d+)' - _re = ('%(external)s:\s{ ( %(mac)s,? | %(iface)s,? | . )* }' - ' \s+ %(name)s \s+ %(port)s' % {'external': external, - 'mac': mac, - 'iface': iface, 'name': name, - 'port': port}) + external = r'external_ids\s*' + mac = r'attached-mac="(?P([a-fA-F\d]{2}:){5}([a-fA-F\d]{2}))"' + iface = r'iface-id="(?P[^"]+)"' + name = r'name\s*:\s"(?P[^"]*)"' + port = r'ofport\s*:\s(?P-?\d+)' + _re = (r'%(external)s:\s{ ( %(mac)s,? | %(iface)s,? | . )* }' + r' \s+ %(name)s \s+ %(port)s' % {'external': external, + 'mac': mac, + 'iface': iface, 'name': name, + 'port': port}) return re.compile(_re, re.M | re.X) def run_vsctl(self, args): diff --git a/manila/share/drivers/container/storage_helper.py b/manila/share/drivers/container/storage_helper.py index 8ebafbb93b..0df3bb2220 100644 --- a/manila/share/drivers/container/storage_helper.py +++ b/manila/share/drivers/container/storage_helper.py @@ -63,7 +63,7 @@ class LVMHelper(driver.ExecuteMixin): msg % {'vg': self.configuration.container_volume_group, 'err': err}) - (free_size, total_size) = sorted(re.findall("\d+\.\d+|\d+", out), + (free_size, total_size) = sorted(re.findall(r"\d+\.\d+|\d+", out), reverse=False) return [{ 'pool_name': self.configuration.container_volume_group, diff --git a/manila/share/drivers/dell_emc/plugins/powermax/object_manager.py b/manila/share/drivers/dell_emc/plugins/powermax/object_manager.py index 527f5e8d53..355efffca0 100644 --- a/manila/share/drivers/dell_emc/plugins/powermax/object_manager.py +++ b/manila/share/drivers/dell_emc/plugins/powermax/object_manager.py @@ -837,9 +837,9 @@ class Mover(StorageObject): out, err = self._execute_cmd(cmd_sysconfig) - re_pattern = ('0:\s*(?P\S+)\s*IRQ:\s*(?P\d+)\n' - '.*\n' - '\s*Link:\s*(?P[A-Za-z]+)') + re_pattern = (r'0:\s*(?P\S+)\s*IRQ:\s*(?P\d+)\n' + r'.*\n' + r'\s*Link:\s*(?P[A-Za-z]+)') for device in re.finditer(re_pattern, out): if 'Up' in device.group('link'): @@ -995,8 +995,8 @@ class VDM(StorageObject): 'nfs': [], } - re_pattern = ('Interfaces to services mapping:' - '\s*(?P(\s*interface=.*)*)') + re_pattern = (r'Interfaces to services mapping:' + r'\s*(?P(\s*interface=.*)*)') command_get_interfaces = [ 'env', 'NAS_DB=/nas', '/nas/bin/nas_server', @@ -1010,8 +1010,8 @@ class VDM(StorageObject): if m: if_list = m.group('interfaces').split('\n') for i in if_list: - m_if = re.search('\s*interface=(?P.*)\s*:' - '\s*(?P.*)\s*', i) + m_if = re.search(r'\s*interface=(?P.*)\s*:' + r'\s*(?P.*)\s*', i) if m_if: if_name = m_if.group('if').strip() if 'cifs' == m_if.group('type') and if_name != '': @@ -1863,7 +1863,7 @@ class NFSShare(StorageObject): LOG.exception(message) raise exception.EMCPowerMaxXMLAPIError(err=message) - re_exports = '%s\s*:\s*\nexport\s*(.*)\n' % mover_name + re_exports = r'%s\s*:\s*\nexport\s*(.*)\n' % mover_name m = re.search(re_exports, out) if m is not None: nfs_share['path'] = path diff --git a/manila/share/drivers/dell_emc/plugins/vnx/object_manager.py b/manila/share/drivers/dell_emc/plugins/vnx/object_manager.py index 1411dd2d4c..0f7cc879cc 100644 --- a/manila/share/drivers/dell_emc/plugins/vnx/object_manager.py +++ b/manila/share/drivers/dell_emc/plugins/vnx/object_manager.py @@ -836,9 +836,9 @@ class Mover(StorageObject): out, err = self._execute_cmd(cmd_sysconfig) - re_pattern = ('0:\s*(?P\S+)\s*IRQ:\s*(?P\d+)\n' - '.*\n' - '\s*Link:\s*(?P[A-Za-z]+)') + re_pattern = (r'0:\s*(?P\S+)\s*IRQ:\s*(?P\d+)\n' + r'.*\n' + r'\s*Link:\s*(?P[A-Za-z]+)') for device in re.finditer(re_pattern, out): if 'Up' in device.group('link'): @@ -994,8 +994,8 @@ class VDM(StorageObject): 'nfs': [], } - re_pattern = ('Interfaces to services mapping:' - '\s*(?P(\s*interface=.*)*)') + re_pattern = (r'Interfaces to services mapping:' + r'\s*(?P(\s*interface=.*)*)') command_get_interfaces = [ 'env', 'NAS_DB=/nas', '/nas/bin/nas_server', @@ -1009,8 +1009,8 @@ class VDM(StorageObject): if m: if_list = m.group('interfaces').split('\n') for i in if_list: - m_if = re.search('\s*interface=(?P.*)\s*:' - '\s*(?P.*)\s*', i) + m_if = re.search(r'\s*interface=(?P.*)\s*:' + r'\s*(?P.*)\s*', i) if m_if: if_name = m_if.group('if').strip() if 'cifs' == m_if.group('type') and if_name != '': @@ -1865,7 +1865,7 @@ class NFSShare(StorageObject): LOG.error(message) raise exception.EMCVnxXMLAPIError(err=message) - re_exports = '%s\s*:\s*\nexport\s*(.*)\n' % mover_name + re_exports = r'%s\s*:\s*\nexport\s*(.*)\n' % mover_name m = re.search(re_exports, out) if m is not None: nfs_share['path'] = path diff --git a/manila/share/drivers/ganesha/__init__.py b/manila/share/drivers/ganesha/__init__.py index 1a8127b126..03b87ce438 100644 --- a/manila/share/drivers/ganesha/__init__.py +++ b/manila/share/drivers/ganesha/__init__.py @@ -67,7 +67,7 @@ class GaneshaNASHelper(NASHelperBase): super(GaneshaNASHelper, self).__init__(execute, config, **kwargs) self.tag = tag - _confrx = re.compile('\.(conf|json)\Z') + _confrx = re.compile(r'\.(conf|json)\Z') def _load_conf_dir(self, dirpath, must_exist=True): """Load Ganesha config files in dirpath in alphabetic order.""" diff --git a/manila/share/drivers/glusterfs/__init__.py b/manila/share/drivers/glusterfs/__init__.py index 5f7140bd8f..883914e0c0 100644 --- a/manila/share/drivers/glusterfs/__init__.py +++ b/manila/share/drivers/glusterfs/__init__.py @@ -182,7 +182,7 @@ class GlusterNFSHelper(ganesha.NASHelperBase): edl = export_dir.split(',') # parsing export_dir into a dict of {dir: [hostpec,..]..} # format - r = re.compile('\A/(.*)\((.*)\)\Z') + r = re.compile(r'\A/(.*)\((.*)\)\Z') for ed in edl: d, e = r.match(ed).groups() edh[d] = e.split('|') diff --git a/manila/share/drivers/glusterfs/common.py b/manila/share/drivers/glusterfs/common.py index 008c4047bc..c9e544f64a 100644 --- a/manila/share/drivers/glusterfs/common.py +++ b/manila/share/drivers/glusterfs/common.py @@ -77,9 +77,9 @@ def volxml_get(xmlout, *paths, **kwargs): class GlusterManager(object): """Interface with a GlusterFS volume.""" - scheme = re.compile('\A(?:(?P[^:@/]+)@)?' - '(?P[^:@/]+)' - '(?::/(?P[^/]+)(?P/.*)?)?\Z') + scheme = re.compile(r'\A(?:(?P[^:@/]+)@)?' + r'(?P[^:@/]+)' + r'(?::/(?P[^/]+)(?P/.*)?)?\Z') # See this about GlusterFS' convention for Boolean interpretation # of strings: @@ -298,7 +298,7 @@ class GlusterManager(object): def get_vol_option(self, option, boolean=False): """Get the value of an option set on a GlusterFS volume.""" - useropt = re.sub('\Auser\.', '', option) + useropt = re.sub(r'\Auser\.', '', option) if option == useropt: value = self._get_vol_regular_option(option) else: diff --git a/manila/share/drivers/glusterfs/glusterfs_native.py b/manila/share/drivers/glusterfs/glusterfs_native.py index 90675992af..3b4782237f 100644 --- a/manila/share/drivers/glusterfs/glusterfs_native.py +++ b/manila/share/drivers/glusterfs/glusterfs_native.py @@ -115,10 +115,10 @@ class GlusterfsNativeShareDriver(driver.ExecuteMixin, # xlators/protocol/auth/login/src/login.c#L80 # until end of gf_auth() function old_access_list = re.split('[ ,]', ssl_allow_opt) - glusterfs_server_CN_pattern = '\Aglusterfs-server' - manila_host_CN_pattern = '\Amanila-host' + glusterfs_server_CN_pattern = r'\Aglusterfs-server' + manila_host_CN_pattern = r'\Amanila-host' regex = re.compile( - '%(pattern1)s|%(pattern2)s' % { + r'%(pattern1)s|%(pattern2)s' % { 'pattern1': glusterfs_server_CN_pattern, 'pattern2': manila_host_CN_pattern}) access_to = ','.join(filter(regex.match, old_access_list)) diff --git a/manila/share/drivers/helpers.py b/manila/share/drivers/helpers.py index 8ae0468807..bdf6a9b342 100644 --- a/manila/share/drivers/helpers.py +++ b/manila/share/drivers/helpers.py @@ -286,7 +286,7 @@ class NFSHelper(NASHelperBase): access_to = self._get_parsed_address_or_cidr( access['access_to']) found_item = re.search( - re.escape(local_path) + '[\s\n]*' + re.escape(access_to), + re.escape(local_path) + r'[\s\n]*' + re.escape(access_to), out) if found_item is not None: LOG.warning("Access rule %(type)s:%(to)s already " diff --git a/manila/share/drivers/hitachi/hnas/driver.py b/manila/share/drivers/hitachi/hnas/driver.py index 8a15b45b50..8c59f69bc7 100644 --- a/manila/share/drivers/hitachi/hnas/driver.py +++ b/manila/share/drivers/hitachi/hnas/driver.py @@ -310,7 +310,7 @@ class HitachiHNASDriver(driver.ShareDriver): is_snapshot=is_snapshot) def create_share(self, context, share, share_server=None): - """Creates share. + r"""Creates share. :param context: The `context.RequestContext` object for the request :param share: Share that will be created. @@ -449,7 +449,7 @@ class HitachiHNASDriver(driver.ShareDriver): def create_share_from_snapshot(self, context, share, snapshot, share_server=None): - """Creates a new share from snapshot. + r"""Creates a new share from snapshot. :param context: The `context.RequestContext` object for the request :param share: Information about the new share. @@ -521,7 +521,7 @@ class HitachiHNASDriver(driver.ShareDriver): return export_list def ensure_share(self, context, share, share_server=None): - """Ensure that share is exported. + r"""Ensure that share is exported. :param context: The `context.RequestContext` object for the request :param share: Share that will be checked. @@ -646,7 +646,7 @@ class HitachiHNASDriver(driver.ShareDriver): super(HitachiHNASDriver, self)._update_share_stats(data) def manage_existing(self, share, driver_options): - """Manages a share that exists on backend. + r"""Manages a share that exists on backend. :param share: Share that will be managed. :param driver_options: Empty dict or dict with 'volume_id' option. @@ -1168,7 +1168,7 @@ class HitachiHNASDriver(driver.ShareDriver): return export_list def _get_export_path(self, ip, share_proto, hnas_id, is_snapshot): - """Gets and returns export path. + r"""Gets and returns export path. :param ip: IP from HNAS EVS configured. :param share_proto: Share or snapshot protocol (NFS or CIFS). @@ -1223,7 +1223,7 @@ class HitachiHNASDriver(driver.ShareDriver): return export_list def ensure_snapshot(self, context, snapshot, share_server=None): - """Ensure that snapshot is exported. + r"""Ensure that snapshot is exported. :param context: The `context.RequestContext` object for the request. :param snapshot: Snapshot that will be checked. diff --git a/manila/share/drivers/ibm/gpfs.py b/manila/share/drivers/ibm/gpfs.py index 54a5746801..ff682a1635 100644 --- a/manila/share/drivers/ibm/gpfs.py +++ b/manila/share/drivers/ibm/gpfs.py @@ -55,7 +55,7 @@ LOG = log.getLogger(__name__) # matches multiple comma separated avpairs on a line. values with an embedded # comma must be wrapped in quotation marks AVPATTERN = re.compile(r'\s*(?P\w+)\s*=\s*(?P' - '(["][a-zA-Z0-9_, ]+["])|(\w+))\s*[,]?') + r'(["][a-zA-Z0-9_, ]+["])|(\w+))\s*[,]?') ERR_FILE_NOT_FOUND = 2 @@ -884,7 +884,7 @@ class KNFSHelper(NASHelperBase): raise exception.GPFSException(msg) if access_to: - if (re.search(re.escape(local_path) + '[\s\n]*' + if (re.search(re.escape(local_path) + r'[\s\n]*' + re.escape(access_to), out)): return True else: @@ -974,7 +974,7 @@ class KNFSHelper(NASHelperBase): if error_on_exists: # check if present in export out = re.search( - re.escape(local_path) + '[\s\n]*' + re.escape(local_path) + r'[\s\n]*' + re.escape(access['access_to']), self._get_exports()) if out is not None: diff --git a/manila/share/drivers/infortrend/infortrend_nas.py b/manila/share/drivers/infortrend/infortrend_nas.py index 1167286447..5b3ce169cf 100644 --- a/manila/share/drivers/infortrend/infortrend_nas.py +++ b/manila/share/drivers/infortrend/infortrend_nas.py @@ -605,14 +605,14 @@ class InfortrendNAS(object): def _parse_location(self, input_location, share_proto): ip = None folder_name = None - pattern_ip = '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' + pattern_ip = r'[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' if share_proto == 'nfs': - pattern_folder = '[^\/]+$' + pattern_folder = r'[^\/]+$' ip = "".join(re.findall(pattern_ip, input_location)) folder_name = "".join(re.findall(pattern_folder, input_location)) elif share_proto == 'cifs': - pattern_folder = '[^\\\]+$' + pattern_folder = r'[^\\]+$' ip = "".join(re.findall(pattern_ip, input_location)) folder_name = "".join(re.findall(pattern_folder, input_location)) diff --git a/manila/share/drivers/lvm.py b/manila/share/drivers/lvm.py index 6f56a9ab19..a9e121f89a 100644 --- a/manila/share/drivers/lvm.py +++ b/manila/share/drivers/lvm.py @@ -223,8 +223,8 @@ class LVMShareDriver(LVMMixin, driver.ShareDriver): self.configuration.lvm_share_volume_group, '--rows', '--units', 'g', run_as_root=True) - total_size = re.findall("VSize\s[0-9.]+g", out)[0][6:-1] - free_size = re.findall("VFree\s[0-9.]+g", out)[0][6:-1] + total_size = re.findall(r"VSize\s[0-9.]+g", out)[0][6:-1] + free_size = re.findall(r"VFree\s[0-9.]+g", out)[0][6:-1] return [{ 'pool_name': 'lvm-single-pool', 'total_capacity_gb': float(total_size), @@ -492,7 +492,7 @@ class LVMShareDriver(LVMMixin, driver.ShareDriver): mount_path = self._get_mount_path(share) if os.path.exists(mount_path): used_size = (re.findall( - mount_path + "\s*[0-9.]+G", out)[0]. + mount_path + r"\s*[0-9.]+G", out)[0]. split(' ')[-1][:-1]) updated_shares.append({'id': share['id'], 'used_size': used_size, diff --git a/manila/tests/network/linux/test_ip_lib.py b/manila/tests/network/linux/test_ip_lib.py index 62445989bd..faf0ba4d83 100644 --- a/manila/tests/network/linux/test_ip_lib.py +++ b/manila/tests/network/linux/test_ip_lib.py @@ -27,15 +27,15 @@ LINK_SAMPLE = [ '1: lo: mtu 16436 qdisc noqueue state UNKNOWN \\' 'link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00', '2: eth0: mtu 1500 qdisc mq state UP ' - 'qlen 1000\ link/ether cc:dd:ee:ff:ab:cd brd ff:ff:ff:ff:ff:ff' - '\ alias openvswitch', + 'qlen 1000\\ link/ether cc:dd:ee:ff:ab:cd brd ff:ff:ff:ff:ff:ff' + '\\ alias openvswitch', '3: br-int: mtu 1500 qdisc noop state DOWN ' - '\ link/ether aa:bb:cc:dd:ee:ff brd ff:ff:ff:ff:ff:ff', + '\\ link/ether aa:bb:cc:dd:ee:ff brd ff:ff:ff:ff:ff:ff', '4: gw-ddc717df-49: mtu 1500 qdisc noop ' - 'state DOWN \ link/ether fe:dc:ba:fe:dc:ba brd ff:ff:ff:ff:ff:ff', + 'state DOWN \\ link/ether fe:dc:ba:fe:dc:ba brd ff:ff:ff:ff:ff:ff', '5: eth0.50@eth0: mtu 1500 qdisc ' ' noqueue master brq0b24798c-07 state UP mode DEFAULT' - '\ link/ether ab:04:49:b6:ab:a0 brd ff:ff:ff:ff:ff:ff'] + '\\ link/ether ab:04:49:b6:ab:a0 brd ff:ff:ff:ff:ff:ff'] ADDR_SAMPLE = (""" 2: eth0: mtu 1500 qdisc mq state UP qlen 1000 diff --git a/manila/tests/share/drivers/ganesha/test_manager.py b/manila/tests/share/drivers/ganesha/test_manager.py index a4d51f046d..e5a809c8b6 100644 --- a/manila/tests/share/drivers/ganesha/test_manager.py +++ b/manila/tests/share/drivers/ganesha/test_manager.py @@ -126,7 +126,7 @@ class GaneshaConfigTests(test.TestCase): # split to expressions by the delimiter ";" # (braces are forced to be treated as expressions # by sandwiching them in ";"-s) - conf = re.sub('[{}]', ';\g<0>;', conf).split(';') + conf = re.sub(r'[{}]', r';\g<0>;', conf).split(';') # whitespace-split expressions to tokens with # (equality is forced to be treated as token by # sandwiching in space) diff --git a/manila/tests/share/drivers/glusterfs/test_glusterfs_native.py b/manila/tests/share/drivers/glusterfs/test_glusterfs_native.py index 98193892b2..84d7ca8260 100644 --- a/manila/tests/share/drivers/glusterfs/test_glusterfs_native.py +++ b/manila/tests/share/drivers/glusterfs/test_glusterfs_native.py @@ -82,7 +82,7 @@ class GlusterfsNativeShareDriverTestCase(test.TestCase): 'root@host2:/manila-share-2-2G']) CONF.set_default('glusterfs_volume_pattern', - 'manila-share-\d+-#{size}G$') + r'manila-share-\d+-#{size}G$') CONF.set_default('driver_handles_share_servers', False) self.fake_conf = config.Configuration(None) diff --git a/manila/tests/share/drivers/glusterfs/test_layout_volume.py b/manila/tests/share/drivers/glusterfs/test_layout_volume.py index 3985c0bfb1..e94a9f394e 100644 --- a/manila/tests/share/drivers/glusterfs/test_layout_volume.py +++ b/manila/tests/share/drivers/glusterfs/test_layout_volume.py @@ -105,7 +105,7 @@ class GlusterfsVolumeMappedLayoutTestCase(test.TestCase): CONF.set_default('glusterfs_path_to_private_key', '/fakepath/to/privatekey') CONF.set_default('glusterfs_volume_pattern', - 'manila-share-\d+-#{size}G$') + r'manila-share-\d+-#{size}G$') CONF.set_default('driver_handles_share_servers', False) self.fake_driver = mock.Mock() @@ -151,7 +151,7 @@ class GlusterfsVolumeMappedLayoutTestCase(test.TestCase): self.assertEqual(fake_obj, ret) def test_compile_volume_pattern(self): - volume_pattern = 'manila-share-\d+-(?P\d+)G$' + volume_pattern = r'manila-share-\d+-(?P\d+)G$' ret = self._layout._compile_volume_pattern() @@ -242,7 +242,7 @@ class GlusterfsVolumeMappedLayoutTestCase(test.TestCase): self.mock_object(self._layout, '_glustermanager', mock.Mock(side_effect=_glustermanager_calls)) self.mock_object(self._layout, 'volume_pattern', - re.compile('manila-share-\d+(-(?P\d+)G)?$')) + re.compile(r'manila-share-\d+(-(?P\d+)G)?$')) expected_output = {'root@host1:/manila-share-1': {'size': None}} ret = self._layout._fetch_gluster_volumes() diff --git a/manila/tests/share/drivers/hpe/test_hpe_3par_driver.py b/manila/tests/share/drivers/hpe/test_hpe_3par_driver.py index 16f2a187b3..55807fc419 100644 --- a/manila/tests/share/drivers/hpe/test_hpe_3par_driver.py +++ b/manila/tests/share/drivers/hpe/test_hpe_3par_driver.py @@ -438,8 +438,8 @@ class HPE3ParDriverTestCase(test.TestCase): def test_driver_create_cifs_share(self): self.init_driver() - expected_location = '\\\\%s\%s' % (constants.EXPECTED_IP_10203040, - constants.EXPECTED_SHARE_NAME) + expected_location = '\\\\%s\\%s' % (constants.EXPECTED_IP_10203040, + constants.EXPECTED_SHARE_NAME) self.mock_mediator.create_share.return_value = ( constants.EXPECTED_SHARE_NAME) @@ -496,8 +496,8 @@ class HPE3ParDriverTestCase(test.TestCase): def test_driver_create_cifs_share_from_snapshot(self): self.init_driver() - expected_location = '\\\\%s\%s' % (constants.EXPECTED_IP_10203040, - constants.EXPECTED_SHARE_NAME) + expected_location = '\\\\%s\\%s' % (constants.EXPECTED_IP_10203040, + constants.EXPECTED_SHARE_NAME) self.mock_mediator.create_share_from_snapshot.return_value = ( constants.EXPECTED_SHARE_NAME) diff --git a/tox.ini b/tox.ini index e4fbac37df..3b4a7ca10a 100644 --- a/tox.ini +++ b/tox.ini @@ -133,8 +133,7 @@ commands = alembic -c manila/db/migrations/alembic.ini revision -m ""{posargs} # E402 module level import not at top of file # W503 line break before binary operator # W504 line break after binary operator -# W605 invalid escape sequence -ignore = E123,E402,W503,W504,W605 +ignore = E123,E402,W503,W504 builtins = _ # [H106] Don't put vim configuration in source files. # [H203] Use assertIs(Not)None to check for None.