NetworkManager/src/tests/client
Thomas Haller 8e1330964d
cli: fix sorting of active connections
CMP() is a confusing pattern. Sure enough, the sort order was wrong, for
example, `nmcli connection` would show

    $ nmcli -f STATE,UUID,DEVICE c
    STATE       UUID                                  DEVICE
    activating  3098c902-c59c-45f4-9e5a-e4cdb79cfe1b  nm-bond
    activated   e4fc23ac-54ab-4b1a-932a-ebed12c96d9b  eth1

("activating" shown before "activated").

With `nmcli device`, we sort with compare_devices(). This first sorts by
device state (with "connected" being sorted first). Only when the device
state is equal, we fallback to nmc_active_connection_cmp().  So with
`nmcli device` we usually get "connected" devices first, and we don't
really notice that there is a problem with nmc_active_connection_cmp().

On the other hand, `nmcli connection` likes to sort first via
nmc_active_connection_cmp(), which gets it wrong. Profiles in
"activating" state are sorted first. That's inconsistent with `nmcli
device`, but it's also not what is intended.

Fix that.

Note the change in the test output. Both eth1 and eth0 are connected to
to the same profile, but one "eth0" the active-connection's state is
DEACTIVATING, while on "eth1" it's ACTIVATED (but both device's states
are "CONNECTED"). That's why "eth1" is now sorted first (as desired).

Fixes: a1b25a47b0 ('cli: rework printing of `nmcli connection` for multiple active connections')
2023-11-15 09:34:46 +01:00
..
terminal-colors.d client/tests: move "clients/tests/test-client.py" to "src/tests/client/" 2021-03-15 17:10:55 +01:00
test-client.check-on-disk cli: fix sorting of active connections 2023-11-15 09:34:46 +01:00
meson.build tests: increase timeout for check-local-tests-cloud-setup test with meson 2023-05-19 16:02:29 +02:00
test-client.py client/tests: add checks to "test-client.py" 2023-11-15 09:34:45 +01:00
test-client.sh tests/client: test nm-cloud-setup 2023-03-21 23:35:42 +01:00