Commit graph

478 commits

Author SHA1 Message Date
Gris Ge
c4643e56bb nm provider: Refactor the down action of network connection
When deactivating a profile in libNM, we should:

 * Check `NM.ActionConnection` existence
 * Check `NM.ActionConnection.props.state` not DEACTIVATED
 * Use signal `state-changed` of `NM.ActionConnection`.
 * Only invoke `NM.Client.deactivate_connection_async()` if not
   in DEACTIVATING state.
 * Ignore `NM.ManagerError.CONNECTIONNOTACTIVE` error.

This patch also introduced a new class `NetworkManagerProvider`
in `module_utils/network_lsr/nm`:

 * Independent from Ansible but need to use absolute import due to
   limitation of ansible 2.8.
 * Provide sync function wrapping async calls of libNM.
 * Use stable logging method of python.
 * Only load this module when provider is nm.

This patch also changed how logging is handling in
`Cmd_nm.run_action_down()` as initial step on isolate ansible log
mechanism from provider module.

By moving provider codes to `module_utils` folder, we can eventually
simplify the bloated `library/network_connections.py`.

Signed-off-by: Gris Ge <fge@redhat.com>
2020-11-19 18:58:26 +08:00
Fernando Fernandez Mancera
6812aab616 README.md: replace reference to "master" branch with "main" branch
All links containing references to the "master" branch must be replaced
by the "main" branch.

Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
2020-11-10 10:36:22 +01:00
Noriko Hosoi
18ed81168f Sync with travis/runcollection.sh template
Source commit in the template repo: e9f2c3a 4f3c96a
    Merge pull request #48 from nhosoi/collections
    runcollection.sh - stop passing an argument list

This change allows to eliminate the test argument list as well as the
branch name to retrieve the lsr_role2collection.py script for the
collection test.

Signed-off-by: Noriko Hosoi <nhosoi@redhat.com>
2020-11-06 10:45:54 +01:00
Rich Megginson
c6b0226bf6 lock ansible-lint version at 4.3.5; suppress role name lint warning
lock the ansible-lint version to use the latest version 4.3.5 which
is compatible with the latest ansible 2.10
This means we need to suppress the error about the role name

Signed-off-by: Rich Megginson <rmeggins@redhat.com>
2020-10-27 11:37:20 +01:00
Fernando Fernandez Mancera
dc4bfa7272 github: add stale workflow
To ensure that old/untouched pull requests do not pile up, configure the
probot stale bot to mark pull requests without activity in the last 30
days as stale and close them after 14 more days if there is no further
activity. The pull requests are marked with the stale label.

Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
2020-10-26 14:59:30 +01:00
Noriko Hosoi
890af84071 RHELPLAN-56586 - sync collections related changes from template to network role
The task 56586 is for adding tests against the collection converted
format to the tox/travis CI to capture a problem before merging the
pr, if any. It'd be helpful to find out bugs in the conversion tool
lsr_role2collection.py, as well. The source of this commit is located
in linux-system-roles/template. They are synced by auto-maintenance/
sync-template.sh, then manually adjusted to the network role.

.travis/runcollection.sh is the test script. tox.ini is modified to run
it in the tox/travis CI. The script downloads lsr_role2collection.py,
then converts the network role into the conversion format in the working
directory .tox. In the collection, it runs a set of tests black, flake8,
yamllint, py38 to check the converted result.
2020-10-23 13:35:14 +08:00
Wen Liang
3c7580d7f9 Remove comment about host selection workaround
Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2020-10-15 07:40:33 +02:00
Wen Liang
e92a5c272a Document where to find other images used for testing
Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2020-10-07 22:31:17 +02:00
Wen Liang
c7af145a9a Install NetworkManager-team package when team profiles are configured
Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2020-10-07 11:18:30 +02:00
Gris Ge
ed5fa4c606 CHANGELOG: emphasize the backward compatibility
Signed-off-by: Gris Ge <fge@redhat.com>
2020-09-23 15:53:15 +02:00
Wen Liang
eda49e3b38 Document running integration tests with podman
Document how to run integration test with podman, and list the files that are currently not working with podman.

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2020-09-15 19:52:09 +02:00
Wen Liang
d2bd928278 Remove extra quote in configuring git user email
Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2020-09-15 19:52:09 +02:00
Rich Megginson
35a09bbc61 use github_branch: main for galaxy import
Galaxy imports of the network role are failing:
https://galaxy.ansible.com/my-imports/1710
```
Task "703539" failed: Command '['git', 'clone', '--quiet', '--depth', '1', '--branch', 'master', 'https://github.com/linux-system-roles/network.git', '/var/tmp/galaxy/imports/tmpnxdxwzmg']' returned non-zero exit status 128.
```
We need to tell galaxy to use `main` instead of `master`.  The galaxy
roles documentation says that `github_branch` may be used for this
purpose:
https://galaxy.ansible.com/docs/contributing/creating_role.html#role-metadata

Signed-off-by: Rich Megginson <rmeggins@redhat.com>
2020-09-08 19:57:59 +02:00
Till Maas
9a6bdb5403 Update formatting according to new black version
Signed-off-by: Till Maas <opensource@till.name>
2020-08-28 09:11:56 +02:00
Rafael G. Ruiz
062b3a40ac contributing: add DCO requirement
Signed-off-by: Rafael G. Ruiz <llerrak@hotmail.com>
2020-08-28 09:10:43 +02:00
Till Maas
21de2fc95c Add CHANGELOG
Signed-off-by: Till Maas <opensource@till.name>
2020-08-26 18:41:46 +02:00
Elvira García Ruiz
5320e96a0e Add playbooks to automate integration testing
The main playbook executes integration/test_ethernet.py with pytest, adapting the
installation for different distributions.

Signed-off-by: Elvira García Ruiz <elviragr@riseup.net>
2020-08-24 21:52:25 +02:00
Elvira García Ruiz
c29a2bf708 Add Pytest integration tests
tests/integration/test_ethernet.py is a script capable of using the network
module without executing it from Ansible and using Pytest. The example test
sets an ip in a test interface. The changes in tox.ini adapt the testing to the
new script. The __init__.py files were added to allow python2.7 compatibility.

Signed-off-by: Elvira García Ruiz <elviragr@riseup.net>
2020-08-24 21:52:25 +02:00
Till Maas
bf4501bb87 tests: Do not check arch for NM version
To allow running the tests on any arch, do not check for the RPM
architecture when checking the NetworkManager version.

Signed-off-by: Till Maas <opensource@till.name>
2020-08-21 08:43:10 +02:00
Vladimír Beneš
6e85ffe5f2 tests: add simple bond tests for both nm and initscripts
* add a helper to create two veth devices with IPv4/IPv6 infra
 * add a bond in active-backup mode with miimon value
 * add two slaves connections for two veth devices
 * check automated IPv4/IPv6 addresses are assigned to master
 * check all connections are present
 * add a helper to delete previously created veth device setup
2020-08-20 17:06:05 +02:00
Till Maas
cfa84c44c4 Tasks: Explicitly specify file mode
Ansible with molecule warns because the default mode changed. The new
default mode seems to be wrong so specify the correct one.
2020-08-18 17:57:59 +02:00
Till Maas
3188594249 molecule: Hardcode ansible-lint version
This fixes the following traceback:

Traceback (most recent call last):
[...]
  File "/home/travis/build/linux-system-roles/network/.tox/env-3.6/lib/python3.6/site-packages/ansiblelint/utils.py", line 775, in expand_path_vars
    path = path.strip()
AttributeError: 'PosixPath' object has no attribute 'strip'

Reference: https://travis-ci.com/github/linux-system-roles/network/jobs/373270149
2020-08-18 16:47:48 +02:00
Rich Megginson
67c1cced8f Fix Travis CI issue with Docker server API version mismatch
Travis CI is using a version of Docker server that supports API version
1.38.  However, the Python PYPI package `docker` version 4.3 was
recently released which uses Docker server API version 1.39, and there
is apparently no way to tell molecule to configure the `docker` Python
API to use a different API.  The solution is to install the latest 4.2.x
version of the `docker` Python PYPI package.
2020-08-17 14:45:41 +02:00
Till Maas
0b2edc50d8 Forget unmanaged state in NetworkManager
When removing a profile with initscripts, also notify NetworkManager so
it can forget that the specified device was to be ignored.
2020-07-11 16:17:06 +02:00
Till Maas
1a9b140647 Tests: Cleanup ethtool features file 2020-07-11 16:17:06 +02:00
Till Maas
a1e2868f29 print_all_options: Fix formatting 2020-07-11 09:35:28 +02:00
Till Maas
65272e0324 Add script to print all options the role accepts 2020-07-10 21:09:14 +02:00
Till Maas
8deab236f0 README: Clarify order of dependent profiles 2020-07-09 22:40:58 +02:00
Till Maas
fb99ae6777 Simplify persistent state handling
Since the order of the actions list does not matter anymore because the
role iterates over all actions in a defined order, simplify the
handling for persistent states.
2020-07-06 13:13:56 +02:00
Till Maas
e0c7d550a9 States: Ignore already removed profile for absent
When a profile is specified as absent, ignore state requests if the
profile is already removed or not completely specified to improve
idempotence.

Also restructure the states test. This introduces a clear structure for
the individual test steps, properly assigns tags for each test from the
file and provides a clear error message with a description of the test
that failed in case of errors. Support for tests that expect a failure
is still missing.
2020-06-26 20:08:51 +02:00
Till Maas
e98da54b6e Tasks: Remove log output for enabling services
Enabling/starting a service creates a lot of noise in the debug and does not seem
to provide much insights. Therefore disable log output.
2020-06-26 20:08:51 +02:00
Till Maas
71b754de62 Add example to down and remove a profile 2020-06-26 20:08:51 +02:00
Till Maas
87b671cc1d Provider sets: Always run essential tasks
To allow selecting tests with tags, tasks essential tasks need to be
tagged as always to ensure that they are not accidentally skipped when
specifying a tag for a test.
2020-06-25 22:48:25 +02:00
Till Maas
eb6c9c1cc8 library: Rename invocation return value
Since `invocation` is an Ansible special value that is set for
triple verbosity, it is now visible for smaller verbosity. Therefore
rename it to `_invocation`, which seems to work with less verbosity.
Also adjust the content to match the regular `invocation` style.
2020-06-25 14:54:13 +02:00
Elvira Garcia Ruiz
6eb2d1d938 utils: Fix error message format
Signed-off-by: Elvira Garcia Ruiz <elviragr@riseup.net>
2020-06-25 14:00:23 +02:00
Elvira Garcia Ruiz
923c811cba Fail if state and persistent_state are incompatible
When persistent_state is present and state is set to present or absent, a
ValidationError raises. A unit test validating this has been added. The
test_802_1x.yml test was updated so as to follow this rule.

Signed-off-by: Elvira Garcia Ruiz <elviragr@riseup.net>
2020-06-24 21:58:09 +02:00
Till Maas
6a3b311461 Create all profiles before activating them
To reduce problems with profile specification order and to support
creating and activating bond profiles in one run with initscripts,
create all profiles first.
2020-06-18 13:58:36 +02:00
Till Maas
7f884ae09d Update simple bond example 2020-06-18 13:58:36 +02:00
Till Maas
ff1cba43d6 Tests: Check error message in ca_path test 2020-06-17 08:51:12 +02:00
Till Maas
cea278cd11 Tests: Avoid comparing booleans
Instead of testing directly for equality of boolean values, use logical
comparisons since the comparison is broken in Jinja2 before version
2.11.0.
2020-06-17 08:51:12 +02:00
Jack Adolph
5e0f8b1e16 Fix wireless WPA PSK example
Example playbook did not actually import the role.
2020-06-16 09:06:23 +02:00
Jack Adolph
51f8e5b05f Add support for wireless connections
WPA-PSK and WPA-EAP are supported. Uses existing 802.1x features of the role.
Added extra functionality to ArgValidatorStr to enforce a min and max length.
2020-06-15 21:10:54 +02:00
Till Maas
47ad99c7f0 Tests: Allow extra run conditions for NM tests
To be able to restrict running tests with NM, for example only on
CentOS/RHEL 7, allow to specify an extra run condition for the generated
shims.
2020-06-15 21:10:54 +02:00
Jack Adolph
dd4ae77cbf Add ca_path option for 802.1x connections
Special notes:
Hash the cacert in the ca_path as OpenSSL needs symlinks for ca
certificates from their symlinks to their filename if specifying a
directory.

In case ieee802_1x.ca_path is specified but not supported by
NetworkManager, fail to ensure the setting is not silently ignored.

References:
https://stackoverflow.com/questions/25889341/what-is-the-equivalent-of-unix-c-rehash-command-script-on-linux
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/448

Co-authored-by: Till Maas <opensource@till.name>
2020-06-15 18:26:34 +02:00
Till Maas
f72fc394ea library: Return module params for debugging
Set invocation as suggested in
https://docs.ansible.com/ansible/latest/reference_appendices/common_return_values.html#invocation
to report how the internal module was invoked.
2020-06-15 18:26:34 +02:00
Till Maas
371d6f4679 802.1x tests: Improve cleanup 2020-06-15 18:26:34 +02:00
Till Maas
7f222e5dbe Tests: Use command module 2020-06-15 18:26:34 +02:00
Elvira Garcia Ruiz
ef20874f4d library: Change ethtool features to use underscores
Ethtool features should use underscores instead of dashes. A
warning shows in case dashes used, and it fails if underscore and dashes are
mixed. Unit tests and integration tests have been added. Since nm already
needed underscores, the string processing that was made in nm_provider is now
unneeded and therefore removed.
2020-06-15 14:13:23 +02:00
Till Maas
3fc15de068 Library: Introduce debug flags
Allow to disable the checkpoint feature with a debug flag to make
debugging easier.
2020-05-29 08:41:12 +02:00
Elvira Garcia Ruiz
c9d2f8f3b7 Update contributing.md with detailed info of the project
Now the contribution document has some steps to facilitate to get into the
project's workflow for new contributors. It also contains the code
structure and how to use the CI testing of the project and basic info about git
configuration. A small reference to the contributing document has been added to
the readme.

Signed-off-by: Elvira Garcia Ruiz <elviragr@riseup.net>
2020-05-27 13:59:49 +02:00