Commit graph

60 commits

Author SHA1 Message Date
Thomas Haller
2cd6d3dbdf library: ignore failure of ethtool to get permanent MAC address
It's not uncommon that ethtool fails with:

  # ethtool -P dummy0
  Cannot read permanent address: Operation not supported

Ignore such errors.
2017-08-02 20:50:37 +02:00
Thomas Haller
3225b3a89d doc: update IPv6 example address in README.md to use 2001:db8 prefix (RFC3849)
https://github.com/linux-system-roles/network/issues/5
2017-07-17 12:06:31 +02:00
Pavel Cahyna
797dd44ef5 doc: use proper reserved MAC addresses for documentation, according to RFC 7042
https://github.com/linux-system-roles/network/issues/5

https://github.com/linux-system-roles/network/pull/6
2017-07-17 12:01:44 +02:00
Thomas Haller
efe4201f86 library: drop unused "ip_is_present" variable
We don't care whether a 'ip' or 'bond' setting is
entirely omitted or whether some fields are set by
the user.

Omitting a setting should make use of some default
values, but that's it. No need to track whether the
setting is actually specified by the user.
2017-05-31 18:43:29 +02:00
Thomas Haller
c1b62f01d0 add support for bond.mode and bond.miimon options 2017-05-31 18:38:42 +02:00
Thomas Haller
da312da291 examples: add example with bond and VLAN 2017-05-31 17:33:36 +02:00
Thomas Haller
baca667517 library: fix handling bond for initscripts
initscripts require a non-empty BONDING_OPTS variable to
properly handle bond. Set it.
2017-05-31 17:33:36 +02:00
Thomas Haller
fb5ecea19c library: autodetect the "slave_type" property based on "master"
As it is, a slave profile MUST reference an existing "master"
profile. Hence, the "slave_type" is implicitly known and not
required.

However, don't drop the "slave_type" option entirely. It allows a user
to explicitly set it, and network_connections.py will reject mismatching
configurations.

Also, check that the 'master' profile is actually of a valid master
type for the slave.
2017-05-31 17:32:58 +02:00
Thomas Haller
05f49d7922 examples: add example playbooks 2017-05-31 15:51:32 +02:00
Thomas Haller
c4bd00d1b4 library: work around activation isse in NetworkManager 2017-05-31 15:26:41 +02:00
Thomas Haller
0ba7123d8d library: accept space-separated string for list
This allows for

  ip:
    address: '192.168.1.5/24'

instead of

  ip:
    address:
      - '192.168.1.5/24'
2017-05-31 15:09:12 +02:00
Thomas Haller
6334379e93 add support for mtu property 2017-05-31 13:14:06 +02:00
Thomas Haller
e5850ead71 library: fix handling of vlan_id
- the maximum allowed vlan_id is 4094, not 4095.
- for ifcfg, we must convert the value to str()
- for nm, we don't need to convert the value, it's
  already int().
2017-05-31 12:36:59 +02:00
Thomas Haller
bf9b37cbb0 library: add NMUtil.connection_ensure_setting() helper 2017-05-31 12:36:59 +02:00
Thomas Haller
abb8945079 merge branch 'th/wait-nm'
https://github.com/linux-system-roles/network/pull/4
2017-05-30 14:17:10 +02:00
Thomas Haller
2844b3021c library: support sub-second precision for 'wait' property
For testing it is useful to be able to configure very short 'wait'
times. Otherwise, the minimally configuable timeout is 1 second.
2017-05-30 14:16:52 +02:00
Thomas Haller
948d36fa42 library: extend ArgValidatorInt for float and rename to ArgValidatorNum
Let's handle floating point types similarly to integer types.
The only difference is the "numeric_type" argument.
2017-05-30 14:16:52 +02:00
Thomas Haller
a5e62f27db library: implement waiting for activation/deactivation with NetworkManager
Implement what nmcli does when activating/deactivating
a connection: waits until the device is fully activated
or deactivate.

The 'wait' option is basically like nmcli's --wait option.
If omitted, wait a default duration of time. If the action
does not complete within the specified timeout, it fails.
Note that a failure may be suppressed by setting 'ignore_errors',
either globaly or per-state.

Set 'wait=0' not to wait. This was the previous behavior before
this commit.
2017-05-30 14:16:52 +02:00
Thomas Haller
530788a9dc library: cleanup handling of 'wait' argument
- extend the maxiumum wait time to 3600 seconds

 - disallow -1 values for 'wait'. It was used to mark
   the default value, but that marker should not be
   a valid value for user configuration. Instead, internally
   mark the missing value with None.

 - don't coerce a missing 'wait' parameter to 90 in _validate_post().
   Instead, track it as None so we can later decide between an explicitly
   set paramter and a default value. Also, the default for the states
   'up', 'down', and 'wait' differ.
   This also allows us to slience the warning about 'wait' not
   being implemented -- in case the user didn't configure it.

 - However, still allow zero.

   For

     - state: wait
       wait: 0

   allow it for convinience, so a user can disable the statement by
   setting the wait value to zero.

   For

     - name: MyProfile
       state: up
       wait: 0

   'wait' zero makes sense. It is what we currently do -- not wait
   at all. Later, when we implement waiting for complete activation, the
   default of wait will change (to 90 in this case).
2017-05-30 14:16:52 +02:00
Thomas Haller
47f1a3adc9 library: fix error handling in active_connection_deactivate()
Fixes: ac35802240
2017-05-25 16:48:12 +02:00
Terry Bowling
21ac519ebb Merge pull request #3 from linux-system-roles/tbowling
Proposed documentation change.
2017-05-22 16:08:52 -04:00
tabowling
ef581134ab Proposed documentation change. 2017-05-11 18:06:49 -04:00
Thomas Haller
29c7008f61 network: use top-level variables instead of nested "network" variable
The role already supported a default variable ("network_provider") and
host variables ("network_provider_default", "network_service_name",
"network_packages").

Don't use nested variables under "network" like

  network:
    provider:
    ignore_error:
    connections:

instead promote them all to top-level variables like:

  network_provider:
  network_ignore_error:
  network_connections:

This seems more consistent (as we already have multiple top-level
variables), it seems to follow ansible style, and it makes it easier
to overload individual variables via conditional include files.
2017-05-09 13:58:31 +02:00
Thomas Haller
9fbb2aa589 library: fix failure reading interface info because not ignoring non-interface names
The library fetches interface info by reading sysfs. However, "/sys/class/net/"
may contain certain files that are not interface names, like "bonding_master"

Skip over these files. Otherwise, the code fails with

  File "/tmp/ansible_HkmKOM/ansible_module_network_connections.py", line 347,
   in link_infos  b = SysUtil._link_infos_fetch()
  File "/tmp/ansible_HkmKOM/ansible_module_network_connections.py", line 323,
   in _link_infos_fetch  ifindex = SysUtil._link_read_ifindex(ifname)
  File "/tmp/ansible_HkmKOM/ansible_module_network_connections.py", line 302,
   in _link_read_ifindex  c = SysUtil._sysctl_read('/sys/class/net/' + ifname + '/ifindex')
  File "/tmp/ansible_HkmKOM/ansible_module_network_connections.py", line 293,
   in _sysctl_read  with open(filename, 'r') as f: IOError: [Errno 20] Not a directory: '/sys/class/net/bonding_masters/ifindex'
2017-05-03 16:09:07 +02:00
Thomas Haller
03ff040df7 test: add test_unit.yml to run unit tests
This requires to make "library/network_connections.py" more
independent from ansible modules

In the end, the Python code runs on the target machines,
with the python installed there. So, it makes sense to also
run the unit tests as part of the CI tests.
2017-05-02 15:32:25 +02:00
Thomas Haller
16f3bb77f0 library: reduce usage of ansible python module
The unit tests should run without requiring the
ansible module.

At least, all currently existing tests can now run.
In the future, we might have tests that optionally
only run when the ansible libraries are available.
2017-05-02 15:30:34 +02:00
Thomas Haller
25c3a8acf5 library/test: make test compatible with Python 2.6
unittest.TestCase.assertRaises() with a context manager was only
added in Python 2.6. Rework the code for 2.6 compatiblity.
2017-05-02 15:29:10 +02:00
Thomas Haller
52318732bb tasks: name "vars" file by the matching "{{ ansible_distribution }}"
This fixes the role to run on Fedora and CentOS.
2017-05-02 13:28:01 +02:00
Thomas Haller
9ae0bde868 gitignore: ignore temporary .image-cache/ directory 2017-05-02 12:01:51 +02:00
Lars Karlitski
0305e7e55b Remove manual tests
These couldn't be easily automated.
2017-04-28 17:33:45 +02:00
Lars Karlitski
69134b7cb7 Add support for linux-system-api test harness
Also add a simple test that runs the role without any parameters.
2017-04-28 17:33:25 +02:00
Lars Karlitski
9b21e84f47 Update meta data and add COPYING 2017-04-28 12:35:06 +02:00
Thomas Haller
4b5bcf3f67 network/library: fix logging during run_prepare() stage
As the module runs, it constructs debugging information
in run_result array. That is, because we can only pass
on the debugging messages at the end during json_exit()
or json_fail().

During early stage of run_prepare() we must also ensure
no to loose messages.
2017-03-06 14:19:18 +01:00
Thomas Haller
90853dc7cf network/library: don't allow empty string settings for ArgValidatorStr types
In most cases at hand, and empty string value is non-sensical.
Flip the default for "allow_empty" to get this validation for
all string settings.
2017-03-06 13:22:52 +01:00
Thomas Haller
a9634a85f1 network/library: use single quotes for strings consistently 2017-03-06 12:59:36 +01:00
Thomas Haller
b085b9be67 network/library: fix Util.first to properly honor predicate 2017-03-02 18:47:39 +01:00
Thomas Haller
ddc1493a6f module: fix default value for 'auto6' 2017-03-02 16:47:08 +01:00
Thomas Haller
24c6c0755b module: add test for presence of "ip" section 2017-03-02 16:47:08 +01:00
Thomas Haller
d88e79ac8c module: fix default value for dhcp4_send_hostname
We should not set "dhcp4_send_hostname" unless it is explicitly
present in the configuration. That is because initscripts don't
support this parameter and issue a warning.
2017-03-02 16:47:08 +01:00
Thomas Haller
cd2030cde6 module: support dns_search option 2017-03-02 16:47:08 +01:00
Thomas Haller
a928f54f58 module: fix setting ipv6.dns setting 2017-03-02 16:15:55 +01:00
Thomas Haller
151a611695 module: add allow_empty validation option to ArgValidatorStr() 2017-03-02 16:15:23 +01:00
Thomas Haller
adcdd28bb3 library: support configuring manual DNS servers 2017-02-19 22:26:06 +01:00
Thomas Haller
61e91b6c3d library: support prune-all by omiting 'name' for state 'absent'
When omiting the 'name' for state='absent', we prune all existing
profiles that are not explicitly mentioned in the list of connections.
2017-02-19 22:26:06 +01:00
Thomas Haller
0d964dab26 library: fix handling black_list_uuid in connection_list() 2017-02-19 22:08:11 +01:00
Thomas Haller
37664fda92 library: check that 'mac'/'interface_name' refers to an existing interface
When configuring a profile that specifies a MAC address or an
interface-name, make sure that such an interface actually exists.
2017-02-19 22:08:11 +01:00
Thomas Haller
faf3b699ba library: fetch the MAC address from the interfaces 2017-02-19 21:57:55 +01:00
Thomas Haller
8682cb64b8 module: support a 'ignore_errors' argument
It's more idiomatic for ansible then "on_error".

'ignore_errors' can be specified as a module argument.
But it can also be specified on a per-profile level,
with the intuitive behavior that the per-profile setting
overwrites the per-module setting.
2017-02-19 21:57:55 +01:00
Thomas Haller
b30bf38957 library: add timeout for async NM operations
We use libnm for the async operations. We would expect that
an async operation always returns, but there might be a bug
in libnm so that it doesn't

Add our own timeout around the libnm calls to avoid hanging.
2017-01-13 15:29:34 +01:00
Thomas Haller
edcb4a2850 library: let the module handle all connections at once
Instead, of having the tasks call the "network_connections.py"
library for each connection profile individually (using with_items),
pass all profiles at once.

The advantage is:

 - the module can validate the input arguments better as it has
   access to all profiles. For example, when a slave connection
   refers to another master profile from the same play. Previously,
   each invocation of the module only sees the current profile and
   cannot verify whether the reference is valid.

 - while configuring the network, the play might need to shortly
   disconnect the control connection. In the previous way, after
   tearing down the network the target host becomes unreachable for
   ansible and the following steps cannot be executed anymore.
   Now, all steps are done as a whole on the target host, via
   one connection. If the host becomes unreachable for a short
   time, that is not a problem as long as the connectivty is
   restored at the end.
   Ansible also supports to switch the host IP (or SSH port). With
   this new way, the ansible play can apply a bunch of profiles
   autonomously and the ansible play can potentially handle a changing
   IP configuration.
2017-01-12 19:22:52 +01:00