Commit graph

123 commits

Author SHA1 Message Date
Thomas Haller
b2901ebd3f Revert "network: install python-gobject package by default"
The package is not called python-gobject on RHEL.

This reverts commit a799777d1a.
2018-01-24 14:06:41 +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
a799777d1a network: install python-gobject package by default
The "nm" provider talks to NetworkManager via libnm and python GObject
introspection. Install the required python library by default.

Unfortunately, it's not immediately clear whether we want to install
python2-gobject or python3-gobject. Yeay, python.
2018-01-23 16:29:30 +01:00
Thomas Haller
e0c492eeb5 network: install ethtool package by default
The role uses ethtool to obtain the permanent MAC address of interfaces.
It should be installed by the role as well.
2018-01-23 16:19:58 +01:00
Thomas Haller
f62dea9c10 library: merge branch 'th/ansible-independent'
Refactor the code, to make Cmd independent of ansible includes.
This would simplify to extend the library to run as stand-alone
application or to re-use parts without ansible.

Also, it better separates the code.

https://github.com/linux-system-roles/network/pull/23
2018-01-22 11:01:58 +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
886a9c94d1 merge branch 'dsedivec-fw-zone'
https://github.com/linux-system-roles/network/pull/22
2018-01-17 13:24:41 +01:00
Thomas Haller
0ca86c9dbd library: reject setting 'zone' for slave types 2018-01-17 13:23:39 +01:00
Dale Sedivec
1df778917e Add firewalld "zone" variable for connections 2017-12-07 14:08:13 -06:00
Thomas Haller
5e29382bc9 library: merge branch 'th/static-routes'
https://github.com/linux-system-roles/network/pull/21
https://bugzilla.redhat.com/show_bug.cgi?id=1487747
2017-11-22 08:55:21 +01:00
Thomas Haller
9740d8d024 library: add 'rule_append_only' setting
It works like 'route_append_only' and can be used to prevent
the role from deleting rule files. That makes especaily sense,
because the role currently doesn't support routing rules.

Also, NetworkManager still doesn't support routing rules either.
One day, the role (and maybe NetworkManager) will support rules,
and at that point it will start configuring them. That is the
reason why the new option already defaults to 'False'. Because,
once we add support for rules, we want the role to manage them
by default.
2017-11-22 08:54:48 +01:00
Thomas Haller
936b5c93cc library: add support for static routes 2017-11-22 08:54:45 +01:00
Thomas Haller
3df0cb77c1 library/tests: test creating NM connections 2017-11-22 08:54:41 +01:00
Thomas Haller
6d0b0c1468 library: add provider specifiy pre-validation step of input
Depending on the provider, we have additional restrictions on the
input arguments. Validate them early.

Without this, we will only fail later when we want to get the
'interface_name' of a parent or a master profile. Fail early.

The major reason for this, is to expose this validation so that
it can be used by unit tests, to check whether proceeding will
lead to a known failure.
2017-11-22 08:54:36 +01:00
Thomas Haller
55e2e43401 library/tests: refactor validating connections
Move the asserts to a separate function, so that we can add
more checks there.
2017-11-22 08:54:32 +01:00
Thomas Haller
07c37e5e82 library: accept parsing IP address as dictionary in additon to plain string
Addresses (currently) have only few properties, so this might
not make too much sense in the first moment. However, we will
add routes, which have lots of properties.

To support routes, we will treat them as dictionaries, not string
entries. Hence, for consistency, allow that syntax for addresses as
well.
2017-11-22 08:54:27 +01:00
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