Browse Source

Update hacking and fix pep8 violations

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

Change-Id: Ie7028516f41445791125b2f670a309c40150058b
changes/96/782296/4
Dmitry Tantsur 2 months ago
committed by Ian Wienand
parent
commit
4557d573bd
6 changed files with 28 additions and 25 deletions
  1. +13
    -13
      glean/cmd.py
  2. +4
    -3
      glean/install.py
  3. +1
    -2
      glean/tests/test_glean.py
  4. +6
    -5
      glean/utils.py
  5. +1
    -1
      test-requirements.txt
  6. +3
    -1
      tox.ini

+ 13
- 13
glean/cmd.py View File

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


+ 4
- 3
glean/install.py View File

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

+ 1
- 2
glean/tests/test_glean.py View File

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


+ 6
- 5
glean/utils.py View File

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

+ 1
- 1
test-requirements.txt View File

@ -2,7 +2,7 @@
# of appearance. Changing the order has an impact on the overall integration
# 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
mock>=1.0;python_version=='2.7'


+ 3
- 1
tox.ini View File

@ -33,8 +33,10 @@ commands = python setup.py build_sphinx
# Hacking ignored becaues its rules are too zealous and cause more
# grief than value.
# 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
ignore = E123,E125,H
ignore = E123,E125,W503,H
builtins = _
exclude=.venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build

Loading…
Cancel
Save