Commit graph

114 commits

Author SHA1 Message Date
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
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
Till Maas
6bf70bcf60 Use profile name for interface name by default
* by default ```name``` is used as ```interface_name```
* if ```interface_name``` is set to the empty string, it will not be set
* if ```mac``` is specified, ```interface_name``` defaults to not being set

This fixes #41
2018-07-25 21:56:43 +02:00
Till Maas
e32033f995 Use black as formatter and enable flake8/pylint 2018-07-18 17:23:18 +02:00
Till Maas
459601c8e7 Fail when trying to down a non-existing NM profile 2018-07-11 10:06:45 +02:00
Till Maas
756be9a8de Allow to take down connections if not in config
Allow to take down connections regardless of whether they are defined in
the configuration. It should be enough that the connection is defined on
the system.
2018-07-09 14:39:40 +02:00
Thomas Haller
5b9e1331f8 library: fix try-count handling in SysUtil.link_infos()
https://github.com/linux-system-roles/network/issues/61
2018-06-18 21:56:37 +02:00
Till Maas
ed1d30a53d
Merge pull request #60 from linux-system-roles/th/main-function
th/main-function
2018-06-11 20:15:29 +02:00
Till Maas
ec65f5c78e
Merge pull request #59 from tyll/fix_global_connections
Use proper connections attribute
2018-06-11 15:36:37 +02:00
Thomas Haller
cf8522e5cc library: move main code to explicit main() function
Without it, we unintentionally declared 3 global variables
(connections, cmd, run_env_ansible). This was not intended,
and results in possibly wrong behavior by accidentally using
the global variables.
2018-06-11 08:49:35 +02:00
Till Maas
63314aeb92 Use proper connections attribute 2018-06-08 21:35:31 +02:00
Shannon Mascarenhas
5b45f9bc46 Fix handling of autoconnect parameter
This fixes a bug in the `network_connections` module when using the
`initscripts` provider and encountering a connection with `autoconnect`
set to false. It fails to write any `ONBOOT=` line to the interface's
`ifcfg-*` file, which RHEL treats as equivalent to `ONBOOT=yes`.

This explicitly sets `ONBOOT` for all interfaces defined, instead of
relying on what RHEL considers its default value.
2018-05-29 12:52:02 -05:00
Till Maas
dd24f020a9 Handle undefined type attribute
This fixes this exception (issue #40):

 [WARNING]: exception: Traceback (most recent call last):   File
"/tmp/ansible_FfjjGk/ansible_module_network_connections.py", line 2812, in <module>     cmd.run()   File
"/tmp/ansible_FfjjGk/ansible_module_network_connections.py", line 2398, in run     self.run_prepare()   File
"/tmp/ansible_FfjjGk/ansible_module_network_connections.py", line 2653, in run_prepare     if connection['type'] in [
'macvlan' ]: KeyError: 'type'
2018-05-25 19:52:10 +02:00
Till Maas
2185df2a81 Always run commands in C locale 2018-05-23 18:31:54 +02:00
Till Maas
83f2521d5e Fix python3 missing "cmp" keyword for list.sort()
This fixes this exception on Python3:
TypeError: 'cmp' is an invalid keyword argument for this function
2018-05-23 18:29:31 +02:00
Till Maas
fa13ea2388 Fix exception on Python3 in _link_read_permaddress
Bytestrings need to be decoded. Just use UTF-8 here, since everyone
should be using it. Also add a test case to catch this. The exception
was:
TypeError: cannot use a string pattern on a bytes-like object
2018-05-23 18:29:31 +02:00
Till Maas
8e6f1bf96b Move unit tests to tests dir 2018-05-16 20:18:05 +02:00
Till Maas
b3163cdf20 Test more boolean values 2018-05-14 16:53:39 +02:00
Pavel Cahyna
08187ae624 Unset the executable bit on Ansible module.
Per the policy defined in https://docs.ansible.com/ansible/latest/dev_guide/testing/sanity/shebang.html.
(Some RPM checks
f7e8f73ead/f/brp-mangle-shebangs
do not like an executable script to have a #!/usr/bin/python shebang.)
2018-05-10 18:28:13 +02:00
Till Maas
168bd43629 Add unittest for single IPv4 DNS server 2018-03-13 16:15:35 +01:00
Till Maas
f0d0e0637b Add SPDX-License-Identifier headers 2018-03-13 10:06:30 +01:00
Thomas Haller
2dbc68b7d9 library: fix tests for macvlan with initscripts 2018-02-13 08:23:59 +01:00
Roland Pabel
15a1ca8b7c add macvlan support 2018-02-13 08:23:59 +01:00
Thomas Haller
d3f4fe715b library: cleanup Util.boolean() implementation 2018-01-25 12:18:58 +01:00
Thomas Haller
be6d51d7cf library: deprecate top-level 'infiniband*' paramters in favour of nested 'infiniband'
Like for 'bond' and 'ethernet', don't merge the infiniband specific property
in the top-level. Instead, nest them under 'infiniband'.

This duplicates and deprecates the existing infiniband settings, but the old
parameters are still supported.
2018-01-25 11:39:09 +01:00
Thomas Haller
72f7c8ab4d library: deprecate top-level 'vlan_id' paramter in favour of nested 'vlan'
Like for 'bond' and 'ethernet', don't merge the vlan specific property
in the top-level. Instead, nest them under 'vlan'.

This duplicates and deprecates the existing 'vlan_id', but the old
parameter is still supported.
2018-01-25 11:31:09 +01:00
Thomas Haller
d76e98ec64 library: fix handling missing arguments of ArgValidatorNum type
It was impossible to set default_value = ArgValidator.MISSING, which can
be useful.
2018-01-24 12:52:54 +01:00
Thomas Haller
23325cda41 library/test: add tests for validating infiniband profiles 2018-01-24 12:51:46 +01:00
Thomas Haller
83249eb042 library/test: add test for a slave profile 2018-01-24 11:40:46 +01:00
Thomas Haller
068db05080 library: fix handling of "changed" flag
run() supports a --check mode (DRY_RUN) and a real mode,
where the real mode consists of a PRE_RUN that only simulates
the steps and a REAL_RUN.

Actualy changes can only happen during REAL_RUN (and we pretend
that they happen during DRY_RUN).

Fix handling of the change flag, is was broken previously.

Also, we need to set the is-changed flag to True before actually
invoking the action. Because, if we fail, we might fail_json()
right away, and need to correct changed flag.
2018-01-22 10:33:45 +01:00
Thomas Haller
db7fc2b60e library: move ansible_managed header outside of IfcfgUtil 2018-01-22 10:33:45 +01:00
Thomas Haller
a5eb321ef3 library: cleanup handling of run_results in RunEnvironmentAnsible 2018-01-22 10:33:45 +01:00
Thomas Haller
1ae5196a87 library/trivial: rename AnsibleUtil to RunEnvironmentAnsible 2018-01-22 10:33:45 +01:00
Thomas Haller
8db7f496b2 library: don't create AnsibleUtil.module lazily
Now, that we only create the AnsibleUtil instance when we already
know that we run under ansible (not from unit tests), we can avoid
initializing the AnsibleModule lazily.
2018-01-22 10:33:45 +01:00
Thomas Haller
4e6ace727e library: move change-tracking from AnsibleUtil to Cmd 2018-01-22 10:33:45 +01:00
Thomas Haller
c9bbb69d7e library: track connections in Cmd instead of AnsibleUtil
For now this looks more complicated then before. It will get better...
2018-01-22 10:33:44 +01:00
Thomas Haller
e2c575cb84 library: refactor handling of run_results
Make it more independent of AnsibleUtil.connections. Eventually,
we want to move parts to Cmd.
2018-01-22 10:33:44 +01:00
Thomas Haller
7e08386e7e library: handle ignore-errors parameter outside of AnsibleUtil 2018-01-22 10:33:44 +01:00
Thomas Haller
080fb56bfe library: don't call run_command() via AnsibleUtil 2018-01-22 10:33:44 +01:00
Thomas Haller
25497bfa63 library: remove unused function 2018-01-22 10:33:44 +01:00
Thomas Haller
14cc53f7ca library: avoid calls to AnsibleUtil.fail_json() but raise exception 2018-01-22 10:33:44 +01:00
Thomas Haller
f3b5fed04a library: move log wrapper functions from AnsibleUtil to Cmd class 2018-01-22 10:33:44 +01:00
Thomas Haller
97779c1b50 library: move checking force-state-change from AnsibleUtil to Cmd class 2018-01-22 10:33:44 +01:00
Thomas Haller
f58fa752af library: move connection_modified_earlier() from AnsibleUtil to Cmd class 2018-01-22 10:33:44 +01:00
Thomas Haller
e053286d9c library: inject ArgsValidator instance instead of using instance in AnsibleUtil 2018-01-22 10:33:44 +01:00
Thomas Haller
adff2af90b library: handle check-mode in Cmd class instead of AnsibleUtil
It is really related to how the Cmd class operates during run. It
should not be handled by AnsibleUtil.
2018-01-22 10:33:44 +01:00
Thomas Haller
e26449af88 library: introduce a RunEnvironment to make the code independent from ansible parts 2018-01-22 10:33:44 +01:00
Thomas Haller
14dbb3c47d library: make Cmd.create() independent of AnsibleUtil
Instead, pass the provider parameter.
2018-01-22 10:33:44 +01:00
Thomas Haller
e51d0c753a add support for ethtools options "autoneg", "duplex", and "speed"
https://github.com/linux-system-roles/network/issues/17
2018-01-22 10:24:58 +01:00
Thomas Haller
0ca86c9dbd library: reject setting 'zone' for slave types 2018-01-17 13:23:39 +01:00