Unpin flake8, fix lint

Add Python 3.8 env in Travis CI test matrix.

At present the pinning of flake8 disallows running of lint on
Python 3.8 systems.

Update flake8 ignore-list to ignore W504 instead of W503, the PEP
guidance is that either is ok, but there must be local consistency.

There are more occurences of binary operator before line-break
than after in this repository, and we have also chosen to ignore
W504 in most of our other repositories.
This commit is contained in:
Frode Nordahl
2020-04-07 11:04:46 +02:00
parent 456882f8fa
commit f35da80f27
9 changed files with 60 additions and 57 deletions

View File

@@ -13,5 +13,8 @@ matrix:
- name: "Python 3.7"
python: 3.7
env: ENV=pep8,py3
- name: "Python 3.8"
python: 3.7
env: ENV=pep8,py3
script:
- tox -c tox.ini -e $ENV

View File

@@ -4,7 +4,7 @@ boto3
juju
juju_wait
PyYAML<=4.2,>=3.0
flake8>=2.2.4,<=3.5.0
flake8>=2.2.4
flake8-docstrings
flake8-per-file-ignores
pydocstyle<4.0.0

View File

@@ -25,7 +25,7 @@ deps = -r{toxinidir}/requirements.txt
commands = /bin/true
[flake8]
ignore = E402,E226,W503
ignore = E402,E226,W504
per-file-ignores =
unit_tests/**: D

View File

@@ -105,12 +105,12 @@ def _login(dashboard_ip, domain, username, password):
# services/information missing that horizon wants to display data
# for.
# Redirect to /horizon/identity/ instead.
if (openstack_utils.get_os_release()
>= openstack_utils.get_os_release('xenial_queens')):
if (openstack_utils.get_os_release() >=
openstack_utils.get_os_release('xenial_queens')):
auth['next'] = '/horizon/identity/'
if (openstack_utils.get_os_release()
>= openstack_utils.get_os_release('bionic_stein')):
if (openstack_utils.get_os_release() >=
openstack_utils.get_os_release('bionic_stein')):
auth['region'] = 'default'
if api_version == 2:
@@ -122,8 +122,8 @@ def _login(dashboard_ip, domain, username, password):
# NOTE(ajkavanagh) there used to be a trusty/icehouse test in the
# amulet test, but as the zaza tests only test from trusty/mitaka
# onwards, the test has been dropped
if (openstack_utils.get_os_release()
>= openstack_utils.get_os_release('bionic_stein')):
if (openstack_utils.get_os_release() >=
openstack_utils.get_os_release('bionic_stein')):
expect = "Sign Out"
# update the in dashboard seems to require region to be default in
# this test configuration

View File

@@ -214,8 +214,8 @@ class GenericPolicydTest(PolicydTest, test_utils.OpenStackBaseTest):
def setUpClass(cls, application_name=None):
"""Run class setup for running KeystonePolicydTest tests."""
super(GenericPolicydTest, cls).setUpClass(application_name)
if (openstack_utils.get_os_release()
< openstack_utils.get_os_release('xenial_queens')):
if (openstack_utils.get_os_release() <
openstack_utils.get_os_release('xenial_queens')):
raise unittest.SkipTest(
"zaza.openstack.charm_tests.policyd.tests.GenericPolicydTest "
"not valid before xenial_queens")
@@ -276,8 +276,8 @@ class BasePolicydSpecialization(PolicydTest,
def setUpClass(cls, application_name=None):
"""Run class setup for running KeystonePolicydTest tests."""
super(BasePolicydSpecialization, cls).setUpClass(application_name)
if (openstack_utils.get_os_release()
< openstack_utils.get_os_release('xenial_queens')):
if (openstack_utils.get_os_release() <
openstack_utils.get_os_release('xenial_queens')):
raise unittest.SkipTest(
"zaza.openstack.charm_tests.policyd.tests.* "
"not valid before xenial_queens")

View File

@@ -38,26 +38,26 @@ class QuaggaTest(unittest.TestCase):
'tor2', 'peer0', 'peer1']
if app in status.applications.keys())
for application in applications:
for unit in zaza.model.get_units(application):
bgp_sum = zaza.model.run_on_unit(
unit.entity_id,
'echo "sh bgp ipv4 unicast summary" | vtysh')['Stdout']
r = re.compile('^(\d+\.\d+\.\d+\.\d+)')
ip_list = []
for line in bgp_sum.splitlines():
m = r.match(line)
if m:
ip_list.append(m.group(1))
logging.info('unit {} neighbours {}'
.format(unit.entity_id, ip_list))
for unit in zaza.model.get_units(application):
bgp_sum = zaza.model.run_on_unit(
unit.entity_id,
'echo "sh bgp ipv4 unicast summary" | vtysh')['Stdout']
r = re.compile(r'^(\d+\.\d+\.\d+\.\d+)')
ip_list = []
for line in bgp_sum.splitlines():
m = r.match(line)
if m:
ip_list.append(m.group(1))
logging.info('unit {} neighbours {}'
.format(unit.entity_id, ip_list))
if not ip_list:
raise Exception('FAILED: Unit {} has no BGP peers.'
.format(unit.entity_id))
for ip in ip_list:
result = zaza.model.run_on_unit(
unit.entity_id,
'ping -c 3 {}'.format(ip))
logging.info(result['Stdout'])
if result['Code'] == '1':
raise Exception('FAILED')
if not ip_list:
raise Exception('FAILED: Unit {} has no BGP peers.'
.format(unit.entity_id))
for ip in ip_list:
result = zaza.model.run_on_unit(
unit.entity_id,
'ping -c 3 {}'.format(ip))
logging.info(result['Stdout'])
if result['Code'] == '1':
raise Exception('FAILED')

View File

@@ -50,7 +50,7 @@ def skipUntilVersion(service, package, release):
stderr=subprocess.STDOUT,
universal_newlines=True)
return f(*args, **kwargs)
except subprocess.CalledProcessError as cp:
except subprocess.CalledProcessError:
logging.warn("Skipping test for older ({})"
"service {}, requested {}".format(
package_version, service, release))

View File

@@ -534,28 +534,28 @@ def get_file_contents(unit, f):
def is_port_open(port, address):
"""Determine if TCP port is accessible.
"""Determine if TCP port is accessible.
Connect to the MySQL port on the VIP.
Connect to the MySQL port on the VIP.
:param port: Port number
:type port: str
:param address: IP address
:type port: str
:returns: True if port is reachable
:rtype: boolean
"""
try:
telnetlib.Telnet(address, port)
return True
except socket.error as e:
if e.errno == 113:
logging.error("could not connect to {}:{}"
.format(address, port))
if e.errno == 111:
logging.error("connection refused connecting"
" to {}:{}".format(address, port))
return False
:param port: Port number
:type port: str
:param address: IP address
:type port: str
:returns: True if port is reachable
:rtype: boolean
"""
try:
telnetlib.Telnet(address, port)
return True
except socket.error as e:
if e.errno == 113:
logging.error("could not connect to {}:{}"
.format(address, port))
if e.errno == 111:
logging.error("connection refused connecting"
" to {}:{}".format(address, port))
return False
def port_knock_units(units, port=22, expect_success=True):

View File

@@ -1411,11 +1411,11 @@ def get_os_code_info(package, pkg_version):
pkg_version = pkg_version.split(':')[1:][0]
if 'swift' in package:
# Fully x.y.z match for swift versions
match = re.match('^(\d+)\.(\d+)\.(\d+)', pkg_version)
match = re.match(r'^(\d+)\.(\d+)\.(\d+)', pkg_version)
else:
# x.y match only for 20XX.X
# and ignore patch level for other packages
match = re.match('^(\d+)\.(\d+)', pkg_version)
match = re.match(r'^(\d+)\.(\d+)', pkg_version)
if match:
vers = match.group(0)