Commit graph

60 commits

Author SHA1 Message Date
Rich Megginson
c144794faa style: ansible-lint - remove line-length files from .yamllint.yml
Rather than having to maintain .yamllint.yml with a list of files
exempt from yamllint line-length checking, either fix the code
to abide by the line length restriction, or put the yamllint
exceptions in-line in the code.

Signed-off-by: Rich Megginson <rmeggins@redhat.com>
2023-04-28 09:41:30 -06:00
Rich Megginson
211412d035 style: ansible-lint - fix missing YAML document start
ansible-lint requires that YAML documents begin with a line
consisting of `---`

Signed-off-by: Rich Megginson <rmeggins@redhat.com>
2023-04-28 09:15:50 -06:00
Wen Liang
5ff1189409 ansible-lint: Fix name[missing] and name[play] failures
Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2023-04-10 17:49:07 +02:00
Wen Liang
2de826ee24 ansible-lint: Fix yaml[octal-values] failures
Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2023-04-04 09:52:31 -06:00
Noriko Hosoi
77214cbda4 Fingerprint RHEL System Role managed config files
- Add role name to the generated config files.
  # system_role:network

Signed-off-by: Noriko Hosoi <nhosoi@redhat.com>
2023-03-30 13:38:19 -06:00
Wen Liang
2b693d14c0 ansible-lint: Fix no-changed-when failure
Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2023-03-29 13:10:38 +02:00
Rich Megginson
7f26cdb8ac in lsr_assert_when use condition instead of when
ansible-lint is confused by the use of `when:` with `lsr_assert_when`.
It thinks the `when` string should be evaluated as a Jinja expression
but it is really just a plain string.  To make this more friendly to
ansible-lint, use `condition:` instead of `when:` with
`lsr_assert_when`.

Signed-off-by: Rich Megginson <rmeggins@redhat.com>
2023-03-28 18:26:33 -06:00
Wen Liang
8a3dd3c438 ansible-lint: Fix command-instead-of-module failures
Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2023-03-28 18:40:13 +02:00
Wen Liang
8174d5320d ansible-lint: Fix jinja[spacing] warnings
Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2023-03-27 16:25:03 +02:00
Wen Liang
cd72556282 ansible-lint: Fix name[casing] warnings
Start all task names an uppercase letter.

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2023-03-27 16:25:03 +02:00
Wen Liang
a384e5bb00 ansible-lint: Fix key-order[task] failures
Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2023-03-22 10:21:50 +01:00
Wen Liang
4bac670e65 ansible-lint: Fix name[template] warnings
Jinja templates should only be at the end of 'name'. This helps with
the identification of tasks inside the source code when they fail.

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2023-03-21 17:06:29 +01:00
Wen Liang
e8fef16995 ansible-lint: Fix no-jinja-when, yaml[line-legnth] and package-latest failures
Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2023-03-20 14:14:00 +01:00
Wen Liang
f11e720268 ansible-lint: Fix var-naming warnings
Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2023-03-02 12:08:51 +01:00
Wen Liang
101920be5c ansible-lint: Fix yaml[truthy] failures
Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2023-02-20 15:00:28 +01:00
Wen Liang
c526da39c7 Support running the tests with ANSIBLE_GATHERING=explicit
Almost all the network role tests fail with fact gathering disabled.
Therefore, in order to support the tests running with
ANSIBLE_GATHERING=explicit, gather the minimum subset of facts
required.

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2023-01-11 15:24:50 +01:00
Rich Megginson
cf356230ca support ansible-core-2.14, ansible-lint 6.x
ansible-core 2.14 is now the current version of Ansible.  This version
does not support `args: warn: false` so we have to remove it from the
network role.  Users will need to use `COMMAND_WARNINGS` in their
Ansible configuration in order to suppress the warning in older versions
of Ansible such as 2.9, 2.11.
In addition, the gating tests are getting stricter about using new best
practices, such as using `true`, `false` for booleans instead of `yes`,
`no`; use of spaces in Jinja expressions; etc.  These issues were
addressed.
The `tests/` directory contains far too many cases of non-recommended
practices, so this directory has been exempted.

Signed-off-by: Rich Megginson <rmeggins@redhat.com>
2022-11-14 13:54:14 -07:00
Rich Megginson
53208608a4 use rpm -i instead of yum install for epel7
On BaseOS CI systems, `yum install` for the epel7 rpm does not work.
Instead, use `rpm -i` which should work on any system.  We should not
need to use `yum install` here because the epel7 setup rpm does not have
additional dependencies.
In addition, the rpm download sometimes returns 403 - I think it is because
multiple tests run in parallel in BaseOS CI, resulting in too many
download attempts in too short a period of time - so introduce a retry
to mitigate the situation.

Signed-off-by: Rich Megginson <rmeggins@redhat.com>
2022-10-31 16:42:04 -06:00
Rich Megginson
58a8e258ef change include to include_tasks
The keyword `include:` is deprecated in favor of
`include_tasks:`.
See https://docs.ansible.com/ansible/latest/collections/ansible/builtin/include_module.html

Signed-off-by: Rich Megginson <rmeggins@redhat.com>
2022-07-05 12:52:29 -06:00
Wen Liang
48b1619318 Validate the ip addresses added to the DHCP server
DHCP server certainly needs the IP address configured in order to lease
the address to the client. There is a bug in NM which wrongly removes
all addresses on the unmanaged interface while it should not. To
guarantee the IP address indeed configured for DHCP server, rescue it
via adding conditional loop for configuring IP address to DHCP server.

Notice that this workaround will be removed eventually when NM fixes
the bug.

https://bugzilla.redhat.com/show_bug.cgi?id=2079642

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2022-05-05 14:42:00 +02:00
Rich Megginson
c377f993c6 use pgrep instead of pidof; ensure packages exist
The tests are giving failures that are unfortunately being ignored.
One of which is that pidof is not available by default on all platforms,
and on some platforms is not available at all (el7).  Same with sysctl.

There are a couple of fixes:
* run the large embedded test `shell` with `set -euo pipefail` to
trigger script errors to be handled.
* install the procps or procps-ng package which provides the tools
such as pgrep, pkill, sysctl, etc.

Signed-off-by: Rich Megginson <rmeggins@redhat.com>
2022-03-01 08:36:20 +08:00
Noriko Hosoi
79b39792e4 System Roles should consistently use ansible_managed in configuration files it manages
bz#2044640

The network role create an ifcfg file for initscripts. The file
used to append a comment "# this file was created by ansible".
This patch replaces the proprietary string with the ansible
standard {{ ansible_managed }} to adjust to the other system
roles.

For the implementation, it borrowed the method from kernel_settings,
getting the ansible managed comment using the get_ansible_managed.j2
template and pass the comment to network_connections which is added
to the ifcfg file.

In case network_provider is nm, the comment is not added to the
ifcfg file as the file is not managed by Ansible.

Note: the required parameter name to pass the ansible managed comment
to the network_connection module is "__header".

Do not use get_ansible_managed.j2 in the test scripts, but use a
hardcoded ansible managed comment to simplify the tests.

tests/tasks/get_profile_stat.yml: replace the '=' style with the YAML
notation in set_fact.

Signed-off-by: Noriko Hosoi <nhosoi@redhat.com>
2022-02-25 06:10:42 +08:00
Wen Liang
61423ed36f Fix hostapd package installation error
The hostapd package was moved from EPEL to CentOS Stream and therefore
is not available anymore on EPEL, which made the installation failed.
To fix it, install the hostapd via CentOS Stream in order to run
managed host testing in RHEL-8.5.

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2022-02-21 21:51:38 +01:00
Rich Megginson
db10fc2035 add support for ansible-core 2.11 ansible-lint, ansible-test
Add support for using latest ansible-lint and ansible-test with
ansible-core 2.11.  There are a few new warnings that need to
be addressed or suppressed.

One of the changes is to add `# noqa ignore-errors` to the places in
the role where `ignore_errors: true` is used.  In general, it is not
a good idea to use `ignore_errors: true` - instead, it is better to
capture the result of the command using a `register`, then use
`failed_when`.  Or, if that is not possible, use a `block`/`rescue`
for more complex error handling.  However, in the case where the network
role is using `ignore_errors: true` in test code, it is acceptable.
see https://ansible-lint.readthedocs.io/en/latest/default_rules.html#ignore-errors

Another change is to have all tasks have a valid `name:`.  This
is explained at https://ansible-lint.readthedocs.io/en/latest/default_rules.html#unnamed-task

Signed-off-by: Rich Megginson <rmeggins@redhat.com>
2021-10-11 12:03:00 -06:00
Sergei Petrosian
c0f6038082 On RHEL 7, enable epel using yum-config-manager
Fixing the CI on RHEL 7, it was broken by PR #422

Signed-off-by: Sergei Petrosian <spetrosi@redhat.com>
2021-10-06 20:02:12 +02:00
Rich Megginson
867482d35b replace ini_file with yum/dnf
For ansible-core 2.11 compatability, replace the use of `ini_file`
with the yum/dnf config-manager command

Signed-off-by: Rich Megginson <rmeggins@redhat.com>
2021-09-16 08:39:37 -06:00
Wen Liang
a2af42d0f2 wifi: Add Simultaneous Authentication of Equals(SAE) support
Enable WPA3 SAE support via:

    ```yaml
    network_connections:
      - name: wlan0
        type: wireless
        wireless:
          ssid: "WIFI_SSID"
          key_mgmt: "sae"
	  password: "p@55w0rD"
    ```

Integration test case was included for Fedora and CentOS. ( Failed in setting up the
mock wifi on RHEL, so skipped the integration test on RHEL)

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2021-08-09 09:59:22 +08:00
Gris Ge
c1ad6925b7 test: Fix the bond test on DHCP
The `tests_bond_nm.yml` test fails at 50% rate due to bond interface
failed to retrieve IP address from DHCP server.

The root cause of this is NetworkManager by default create default
connections for new managed interface which place the DHCP server
interfaces into IPv4.auto method which then prevent DHCP server running
on these ports.

The fix is mark DHCP server ports(veth endpoint and bridge) as
unmanaged before link up.

Signed-off-by: Gris Ge <fge@redhat.com>
2021-07-28 19:50:09 +08:00
Noriko Hosoi
1f25fbb4fc EPEL yum repository configuration for tests
In tests/tasks/enable_epel.yml, if /etc/yum.repos.d/epel.repo exists
and it is not enabled, it's left disabled. Without the epel enabled,
it fails to install necessary modules such as python-mock, which
makes tests_unit.yml and tests_wireless_nm.yml fail.

This patch adds a task calling ini_file to ensure the repo is always
enabled. See also bz1980439

Signed-off-by: Noriko Hosoi <nhosoi@redhat.com>
2021-07-16 06:11:05 +08:00
Wen Liang
2444e27cce wifi: Add Opportunistic Wireless Encryption (OWE) support
Enable WPA3 OWE support via:

    ```yaml
    network_connections:
      - name: wlan0
        type: wireless
        wireless:
          ssid: "WIFI_SSID"
          key_mgmt: "owe"
    ```

Integration test case was included for Fedora and CentOS. ( Failed in setting up the
mock wifi on RHEL, so skipped the integration test on RHEL)

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2021-05-24 10:51:01 +08:00
Noriko Hosoi
34665b916d Cleaning up ansible-lint errors except '106', '303' and '403'
That is the following errors are fixed.
'206'  # Variables should have spaces before and after: {{ var_name }}
'208'  # File permissions unset or incorrect
'301'  # Commands should not change things if nothing needs doing
'305'  # Use shell only when shell functionality is required
'502'  # All tasks should be named
'601'  # Don't compare to literal True/False
'602'  # Don't compare to empty string

RHELPLAN-73471

Signed-off-by: Noriko Hosoi <nhosoi@redhat.com>
2021-04-15 20:53:53 +02:00
Rich Megginson
209fa56d14 fix collection lookup problem
This fixes the following error:
```
/bin/sh: line 9: cd: /root/.ansible/collections: No such file or directory
```
The fix is to ensure the directory exists before attempting
to `cd` to the directory.

Signed-off-by: Rich Megginson <rmeggins@redhat.com>
2021-02-10 16:50:52 -06:00
Rich Megginson
9c86ff6f76 collections - working unit tests during integration
The unit tests that are run during integration test did not
work for the role converted to collection format.  The tests need to
get the paths from the environment then set up the runtime environment
to look like the real Ansible runtime environment.

Signed-off-by: Rich Megginson <rmeggins@redhat.com>
2021-01-22 05:57:16 +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
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
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
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
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
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
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
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
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
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
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
4753c70c55 library: Separate debug and info logs from warnings
Logs are now separed by severity level. Warnings and failures are the only logs
that appear now on the output. All logs are saved into a new json parameter
called "stderr" that is later shown on a different task. In case of
failure, all logs are shown as output. Tests have been created and modified in
order to assure that this feature works.

Signed-off-by: Elvira Garcia Ruiz <elviragr@riseup.net>
2020-05-06 21:57:34 +02:00