Commit graph

242 commits

Author SHA1 Message Date
Rich Megginson
9e6e150a6e fix: add support for EL10
According to the Ansible team, support for listing platforms in
role `meta/main.yml` files is being removed.
Instead, they recommend using `galaxy_tags`

https://github.com/ansible/ansible/blob/stable-2.17/changelogs/CHANGELOG-v2.17.rst
"Remove the galaxy_info field platforms from the role templates"
https://github.com/ansible/ansible/issues/82453

Many roles already have tags such as "rhel", "redhat", "centos", and "fedora".
I propose that we ensure all of the system roles have these tags.
Some of our roles support Suse, Debian, Ubuntu, and others.
We should add tags for those e.g. the ssh role already has tags for "debian" and "ubuntu".

In addition - for each version listed under `platforms.EL` - add a tag like `elN`.

Q: Why not use a delimiter between the platform and the version e.g. `el-10`?

This is not allowed by ansible-lint:

```
meta-no-tags: Tags must contain lowercase letters and digits only., invalid: 'el-10'
meta/main.yml:1
```

So we cannot use uppercase letters either.

Q: Why not use our own meta/main.yml field?

No other fields are allowed by ansible-lint:

```
syntax-check[specific]: 'myfield' is not a valid attribute for a RoleMetadata
```

Q: Why not use some other field?

There are no other applicable or suitable fields.

Q: What happens when we want to support versions like `N.M`?

Use the word "dot" instead of "." e.g. `el10dot3`.
Similarly - use "dash" instead of "-".

We do not need tags such as `fedoraall`.
The `fedora` tag implies that the role works on all supported versions of fedora.
Otherwise, use tags such as `fedora40` if the role only supports specific versions.

Teaming support is dropped in EL10.  Provide an error to users who attempt
to use teaming and suggest that they use bonding instead.  Skip teaming
tests on EL10.

Signed-off-by: Rich Megginson <rmeggins@redhat.com>
2024-07-02 09:09:05 -06:00
Rich Megginson
5e384bbe8d test: debug deprecated bond test failures
When the test fails, gather additional information to help
diagnose the failure.

Signed-off-by: Rich Megginson <rmeggins@redhat.com>
2024-07-02 09:02:23 -06:00
Rich Megginson
b2fdc87366 fix python black formatting
Signed-off-by: Rich Megginson <rmeggins@redhat.com>
2024-06-04 18:09:20 -06:00
Rich Megginson
ab77dd159e test: improve name text for skipped ostree tests
Improve the name text for skipped ostree tests to explain
why the test is skipped.
Add tests/tasks/ostree_systems_check.yml for use by test
playbooks that may be skipped on ostree systems.

Signed-off-by: Rich Megginson <rmeggins@redhat.com>
2024-03-25 17:30:00 -06:00
Wen Liang
44f937d82b tests: Consent to restart network when specifying wireless or team connections
Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2024-03-15 17:33:36 -04:00
Wen Liang
66c3eef7e3 fix: Ask user's consent to restart NM due to wireless or team interfaces
If updates for network packages are available and wireless or team
connections are specified, NetworkManager must be restarted, the role
requires user's consent to restart NetworkManager. Otherwise, there
might be property conflicts between NetworkManager daemon and plugin, or
NetworkManager plugin is not taking effect.

`update_cache` is enabled in the module tasks to check if updates for
network packages are available due to wireless or team interfaces, in
that case, NetworkManager needs user's explicit consent to be restarted
after the network package updates. And using `state: latest` for
checking the network package updates because we have to guarantee that
NetworkManager and its plugin have the same and most recent version for
configuring the network connections settings in the backend. It is
worthwhile to mention that we have both tasks using dnf and yum module
for checking available updates for network packages. Because checking
package cache update is not supported in Ansible package module, Fedora
and RHEL8+ use DNF package manager by default, RHEL7 uses yum package
manager by default.

This commit will address the situation that users forget to explicitly
specify `network_allow_restart: true` when specifying wireless or team
connections.

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2024-03-15 17:33:36 -04:00
Wen Liang
b90e123708 tests: Team interface is indeed supported on Fedora
Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2024-03-14 17:07:34 -04:00
Rich Megginson
e681c3fea5 test: improve bond test failure debugging
Improve bond test failure debugging
* put test setup into block/always so that cleanup happens for setup failures
* trace shell commands so that we can determine exactly which command failed
* add error reporting so that when certain commands fail, we can determine the error code

Signed-off-by: Rich Megginson <rmeggins@redhat.com>
2024-02-27 13:17:16 -05:00
Wen Liang
c6be8dfde5 test: Purge DNS config at the end of tests_network_state.yml
Without purging the DNS testing config at the end
`tests_network_state.yml`, the managed hosts can not properly resolve
certain hosts (e.g. mirrors.fedoraproject.org, mirrors.centos.org )
in the package installation task of other tests.

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2024-02-14 20:20:49 -07:00
Wen Liang
b4f51e2691 test: Add DNS, routes and network connectivity checks during cleanup
In order to guarantee each test is cleaned up properly in the end, it
is important to add a post-test check to each test checking that:

- Routes and DNS are restored.
- Network connectivity to certain hosts are preserved.

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2024-02-14 20:20:49 -07:00
Wen Liang
ae9f212086 test: Retry until success when installing package
Sometimes the rpm download returns a 403, which is likely caused by
too many parallel jobs attempt the download from the same controller in
too short a period of time, so the epel server throttles additional
downloads - use a retry here to mitigate.

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2024-02-14 20:20:49 -07:00
Wen Liang
910ddd20a9 test: Rewrite tests_bond_options.yml in the new testing format
The new testing format is more concise and easier to debug when test
failure happens.

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2024-02-14 20:20:49 -07:00
Wen Liang
9b76608757 test: Clean up mock wifi at the end of each wireless test
Baseos CI runs different wireless tests in a sequence, the mock wifi
needs to be cleaned up properly at the end of each wireless test,
otherwise, it will cause the failure during the setup of mock wifi
for the next wireless test.

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2024-01-29 14:44:04 -07:00
Wen Liang
b7492a27ba feat: Support blackhole, prohibit and unreachable route types
It is useful and common practice to configure the routes with blackhole,
prohibit, and unreachable route types when users have BGP routing
setups.

Notice that this feature is only for nm provider using
`network_connections` variable. Configuring blackhole, prohibit, and
unreachable route types is also supported by using `network_state` since
nmstate version 2.2.20 (the setting name is `route-type`).

Resolves: https://issues.redhat.com/browse/RHEL-19579

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2024-01-12 14:14:50 -07:00
Rich Megginson
e4d499763c ci: Use supported ansible-lint action; run ansible-lint against the collection
The old ansible-community ansible-lint is deprecated.  There is a
new ansible-lint github action.  The new ansible-lint has several checks
related to ansible-test and the ignore files.  Many of our ignore settings
are not allowed any more and are required to be fixed or addressed in the
Ansible preferred way.

The python imports have to be wrapped in a try/except ImportError, and
where possible, an error must be returned from the module explaining
what was not able to be imported.

The module documentation must comply with the Ansible standards.  One
aspect of this is the `version_added` must be a valid ansible-core
version in X.Y.Z format.  Note that this version isn't really used
anywhere, so it doesn't matter for users of the role, it is purely
an `ansible-test` and import gating issue.

The result of this is that the .sanity files can be reduced to the
bare minimum which will greatly reduce the maintenance burden of
those files, make it easier to support newer versions of Ansible,
and make it easier to import the system roles collection into Galaxy
and Automation Hub.

The latest Ansible repo gating tests run ansible-lint against
the collection format instead of against individual roles.
We have to convert the role to collection format before running
ansible-test.

Role developers can run this locally using
`tox -e collection,ansible-lint-collection`
See https://github.com/linux-system-roles/tox-lsr/pull/125

Add `---` doc start to .markdownlint.yaml

The file `examples/down_profile+delete_interface.yml`
was not used and was causing ansible-lint errors.

ansible-lint enforces the order of keywords in plays - `name`,
then `hosts`, then `vars`, then `tasks`.

Signed-off-by: Rich Megginson <rmeggins@redhat.com>
2024-01-05 17:36:07 -07:00
Wen Liang
bbdc7f77c4 test: Fix wifi test failures
CentOS Stream build process has been moved to
https://kojihub.stream.centos.org.

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2023-12-23 13:51:06 -07:00
Wen Liang
55e953099a tests: Fix installing kernel module in Fedora
`uname -m` will show the machine hardware name.

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2023-12-23 13:49:48 -07:00
Wen Liang
eab5cccfcc test: Skip running tests where initscripts is not supported
Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2023-12-21 08:24:55 -07:00
Rich Megginson
428273cf2a refactor: get_ostree_data.sh use env shebang - remove from .sanity*
Use the `#!/usr/bin/env bash` shebang which is ansible-test friendly.
This means we can remove get_ostree_data.sh from the .sanity* files.
This also means we can remove the .sanity* files if we do not need
them otherwise.  Fix other shell scripts to use the friendly shebang
and remove from the .sanity* files.

Rename `pth` to `path` in honor of nscott

Signed-off-by: Rich Megginson <rmeggins@redhat.com>
2023-12-07 07:25:47 -07:00
Wen Liang
ed93bed847 refractor: Use meaningful variable
Some variables used in the module code are not meaningful at all, which
might be hard to read and understand. Therefore, replace them with
meaningful variables.

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2023-12-01 13:39:57 -07:00
Wen Liang
7c4f11f1d9 tests: Fix tests_network_state_nm.yml CI failure
Since the merge of nmstate commit 'nm dns: Support appending static DNS
before dynamic DNS' (https://github.com/nmstate/nmstate/pull/2438),
nmstate treats interface with `auto-dns: true` as valid to store DNS
and tries to use NetworkManager global DNS as much as possible. However,
in NM, `dns=systemd-resolved` does not support global DNS configuration,
because systemd-resolved only supports per-interface DNS servers (via
the D-Bus API). Therefore, write and validate the DNS configuration in
/run/NetworkManager/no-stub-resolv.conf, which contains the original
DNS settings pushed to the DNS plugin.

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2023-11-29 16:29:50 -07:00
Rich Megginson
0c590cdf5a refactor: improve support for ostree systems
The dependency on `ansible.utils.update_fact` is causing issue with
some users who now must install that collection in order to run
the role, even if they do not care about ostree.

The fix is to stop trying to set `ansible_facts.pkg_mgr`, and instead
force the use of the ostree package manager with the `package:` module
`use:` option.  The strategy is - on ostree systems, set the flag
`__$ROLENAME_is_ostree` if the system is an ostree system.  The flag
will either be undefined or `false` on non-ostree systems.
Then, change every invocation of the `package:` module like this:

```yaml
- name: Ensure required packages are present
  package:
    name: "{{ __$ROLENAME_packages }}"
    state: present
    use: "{{ (__$ROLENAME_is_ostree | d(false)) |
      ternary('ansible.posix.rhel_rpm_ostree', omit) }}"
```

This should ensure that the `use:` parameter is not used if the system
is non-ostree.  The goal is to make the ostree support as unobtrusive
as possible for non-ostree systems.
The user can also set `__$ROLENAME_is_ostree: true` in the inventory or play
if the user knows that ostree is being used and wants to skip the check.
Or, the user is concerned about the performance hit for ostree detection
on non-ostree systems, and sets `__$ROLENAME_is_ostree: false` to skip
the check.
The flag `__$ROLENAME_is_ostree` can also be used in the role or tests to
include or exclude tasks from being run on ostree systems.

This fix also improves error reporting in the `get_ostree_data.sh` script
when included roles cannot be found.

Signed-off-by: Rich Megginson <rmeggins@redhat.com>
2023-11-29 07:05:00 -07:00
Wen Liang
c7a31e7079 fix: Allow address 0.0.0.0/0 or ::/0 for 'from'/'to' in routing rule validation
`from 0.0.0.0/0` means from all IPv4 addresses, `from ::/0` means from
all IPv6 addresses. In NM, if `from` property is not specified in a
routing rule, NM still appends `from 0.0.0.0/0` or `from ::/0` to the
rule. NM also allows to specify `to 0.0.0.0/0` or `to ::/0` in a
routing rule, but the connection profiles will only show the `from`
setting for the rule.

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2023-11-13 14:06:53 -07:00
Rich Megginson
9a16583783 feat: support for ostree systems
Feature: Allow running and testing the role with ostree managed nodes.

Reason: We have users who want to use the role to manage ostree
systems.

Result: Users can use the role to manage ostree managed nodes.

NOTE: The .ostree/packages-*.txt are generated by running the
script https://github.com/linux-system-roles/auto-maintenance/blob/main/check-logs-for-packages.sh
which is used with an integration test CI run with the
https://github.com/linux-system-roles/auto-maintenance/blob/main/callback_plugins/dump_packages.py
plugin.  An example of such a CI run is
https://github.com/linux-system-roles/network/pull/647

Signed-off-by: Rich Megginson <rmeggins@redhat.com>
2023-10-30 12:02:20 -06:00
Wen Liang
ca2180e659 test: Remove bond tests tag expfail
Since the root cause of the bond tests failure is already found and
fixed (by the commit 'fix: Add dhcp client package dependency for
initscripts provider'). Therefore, remove the bond tests tag `expfail`
and enable the bond tests in the downstream testing.

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2023-10-05 15:11:02 -06:00
Wen Liang
17922ca6f3 fix: Install yum-utils package
`yum-config-manager` is provided by the yum-utils package, thus, install
the package as the dependency before using `yum-config-manager`.

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2023-10-05 15:11:02 -06:00
Wen Liang
94254894de test(infiniband): Negate the error message in assertion
Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2023-09-25 14:40:16 -06:00
Wen Liang
b97c9bd01e test: Use variable to hold infiniband interface name
To avoid hard coded interface name used all over the place in
`tests_infiniband.yml`, specify a variable to hold the infiniband
interface name instead.

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2023-09-25 14:40:16 -06:00
Wen Liang
835872e681 feat: Support "no-aaaa" DNS option
reason: The administrator wants to suppress the AAAA queries made by
the stub resolver, including AAAA lookups triggered by NSS-based
interfaces such as getaddrinfo. Only the DNS lookups are affected.

result: The administrator is able to suppress AAAA queries made by the
stub resolver.

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2023-06-29 13:10:20 +02:00
Wen Liang
ffe01a5f8b feat: Support ipv4_ignore_auto_dns and ipv6_ignore_auto_dns settings
reason: The user wants to ignore automatically configured name servers and
search domains (e.g. dns record from DHCP), and only use the name
servers and search domains specified in the `dns` and `dns_search`
properties.

result: The user is able to ignore automatically configured name servers
and search domains.

Notice that there are two settings here distinguished by the address
families, which aims to be compatible with NetworkManager
(`ipv4.ignore-auto-dns` and `ipv6.ignore-auto-dns`)and Nmstate (setting
`auto-dns` on `ipv4` or `ipv6` section). Also, the users can get auto
DNS from DHCPv4, DHCPv6, modem etc, and they may want to ignore auto
DNS on Ipv4 but not on IPv6, in this case, it is better to have two
settings distinguished by the address families.

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2023-05-29 12:56:41 +02:00
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
Rich Megginson
c0a626ddbb style: Use standard Ansible braces and brackets spacing
Use standard Ansible spacing for braces and brackets.  This
allows us to remove those rule exceptions from .yamllint.yml

Signed-off-by: Rich Megginson <rmeggins@redhat.com>
2023-04-28 09:13:55 -06:00
Wen Liang
b02e58db76 Fix the failure of running ANSIBLE_GATHERING=explicit on tests_switch_provider.yml
The test `tests_switch_provider.yml` fails to run with
`ANSIBLE_GATHERING=explicit` with the error described below. Therefore,
include the task 'el_repo_setup.yml' before running the test which
supports gathering the minimum subset of facts required.

```
TASK [set fact to use initscripts network_provider]
task path: /tmp/tmp.Q6nP8W4iPS/rhel_system_roles/tests/network/playbooks/tests_switch_provider.yml:8
fatal: [/tmp/tmp.Q6nP8W4iPS/RHEL_8_8_TESTING.qcow2]: FAILED! => {}
MSG:
The conditional check 'ansible_distribution in ['CentOS', 'RedHat'] and
ansible_distribution_major_version in ['7', '8']' failed. The error
was: error while evaluating conditional (ansible_distribution in
['CentOS', 'RedHat'] and ansible_distribution_major_version in
['7', '8']): 'ansible_distribution' is undefined.
```

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2023-04-27 15:14:49 -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
aa3b6bd8dc ansible-lint: Fix remaining name[casing] warnings
More name[casing] warnings are discovered by ansible-lint,
this may be due to the upgrade of ansible-lint.

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2023-04-05 16:52:39 -06:00
Wen Liang
b1d2f305c2 ansible-lint: Fix remaining jinja[spacing] warnings
Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2023-04-05 16:44:41 -06: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
8eed9ae4a9 ansible-lint: Fix ignore-errors failures
In some test playbooks, the `ignore_errors: true` can not be replaced
by `changed_when: false`, because `changed_when` is not a valid
attribute for a IncludeRole.

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2023-03-28 18:41:23 +02: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
2d0d217070 ansible-lint: Fix schema[playbook] failure
Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2023-03-08 16:55:28 +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