Commit Graph

44 Commits

Author SHA1 Message Date
Thomas Haller
4b09c27d64 cli/tests: cache UUID for test replacement in stdout
Instead of re-fetching the UUID each time with a D-Bus call,
cache/memoize it.

On my system, this improves

  $ make check-local-clients-tests-test-client

from 20.9 to 20.4 seconds (- 2.6%). That is not stellar, but noticible
enough to warrant this simple change.
2018-07-25 17:08:37 +02:00
Thomas Haller
4d435ee92a cli/tests: avoid duplicate --terse option in tests
These nmcli calls are inside a Util.iter_nmcli_output_modes()
loop, hence, --terse will passed to them already.

Specifying --terse more than once, causes nmcli to fail.
We didn't actually want to test how nmcli rejects such
duplicate arguments. Adjust the test.
2018-07-25 17:08:37 +02:00
Thomas Haller
f0ceb3f393 cli/tests: add more tests for nmcli output
Add more tests for various output modes of nmcli.
This most interestingly includes a terse output for

  $ nmcli device status

Which was not tested previously (but a later commit will change
behavior here).

This blows up the number of tests even further.

Previously, the test invoked nmcli 850 times (taking ~15 seconds
ony my machine), afterwards, it is 1334 times (taking ~20 seconds).

No doubt, this seems excessive and questionable.

However, I maintain that the computer doesn't mind running a lot of
redundant tests. The important thing is, that we cover as many cases
as possible. Trying at the same time to minimize the number of tests
by avoiding duplicates and redundant tests, is just a lot of manual
labor. Manual labor that must be repeated whenever new tests are added, to
ensure that this test case is not yet covered. So, I am fine
with the large number of tests. Let the computer do the work.
2018-07-25 17:08:37 +02:00
Thomas Haller
795ec17a7e cli/tests: rework clients-tests.py to combine .expected output
Instead of letting each nmcli run write an individual .expected file,
combine the output of multiple runs in one file (per test).

Advantages:

- since there is a very large number of tests, having a file for each
  tests is cumbersome. For example, since they are all added to
  $(EXTRA_DIST) (and since we use non-recursive make), autoconf can
  easily hit a length limit when processing all the file names.

- previously, whenever we added tests, all .expected files shifted
  and the diff was large. Now, there is a chance that the diff is
  smaller and more accurate.
2018-07-25 17:08:37 +02:00
Thomas Haller
3ec62e41de clients/tests: add tests for coloring 2018-06-26 11:32:39 +02:00
Thomas Haller
3b1b6427d1 clients/tests: add more tests showing nmcli output
Of special interest here is

  $ nmcli --mode tabular -f all dev show eth0

to look how multiple available connections are printed.
2018-06-21 13:43:16 +02:00
Lubomir Rintel
4f557db063 clients/tests: utilize nm_utils_get_timestamp_msec() 2018-06-15 16:23:30 +02:00
Thomas Haller
fb5f555a54 clients/tests: add more tests printing wifi details in nmcli 2018-06-14 15:45:34 +02:00
Thomas Haller
ed638b7126 clients/tests: document importance of locale for clients tests 2018-06-14 13:57:14 +02:00
Lubomir Rintel
34412a8d3d cli/devices: rescan the Wi-Fi network if the AP list is not fresh enough 2018-06-13 14:48:23 +02:00
Thomas Haller
c2932dd7db clients/tests: better document how to re-generate files for clients tests 2018-06-13 08:50:46 +02:00
Thomas Haller
d739247e9f clients/tests: minor cleanup iterating over various nmcli output modes 2018-06-11 19:30:50 +02:00
Thomas Haller
acdc9df824 clients/tests: add tests for nmcli device wifi list output
This test shows how

  $ nmcli device wifi list bssid "$BSSID"

is broken.
2018-06-11 19:30:50 +02:00
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
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
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
1410dac5c3 clients/tests: add test for terse output of nmcli -t connection show $VPN 2018-06-11 10:30:27 +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
3690f8bcd5 clients/tests: add test for showing connection's active state 2018-06-01 16:03:23 +02:00
Thomas Haller
3645be6484 clients/tests: add test for showing invisible connection in nmcli
It also shows how we handle invisible connections wrongly, when we have
multiple active-connections that reference them.
2018-06-01 16:03:23 +02:00
Thomas Haller
46b7d52109 clients/tests: add tests for output of nmcli con show 2018-06-01 16:03:23 +02:00
Thomas Haller
baaab52266 clients/tests: run nmcli commands in parallel
Most nmcli calls from clients/tests don't change the server's state.
Hence, they can easily run in parallel.

Run tests in parallel. No longer handle one nmcli invocation after the other.
Instead, spawn groups of processes in parallel, and track the pending jobs.

Only at certain synchronization points we call self.async_wait() to
wait for all previous jobs to complete.

This reduces the test time on my machine from 7 to 3 seconds. Arguably,
that matters less during a full `make check -j 8`, because the entire
set of tests anyway takes longer than 7 seconds. So when running the
entire test suite, the machine is kept busy anyway. It matters however
for manual invocations.
2018-05-28 16:24:22 +02:00
Beniamino Galvani
1f7780cba9 cli: fix property matching
@ret was not initialized when there was only one partial match.

Also, refactor the code to return all matching values.

Fixes: 3fd9bf9d7d

https://github.com/NetworkManager/NetworkManager/pull/123
2018-05-28 11:33:40 +02:00
Thomas Haller
78e877ee3c clients/tests: refactor by moving replace-text helper function
Have less logic in TestNmcli.
2018-05-28 08:57:29 +02:00
Thomas Haller
ee85151a4a clients/tests: generate Makefile.am for expected files
The developer can re-generate .expected files with

 $ NM_TEST_REGENERATE=1 ./clients/tests/test-client.py

Note that these files are also dist-ed, so that the tests also work
from a source-tarball. For that, we need to add them to EXTRA_DIST.

Previously, this was done manually in the base Makefile.am file. This
was cumbersome, because when adding a new test, the developer would need
to manually add the files.

Now, let the test (with NM_TEST_REGENERATE=1) also generate a makefile
part.
2018-05-27 22:25:44 +02:00
Thomas Haller
5090c1f255 cli/tests: add test for output of nmcli general permissions 2018-05-25 17:24:57 +02:00
Thomas Haller
41dbf2b9d3 clients/tests: drop duplicate tests for German translation
call_nmcli_l() would test for 3 languages: 'C', 'de', and 'pl'. There
is no fundamental difference between 'de' and 'pl', so there is no need
to test for two languages.
2018-05-24 16:40:17 +02:00
Thomas Haller
2cae37ca40 clients/tests: test nmcli output for active-connection state DEACTIVATING 2018-05-24 16:40:17 +02:00
Thomas Haller
6f82c880a6 clients/tests: load libnm via GObject introspection
We will use it, and it must be available anyway, because the stub server
also requires it.
2018-05-24 16:40:17 +02:00
Thomas Haller
d424de10bf clients/tests: add SetProperties operation to test-networkmanager-service.py stub
It is a hook to set one or several D-Bus properties at once. Properties that are
to be set-able, have to be whitelisted in the stub.
2018-05-24 16:40:17 +02:00
Thomas Haller
7ae5fb7ec6 clients/tests: test nmcli output for multiple activation of same profile
Activate the same profile on two devices. Arguably, real NetworkManager
(currently) does not allow that. But the D-Bus API is fine with
having multiple ActiveConnections for one SettingsConnection.

So, also the client should do something sensible.

Also, later we will add wildcard support to NetworkManager, which means
that a profile can be active multiple times (simultaneously).
2018-05-24 16:40:17 +02:00
Thomas Haller
d5e25a4324 clients/tests: print active fields during nmcli con show 2018-05-24 16:40:17 +02:00
Thomas Haller
ea1830a429 clients/tests: add extra_env argument to call_nmcli()
This is purely for (manual) printf debugging. Hence, it is unused in the commited code.
The point is, to add printf statements to nmcli or libnm, like

  if (getenv ("MY_HACK1")) { ...

and trigger it from test-client.py via

  self.call_nmcli(..., extra_env = { 'MY_HACK1': '1' } )
2018-05-24 16:40:17 +02:00
Thomas Haller
15071e4741 clients/tests: add nmcli test for activating connection
Add a test to call `nmcli con up`, and also how the activated
state looks afterwards.
2018-05-14 17:53:03 +02:00
Thomas Haller
7224461069 clients/tests: add more checks for output of nmcli by language
Let the computer do the hard stuff. Since we already call the tests,
why only check for one language?
2018-05-14 17:53:03 +02:00
Thomas Haller
beca21be80 clients/tests: add test for nmcli device wifi output
Thereby, drop unneeded NM_TEST_CLIENT_IN_DBUS_SESSION=0 environment
variable from Makefile.am.
2018-05-14 17:53:03 +02:00
Thomas Haller
d4093a3a2c clients/tests: add python test script for nmcli tests
Add a test which runs nmcli against our stub NetworkManager
service and compares the output.

The output formats of nmcli are complicated and not easily understood.
For example how --mode tabular|multiline interacts with selecting
output-fields (--fields) and output modes ([default]|--terse|--pretty).
Also, there are things like `nmcli connection show --order $FIELD_SPEC`.

We need unit tests to ensure that we don't change the output
accidentally.
2018-05-11 16:51:20 +02:00