Commit graph

49 commits

Author SHA1 Message Date
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
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
Rich Megginson
570246bad3 no need for __init__.py in module_utils/
The file module_utils/__init__.py is not needed.

Signed-off-by: Rich Megginson <rmeggins@redhat.com>
2021-05-06 11:15:11 +02:00
Rich Megginson
c1b0002bc9 fix python black issues
There was recently an upgrade to python black which made function
documentation checking stricter.  This caused network tox CI to
break.  The fix is to format the function doc text in the manner
expected by black.

Signed-off-by: Rich Megginson <rmeggins@redhat.com>
2021-05-03 18:41:05 +02:00
Thomas Haller
c2e83b1d82 argval: use callable() check in get_default_value()
Previously, we would catch any kind of exception. We only want
to suppress an error if the default value is not a callable
(but instead a plain value).

Usually, in python they say it's easier to ask for forgiveness
than permission. However, that is often not true (the code here
this case becomes simpler, not more complicated). But more important,
in this case we only get a TypeError, which doesn't exactly tell
us what is wrong. We want to only suppress the error, if the
instance is not callable.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2021-04-16 12:09:43 +02:00
Thomas Haller
bf9933e482 argval: cleanup default values in ArgValidatorDict._validate_impl()
- split the "if" block in two. It's easier to read to only
  have one condition and to think about them independently.

- check "self.all_missing_during_validate" before getting the
  default value.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2021-04-16 12:09:43 +02:00
Rich Megginson
f5ff30a66c fix most ansible-test issues, suppress the rest
Automation Hub, and possibly Galaxy in the future, require the
collection to be screened with `ansible-test sanity` among other
checks.  The role had a number of issues:
* Use `AssertionError` instead of `assert`
* Use of `logging` module not in accordance with standards, but these
  are ok and the errors were suppressed
* Several import errors which are ok because they are checked
  elsewhere
* __init__.py in the module_utils directories must be empty, so a
  new file myerror.py was added to move the code from __init__.py
  * NOTE: network_lsr/nm/__init__.py is not empty
* The documentation block in the module was not properly constructed
  or formatted.
* shellcheck issues, including removing unused files
* use `unused` instead of `_` (underscore) for variables that are
  unused

add WARNING to module docs - collection users should not use directly

Signed-off-by: Rich Megginson <rmeggins@redhat.com>
2021-04-09 19:57:55 +02:00
Wen Liang
8318686620 Support ipv6.method disabled in network role
Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2021-02-19 18:12:52 +01:00
Fernando Fernandez Mancera
3167b3c125 inclusive language: use "port" instead of "slave"
In order to promote a diverse and inclusive environment we are replacing
all the reference to "slave" for "port".

Test case added.

Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
2021-02-03 15:15:04 +01:00
Fernando Fernandez Mancera
a283e47c12 inclusive language: use "controller" instead of "master"
In order to promote a diverse and inclusive environment we are replacing
all the reference to "master" for "controller".

Test case added.

Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
2021-02-03 12:57:03 +01:00
Wen Liang
880b7ab0cc Support dns-options in network role
Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2021-01-28 09:57:45 +08:00
Thomas Haller
675c7e8073 argument_validator: add documentation comments
Signed-off-by: Thomas Haller <thaller@redhat.com>
2021-01-24 20:51:48 +08:00
Gris Ge
19139286ed nm provider: Refactor the volatilize action of network connection
Refactor the volatilize action of nm provider:
 * Move code to `module_utils/network_lsr/nm`
 * The `module_utils/network_lsr/nm` only volatilize profile by given UUID
   instead of guess. The `library/network_connections.py` is responsible
   on choosing UUID.

Signed-off-by: Gris Ge <fge@redhat.com>
2021-01-23 11:19:32 +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
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
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
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
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
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
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
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
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
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
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
Fernando Fernandez Mancera
2e5dd50852 ethtool: use GPERMADDR instead the ethtool command line tool
This patch implements the ETHTOOL_GPERMADDR command in order to retrieve
the permanent address from ethtool instead using command line tool.

Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
2020-05-15 16:11:56 +02:00
Fernando Fernandez Mancera
024ba709f6 library: all the imports must be on the top
According to PEP8 [1], the import are always put at the top of the file,
just after any module comments and docstrings, and before module globals
and constants.

[1] https://www.python.org/dev/peps/pep-0008/#imports

Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
2020-05-14 11:34:27 +02:00
Jack Adolph
939772fdc1 Add support for domain-suffix-match 802.1x option
Role now supports validating the domain name of the EAP server certificate.
Regenerated the CA certificate as the private key for the original CA has been lost.
Updated test certificates to include a domain name in the CN so the domain-suffix-match
feature can be tested.
2020-05-04 13:01:41 +02:00
Jack Adolph
330729c6dd Change 802.1x parameters to be valid python identifiers 2020-04-21 08:11:15 +02:00
Jack Adolph
4af8f23955 Add support for 802.1x wired connections (EAP-TLS only)
Only EAP-TLS method is supported. Must use NetworkManager as the network_provider.
Also fixed bug in do_connections_validate_nm() function.
2020-03-25 10:49:10 +01:00
Till Maas
70aa9875aa Add support for ethtool features 2019-06-14 15:18:11 +02:00
Till Maas
c443947150 Utils: Add helper to call sync NM methods 2019-06-14 12:00:15 +02:00
Till Maas
4ad865af8a Argument validator: generate Ethernet defaults 2019-06-06 22:07:40 +02:00
Thomas Haller
c0b2430144 module: minor cleanup of Util.GMainLoop_run()
It was rather confusing whether the boolean return value meant
that the timeout was reached or the opposite.

Rename the internal variable, I think now it's quite clear.
2019-01-10 14:39:15 +01:00
Till Maas
6fc00a0d43 Make connections volatile instead of removing them
This keeps the profile up in Network Manager for
persistent_state:absent.
2019-01-10 14:39:15 +01:00
Thomas Haller
b4972517a4 module: fix name for ArgValidator_DictConnection
The name is actually not ever used, because
ArgValidator_DictConnection() is never validated directly.
Instead, it is always nested inside ArgValidator_ListConnections()
which passes "connections[$IDX]" as name to self.nested._validate().

Anyway, still when looking at the name of a ArgValidator_DictConnection
instance, it makes slightly more sense to call it just "connection".
2018-10-10 15:20:25 +02:00
Thomas Haller
97e216c716 module: don't expose "name" parameter for ArgValidator.validate()
The "name" argument is an implementation detail, that is used
by ArgValidatorDict and ArgValidatorList to pass a complex (nested)
name of what is currently parsed.

Callers are not supposed to see or use this argument.
Hide it, by adding an internal helper method _validate().
2018-10-10 15:20:25 +02:00
Thomas Haller
6856b5407d module: rename internal ArgValidator._validate()
First a trivial renaming because the next commit will
add a different "_validate" method.
2018-10-10 15:20:25 +02:00
Thomas Haller
8daa14eb36 module: make Utils.create_uuid() working without pygobject
Utils.create_uuid() only needs the "uuid" module, which
is commonly available. Don't load it together with the
NM module, as that requires pygobject.
2018-10-10 15:20:25 +02:00
Till Maas
09258d84e3 Support compatibility values for 'state' setting 2018-08-15 10:04:47 +02:00
Till Maas
23605615da Separate 'persistent_state' from 'state'
- persistent_state represents whether a profile is stored on disk
- persistent_state defaults to 'present'
- When there is no type specified for the profile, it is enough for a
profile with the same name to be stored on the target's systems file
system. Otherwise the role will fail
- state now represents the runtime state and can be up, down or
unspecified
- translate the state definitions into actions that will be performed.
The actions correspond to the previous states.
- add the possibility to write unit tests to only verify parts of the
resulting connection dictionary to only check for the expected changes
instead of the full connection that can also contain unrelated defaults
2018-08-15 10:04:47 +02:00
Till Maas
d76ac65581 Do not require profiles to be specified for 'up'
This allows to up profiles that are only available on disk.
2018-08-15 10:04:47 +02:00
Till Maas
382c34197b Modularize role
Splitting the role in smaller parts helps to keep the overview and to
develop separate tests.
2018-08-15 10:04:47 +02:00