Commit Graph

21088 Commits

Author SHA1 Message Date
Thomas Haller
ee4655d168 clients/tests: extend tests to gracefully handle unstable output
Commands that fail with G_DEBUG=fatal-warnings produce unstable
output like

  (process:10743): GLib-CRITICAL **: 16:29:13.635: g_ptr_array_add: assertion 'rarray' failed

To workaround that, add a new option for marking the output as unstable.

An alternative might be to extend the replace_stdout, replace_stderr
arguments to support more powerful matching, like by specifying regular
expression for replacing. However, it's just too complicated. Add a simpler
workaround by passing _UNSTABLE_OUTPUT.
2018-06-11 19:30:50 +02:00
Thomas Haller
3044caa07a clients/tests: run tests with G_DEBUG=fatal-warnings
We don't want any g_critial() or g_warning() in our nmcli
output. By default, let the tests crash. But tests could opt-out of
this.
2018-06-11 17:14:47 +02:00
Lubomir Rintel
d3ae93cc03 merge: branch 'lr/alternatives'
https://github.com/NetworkManager/NetworkManager/pull/114
2018-06-11 15:43:25 +02:00
Lubomir Rintel
28d2c07661 rpm: install alternative implementations of ifup/ifdown
Unless the initscripts package too old to allow alternatives is present,
install nmcli as an alternative implementation of ifup and ifdown.

The triggerin scriptlet allow us to do the right thing regardless of
which initscripts version is installed or even when it's upgraded.

The initscripts patch was included in Fedora 29:
https://github.com/fedora-sysv/initscripts/pull/197
2018-06-11 15:09:42 +02:00
Lubomir Rintel
d815130468 ifcfg-rh: add nm-ifup and nm-ifdown scripts
They're intended to be used via update-alternatives(8) as compatibility
shims for Red Hat systems without the legacy network control scripts.

While they're not strictly parts of the settings plugin, they're best
just installed along with it, since they're supposed to be available on
systems that use the ifcfg files.
2018-06-11 15:09:42 +02:00
Lubomir Rintel
d52573d125 cli: allow specifying the connection by its filename
This is handy for users who configure NetworkManager by dropping files
into /etc.
2018-06-11 15:09:42 +02:00
Lubomir Rintel
386129d92b cli: add connection FILENAME field
This allows the user to look up the file where the connection is stored.
Useful especially for ifcfg users.

Not shown by default.
2018-06-11 15:09:30 +02:00
Lubomir Rintel
f037aaeb90 tools/test-service: mock o.fd.NM.Settings.Connection.Filename property 2018-06-11 15:06:49 +02:00
Lubomir Rintel
bd6fe17815 libnm/remote-connection: add filename property 2018-06-11 15:06:49 +02:00
Lubomir Rintel
87f5ff6927 settings-connection: expose Filename property on D-Bus
This allows implementing some convenience features in nmcli -- listing
the backing store for the connection in "nmcli c show", and using the
filename for specifying connection in "nmcli c up/down".

Eventually, paired with ReloadConnections(), this could be used to
implement something similar to what "systemctl edit" does for units
(though we'd need to pick another command name as we aready use
"nmcli c edit" for something different).
2018-06-11 15:06:49 +02:00
Thomas Haller
f3c63ca4b1 clients/tests: merge branch 'th/more-clients-tests' 2018-06-11 11:25:04 +02:00
Thomas Haller
1403ebf435 clients/tests: show device fields with invisible connection
How does `nmcli -f ALL dev show $DEV` look, if it references
a connection that is invisible to the user?

Note in the output:

  CONNECTIONS.AVAILABLE-CONNECTIONS[1]:   (null) | (null)
2018-06-11 11:20:31 +02:00
Thomas Haller
d32ad46a62 clients/tests: add more tests for nmcli showing connections and devices 2018-06-11 11:20:31 +02:00
Thomas Haller
f671fa5137 clients/tests: expose IP and DHCP configs in test-networkmanager-service.py stub
For adding tests what nmcli shows regarding IP and DHCP configuration,
let the stub service generate config instances.
2018-06-11 11:20:31 +02:00
Thomas Haller
dd2da759de clients/tests: seed generated numbers for test-networkmanager-service.py
At several places, "test-networkmanager-service.py" uses generated numbers
with a defined seed. For example, generated connection's UUID is
generated in a predictable, but randomized way (if you forgive the
inprecise use of the word "random" in context of using a deterministic
seed).

Aside the connection's UUID, this becomes more interesting in the next commit
where the stub server generates a list of IP and DHCP settings in a predictable
randomized way.

For "clients/tests" we spawn the test service multiple times, but also
create similar environments by calling init_001(). This is done for
convenience, where out of lazyness all the tests share one setup. But it's
still a good idea that these tests generate slightly different setups,
wherever applicable. this increases the possible setups which get tested.
For example, the number of static IPv4 addresses (the following commit) is
interested to explicitly test for zero or a non-zero number of
addresses. If all tests happen to use the same seed, the tests are expected
to also generate the same number of addresses, and we miss an opportunity to
hit interesting test cases.

There is still no guarantee that all interesting cases are hit, the chances are just
better. The approach of generating the setup randomly, does not preclude that
the stub-server allows to explicitly configure the setup. However, due to the
sheer number of combinations that might be interesting to test, it's much simpler
to rely on some randomization and have the justifid hope we catch interesting cases.
Also in terms of runtime of the test, the cli unit tests should complete within
few seconds. Testing every combination would result in huge tests and long runtimes.

Also, the patch refactors generating random numbers in
"test-networkmanager-service.py". For example, it introduces
Util.RandomSeed(), which can be used to generate a sequence of different
random numbers. It works by having an internal state and a counter which is
combined to chain the seed and generate different numbers on each call.
2018-06-11 11:20:31 +02:00
Thomas Haller
ac8f786987 clients/tests: add optional "required" argument to findConnectionUuid()
It's still unused, but commit it individually, as it also causes
trivial changes to the .expected files.
2018-06-11 10:30:27 +02:00
Thomas Haller
2a53555faa tests: simulate available-connections in test-networkmanager-service.py 2018-06-11 10:30:27 +02:00
Thomas Haller
3255a97b3a tests: fix dry-run for _dbus_property_set() in test-networkmanager-service.py 2018-06-11 10:30:27 +02:00
Thomas Haller
1410dac5c3 clients/tests: add test for terse output of nmcli -t connection show $VPN 2018-06-11 10:30:27 +02:00
Lubomir Rintel
e7d70561aa cli: spawn pager on "nmcli c" and "nmcli g permsisions"
There's a couple of places where compose the output using nmc_print().
However, most of them (such as connectivity status or logging level) are
mostly one-line outputs where pager wouldn't make sense. These two stand
out.
2018-06-11 10:28:50 +02:00
Thomas Haller
152560e294 policy: log connection UUID for auto-activation
The connection.id (NAME) is not necessarily unique.
To avoid confusion, log the UUID as well.
2018-06-11 09:44:05 +02:00
Francesco Giudici
ab441df297 merge: branch 'fg/manage_DUID-rh1414093'
https://bugzilla.redhat.com/show_bug.cgi?id=1414093
2018-06-11 09:29:55 +02:00
Francesco Giudici
02c4b2c9a8 cli: add dhcp-duid support 2018-06-09 22:20:39 +02:00
Francesco Giudici
f913ed4d0c ifcfg: introduce DHCPV6_DUID to map ipv6.dhcp-duid property 2018-06-09 22:20:39 +02:00
Francesco Giudici
e9321713a9 ifcfg: make_ip6_setting cleanup & optimization 2/2
get rid of svGetValueStr_cp() in favor of svGetValueStr() in the
make_ip6_setting() function
2018-06-09 22:20:39 +02:00
Francesco Giudici
fa478d8f22 ifcfg: make_ip6_setting cleanup & optimization 1/2
get rid of the useless "str_value" variable.
2018-06-09 22:20:39 +02:00
Francesco Giudici
f054c3fcaa dhcp: allow to skip DUID search from DHCP client global configuration
When the used client is dhclient we were used to search for DUID not
only in the specific lease files generated by NetworkManager, but also
in the global lease file generated outside NetworkManager.
Keep this capability but allow to just search in the NM lease files if
a value different from the default one is specified in dhcp-duid.
2018-06-09 22:20:39 +02:00
Francesco Giudici
0d841e7471 dhcp: remove fallback DUID-UUID generation from dhcp code
This commit centralizes the DUID generation in nm-device.c.
As a consequence, a DUID is always provided when starting a
DHCPv6 client. The DHCP client can override the passed DUID
with the value contained in the client-specific lease file.
2018-06-09 22:20:39 +02:00
Francesco Giudici
7a0b6b17bb libnm-core: add ipv6.dhcp-duid property
allow to specify the DUID to be used int the DHCPv6 client identifier
option: the dhcp-duid property accepts either a hex string or the
special values "lease", "llt", "ll", "stable-llt", "stable-ll" and
"stable-uuid".

"lease": give priority to the DUID available in the lease file if any,
         otherwise fallback to a global default dependant on the dhcp
         client used. This is the default and reflects how the DUID
         was managed previously.
"ll": enforce generation and use of LL type DUID based on the current
      hardware address.
"llt": enforce generation and use of LLT type DUID based on the current
       hardware address and a stable time field.
"stable-ll": enforce generation and use of LL type DUID based on a
             link layer address derived from the stable id.
"stable-llt": enforce generation and use of LLT type DUID based on
              a link layer address and a timestamp both derived from the
              stable id.
"stable-uuid": enforce generation and use of a UUID type DUID based on a
               uuid generated from the stable id.
2018-06-08 18:23:31 +02:00
Francesco Giudici
fcc6bf7198 core: add function to retrieve secret_key generation time
This will be soon used to derive the timestamp to generate DHCPv6
DUIDs of type DUID-LLT.
2018-06-07 14:38:02 +02:00
Francesco Giudici
84c9ce0d79 dhclient: always update the DUID in the lease file
We will soon introduce a property to set a custom DUID and we want
to enforce that the provided value is used.
Note that this commit does not cause any change in behavior in current
code.
2018-06-07 14:38:02 +02:00
Francesco Giudici
5686536647 dhclient: fix updating the DUID in multiline lease files
The nm_dhcp_dhclient_save_duid() function will save a newly generated
DUID to a previously existing lease file. The function will only save
the DUID if not present in the lease file: in this case, should preserve
the other contents of the lease file.
A dhclient lease file for IPv6 generated by NetworkManager will always
add the DUID as a first item: so in practice finding a lease file
without DUID will never happen.
This has hidden a bug in the function: the loop that is meant to append
the non-duid lines in the lease file would strip all the newlines,
mangling the lease file.
Fix the function allowing to keep the original lines and add a test to
check this functionality is kept well functioning.

FIXME: the new test and the other duid ones already there  store the file
in the current working-directory. Tests should not do that.
2018-06-07 14:38:02 +02:00
Thomas Haller
5f94476b26 man: improve explaining settings plugins in manual NetworkManager.conf
https://bugzilla.redhat.com/show_bug.cgi?id=1586351
2018-06-07 11:32:34 +02:00
Thomas Haller
c318d8c18f clients/tests: merge branch 'th/clients-tests'
https://github.com/NetworkManager/NetworkManager/pull/130
2018-06-06 10:29:36 +02:00
Thomas Haller
2e22c931f9 clients/tests: test creating and activating VPN connection 2018-06-06 10:27:35 +02:00
Thomas Haller
eceaba025f clients/tests: add Util.debug_dbus_interface() helper function 2018-06-06 09:55:43 +02:00
Thomas Haller
7c55c4da23 clients/tests: test adding IPv4/IPv6 addresses and routes 2018-06-05 20:08:03 +02:00
Thomas Haller
360f952399 clients/tests: test nmcli con mod command with different locale
Just to give it some variety. Also, note how the message from the
server cannot be translated. Which is the case with real NetworkManager
as well, and is a major usability issue.
2018-06-05 20:08:03 +02:00
Thomas Haller
f3dddcff2a clients/tests: verify connections in test-networkmanager-service.py using libnm
The real NetworkManager service has a clear understanding how a valid
connection looks like. This is what nm_connection_verify() returns.

Let also our stub-service verify connections the same way.

Note that this is cumbersome, because the stub service uses python's
dbus module, while libnm only accepts creating NMConnection instances
from GVariant. Thus, we need to a cumbersome conversion first.

It would be better if test-networkmanager-service.py would also expose
normalized connections on D-Bus. But that requires the inverse converion
from GVariant to python dbus.
2018-06-05 20:08:03 +02:00
Thomas Haller
780af4cffb tests: nest custom exceptions in common namespace 2018-06-05 20:08:03 +02:00
Thomas Haller
ef612b8e23 tests: reorder definitions in test-networkmanager-service.py
Define all custom exception types together.
2018-06-05 20:08:03 +02:00
Thomas Haller
e862e67f48 tests: use libnm defines for NM test stub
These names are unique and well-known.
2018-06-05 20:08:03 +02:00
Thomas Haller
78576794eb tests: rename local variables in NM test stub (2)
lso, the name "connection" and "con" is overused.

Use "con_inst" where we mean an instance of a "Connection" class,
that is, the object exposed on D-Bus.
2018-06-05 20:08:03 +02:00
Thomas Haller
9cc1876fd7 tests: rename local variables in NM test stub (1)
- don't use "hash" for a local variable in python.
  The editor highlights it like a special python name.

- don't use "settings" for Connection.settings. Name it
  Connection.con_hash. The name "settings" is over-used already.
  "con_hash" really is the nested dictionary that we expose/receive
  from D-Bus. If we would use libnm for it, it would be an
  NMSimpleConnection instance, but we don't.
2018-06-05 20:08:03 +02:00
Thomas Haller
644aa42f68 dns: change main.rc-manager=file behavior to always follow symlink
With "main.rc-manager=file", if /etc/resolv.conf is a symlink, NetworkManager
would follow the symlink and update the file instead.

However, note that realpath() only returns a target, if the file actually
exists. That means, if /etc/resolv.conf is a dangling symlink, NetworkManager
would replace the symlink with a file.

This was the only case in which NetworkManager would every change a symlink
resolv.conf to a file. I think this is undesired behavior.

This is a change in long established behavior. Although note that there were several
changes regarding rc-manager settings in the past. See for example commit [1] and [2].

Now, first still try using realpath() as before. Only if that fails, try
to resolve /etc/resolv.conf as a symlink with readlink().

Following the dangling symlink is likely not a problem for the user, it
probably is even desired. The part that most likely can cause problems
is if the destination file is not writable. That happens for example, if
the destination's parent directories are missing. In this case, NetworkManager
will now fail to write resolv.conf and log a warning. This has the potential of
breaking existing setups, but it really is a mis-configuration from the user's
side.

This fixes for example the problem, if the user configures
/etc/resolv.conf as symlink to /tmp/my-resolv.conf. At boot, the file
would not exist, and NetworkManager would previously always replace the
link with a plain file. Instead, it should follow the symlink and create
the file.

[1] 718fd22436
[2] 15177a34be

https://github.com/NetworkManager/NetworkManager/pull/127
2018-06-05 16:21:10 +02:00
Beniamino Galvani
92ebd16cee cli: fix array out-of-bounds access on command timeout
Fixes: 4b3297271e

https://bugzilla.redhat.com/show_bug.cgi?id=1573839
2018-06-05 14:49:24 +02:00
Beniamino Galvani
7696e6c1fa manager: fix failed assertion on user activations
We can't use g_steal_pointer(&active) in the argument list if another
argument uses @active because the order of evaluation is not defined.

This fixes the following bug:

 src/nm-manager.c:511:_async_op_complete_ac_auth_cb: assertion failed: (active == async_op_data->ac_auth.active)

Fixes: f4fc62bad8

https://bugzilla.redhat.com/show_bug.cgi?id=1585494
2018-06-04 18:06:47 +02:00
Beniamino Galvani
3fb4eed3ef settings: let connections keep NMSettings alive
The NMSettings instance can't be disposed while there is any exported
connection. Ideally we should unexport all connections on NMSettings'
disposal, but for now leak @self on termination when there are
connections alive.

This fixes the following bug on shutdown:

 assertion failed: (c_list_is_empty (&priv->connections_lst_head))
 #0  raise () from target:/lib64/libc.so.6
 #1  abort () from target:/lib64/libc.so.6
 #2  g_assertion_message (domain=0x66cab2 "NetworkManager", file=0x6a5e48 "src/settings/nm-settings.c", line=1929)
 #3  g_assertion_message_expr () at gtestutils.c:2555
 #4  finalize (object=0x1dab170) at src/settings/nm-settings.c:1929
 #5  g_object_unref (_object=0x1dab170) at gobject.c:3340
 #6  dispose (object=0x1de50b0) at src/nm-manager.c:7139
 #7  g_object_unref (_object=0x1de50b0) at gobject.c:3303
 #8  _nm_singleton_instance_destroy () at src/nm-core-utils.c:138
 #9  _dl_fini () from target:/lib64/ld-linux-x86-64.so.2
 #10 __run_exit_handlers () from target:/lib64/libc.so.6
 #11 exit () from target:/lib64/libc.so.6
 #12 main (argc=<optimized out>, argv=<optimized out>) at src/main.c:460

https://bugzilla.redhat.com/show_bug.cgi?id=1579858
2018-06-03 16:46:48 +02:00
Beniamino Galvani
bd63d39252 dhcp: fix handling of failure events
DHCPv4 can fail for two reasons:

 (a) the client failed to contact server and to get an initial lease

 (b) the client failed to renew the lease after it was successfully
     acquired

For (a) the client generates a TIMEOUT event, for (b) an EXPIRED
event.  Currently we fail the IP method immediately after (a), but
this doesn't work well when the carrier flickers and we restart the
client because if the server goes temporarily down, the IP method
fails and DHCP is never restarted.

Let's change this, and determine whether to fail IP configuration only
by looking at the current IP state: when it's IP_CONF then we are
getting the initial lease and a failure means that IP configuration
must fail; otherwise any other state means that the lease expired or
could not be renewed and thus we keep the client running for the grace
period.

https://bugzilla.redhat.com/show_bug.cgi?id=1573780
2018-06-02 10:50:18 +02:00
Beniamino Galvani
0aa2d252bf cli: fix active connections color
Fixes: a1b25a47b0
2018-06-01 18:10:03 +02:00