Commit graph

583 commits

Author SHA1 Message Date
Wen Liang
1112bc2664 refactor IPv6 DNS test when IPv6 is disabled
Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2021-10-13 10:19:18 +02: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
Wen Liang
9fd19afa25 Allow configuring network connection via matching path
Users can easily configure or update network connection via matching
physical device path of the interface, which add certain flexibilty of
user experience.

Update connection profile via matching `path` setting:

```yaml
  - name: eth0
    type: ethernet
    autoconnect: yes
    # For PCI devices, the path has the form "pci-$domain:$bus:$device.$function"
    # It will only update the interface with the path "pci-0000:00:03.0"
    match:
      path:
        - pci-0000:00:03.0
```

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2021-10-06 18:22:42 +08:00
Wen Liang
b569704c72 arg_validator: accept None as valid input for ArgValidatorDict
Users might want to use jinja2 templates to set properties. As such,
it's convenient to accept None as an alias for an empty dictionary.

For exmaple, setting like `"match": None` will be allowed by the role:
e.g.
        network_connections:
          - name: enp0s8
            type: ethernet
            persistent_state: present
            state: up
            match:
            ip:
              route_metric4: 10

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2021-10-06 18:22:42 +08:00
Wen Liang
af07c2a58d arg_validator: accept None as valid input for ArgValidatorList
Users might want to use jinja2 templates to set properties. As such,
it's convenient to accept None as an alias for an empty list.

For exmaple, setting like `"match": {"path": None}` will be allowed by
the role:

        network_connections:
          - name: enp0s8
            type: ethernet
            persistent_state: present
            state: up
            match:
              path:
            ip:
              route_metric4: 10

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2021-10-06 18:22:42 +08:00
Wen Liang
71b4ff9357 Replace setting_type.new() with setting_type()
When `setting_type` is `NM.SettingMatch`, `setting_type.new()` will not
work because `nm_setting_match_new()` symbol is only exposed and usable
since libnm version 1.32 (using `setting_type.new()` is equivalent to
call libnm function `nm_setting_*_new()`).

Function `setting_type()` will always construct an instance of that
`setting_type` and will not need a workaround when `setting_type` is
`NM.SettingMatch`. So drop `setting_type.new()` in favor of
`setting_type()`.

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2021-10-06 18:22:42 +08:00
Brian Smith
46ff0ece04 Update README.md to note that network teaming is deprecated in RHEL 9.
Signed-off-by: Brian Smith <briasmit@redhat.com>
2021-10-04 22:58:50 -04:00
Wen Liang
fbd335af27 validate that ipv6_disabled is conflicting with other settings
When IPv6 is disabled, it is conflicting with enabling `auto6`
or configuring static IPv6 or configuring `gateway6` or
configuring `route_metric6`. Add unit tests to check if
this is properly handled in Argvalidator.

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2021-09-27 14:12:56 -04: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
Rich Megginson
81248c01c4 use apt-get install -y
Signed-off-by: Rich Megginson <rmeggins@redhat.com>
2021-09-15 16:17:55 -06:00
Rich Megginson
9ce48eb05a replace json_query with selectattr
In order to work with ansible-core, json_query is replaced
with selectattr.

Signed-off-by: Rich Megginson <rmeggins@redhat.com>
2021-09-14 07:49:16 -06:00
Rich Megginson
fca9ca5f36 use tox-lsr 2.5.1
Signed-off-by: Rich Megginson <rmeggins@redhat.com>
2021-09-13 09:58:18 -06:00
Thomas Haller
7a1683848c arg_validator: make ArgValidator.DEFAULT the default for dictionary's default value
The most used default value for ArgValidatorDict is
ArgValidator.DEFAULT, which means to generate the default value
based on the nested validators.

ArgValidator.DEFAULT is also a better default for the default_value.
Otherwise, it's a bit odd to have (and honor) ArgValidator.DEFAULT, if
that is not in fact the default default_value.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2021-08-26 16:30:09 +08:00
Thomas Haller
63ddf64a41 arg_validator: use DEFAULT argument to generate default value for dictionaries
The previous solution was ugly, as it hacked the private
self._default_value of the parent.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2021-08-26 16:30:09 +08:00
Thomas Haller
e01e550c59 arg_validator: support generating default value for ArgValidatorDict
Some dictionaries may wish to have a default value that is a dictionary
with the default of all keys.

Add a method to generate this.

This returns a callable instead of a plain dictionary. In practice, the
generated default value should always be the same. However, we also
expect that ArgValidator validation gives a result that is owned by the
caller. In case of mutable values (like a dictionary), we want a deep
clone.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2021-08-26 16:30:09 +08:00
Thomas Haller
e0a1b6af68 arg_validator: make ArgValidatorDeprecated a subclass of ArgValidator
ArgValidatorDeprecated is used as a nested validator, it also should
subtype ArgValidator base class. Technially, in python you can do duck
typing and get away with a different class that merely behaves
sufficiently similar. But why?

That way, we also can set default_value=ArgValidator.MISSING.
As a result, we no longer need to special case ArgValidatorDeprecated
at various places, because the default value will indicate that
it should not be present.

Co-authored-by: Till Maas <opensource@till.name>

Signed-off-by: Thomas Haller <thaller@redhat.com>
2021-08-26 16:30:09 +08:00
Thomas Haller
a262c77c26 arg_validator: expect ArgValidatorDeprecated.deprecated_by setting to be valid
"validator.deprecated_by" is user configuration of the validator. It depends on the
setup of the current ArgValidatorDict instance. It would be a bug if the user
references a non-existing validator.

Thus, use dictionary lookup instead of get() and fail early.

The previous code of course also didn't work, because the
returned None value would have led to an exception shortly after.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2021-08-26 16:30:09 +08:00
Thomas Haller
72319a1294 arg_validator: call get_default_value() for getting the default value
self._default_value might be a callable, to get the actual default
value, self.get_default_value() must be called.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2021-08-26 16:30:09 +08:00
Thomas Haller
8a00e7fab2 arg_validator: rename "default_value" field to "_default_value"
The name "default_value" is also used as parameter name, which
means that searching the source for the term gives unrelated
results. Rename to give a unique name.

Also, the field is really private and should usually not be called
directly. Instead get_default_value() should be called.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2021-08-26 16:30:09 +08:00
Thomas Haller
4afa81cdd0 arg_validator: rename ArgValidator.DEFAULT_SENTINEL to DEFAULT
To be consistent with ArgValidator.MISSING, which serves a similar
purpose.

Also, replace the if-else python ternary, which I find hard to read.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2021-08-26 16:30:09 +08:00
Thomas Haller
03833e8ac2 arg_validator: drop wrong default value for ArgValidatorIPRoute
The parameter is not used (neither by callers not the implementation).
It also makes not sense.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2021-08-26 16:30:09 +08:00
Thomas Haller
6e53bcf65f arg_validator: drop wrong default value for ArgValidatorIPAddr
The parameter is not used (neither by callers not the implementation).
It also makes not sense.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2021-08-26 16:30:09 +08:00
Wen Liang
647080eade CHANGELOG: update changelog for 1.4.0 release
Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2021-08-12 11:21:26 -04:00
Sergei Petrosian
133672663d Drop support for Ansible 2.8 by bumping the Ansible version to 2.9
Bug 1989197 - drop support for Ansible 2.8
https://bugzilla.redhat.com/show_bug.cgi?id=1989197

Signed-off-by: Sergei Petrosian <spetrosi@redhat.com>
2021-08-12 17:08:05 +08: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
Wen Liang
b08a0b3748 Disable initscripts tests in rhel-9
Since network-scripts package will be dropped in rhel-9, disable all
the initscripts tests in rhel-9.

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2021-07-29 16:44:44 -04:00
Wen Liang
0bfd29c029 Include task 'el_repo_setup.yml' for initscripts provider
To warrant the integration tests succeed when running with initscripts
provider, include task 'el_repo_setup.yml' to enable the base repo
support.

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2021-07-29 16:44:44 -04:00
Wen Liang
529ca94b81 fix: move ethtool features tests into NM_CONDITIONAL_TESTS
Because ethtool features tests also support initscripts provider, move
ethtool features tests into NM_CONDITIONAL_TESTS.

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2021-07-29 16:44:44 -04:00
Gris Ge
0cc8e46dc8 CI: Fix the correct container image name.
Prefer pre-existing https://quay.io/organization/linux-system-roles over
newly created https://quay.io/organization/linux_system_roles one.

Signed-off-by: Gris Ge <fge@redhat.com>
2021-07-29 11:50:11 +08:00
Gris Ge
95924e05f5 test: Restore the resolv.conf for bond dhcp test
The `tests_bond_initscripts.yml` will leave the VM holding the testing
DNS entry (nameserver 192.0.2.1) which break network connection.

The root cause is initscript will use dhcp-client for bond DHCP testing
which override the /etc/resolv.conf file. After test bond interface been
removed, the initscript will not restore the DNS settings.

The fix is backup the /etc/resolv.conf and restore it on clean up for
initscript provider.

Signed-off-by: Gris Ge <fge@redhat.com>
2021-07-29 10:17:51 +08:00
Rich Megginson
4b7f5d51fc fix yamllint issue - indentation
Signed-off-by: Rich Megginson <rmeggins@redhat.com>
2021-07-29 00:40:40 +08:00
Rich Megginson
0fcce91919 should not have removed epel setup from 802 tests
The commit b4584c88a8 to skip
tests that use hostapd also removed the epel repo setup.  This
breaks other platforms that require epel.

Signed-off-by: Rich Megginson <rmeggins@redhat.com>
2021-07-29 00:40:40 +08:00
Gris Ge
daac665933 CI: Enable integration test in Github Action
Using container to run `ansible-playbook` against localhost.

To debug it, try

```bash
sudo DEBUG=1 ./.github/run_test.sh tests_bond_nm.yml
```

Attached two container files for CentOS 8 and CentOS Stream 8.
The container image is stored under quay:
    https://quay.io/organization/linux_system_roles

Only a small mount of tests has been chose in order to give stable CI
test feedback.

The github action CI will run two instances using above container image.

Signed-off-by: Gris Ge <fge@redhat.com>
2021-07-28 19:50:09 +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
Rich Megginson
b4584c88a8 Skip tests on RHEL9 that use hostapd
The tests expect there is a hostapd package for doing wireless testing,
and that this package comes from EPEL on EL platforms.  Since there
is no EPEL9, skip tests that require hostapd.

Signed-off-by: Rich Megginson <rmeggins@redhat.com>
2021-07-28 13:44:48 +08:00
Wen Liang
e10919ec62 fix: pytest not reproducible in RHEL8
Previously when we run `tests_integration_pytest.yml` in RHEL 8, device
becoming unmanaged and NM `ifup` command failed to bring up the
connection when running pytest with initscripts, because network scripts
are deprecated in RHEL8 and they are no longer provided by default.

To fix that, install `network-scripts` package to utilize the legacy
`ifup` command.

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2021-07-22 21:23:09 +08:00
Thomas Haller
a9f9c04a0b connections: workaround DeprecationWarning for NM.SettingEthtool.set_feature()
If present, use the newer API to avoid the deprecation warning:

  $ pytest tests/unit/test_network_connections.py -v
  ...
  tests/unit/test_network_connections.py::TestValidator::test_802_1x_1
    /data/src/linux-system-roles-network/tests/unit/fake_env/network_connections.py:956: DeprecationWarning: NM.SettingEthtool.set_feature is deprecated
      s_ethtool.set_feature(nm_feature, NM.Ternary.DEFAULT)
2021-07-20 15:54:45 +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
Gris Ge
245ff58e25 nm: Fix the incorrect change indication for dns option
When applying with `dhcp4: "no"` or `auto6: "no"`, we get incorrect
change indication even when network connection was not changed.

The root cause is the `NM.SettingIPConfig.clear_dns_options(True)` will
create an empty list which will be discard by ifcfg plugin.
The follow up `NM.Connection.compare()` will show configuration changed
as dns option entry missing.

Fixed by remove dns option completely before appending.

Signed-off-by: Gris Ge <fge@redhat.com>
2021-07-05 20:15:57 +08:00
Gris Ge
f538865c68 nm: Fix the incorrect change indication when apply the same config twice
When applying the same network connections twice, the second apply still
shows `changed: true`.

The root cause:
 * When user never asked about ethtool configuration, network-role
   will generate an all-default `NM.SettingEthtool` and pass it to
   NetworkManager daemon. But NetworkManager discard it when saving to
   ifcfg plugin as ifcfg plugin will not keep empty ethtool option.

 * During second apply, the `NM.SimpleConnection.compare` will return
   False indicating configuration changed because of on-disk connection
   has no ethtool setting while pending connection does.

To fix it, we just remove the all-default `NM.SettingEthtool`.

Signed-off-by: Gris Ge <fge@redhat.com>
2021-07-05 20:15:57 +08:00
Wen Liang
833b6f3075 fix: dhclient is already running for nm-bond
Running `tests_bond_deprecated_initscripts.yml` and
`tests_bond_initscripts.yml` consecutively will fail in the downstream
testing with error "Determining IP information for nm-bond...dhclient is already running - exiting.".
Because the two tests have the same controller device name and dhclient
will keep running for the controller device `nm-bond`.

A workaround for this bug is to change the controller device name
associated with `tests_bond_deprecated_initscripts.yml`.

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2021-07-01 22:42:59 +02:00
Kristof Wevers
85b75b6c8c Only show stderr_lines by default
This avoids dumping all the parameters which can cause rather lengthy
output if multiple interfaces, routers, ... are configured.
The previous behaviour where all the params etc were displayed can
still be achieved by adding `-v` to the `ansible-playbook` command.

Resolves: #394

Signed-off-by: Kristof Wevers <kristof.wevers@infura.eu>
2021-06-11 06:03:23 +08:00
Jack Adolph
b368bce8aa Add 'auto_gateway' option
If enabled, a default route will be configured using the default gateway. If disabled,
the default route will be removed.

If this variable is not specified, the role will use the default behavior of the
`network_provider` selected.

Setting this option to `no` is equivalent to:
- `DEFROUTE = no` in initscripts, or
- `ipv4.never-default/ipv6.never-default yes` in nmcli

Signed-off-by: Jack Adolph <jack.adolph@gmail.com>
2021-06-04 07:07:13 +08:00
Jakub Haruda
6fdac168a9 CI: Add support for RHEL-9
Signed-off-by: Jakub Haruda <jharuda@redhat.com>
2021-05-28 06:06:51 +08:00
Wen Liang
a6c98bd660 arg_validator: reject bool arguments from ArgValidatorNum
`ArgValidatorNum` would normalize boolean into int when
`self.numeric_type` is int, then `self.numeric_type(False)` is 0 and
`self.numeric_type(True)` is 1. Therefore, we need to fix
`ArgValidatorNum()` to reject boolean values when integer values are
expected for the setting. This bug fix potentially breaks previously
"working" playbooks (but realistically, they were not working, because
setting 0 or 1 was unlikely intended).

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2021-05-24 18:51:54 +08:00
Wen Liang
dfacbf72f7 arg_validator: normalize numeric value for ArgValidatorNum
In python, bool is a subclass of int. Thus,
isinstance(value, self.numeric_type) would be True, with value being a
bool and numeric_type an int.

ArgValidatorNum should normalize the input values to be of type
self.numeric_type, except the default_value, which might be None (or
anything really).

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2021-05-24 18:51:54 +08:00
Wen Liang
93e509b533 Fix: support dns_search and dns_options for all address family
`dns_search` and `dns_options` should not be specific to the address
family. Previously, `dns_search` and `dns_options` were only supported
for IPv4 nameservers, so we also need to support `dns_search` and
`dns_options` for IPv6 nameservers.

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2021-05-24 15:34:52 +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
Wen Liang
ae2d60a0b2 Add support for ETHTOOL Ring option
ETHTOOL Ring option is not supported by NetworkManager until
NM 1.25.2. Currently, ETHTOOL Ring option is not suppored by
Network role, so enable the support for ETHTOOL Ring option.

Configure ethtool ring option via:

	```yaml
            network_connections:
              - name: testnic1
                type: ethernet
                state: up
                ip:
                  dhcp4: no
                  auto6: no
                ethtool:
                  ring:
                    rx: 128
                    rx_jumbo: 128
                    rx_mini: 128
                    tx: 128
	```

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2021-05-11 18:19:16 +02:00