Commit graph

86 commits

Author SHA1 Message Date
Thomas Haller
5282966bca library: drop redundant "is_v4" property and use address family only
Redundancy is bad.
2017-11-22 08:54:23 +01:00
Thomas Haller
948fd7bf36 library: derive ArgValidatorIPAddr from ArgValidator instead of ArgValidatorStr
Next we will hack it up, to also support dictionary input arguments.
2017-11-22 08:54:14 +01:00
Thomas Haller
936c9b908e library/trivial: move code around
Have the base types of ArgValidator classes closer together.
2017-11-22 08:54:00 +01:00
Roman Bolshakov
9b8a46e3e3 Fix exception when dns is present
ifcfg_create expects list of dns addresses to be non plain values, while
dns validator returns only a string.

https://github.com/linux-system-roles/network/pull/20
2017-11-14 15:40:46 +01:00
Thomas Haller
f28b24ac05 test: merge branch 'larskarlitski-test' (pr#18)
https://github.com/linux-system-roles/network/pull/18
2017-10-03 14:03:25 +02:00
Lars Karlitski
7b3a8bee22 test: use relative role path 2017-10-02 21:49:36 +02:00
Lars Karlitski
8e22918694 Remove semaphore test scripts 2017-10-02 21:49:36 +02:00
Lars Karlitski
8d5d7c0367 test: add name 2017-10-02 21:49:36 +02:00
Thomas Haller
b856c7481b tests: add unit test for parsing address list as string 2017-09-27 16:40:01 +02:00
Thomas Haller
16ad34c20a role: improve making "network_provider" configurable via host vars
The role currently supports two providers: "nm" and "initscripts".

The provider is autodetected by loading one of the vars/*.yml files
(where the default is set via the internal "network_provider_default" variable).
The user can still overwrite the provider, by explicitly setting the
"network_provider" variable.

Depending on the provider there is the list of packages that shall be
installed and the service to start. Selecting this was broken before.

This is now fixed and works like following:

The variables "network_service_name" and "network_packages" can be
specified by the user as host variables. But usually the user wouldn't
want to do that. Instead, those settings depend on "network_provider".
The role looks into the internal "_network_provider_setup" dictionary,
which defaults to "network_service_name_nm", "network_service_name_initscripts",
"network_packages_nm", and "network_packages_initscripts".

These default variables are initialized in "defaults/main.yml" as well,
but they could be overwritten via "vars/*.yml" files, or via any other
mechanism.

https://github.com/linux-system-roles/network/pull/14
https://bugzilla.redhat.com/show_bug.cgi?id=1485074
2017-09-25 11:37:48 +02:00
Pavel Cahyna
a4ebfadded examples: replace yet another RFC1918 address in an example by a RFC5737 one
https://github.com/linux-system-roles/network/pull/12
2017-08-28 14:38:27 +02:00
Thomas Haller
a732893132 network: merge branch 'rh1476053'
https://bugzilla.redhat.com/show_bug.cgi?id=1476053
2017-08-28 14:17:10 +02:00
Thomas Haller
5deb2afd46 library: don't do anything for "up" and "down" states if already in state
The states "up" and "down" previously would always change state. That
is, specifying them in the playbook will always invoke `ifup` (or
`ifdown`) or the corresponding of `nmcli connection up` (or `nmcli
connection down`).
That was intentional behavior, because the role doesn't really know which
profile is currently active. That is certainly the case for "initscripts",
where the role has almost no information about the current runtime
state. For "nm" provider, the role knows whether the connection is
already active. However, that alone also does not guarantee that the
current runtime state is idential to what would be the result of an
explicit `nmcli connection up`.
Hence, to be sure that the current state is always as expected, the role
would always explicitly issue the commands and report "changed=1".

That is quite harmful, because running the same role multiple times
should not report changes every time. Also, issuing `ifup` may behave
badly, if the interface is already configured.

Now, try to determine whether the desire "up" or "down" state is already
reached and do nothing.

For "nm" provider that is easy and quite safe. There is still the
possibility to trick the role into thinking that the right configuration
is active, when it actually is not. For example via `nmcli device
modify` on the host. But in general, it should work just fine.
Especially, if the admin manually modifies the runtime state, it may be
just desired for "state: up" not to change anything.

For "initscripts" this is much more fragile. There isn't really much
that can be done about it, because the role doesn't know what is currently
configured on the system.

There is also a new option "force_state_change" to restore the previous
behavior.

https://bugzilla.redhat.com/show_bug.cgi?id=1476053
2017-08-28 12:10:13 +02:00
Thomas Haller
2eaf5a9a61 library: refactor evaluating "ignore_errors" flag 2017-08-28 12:08:35 +02:00
Thomas Haller
1fc26b11fa library: workaround missing active connection state in pre 1.8 API of NetworkManager
The role targets NetworkManager 1.8.0 API or newer. Exposing the
active connection state was added in 1.8 API, hence the role failed
against older NetworkManager version.

While that is not officially supported, the workaround is simple,
so do it.

https://bugzilla.redhat.com/show_bug.cgi?id=1476053
2017-08-28 12:08:35 +02:00
Thomas Haller
c9902bf697 library: don't print traceback for configuration error
It makes the output confusing. It's not a bug, but a user-error.
2017-08-28 12:08:35 +02:00
Thomas Haller
b9b6f0a796 merge branch 'rh1478910-downup-fail'
https://github.com/linux-system-roles/network/issues/7
https://bugzilla.redhat.com/show_bug.cgi?id=1478910
2017-08-24 18:21:11 +02:00
Thomas Haller
5d09a75fe1 library: wait for connection to disappear from libnm cache during delete
We delete the connection asynchrnonously using libnm. Even after the
asynchronous request completes, the connection may still in the cache.
That is a bit odd, but maybe not a bug in libnm. Because it can happen
that the connection was active, so it takes time to bring it down.

Maybe the asynchronous request should not complete in libnm before
the connection is truly gone. But note that deactivating a connection
can take arbitrary long, so it's not clear that his would be the best
behavior.

Anyway, work around it by waiting.

The effect of this bug is if you have "state: absent" followed by
"state:up", then the intermediate "present" state will be skipped.
That is, because it appears that the connection still exists, although
it's about to be deleted. The subsequent "up" will then fail as the
connection is gone in the meantime.

https://github.com/linux-system-roles/network/issues/7
https://bugzilla.redhat.com/show_bug.cgi?id=1478910
2017-08-24 18:19:06 +02:00
Thomas Haller
ab21a41748 library: allow logging of general messages, not tied to a connection
Mainly for printf debugging of the module, where we don't have a connection
index handy.
2017-08-24 18:17:11 +02:00
Thomas Haller
71102f9253 library: ensure chronological order of logging messages
We group logging messages by their connection (@idx). Finally,
when constructing the overall result, reorder the messages
to ensure that their are still in chronological order.

Usually they are anyway, because we handle connections one-by-one,
and wouldn't log messages for previous connections.
2017-08-24 18:00:14 +02:00
Thomas Haller
e0675f7a31 library: avoid suppressing duplicate logging messages
We hack the "warnings" JSON result to return logging messages. However,
ansible will suppress duplicate warnings. That is inconvenient. Avoid that
by prefixing each logging message with an index.
2017-08-24 17:57:22 +02:00
Thomas Haller
366aeff44d library: remove unused argument @mainloop_iterate from list functions
If the caller wants to iterate the mainloop, he shall just do it.
2017-08-24 17:18:40 +02:00
Pavel Cahyna
e1c5ba55bb doc: change one more forgotten RFC 1918 address to RFC 5737
https://github.com/linux-system-roles/network/pull/11
2017-08-24 17:17:47 +02:00
Pavel Cahyna
6fdf07fff1 doc: use proper reserved IPv4 addresses for documentation, according to RFC 5737
This way one will be able to reliably detect when the example playbook was
forgotten to be upated with correct addresses, as the RFC 5737 addresses are
never used in production (the original RFC 1918 ones often are).

https://github.com/linux-system-roles/network/issues/5
2017-08-24 16:52:49 +02:00
Thomas Haller
dace7654fe add support for "infiniband" type
https://bugzilla.redhat.com/show_bug.cgi?id=1470712
2017-08-02 20:50:37 +02:00
Thomas Haller
36cd010fe9 library: refactor getting master connection
Move the utility functions to ArgUtil class.
2017-08-02 20:50:37 +02:00
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