-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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]>
- Loading branch information
Showing
23 changed files
with
202 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
tests/network/ensure_provider_tests.py compile-2.7!skip | ||
tests/network/ensure_provider_tests.py compile-3.5!skip | ||
plugins/module_utils/network_lsr/nm/__init__.py empty-init!skip | ||
plugins/module_utils/network_lsr/nm/active_connection.py import-2.7!skip | ||
plugins/module_utils/network_lsr/nm/client.py import-2.7!skip | ||
plugins/module_utils/network_lsr/nm/connection.py import-2.7!skip | ||
plugins/module_utils/network_lsr/nm/provider.py import-2.7!skip | ||
plugins/module_utils/network_lsr/nm/active_connection.py import-3.5!skip | ||
plugins/module_utils/network_lsr/nm/client.py import-3.5!skip | ||
plugins/module_utils/network_lsr/nm/connection.py import-3.5!skip | ||
plugins/module_utils/network_lsr/nm/provider.py import-3.5!skip | ||
plugins/module_utils/network_lsr/nm/active_connection.py import-3.6!skip | ||
plugins/module_utils/network_lsr/nm/client.py import-3.6!skip | ||
plugins/module_utils/network_lsr/nm/connection.py import-3.6!skip | ||
plugins/module_utils/network_lsr/nm/provider.py import-3.6!skip | ||
plugins/module_utils/network_lsr/nm/active_connection.py import-3.7!skip | ||
plugins/module_utils/network_lsr/nm/client.py import-3.7!skip | ||
plugins/module_utils/network_lsr/nm/connection.py import-3.7!skip | ||
plugins/module_utils/network_lsr/nm/provider.py import-3.7!skip | ||
plugins/module_utils/network_lsr/nm/active_connection.py import-3.8!skip | ||
plugins/module_utils/network_lsr/nm/client.py import-3.8!skip | ||
plugins/module_utils/network_lsr/nm/connection.py import-3.8!skip | ||
plugins/module_utils/network_lsr/nm/provider.py import-3.8!skip | ||
plugins/module_utils/network_lsr/__init__.py shebang!skip | ||
plugins/module_utils/network_lsr/argument_validator.py shebang!skip | ||
plugins/module_utils/network_lsr/utils.py shebang!skip | ||
plugins/module_utils/network_lsr/myerror.py shebang!skip | ||
tests/network/covstats shebang!skip | ||
tests/network/ensure_provider_tests.py shebang!skip | ||
tests/network/get_coverage.sh shebang!skip | ||
tests/network/get_total_coverage.sh shebang!skip | ||
tests/network/merge_coverage.sh shebang!skip | ||
tests/network/ensure_provider_tests.py future-import-boilerplate!skip | ||
tests/network/integration/conftest.py future-import-boilerplate!skip | ||
tests/network/integration/test_ethernet.py future-import-boilerplate!skip | ||
tests/network/unit/test_network_connections.py future-import-boilerplate!skip | ||
tests/network/unit/test_nm_provider.py future-import-boilerplate!skip | ||
tests/network/ensure_provider_tests.py metaclass-boilerplate!skip | ||
tests/network/integration/conftest.py metaclass-boilerplate!skip | ||
tests/network/integration/test_ethernet.py metaclass-boilerplate!skip | ||
tests/network/unit/test_network_connections.py metaclass-boilerplate!skip | ||
tests/network/unit/test_nm_provider.py metaclass-boilerplate!skip | ||
plugins/modules/network_connections.py validate-modules:missing-examples | ||
plugins/modules/network_connections.py validate-modules:missing-gplv3-license | ||
plugins/modules/network_connections.py validate-modules:no-default-for-required-parameter | ||
plugins/modules/network_connections.py validate-modules:parameter-type-not-in-doc | ||
plugins/modules/network_connections.py validate-modules:undocumented-parameter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,30 @@ | |
# -*- coding: utf-8 -*- | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
|
||
from __future__ import absolute_import, division, print_function | ||
|
||
__metaclass__ = type | ||
|
||
DOCUMENTATION = """ | ||
--- | ||
module: network_connections | ||
author: Thomas Haller (@thom311) | ||
short_description: module for network role to manage connection profiles | ||
requirements: [pygobject, dbus, NetworkManager] | ||
version_added: "2.0" | ||
description: | ||
- "WARNING: Do not use this module directly! It is only for role internal use." | ||
- | | ||
Manage networking profiles (connections) for NetworkManager and | ||
initscripts networking providers. Documentation needs to be written. Note | ||
that the network_connections module tightly integrates with the network | ||
role and currently it is not expected to use this module outside the role. | ||
Thus, consult README.md for examples for the role. The requirements are | ||
only for the NetworkManager (nm) provider. | ||
options: {} | ||
""" | ||
|
||
|
||
import errno | ||
import functools | ||
import os | ||
|
@@ -16,7 +40,7 @@ | |
# pylint: disable=import-error, no-name-in-module | ||
from ansible.module_utils.basic import AnsibleModule | ||
from ansible.module_utils.network_lsr import ethtool # noqa:E501 | ||
from ansible.module_utils.network_lsr import MyError # noqa:E501 | ||
from ansible.module_utils.network_lsr.myerror import MyError # noqa:E501 | ||
|
||
from ansible.module_utils.network_lsr.argument_validator import ( # noqa:E501 | ||
ArgUtil, | ||
|
@@ -30,22 +54,6 @@ | |
# pylint: enable=import-error, no-name-in-module | ||
|
||
|
||
DOCUMENTATION = """ | ||
--- | ||
module: network_connections | ||
author: "Thomas Haller ([email protected])" | ||
short_description: module for network role to manage connection profiles | ||
requirements: for 'nm' provider requires pygobject, dbus and NetworkManager. | ||
version_added: "2.0" | ||
description: Manage networking profiles (connections) for NetworkManager and | ||
initscripts networking providers. | ||
options: Documentation needs to be written. Note that the network_connections | ||
module tightly integrates with the network role and currently it is not | ||
expected to use this module outside the role. Thus, consult README.md for | ||
examples for the role. | ||
""" | ||
|
||
|
||
############################################################################### | ||
PERSISTENT_STATE = "persistent_state" | ||
ABSENT_STATE = "absent" | ||
|
@@ -772,7 +780,7 @@ def connection_compare( | |
if compare_flags is None: | ||
compare_flags = NM.SettingCompareFlags.IGNORE_TIMESTAMP | ||
|
||
return not (not (con_a.compare(con_b, compare_flags))) | ||
return con_a.compare(con_b, compare_flags) | ||
|
||
def connection_is_active(self, con): | ||
NM = Util.NM() | ||
|
@@ -1399,7 +1407,7 @@ def _check_mode_changed(self, old_check_mode, new_check_mode, connections): | |
def check_mode_set(self, check_mode, connections=None): | ||
c = self._check_mode | ||
self._check_mode = check_mode | ||
assert ( | ||
if not ( | ||
(c is None and check_mode in [CheckMode.PREPARE]) | ||
or ( | ||
c == CheckMode.PREPARE | ||
|
@@ -1408,7 +1416,12 @@ def check_mode_set(self, check_mode, connections=None): | |
or (c == CheckMode.PRE_RUN and check_mode in [CheckMode.REAL_RUN]) | ||
or (c == CheckMode.REAL_RUN and check_mode in [CheckMode.DONE]) | ||
or (c == CheckMode.DRY_RUN and check_mode in [CheckMode.DONE]) | ||
) | ||
): | ||
raise AssertionError( | ||
"updating check_mode value from {0} into {1} is incorrect".format( | ||
c, check_mode | ||
) | ||
) | ||
self._check_mode_changed(c, check_mode, connections) | ||
|
||
|
||
|
@@ -1470,7 +1483,8 @@ def log( | |
warn_traceback=False, | ||
force_fail=False, | ||
): | ||
assert idx >= -1 | ||
if not idx >= -1: | ||
raise AssertionError("idx {0} is less than -1".format(idx)) | ||
self._log_idx += 1 | ||
self.run_results[idx]["log"].append((severity, msg, self._log_idx)) | ||
if severity == LogLevel.ERROR: | ||
|
@@ -1607,14 +1621,15 @@ def connections(self): | |
def connections_data(self): | ||
c = self._connections_data | ||
if c is None: | ||
assert self.check_mode in [ | ||
if self.check_mode not in [ | ||
CheckMode.DRY_RUN, | ||
CheckMode.PRE_RUN, | ||
CheckMode.REAL_RUN, | ||
] | ||
c = [] | ||
for _ in range(0, len(self.connections)): | ||
c.append({"changed": False}) | ||
]: | ||
raise AssertionError( | ||
"invalid value {0} for self.check_mode".format(self.check_mode) | ||
) | ||
c = [{"changed": False}] * len(self.connections) | ||
self._connections_data = c | ||
return c | ||
|
||
|
@@ -1623,11 +1638,14 @@ def connections_data_reset(self): | |
c["changed"] = False | ||
|
||
def connections_data_set_changed(self, idx, changed=True): | ||
assert self._check_mode in [ | ||
if self._check_mode not in [ | ||
CheckMode.PRE_RUN, | ||
CheckMode.DRY_RUN, | ||
CheckMode.REAL_RUN, | ||
] | ||
]: | ||
raise AssertionError( | ||
"invalid value {0} for self._check_mode".format(self._check_mode) | ||
) | ||
if not changed: | ||
return | ||
self.connections_data[idx]["changed"] = changed | ||
|
@@ -1697,7 +1715,10 @@ def connection_modified_earlier(self, idx): | |
# modify the connection. | ||
|
||
con = self.connections[idx] | ||
assert con["state"] in ["up", "down"] | ||
if con["state"] not in ["up", "down"]: | ||
raise AssertionError( | ||
"connection state {0} not 'up' or 'down'".format(con["state"]) | ||
) | ||
|
||
# also check, if the current profile is 'up' with a 'type' (which | ||
# possibly modifies the connection as well) | ||
|
@@ -1745,7 +1766,9 @@ def check_mode_next(self): | |
elif self._check_mode != CheckMode.DONE: | ||
c = CheckMode.DONE | ||
else: | ||
assert False | ||
raise AssertionError( | ||
"invalid value {0} for self._check_mode".format(self._check_mode) | ||
) | ||
self._check_mode = c | ||
self.run_env.check_mode_set(c) | ||
return c | ||
|
@@ -1911,7 +1934,12 @@ def run_prepare(self): | |
|
||
name = connection["name"] | ||
if not name: | ||
assert connection["persistent_state"] == "absent" | ||
if not connection["persistent_state"] == "absent": | ||
raise AssertionError( | ||
"persistent_state must be 'absent' not {0} when there is no connection 'name'".format( | ||
connection["persistent_state"] | ||
) | ||
) | ||
continue | ||
if name in names: | ||
exists = names[name]["nm.exists"] | ||
|
@@ -1988,7 +2016,7 @@ def _check_ethtool_setting_support(self, idx, connection): | |
idx, "ethtool.%s specified but not supported by NM", specified | ||
) | ||
|
||
for option, _ in specified.items(): | ||
for option in specified.keys(): | ||
nm_name = nm_get_name_fcnt(option) | ||
if not nm_name: | ||
self.log_fatal( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +0,0 @@ | ||
#!/usr/bin/python3 -tt | ||
# vim: fileencoding=utf8 | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
|
||
|
||
class MyError(Exception): | ||
pass | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/usr/bin/python3 -tt | ||
# vim: fileencoding=utf8 | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
|
||
from __future__ import absolute_import, division, print_function | ||
|
||
__metaclass__ = type | ||
|
||
|
||
class MyError(Exception): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.