Skip to content

Commit f3e4970

Browse files
committed
fix most ansible-test issues, suppress the rest
Automation Hub, and possibly Galaxy in the future, require the collection to be screened with `ansible-test sanity` among other checks. The role had a number of issues: * Use `AssertionError` instead of `assert` * Use of `logging` module not in accordance with standards, but these are ok and the errors were suppressed * Several import errors which are ok because they are checked elsewhere * Many of the module files use `#!` shebang - not sure why, but the usage is allowed * __init__.py in the module_utils directories must be empty, so a new file myerror.py was added to move the code from __init__.py * The documentation block in the module was not properly constructed or formatted. * shellcheck issues, including removing unused files * use `dummy` instead of `_` (underscore) for variables that are unused add WARNING to module docs - collection users should not use directly Signed-off-by: Rich Megginson <[email protected]>
1 parent 0f5a882 commit f3e4970

23 files changed

+203
-129
lines changed

.github/workflows/tox.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: tox
33
on: # yamllint disable-line rule:truthy
44
- pull_request
55
env:
6-
TOX_LSR: "git+https://github.com/linux-system-roles/tox-lsr@2.2.0"
6+
TOX_LSR: "git+https://github.com/linux-system-roles/tox-lsr@2.3.0"
77
LSR_ANSIBLES: 'ansible==2.8.* ansible==2.9.*'
88
LSR_MSCENARIOS: default
99
# LSR_EXTRA_PACKAGES: "libdbus-1-dev libgirepository1.0-dev python3-dev"
@@ -36,7 +36,7 @@ jobs:
3636
toxenvs="py${toxpyver}"
3737
case "$toxpyver" in
3838
27) toxenvs="${toxenvs},coveralls,flake8,pylint" ;;
39-
36) toxenvs="${toxenvs},coveralls,black,yamllint,ansible-lint,collection" ;;
39+
36) toxenvs="${toxenvs},coveralls,black,yamllint,ansible-lint,collection,ansible-test" ;;
4040
37) toxenvs="${toxenvs},coveralls" ;;
4141
38) toxenvs="${toxenvs},coveralls" ;;
4242
esac

.sanity-ansible-ignore-2.9.txt

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
tests/network/ensure_provider_tests.py compile-2.7!skip
2+
tests/network/ensure_provider_tests.py compile-3.5!skip
3+
plugins/module_utils/network_lsr/nm/__init__.py empty-init!skip
4+
plugins/module_utils/network_lsr/nm/active_connection.py import-2.7!skip
5+
plugins/module_utils/network_lsr/nm/client.py import-2.7!skip
6+
plugins/module_utils/network_lsr/nm/connection.py import-2.7!skip
7+
plugins/module_utils/network_lsr/nm/provider.py import-2.7!skip
8+
plugins/module_utils/network_lsr/nm/active_connection.py import-3.5!skip
9+
plugins/module_utils/network_lsr/nm/client.py import-3.5!skip
10+
plugins/module_utils/network_lsr/nm/connection.py import-3.5!skip
11+
plugins/module_utils/network_lsr/nm/provider.py import-3.5!skip
12+
plugins/module_utils/network_lsr/nm/active_connection.py import-3.6!skip
13+
plugins/module_utils/network_lsr/nm/client.py import-3.6!skip
14+
plugins/module_utils/network_lsr/nm/connection.py import-3.6!skip
15+
plugins/module_utils/network_lsr/nm/provider.py import-3.6!skip
16+
plugins/module_utils/network_lsr/nm/active_connection.py import-3.7!skip
17+
plugins/module_utils/network_lsr/nm/client.py import-3.7!skip
18+
plugins/module_utils/network_lsr/nm/connection.py import-3.7!skip
19+
plugins/module_utils/network_lsr/nm/provider.py import-3.7!skip
20+
plugins/module_utils/network_lsr/nm/active_connection.py import-3.8!skip
21+
plugins/module_utils/network_lsr/nm/client.py import-3.8!skip
22+
plugins/module_utils/network_lsr/nm/connection.py import-3.8!skip
23+
plugins/module_utils/network_lsr/nm/provider.py import-3.8!skip
24+
plugins/module_utils/network_lsr/__init__.py shebang!skip
25+
plugins/module_utils/network_lsr/argument_validator.py shebang!skip
26+
plugins/module_utils/network_lsr/utils.py shebang!skip
27+
plugins/module_utils/network_lsr/myerror.py shebang!skip
28+
tests/network/covstats shebang!skip
29+
tests/network/ensure_provider_tests.py shebang!skip
30+
tests/network/get_coverage.sh shebang!skip
31+
tests/network/get_total_coverage.sh shebang!skip
32+
tests/network/merge_coverage.sh shebang!skip
33+
tests/network/ensure_provider_tests.py future-import-boilerplate!skip
34+
tests/network/integration/conftest.py future-import-boilerplate!skip
35+
tests/network/integration/test_ethernet.py future-import-boilerplate!skip
36+
tests/network/unit/test_network_connections.py future-import-boilerplate!skip
37+
tests/network/unit/test_nm_provider.py future-import-boilerplate!skip
38+
tests/network/ensure_provider_tests.py metaclass-boilerplate!skip
39+
tests/network/integration/conftest.py metaclass-boilerplate!skip
40+
tests/network/integration/test_ethernet.py metaclass-boilerplate!skip
41+
tests/network/unit/test_network_connections.py metaclass-boilerplate!skip
42+
tests/network/unit/test_nm_provider.py metaclass-boilerplate!skip
43+
plugins/modules/network_connections.py validate-modules:missing-examples
44+
plugins/modules/network_connections.py validate-modules:missing-gplv3-license
45+
plugins/modules/network_connections.py validate-modules:no-default-for-required-parameter
46+
plugins/modules/network_connections.py validate-modules:parameter-type-not-in-doc
47+
plugins/modules/network_connections.py validate-modules:undocumented-parameter

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ a consequence, `state: up` always changes the system.
145145

146146
You can deactivate a connection profile, even if is currently not active. As a consequence, `state: down` always changes the system.
147147

148-
Note that if the `state` option is unset, the connection profiles runtime state will not be changed.
148+
Note that if the `state` option is unset, the connection profile's runtime state will not be changed.
149149

150150

151151
### `persistent_state`

library/network_connections.py

Lines changed: 60 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,30 @@
22
# -*- coding: utf-8 -*-
33
# SPDX-License-Identifier: BSD-3-Clause
44

5+
from __future__ import absolute_import, division, print_function
6+
7+
__metaclass__ = type
8+
9+
DOCUMENTATION = """
10+
---
11+
module: network_connections
12+
author: Thomas Haller (@thom311)
13+
short_description: module for network role to manage connection profiles
14+
requirements: [pygobject, dbus, NetworkManager]
15+
version_added: "2.0"
16+
description:
17+
- "WARNING: Do not use this module directly! It is only for role internal use."
18+
- |
19+
Manage networking profiles (connections) for NetworkManager and
20+
initscripts networking providers. Documentation needs to be written. Note
21+
that the network_connections module tightly integrates with the network
22+
role and currently it is not expected to use this module outside the role.
23+
Thus, consult README.md for examples for the role. The requirements are
24+
only for the NetworkManager (nm) provider.
25+
options: {}
26+
"""
27+
28+
529
import errno
630
import functools
731
import os
@@ -16,7 +40,7 @@
1640
# pylint: disable=import-error, no-name-in-module
1741
from ansible.module_utils.basic import AnsibleModule
1842
from ansible.module_utils.network_lsr import ethtool # noqa:E501
19-
from ansible.module_utils.network_lsr import MyError # noqa:E501
43+
from ansible.module_utils.network_lsr.myerror import MyError # noqa:E501
2044

2145
from ansible.module_utils.network_lsr.argument_validator import ( # noqa:E501
2246
ArgUtil,
@@ -30,22 +54,6 @@
3054
# pylint: enable=import-error, no-name-in-module
3155

3256

33-
DOCUMENTATION = """
34-
---
35-
module: network_connections
36-
author: "Thomas Haller ([email protected])"
37-
short_description: module for network role to manage connection profiles
38-
requirements: for 'nm' provider requires pygobject, dbus and NetworkManager.
39-
version_added: "2.0"
40-
description: Manage networking profiles (connections) for NetworkManager and
41-
initscripts networking providers.
42-
options: Documentation needs to be written. Note that the network_connections
43-
module tightly integrates with the network role and currently it is not
44-
expected to use this module outside the role. Thus, consult README.md for
45-
examples for the role.
46-
"""
47-
48-
4957
###############################################################################
5058
PERSISTENT_STATE = "persistent_state"
5159
ABSENT_STATE = "absent"
@@ -772,7 +780,7 @@ def connection_compare(
772780
if compare_flags is None:
773781
compare_flags = NM.SettingCompareFlags.IGNORE_TIMESTAMP
774782

775-
return not (not (con_a.compare(con_b, compare_flags)))
783+
return con_a.compare(con_b, compare_flags)
776784

777785
def connection_is_active(self, con):
778786
NM = Util.NM()
@@ -1399,7 +1407,7 @@ def _check_mode_changed(self, old_check_mode, new_check_mode, connections):
13991407
def check_mode_set(self, check_mode, connections=None):
14001408
c = self._check_mode
14011409
self._check_mode = check_mode
1402-
assert (
1410+
if not (
14031411
(c is None and check_mode in [CheckMode.PREPARE])
14041412
or (
14051413
c == CheckMode.PREPARE
@@ -1408,7 +1416,12 @@ def check_mode_set(self, check_mode, connections=None):
14081416
or (c == CheckMode.PRE_RUN and check_mode in [CheckMode.REAL_RUN])
14091417
or (c == CheckMode.REAL_RUN and check_mode in [CheckMode.DONE])
14101418
or (c == CheckMode.DRY_RUN and check_mode in [CheckMode.DONE])
1411-
)
1419+
):
1420+
raise AssertionError(
1421+
"updating check_mode value from {0} into {1} is incorrect".format(
1422+
c, check_mode
1423+
)
1424+
)
14121425
self._check_mode_changed(c, check_mode, connections)
14131426

14141427

@@ -1470,7 +1483,8 @@ def log(
14701483
warn_traceback=False,
14711484
force_fail=False,
14721485
):
1473-
assert idx >= -1
1486+
if not idx >= -1:
1487+
raise AssertionError("idx {0} is less than -1".format(idx))
14741488
self._log_idx += 1
14751489
self.run_results[idx]["log"].append((severity, msg, self._log_idx))
14761490
if severity == LogLevel.ERROR:
@@ -1607,14 +1621,15 @@ def connections(self):
16071621
def connections_data(self):
16081622
c = self._connections_data
16091623
if c is None:
1610-
assert self.check_mode in [
1624+
if self.check_mode not in [
16111625
CheckMode.DRY_RUN,
16121626
CheckMode.PRE_RUN,
16131627
CheckMode.REAL_RUN,
1614-
]
1615-
c = []
1616-
for _ in range(0, len(self.connections)):
1617-
c.append({"changed": False})
1628+
]:
1629+
raise AssertionError(
1630+
"invalid value {0} for self.check_mode".format(self.check_mode)
1631+
)
1632+
c = [{"changed": False}] * len(self.connections)
16181633
self._connections_data = c
16191634
return c
16201635

@@ -1623,11 +1638,14 @@ def connections_data_reset(self):
16231638
c["changed"] = False
16241639

16251640
def connections_data_set_changed(self, idx, changed=True):
1626-
assert self._check_mode in [
1641+
if self._check_mode not in [
16271642
CheckMode.PRE_RUN,
16281643
CheckMode.DRY_RUN,
16291644
CheckMode.REAL_RUN,
1630-
]
1645+
]:
1646+
raise AssertionError(
1647+
"invalid value {0} for self._check_mode".format(self._check_mode)
1648+
)
16311649
if not changed:
16321650
return
16331651
self.connections_data[idx]["changed"] = changed
@@ -1697,7 +1715,10 @@ def connection_modified_earlier(self, idx):
16971715
# modify the connection.
16981716

16991717
con = self.connections[idx]
1700-
assert con["state"] in ["up", "down"]
1718+
if con["state"] not in ["up", "down"]:
1719+
raise AssertionError(
1720+
"connection state {0} not 'up' or 'down'".format(con["state"])
1721+
)
17011722

17021723
# also check, if the current profile is 'up' with a 'type' (which
17031724
# possibly modifies the connection as well)
@@ -1745,7 +1766,9 @@ def check_mode_next(self):
17451766
elif self._check_mode != CheckMode.DONE:
17461767
c = CheckMode.DONE
17471768
else:
1748-
assert False
1769+
raise AssertionError(
1770+
"invalid value {0} for self._check_mode".format(self._check_mode)
1771+
)
17491772
self._check_mode = c
17501773
self.run_env.check_mode_set(c)
17511774
return c
@@ -1911,7 +1934,12 @@ def run_prepare(self):
19111934

19121935
name = connection["name"]
19131936
if not name:
1914-
assert connection["persistent_state"] == "absent"
1937+
if not connection["persistent_state"] == "absent":
1938+
raise AssertionError(
1939+
"persistent_state must be 'absent' not {0} when there is no connection 'name'".format(
1940+
connection["persistent_state"]
1941+
)
1942+
)
19151943
continue
19161944
if name in names:
19171945
exists = names[name]["nm.exists"]
@@ -1988,7 +2016,7 @@ def _check_ethtool_setting_support(self, idx, connection):
19882016
idx, "ethtool.%s specified but not supported by NM", specified
19892017
)
19902018

1991-
for option, _ in specified.items():
2019+
for option in specified.keys():
19922020
nm_name = nm_get_name_fcnt(option)
19932021
if not nm_name:
19942022
self.log_fatal(

module_utils/network_lsr/__init__.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +0,0 @@
1-
#!/usr/bin/python3 -tt
2-
# vim: fileencoding=utf8
3-
# SPDX-License-Identifier: BSD-3-Clause
4-
5-
6-
class MyError(Exception):
7-
pass

module_utils/network_lsr/argument_validator.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
22
# vim: fileencoding=utf8
33
# SPDX-License-Identifier: BSD-3-Clause
44

5+
from __future__ import absolute_import, division, print_function
6+
7+
__metaclass__ = type
8+
59
import posixpath
610
import socket
711
import re
812

913
# pylint: disable=import-error, no-name-in-module
10-
from ansible.module_utils.network_lsr import MyError # noqa:E501
14+
from ansible.module_utils.network_lsr.myerror import MyError # noqa:E501
1115
from ansible.module_utils.network_lsr.utils import Util # noqa:E501
1216

1317
UINT32_MAX = 0xFFFFFFFF
@@ -72,7 +76,8 @@ def connection_get_non_absent_names(connections):
7276

7377
class ValidationError(MyError):
7478
def __init__(self, name, message):
75-
Exception.__init__(self, name + ": " + message)
79+
# pylint: disable=non-parent-init-called
80+
super(ValidationError, self).__init__(name + ": " + message)
7681
self.error_message = message
7782
self.name = name
7883

module_utils/network_lsr/ethtool.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# SPDX-License-Identifier: BSD-3-Clause
22

3+
from __future__ import absolute_import, division, print_function
4+
5+
__metaclass__ = type
6+
37
import array
48
import struct
59
import fcntl
@@ -46,7 +50,7 @@ def get_perm_addr(ifname):
4650
res = ecmd.tobytes()
4751
except AttributeError: # tobytes() is not available in python2
4852
res = ecmd.tostring()
49-
_, size, perm_addr = struct.unpack("II%is" % MAX_ADDR_LEN, res)
53+
unused, size, perm_addr = struct.unpack("II%is" % MAX_ADDR_LEN, res)
5054
perm_addr = Util.mac_ntoa(perm_addr[:size])
5155
except IOError:
5256
perm_addr = None

module_utils/network_lsr/myerror.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/python3 -tt
2+
# vim: fileencoding=utf8
3+
# SPDX-License-Identifier: BSD-3-Clause
4+
5+
from __future__ import absolute_import, division, print_function
6+
7+
__metaclass__ = type
8+
9+
10+
class MyError(Exception):
11+
pass

module_utils/network_lsr/nm/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Relative import is not support by ansible 2.8 yet
22
# pylint: disable=import-error, no-name-in-module
3+
from __future__ import absolute_import, division, print_function
4+
5+
__metaclass__ = type
6+
37
from ansible.module_utils.network_lsr.nm import provider # noqa:E501
48

59
# pylint: enable=import-error, no-name-in-module

0 commit comments

Comments
 (0)