Update hacking and fix pep8 violations

Using version 2.0.0 which was the last to support Python 2.

Change-Id: Ie7028516f41445791125b2f670a309c40150058b
This commit is contained in:
Dmitry Tantsur 2021-03-22 17:51:38 +01:00 committed by Ian Wienand
parent 32a7409814
commit 4557d573bd
6 changed files with 28 additions and 25 deletions

View File

@ -26,10 +26,10 @@ import subprocess
import sys import sys
import time import time
from glean._vendor import distro
from glean import install from glean import install
from glean import systemlock from glean import systemlock
from glean import utils from glean import utils
from glean._vendor import distro
try: try:
import configparser import configparser
@ -357,9 +357,10 @@ def _write_networkd_interface(name, interfaces, args, files_struct=dict()):
) )
# define network if needed (basically always) # define network if needed (basically always)
if ((interface['type'] in ['ipv4_dhcp', 'ipv6_slaac', if ((interface['type'] in ['ipv4_dhcp', 'ipv6_slaac',
'ipv6_dhcpv6_stateful', 'manual', 'ipv4', 'ipv6']) or 'ipv6_dhcpv6_stateful', 'manual',
('vlan_id' in interface) or 'ipv4', 'ipv6'])
('bond_mode' in interface)): or ('vlan_id' in interface)
or ('bond_mode' in interface)):
if '[Network]' not in files_struct[network_file]: if '[Network]' not in files_struct[network_file]:
files_struct[network_file]['[Network]'] = list() files_struct[network_file]['[Network]'] = list()
if 'services' in interface: if 'services' in interface:
@ -383,8 +384,8 @@ def _write_networkd_interface(name, interfaces, args, files_struct=dict()):
else: else:
files_struct[network_file]['[Network]'].append('DHCP=ipv6') files_struct[network_file]['[Network]'].append('DHCP=ipv6')
# slaac can start dhcp6 if the associated RA option is sent to server # slaac can start dhcp6 if the associated RA option is sent to server
if (interface['type'] == 'ipv6_slaac' or if (interface['type'] == 'ipv6_slaac'
interface['type'] == 'ipv6_dhcpv6-stateless'): or interface['type'] == 'ipv6_dhcpv6-stateless'):
# we are accepting slaac now, remove the disabling of slaac # we are accepting slaac now, remove the disabling of slaac
if 'IPv6AcceptRA=no' in files_struct[network_file]['[Network]']: if 'IPv6AcceptRA=no' in files_struct[network_file]['[Network]']:
files_struct[network_file]['[Network]'].remove( files_struct[network_file]['[Network]'].remove(
@ -666,11 +667,10 @@ mac_{name}="{hwaddr}\"\n""".format(
) )
routes = list() routes = list()
for route in interface.get('routes', ()): for route in interface.get('routes', ()):
if (route['network'] == '0.0.0.0' and if (route['network'] == '0.0.0.0'
route['netmask'] == '0.0.0.0'): and route['netmask'] == '0.0.0.0'):
# add default route if it exists # add default route if it exists
routes.append('default via {gw}'.format( routes.append('default via {gw}'.format(
name=name,
gw=route['gateway'] gw=route['gateway']
)) ))
else: else:
@ -903,10 +903,10 @@ def write_debian_interfaces(interfaces, sys_interfaces, args):
utils.ipv6_netmask_length(interface['netmask'])) utils.ipv6_netmask_length(interface['netmask']))
for route in interface.get('routes', ()): for route in interface.get('routes', ()):
if ((route['network'] == '0.0.0.0' and if ((route['network'] == '0.0.0.0'
route['netmask'] == '0.0.0.0') or and route['netmask'] == '0.0.0.0')
(route['network'] == '::' and or (route['network'] == '::'
route['netmask'] == '::')): and route['netmask'] == '::')):
result += " gateway {0}\n".format(route['gateway']) result += " gateway {0}\n".format(route['gateway'])
else: else:
if interface['type'] == 'ipv4': if interface['type'] == 'ipv4':

View File

@ -119,9 +119,9 @@ def main():
# may be wrong as install is generally executed in a chroot # may be wrong as install is generally executed in a chroot
# with diskimage-builder. # with diskimage-builder.
if (os.path.exists('/usr/lib/systemd/system') and if (os.path.exists('/usr/lib/systemd/system')
(os.path.exists('/usr/bin/systemctl') or and (os.path.exists('/usr/bin/systemctl')
os.path.exists('/bin/systemctl'))): or os.path.exists('/bin/systemctl'))):
log.info("Installing systemd services") log.info("Installing systemd services")
log.info("glean.sh in %s" % p) log.info("glean.sh in %s" % p)
@ -180,5 +180,6 @@ def main():
replacements={'EXTRA_ARGS': extra_args}) replacements={'EXTRA_ARGS': extra_args})
os.system('update-rc.d glean defaults') os.system('update-rc.d glean defaults')
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View File

@ -224,8 +224,7 @@ class TestGlean(base.BaseTestCase):
with open(output_path) as f: with open(output_path) as f:
for line in f: for line in f:
if line == '%NM_CONTROLLED%\n': if line == '%NM_CONTROLLED%\n':
line = 'NM_CONTROLLED=%s\n' % \ line = 'NM_CONTROLLED=%s\n' % ("yes" if use_nm else "no")
("yes" if use_nm else "no")
lines.append(line) lines.append(line)
write_dest = None write_dest = None
write_content = None write_content = None

View File

@ -26,16 +26,17 @@ def ipv6_netmask_length(netmask):
if not w or int(w, 16) == 0: if not w or int(w, 16) == 0:
break break
count += bitCount.index(int(w, 16)) count += bitCount.index(int(w, 16))
except: except Exception:
raise SyntaxError('Bad Netmask') raise SyntaxError('Bad Netmask')
return count return count
# code to convert netmask ip to cidr number
# https://stackoverflow.com/a/43885814
def ipv4_netmask_length(netmask): def ipv4_netmask_length(netmask):
''' """Convert netmask IP to CIDR number.
From https://stackoverflow.com/a/43885814
:param netmask: netmask ip addr (eg: 255.255.255.0) :param netmask: netmask ip addr (eg: 255.255.255.0)
:return: equivalent cidr number to given netmask ip (eg: 24) :return: equivalent cidr number to given netmask ip (eg: 24)
''' """
return sum([bin(int(x)).count('1') for x in netmask.split('.')]) return sum([bin(int(x)).count('1') for x in netmask.split('.')])

View File

@ -2,7 +2,7 @@
# of appearance. Changing the order has an impact on the overall integration # of appearance. Changing the order has an impact on the overall integration
# process, which may cause wedges in the gate later. # process, which may cause wedges in the gate later.
hacking>=0.9.2,<0.10 hacking>=2.0.0,<3.0.0
coverage>=3.6 coverage>=3.6
mock>=1.0;python_version=='2.7' mock>=1.0;python_version=='2.7'

View File

@ -33,8 +33,10 @@ commands = python setup.py build_sphinx
# Hacking ignored becaues its rules are too zealous and cause more # Hacking ignored becaues its rules are too zealous and cause more
# grief than value. # grief than value.
# E123, E125 skipped as they are invalid PEP-8. # E123, E125 skipped as they are invalid PEP-8.
# W503 contradicts W504 which seems more preferred per
# https://www.python.org/dev/peps/pep-0008/#should-a-line-break-before-or-after-a-binary-operator
show-source = True show-source = True
ignore = E123,E125,H ignore = E123,E125,W503,H
builtins = _ builtins = _
exclude=.venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build exclude=.venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build