Browse Source

Hacking: Fix W605

Fix:
W605 invalid escape sequence

This is the final change I plan for hacking, the remaining problems
need further investigation by manila team and decision whether and how
to solve them.

Change-Id: I73d73e044eaaf412bf7ace358a3f07c8d269d6cf
changes/73/716573/1
Andreas Jaeger 1 year ago
parent
commit
3fdd9983e0
  1. 2
      manila/exception.py
  2. 20
      manila/network/linux/ovs_lib.py
  3. 2
      manila/share/drivers/container/storage_helper.py
  4. 16
      manila/share/drivers/dell_emc/plugins/powermax/object_manager.py
  5. 16
      manila/share/drivers/dell_emc/plugins/vnx/object_manager.py
  6. 2
      manila/share/drivers/ganesha/__init__.py
  7. 2
      manila/share/drivers/glusterfs/__init__.py
  8. 8
      manila/share/drivers/glusterfs/common.py
  9. 6
      manila/share/drivers/glusterfs/glusterfs_native.py
  10. 2
      manila/share/drivers/helpers.py
  11. 12
      manila/share/drivers/hitachi/hnas/driver.py
  12. 6
      manila/share/drivers/ibm/gpfs.py
  13. 6
      manila/share/drivers/infortrend/infortrend_nas.py
  14. 6
      manila/share/drivers/lvm.py
  15. 10
      manila/tests/network/linux/test_ip_lib.py
  16. 2
      manila/tests/share/drivers/ganesha/test_manager.py
  17. 2
      manila/tests/share/drivers/glusterfs/test_glusterfs_native.py
  18. 6
      manila/tests/share/drivers/glusterfs/test_layout_volume.py
  19. 8
      manila/tests/share/drivers/hpe/test_hpe_3par_driver.py
  20. 3
      tox.ini

2
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)

20
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<vif_mac>([a-fA-F\d]{2}:){5}([a-fA-F\d]{2}))"'
iface = 'iface-id="(?P<vif_id>[^"]+)"'
name = 'name\s*:\s"(?P<port_name>[^"]*)"'
port = 'ofport\s*:\s(?P<ofport>-?\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<vif_mac>([a-fA-F\d]{2}:){5}([a-fA-F\d]{2}))"'
iface = r'iface-id="(?P<vif_id>[^"]+)"'
name = r'name\s*:\s"(?P<port_name>[^"]*)"'
port = r'ofport\s*:\s(?P<ofport>-?\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):

2
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,

16
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<name>\S+)\s*IRQ:\s*(?P<irq>\d+)\n'
'.*\n'
'\s*Link:\s*(?P<link>[A-Za-z]+)')
re_pattern = (r'0:\s*(?P<name>\S+)\s*IRQ:\s*(?P<irq>\d+)\n'
r'.*\n'
r'\s*Link:\s*(?P<link>[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<interfaces>(\s*interface=.*)*)')
re_pattern = (r'Interfaces to services mapping:'
r'\s*(?P<interfaces>(\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<if>.*)\s*:'
'\s*(?P<type>.*)\s*', i)
m_if = re.search(r'\s*interface=(?P<if>.*)\s*:'
r'\s*(?P<type>.*)\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

16
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<name>\S+)\s*IRQ:\s*(?P<irq>\d+)\n'
'.*\n'
'\s*Link:\s*(?P<link>[A-Za-z]+)')
re_pattern = (r'0:\s*(?P<name>\S+)\s*IRQ:\s*(?P<irq>\d+)\n'
r'.*\n'
r'\s*Link:\s*(?P<link>[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<interfaces>(\s*interface=.*)*)')
re_pattern = (r'Interfaces to services mapping:'
r'\s*(?P<interfaces>(\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<if>.*)\s*:'
'\s*(?P<type>.*)\s*', i)
m_if = re.search(r'\s*interface=(?P<if>.*)\s*:'
r'\s*(?P<type>.*)\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

2
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."""

2
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('|')

8
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<user>[^:@/]+)@)?'
'(?P<host>[^:@/]+)'
'(?::/(?P<volume>[^/]+)(?P<path>/.*)?)?\Z')
scheme = re.compile(r'\A(?:(?P<user>[^:@/]+)@)?'
r'(?P<host>[^:@/]+)'
r'(?::/(?P<volume>[^/]+)(?P<path>/.*)?)?\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:

6
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))

2
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 "

12
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.

6
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<attr>\w+)\s*=\s*(?P<val>'
'(["][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:

6
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))

6
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,

10
manila/tests/network/linux/test_ip_lib.py

@ -27,15 +27,15 @@ LINK_SAMPLE = [
'1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN \\'
'link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00',
'2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> 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: <BROADCAST,MULTICAST> 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: <BROADCAST,MULTICAST> 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: <BROADCAST,MULTICAST,UP,LOWER_UP> 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: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000

2
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)

2
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)

6
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<size>\d+)G$'
volume_pattern = r'manila-share-\d+-(?P<size>\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<size>\d+)G)?$'))
re.compile(r'manila-share-\d+(-(?P<size>\d+)G)?$'))
expected_output = {'root@host1:/manila-share-1': {'size': None}}
ret = self._layout._fetch_gluster_volumes()

8
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)

3
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.

Loading…
Cancel
Save