Commit graph

494 commits

Author SHA1 Message Date
Rich Megginson
7798dcdfd3 add ansible-lint to github actions
Since we have disabled linting in molecule, use tox for running
ansible-lint.
In addition, fix molecule config to use `false` instead of `False`
since the former is the correct YAML boolean value.  This also
will make network consistent with the other roles.

Signed-off-by: Rich Megginson <rmeggins@redhat.com>
2021-01-15 16:21:07 +08:00
Noriko Hosoi
023ecbd027 Collections - workaround for the module_utils path finding issue in ansible 2.9
The details of the issue is described in this ansible issue:
   https://github.com/ansible/ansible/issues/68361

The workaround contains 2 changes.
1) Advice from @sivel:
   replacing, e.g.,
     from ansible.module_utils.network_lsr.nm.provider import NetworkManagerProvider
   with
     from ansible.module_utils.network_lsr.nm import provider
   and then use provider.NetworkManagerProvider
2) In the later module_utils path finding path, gi.require_version("NM", "1.0")
   in module_utils/network_lsr/nm/client.py fails with "ValueError: Namespace
   NM not available" on the control node. By ignoring the exception, the failure
   is worked around. Please note that the missing package issue never occurs
   on the managed nodes since in case of "nm", the NetworkManager package is
   installed in the network role.

Signed-off-by: Noriko Hosoi <nhosoi@redhat.com>
2021-01-14 17:04:10 -05:00
Rich Megginson
977f149f1e Fix centos6 repos; use standard centos images; add centos8
Use the new vault.centos.org repos.  Fix the yum repo configs in the
image if necessary to use these new repos.
Use the standard centos images from the centos registry rather than
custom lsr images from dockerhub.
Add support for centos8.  Note that using ansible 2.7 on centos8
requires setting /usr/bin/python3 to be the ansible python
interpreter.  Later versions of ansible have better auto-detection.
We can get rid of this once we drop support for ansible 2.7
Use tox-lsr 1.0.1 - which means we do not need
molecule_extra_requirements.txt

Signed-off-by: Rich Megginson <rmeggins@redhat.com>
2021-01-13 23:43:11 +08:00
Antonio Cardace
69ae6b5b2a readme: Update README with ethtool coalescing options
Resolves: #112
Signed-off-by: Antonio Cardace <acardace@redhat.com>
2021-01-09 11:02:07 +08:00
Antonio Cardace
b586d11e79 Add support for ethtool coalesce settings
Also add related tests.

Resolves: #112
Signed-off-by: Antonio Cardace <acardace@redhat.com>
2021-01-09 11:02:07 +08:00
Gris Ge
b0f5d6352a test: Fix EL6 repo
* As EPEL6 has been moved to archive, created `tests/tasks/enable_epel.yml`.
 * As CentOS6 has been moved to vault, created `tests/tests_00_setup.yml`.

Signed-off-by: Gris Ge <fge@redhat.com>
2020-12-22 08:14:39 +08:00
Wen Liang
f01655c47a Add NetworkManager development documentation to contributing guide
Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2020-12-18 17:54:56 +08:00
Rich Megginson
4f9f7a4c94 make CI work with tox-lsr
Use tox-lsr instead of the scripts in the `.travis/` directory and the
asssociated config files.  Yes, `.travis/custom.sh` is still there,
but once you are familiar with the way that tox-lsr works, you can
remove it and use your own custom tox.ini action.  The goal of this
commit was to make as few changes as possible, to keep feature parity
with the old `.travis/` script way of running CI.  Also note that
linting has moved into tox, so we needed to disable molecule linting.
The new version of ansible-lint adds a lot of checks, so these are
disabled for now, and should be fixed later.  Also, shellcheck is
turned off until the network team can address the issues.

The `.travis/custom.sh` script is not run in the CI environment, so
this was changed slightly to remove the check for `$TRAVIS`, and it is
no longer run as a tox testenv in CI.

Signed-off-by: Rich Megginson <rmeggins@redhat.com>
2020-12-18 10:32:16 +08:00
Rich Megginson
302e682136 Fix python line length problem
The line was too long, and needed to be wrapped in a way that was
compatible with python black formatting.

Signed-off-by: Rich Megginson <rmeggins@redhat.com>
2020-12-17 11:47:22 -07:00
Wen Liang
f848949c76 RFE: Support dummy interfaces
Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2020-12-16 14:28:41 +08:00
Gris Ge
637e1e6bbe test: Fix profile assertion on Fedora 33
The NetworkManager in Fedora 33 does not use ifcfg-rh plugin by default,
the CI will fail on Fedora 33 with:

```
TASK [assert that profile 'bond0' is present] **********************************
task path: /tmp/tmpaz9m374e/tests/playbooks/tasks/assert_profile_present.yml:4
fatal: [/cache/fedora-33.qcow2]: FAILED! => {
    "assertion": "profile_stat.stat.exists",
    "changed": false,
    "evaluated_to": false,
    "msg": "profile /etc/sysconfig/network-scripts/ifcfg-bond0 does not exist"
}
```

Previously, we are checking the existence of
`/etc/sysconfig/network-scripts/` to determine whether ifcfg-rh plugin
is enabled. This is incorrect on Fedora 33.

The fix is checking the FILENAME[1] used for storing the NetworkManager
connection, the profile is considered as exists when it exists and does
not contains `/run`.

Since we cannot tell which provider we are using, we just check both
initscripts files and NetworkManager connections.

[1]: nmcli -f NAME,FILENAME connection show

Signed-off-by: Gris Ge <fge@redhat.com>
2020-12-16 10:39:13 +08:00
Rich Megginson
c64b3b15ba use github actions instead of travis
adds a github actions tox workflow for CI testing, since
travis is discontinuing support for open source projects

Signed-off-by: Rich Megginson <rmeggins@redhat.com>
2020-12-11 14:46:40 +08:00
Jakub Haruda
899edea426 meta/main.yml: CI - Add support for all Fedora images
Signed-off-by: Jakub Haruda <jharuda@redhat.com>
2020-11-30 14:05:24 +08:00
Wen Liang
c183fff523 Disable Python2 unit tests on Fedora
Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2020-11-30 13:31:56 +08:00
Gris Ge
ad2a8bfd29 test env: Bring test veth peer up
In order to allows NetworkManager to control veth interface,
the veth peer should be in up state and the veth should be marked as
managed.

Signed-off-by: Gris Ge <fge@redhat.com>
2020-11-27 16:36:57 +08:00
Gris Ge
acb1d0165e test 802.1x: Install openssl as test dependency
The Fedora 33 cloud image does not have openssl installed by default,
install openssl before using its cli tool.

Signed-off-by: Gris Ge <fge@redhat.com>
2020-11-23 15:55:35 +08:00
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