Commit graph

391 commits

Author SHA1 Message Date
Íñigo Huguet
d00a5d2a8b tools: nm-in-container: don't generate files from the script
The script was generating the data-* files that later copies to the
container.

In order to the files being reusable for nm-in-vm, put them as separate
files inside the data directory.

However, some of the files need the full path to NetworkManager project,
which varies for each user. Instead, make a sed replacement on them and
generate the actual files that will be copied. Replacement:
{{BASEDIR_NM}} -> $BASEDIR_NM

Also, rename the files to more descriptive names, using some prefixes
that give a hint of where those files will be put, and the .in extension
to indicate that they will be processed.
2023-09-21 15:53:03 +02:00
Íñigo Huguet
3100e4b6e2 tools: nm-in-container: move data to a common path for nm-in-vm
nm-in-vm can use the same generated files than nm-in-container, so let's
move them to a place common for both: tools/nm-guest-data.

With this change, it is not worth it to have the nm-in-container
directory, so move the script to tools and delete the subdirectory.
2023-09-21 15:53:03 +02:00
Íñigo Huguet
97595fb00b tools: add nm-in-vm script
Script to download, configure and install a virtual machine to build and
test NetworkManager. This is useful because there are some things that
doesn't work properly on containers so a VM is needed to test.

It works almost the same way than nm-in-container.

Configurations specific to NetworkManager such as installing the required
packages are not implemented yet.
2023-09-21 15:53:03 +02:00
Íñigo Huguet
fb851f3294 nmcli: warn if daemon version mismatch
When updating NetworkManager to a new version, normally the service is
not restarted by the installer to avoid interrupting networking.
However, next nmcli invocation will use the updated version, but against
the older version of the daemon that is still running. Although this is
suposed to work, it is advisable that nmcli and daemon's versions are
the same. Emit a warning recommending restarting the daemon.

Add nmcli test to check the new feature. To avoid breaking the existing
tests, test-networkmanager-service now reports the same version than the
running nmcli except if it's instructed to report a different one.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1703
2023-08-03 10:09:06 +02:00
Fernando Fernandez Mancera
2115032869 nmcli: show bandwidth on wifi device output
Example output:

```
NAME:                                   AP[3]
SSID:                                   testX
SSID-HEX:                               4D4F5649535441525F504C55535F32453037
BSSID:                                  80:78:71:90:2E:15
MODE:                                   Infra
CHAN:                                   104
FREQ:                                   5520 MHz
RATE:                                   540 Mbit/s
BANDWIDTH:                              40 MHz
SIGNAL:                                 32
BARS:                                   ▂▄__
SECURITY:                               WPA2
WPA-FLAGS:                              (none)
RSN-FLAGS:                              pair_ccmp group_ccmp psk
DEVICE:                                 wlp0s20f3
ACTIVE:                                 yes
IN-USE:                                 *
DBUS-PATH:                              /org/freedesktop/NetworkManager/AccessPoint/3
```
2023-08-02 00:54:32 +02:00
Thomas Haller
6985c011c7
nm-in-container: add NetworkManager.service override 2023-06-30 15:44:05 +02:00
Thomas Haller
c59e7dfdee
nm-in-container: install pytest by default
It is useful for running unit tests on NetworkManager-ci.
2023-06-28 12:20:11 +02:00
Thomas Haller
ddcb396495
tests: avoid Python3 f-string in "test-cloud-meta-mock.py"
It breaks tests on Debian:9, which use Python2 still.

Fixes: e1f3acf3a6 ('test-cloud-meta-mock: allow configuring the provider that are mimicked')
2023-06-28 12:14:21 +02:00
Wen Liang
f04a9eb098 cloud-setup: add pre-up event to prevent reaching network-online.target
network-online.target should not be reached before nm-cloud-setup
completes configuring the network, which may make user service get
started before the network is fully configured.

Setting nm-cloud-setup.service as "Before=network-online.target" would
maybe have already achieved that. However, also use a pre-up dispatcher
script, so that the device activation in NetworkManager is also waiting
for nm-cloud-setup to complete.

https://bugzilla.redhat.com/show_bug.cgi?id=2151040
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1653
2023-06-09 09:18:20 -04:00
Frederic Martinsons
ae408fe4ab tools/tests: correct variant parsing
Seen in NM 1.42.6 where there is now a ipv4.dns-data key which
have as signature:
dbus.Array([dbus.String('a.b.c.d')], signature=dbus.Signature('s'), variant_level=1)

This lead to the following exception:
Cannot convert array element to type 's': Must be string, not Variant

Moreover, the exception TypeError has no message field so it raised
another expcetion which gave me trouble to find what's going on.

Hence the addition of a log file from the previous commit

Signed-off-by: Frederic Martinsons <frederic.martinsons@gmail.com>
2023-06-07 05:48:09 +00:00
Frederic Martinsons
2f7a571759 tools/tests: add ability to log to a file
That has been proven useful for debugging the tool during tests

Signed-off-by: Frederic Martinsons <frederic.martinsons@gmail.com>
2023-06-07 05:48:09 +00:00
Thomas Haller
e432b26112
nm-in-container: improve documentation 2023-06-06 15:01:56 +02:00
Thomas Haller
d67d63bf14
nm-in-container: improve README.md 2023-05-30 10:20:29 +02:00
Thomas Haller
e1f3acf3a6
test-cloud-meta-mock: allow configuring the provider that are mimicked
"test-cloud-meta-mock.py" needs to be mocked, so it only replies
to stuff that we tell it to. Except for the API token, that is
pushed by the client.

We need to be able to tell the mock whether it supports that API
or not. By default it does, but by setting "/.nmtest/providers"
we can limit that.

The DEFAULT_RESOURCE are now grouped by provider. If a path is not
explicitly mocked, we may fallback to the DEFAULT_RESOURCE, but only if
the respective "/.nmtest/providers" is enabled and if /.nmtest/allow-default"
indicates so (which they do by default).
2023-05-22 17:26:10 +02:00
Thomas Haller
4691f45bde
test-cloud-meta-mock: add and use helper to send response code 2023-05-22 17:24:55 +02:00
Thomas Haller
77fd4d5f0e
test-cloud-meta-mock: update default MAC address for test-cloud-meta-mock.py
Choose a MAC address that is easily recognizable. And where you can
see which is mac1 and mac2.
2023-05-22 17:24:55 +02:00
Thomas Haller
6dad817c05
tools: fix python2 compatibility in "generate-docs-nm-settings-docs-merge.py"
Fixes: 42aa225185 ('docs: better handle description tags in generate-docs-nm-settings-docs-merge.py')
2023-05-19 15:53:20 +02:00
Thomas Haller
b7d0218ee1
docs: rework selecting properties with "generate-docs-nm-settings-docs-merge.py"
"generate-docs-nm-settings-docs-merge.py" merges properties from
multiple XMLs. It supported an argument "--only-from-first", to
only select properties that were in the first of the provided XMLs.

The idea is that the first XML would be "src/nmcli/gen-metadata-nm-settings-nmcli.xml"
which is generated from nmcli meta-data and exactly describes the
supported properties. For example, "connection.read-only", "user.data"
or "wireless.tx-power" exist as properties somewhere, but not supported
by nmcli.

Change that, to not tie the selected property to the first XML.
"gen-metadata-nm-settings-nmcli.xml" is the XML that contains which
properties to select from, but "src/libnm-client-impl/nm-property-infos-nmcli.xml"
contains hand crafted descriptions. The latter descriptions are
preferred. As the order of the XML is already relevant for which
description is preferred, the selection is orthogonal to that.

With this, prefer descriptions from "src/libnm-client-impl/nm-property-infos-nmcli.xml"
but still select properties from "src/nmcli/gen-metadata-nm-settings-nmcli.xml".

Note that the argument is only used to generate "man/nm-settings-docs-nmcli.xml",
and with the current input, there is no actual change in behavior.
2023-05-19 12:52:01 +02:00
Thomas Haller
42aa225185
docs: better handle description tags in generate-docs-nm-settings-docs-merge.py
When we generate the manual page for nm-settings-nmcli, we run:

   "/usr/bin/python" \
        ./tools/generate-docs-nm-settings-docs-merge.py \
        --only-from-first \
        man/nm-settings-docs-nmcli.xml \
        src/nmcli/gen-metadata-nm-settings-nmcli.xml \
        src/libnm-client-impl/nm-property-infos-nmcli.xml \
        src/libnm-client-impl/nm-settings-docs-gir.xml

If "gen-metadata-nm-settings-nmcli.xml" contains either a <description>
or a <description-docbook>, then we must not continue searching the
other XML documents. The user provided an explicit override, and
fallback (search further) is wrong. Previously, we might take
<description> from the first file, and <description-docbook> from the
second file. As "man/nm-settings-nmcli.xsl" prefers
<description-docbook>, it takes the wrong text. Instead, as we search
the files during merge, we must prefer the first one.

Note that the change doesn't really matter anymore, because each XML
now must also contain both <description> and <description-docbook>.
There is an assertion for that.

Also, stop generating <deprecated-docbook>. First, it lacked the
important "since=" attribute and was necessary. Also, it's redundant and
does not contain anything interesting. So far, we don't need special
formatting for the deprecated message, and we likely never will.

Also, stop accepting or generating the "description=" attribute. This
should always be an XML element now.
2023-05-19 12:52:00 +02:00
Thomas Haller
89abede3df
docs: rework generating property infos to use <description> element
The "generate-docs-nm-property-infos.py" script parses the tags like
"---nmcli---" and generates an XML.

Rework it:

- don't put long text descriptions in a "description=" XML attribute.
  Instead, use an XML element. That is in line with what
  "generate-docs-nm-settings-docs-gir.py" does, which generates
  a similar file.

- if there is no <description-docbook> element, generate one based
  on <description>. That is important, because we want to create
  paragraphs.
  It's also important because "generate-docs-nm-settings-docs-gir.py"
  tends to generate <description-docbook> from the libnm/gir data.
  However, if you specify a "---nmcli---" override, then that should
  automatically apply to <description> and <description-docbook>.
2023-05-19 12:52:00 +02:00
Thomas Haller
676a99c96a
docs: drop redundant list([...]) in "generate-docs-nm-settings-docs-merge.py" 2023-05-19 12:51:59 +02:00
Thomas Haller
8c17077289
docs: simplify generating paragraphs in "generate-docs-nm-settings-docs-gir.py" 2023-05-19 12:51:59 +02:00
Thomas Haller
e37a15acad
all: avoid "==" bashism in scripts 2023-05-18 09:16:41 +02:00
Thomas Haller
33f7ee0bb7
nm-in-container: run with "--no-hosts" to have a plain /etc/hosts in the container
The bind mount interferes with running certain CI tests that want to
change /etc/hosts.
2023-05-15 11:02:10 +02:00
Lubomir Rintel
c72e085f5c
test/cloud-meta-mock: mock GCP metadata API
Not used for testing, but still might be useful for development.
2023-05-12 12:42:55 +02:00
Lubomir Rintel
5b5ef08aee
test/cloud-meta-mock: mock azure metadata API
Not used for testing, but still might be useful for development.
2023-05-12 12:42:55 +02:00
Lubomir Rintel
620a737cb7
test/cloud-meta-mock: mock aliyun metadata API
Not used for testing, but still might be useful for development.
2023-05-12 12:42:55 +02:00
Lubomir Rintel
41f0f6fec8
test/cloud-meta-mock: allow putting the resources
This reworks the cloud metadata mock server in a significant way.

Most importantly this makes it possible for the client to add and
modify the resources for later retrieval using the PUT method.
This allows the test to create the fixture for itself.

The default set of resources is still provided, so that the too remains
useful as a development aid. If that is not desirable, the --empty
parameter might be passed to cause the server to start with no
resources.
2023-05-12 12:42:55 +02:00
Lubomir Rintel
2e8ff9f8a0
Revert "client/tests: don't do dup2() dance to pass file descriptor to "tools/test-cloud-meta-mock.py""
This changed the fd passing protocol making it not compatible with
systemd-socket-activate(1).

This reverts commit 342ee618c7.
2023-05-12 12:42:54 +02:00
Thomas Haller
840abc6c45
nm-in-container: set NMCI_DEBUG=1 in bashrc 2023-04-26 11:05:18 +02:00
Thomas Haller
105eb39cda
nm-in-container: add commands to bash history 2023-04-18 20:47:32 +02:00
Beniamino Galvani
230f3f5ce7 nm-in-container: install libselinux-utils
It contains "getenforce" and "setenforce", which are needed by some
NMCI tests.
2023-04-18 10:10:56 +02:00
Thomas Haller
342ee618c7
client/tests: don't do dup2() dance to pass file descriptor to "tools/test-cloud-meta-mock.py"
"preexec_fn" is not great, because it is not generally safe in multi
threaded code (and we don't know whether the test didn't start other
threads already, like a GDBus worker thread). Well, it probably is safe,
if you only call async signal safe code, but it's not clear what os.dup2()
does under the hood.

Just avoid that. We can pass on the FD directly.
2023-03-30 15:36:16 +02:00
Lubomir Rintel
1e114c804b tools/test-cloud-meta-mock: add a mock metadata server for cloud-setup
Useful for testing/development.
2023-03-21 23:35:42 +01:00
Lubomir Rintel
fa191c929b test/nm-service: short circuit activation if AC activation delay is zero
This makes it possible for use to create a connection in immediately
rely on it being activated.
2023-03-21 21:56:17 +01:00
Lubomir Rintel
472e49e7b3 test/nm-service: make activation delay actually useful
The activation_state_change_delay_ms was not too useful, since it could
be changed only after the AC started activating. Not a big deal, since
it was actually unused.

Apart from that, the SetActiveConnectionStateChangedDelay() didn't make
a whole lot of sense either: it accepted a Device path, but actually
was looking up an AC.

Let's move the property to the Device, so that 1.) it can be adjusted
before the AC is constructed (the AC will inherit it from the Device)
and 2.) SetActiveConnectionStateChangedDelay() does no longer hurt my
feelings.
2023-03-21 21:56:17 +01:00
Lubomir Rintel
5ae3dc03a5 test/nm-service: implement applied connection handling
GetAppliedConnection() and Reapply(), both just enough to support
nm-cloud-setup.
2023-03-21 21:56:17 +01:00
Lubomir Rintel
f8188d51b2 test/nm-service: deconstruct string properties in connections too
I don't know what's going on:

  ======================================================================
  ERROR: test_ec2 (__main__.TestNmCloudSetup.test_ec2)
  ----------------------------------------------------------------------
  Traceback (most recent call last):
    File "NetworkManager/src/tests/client/test-client.py", line 2169, in f
      func(self)
    File "NetworkManager/src/tests/client/test-client.py", line 2194, in test_ec2
      conn = self.srv.op_AddAndActivateConnection(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "NetworkManager/src/tests/client/test-client.py", line 748, in __call__
      return method(*args)
             ^^^^^^^^^^^^^
    File "/usr/lib64/python3.11/site-packages/dbus/proxies.py", line 72, in __call__
      return self._proxy_method(*args, **keywords)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/usr/lib64/python3.11/site-packages/dbus/proxies.py", line 141, in __call__
      return self._connection.call_blocking(self._named_service,
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/usr/lib64/python3.11/site-packages/dbus/connection.py", line 634, in call_blocking
      reply_message = self.send_message_with_reply_and_block(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  dbus.exceptions.DBusException: org.freedesktop.DBus.Python.Exception: Traceback (most recent call last):
    File "/usr/lib64/python3.11/site-packages/dbus/service.py", line 712, in _message_cb
      retval = candidate_method(self, *args, **keywords)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "NetworkManager/tools/test-networkmanager-service.py", line 1693, in AddAndActivateConnection
      conpath, acpath, result = self.AddAndActivateConnection2(
                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "NetworkManager/tools/test-networkmanager-service.py", line 1707, in AddAndActivateConnection2
      conpath = gl.settings.AddConnection(con_hash)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "NetworkManager/tools/test-networkmanager-service.py", line 2198, in AddConnection
      return self.add_connection(con_hash)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "NetworkManager/tools/test-networkmanager-service.py", line 2208, in add_connection
      con_inst = Connection(self.c_counter, con_hash, do_verify_strict)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "NetworkManager/tools/test-networkmanager-service.py", line 2045, in __init__
      NmUtil.con_hash_verify(con_hash, do_verify_strict=do_verify_strict)
    File "NetworkManager/tools/test-networkmanager-service.py", line 594, in con_hash_verify
      BusErr.raise_nmerror(e)
    File "NetworkManager/tools/test-networkmanager-service.py", line 497, in raise_nmerror
      raise e
    File "NetworkManager/tools/test-networkmanager-service.py", line 590, in con_hash_verify
      con_nm = NmUtil.con_hash_to_connection(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "NetworkManager/tools/test-networkmanager-service.py", line 537, in con_hash_to_connection
      assert GLib.Variant.equal(x_con, Util.variant_from_dbus(con_hash))
                                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "NetworkManager/tools/test-networkmanager-service.py", line 378, in variant_from_dbus
      raise Exception("Unsupported type for value '%s'" % (repr(val)))
  Exception:
  Unsupported type for value 'dbus.Dictionary({
    dbus.String('connection'): dbus.Dictionary({
      dbus.String('type'): dbus.String('802-3-ethernet'),
      dbus.String('id'): dbus.String('con-eth0'),
      'uuid': '5fcfd6d7-1e63-3332-8826-a7eda103792d'
    }, signature=dbus.Signature('ss')),
    dbus.String('ipv4'): dbus.Dictionary({
      dbus.String('method'): dbus.String('auto')
    }, signature=dbus.Signature('ss'))
  }, signature=dbus.Signature('sa{ss}'))'
2023-03-21 21:56:17 +01:00
Thomas Haller
2c9faea63c
contrib,tools: move "nm-in-container.sh" script to "tools"
This script seems very useful to me. Give it a more prominent place and
move it out from "contrib/scripts". Also do some further renaming.
2023-03-20 08:59:59 +01:00
Daniel Kolesa
97abbbb987
build: fix pretty() sed invocation portability in .ver script
The `\0` being used to refer to the whole match is a GNU
extension. On other implementations of sed, this will simply
replace the each matched line with `	0;`, resulting in symbols
being missing in the NetworkManager executable, which breaks the
wifi plugin and others.

Use `&` instead, which behaves as expected in all implementations.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1562
2023-03-07 08:02:22 +01:00
Thomas Haller
dd5e769f24
build: add test for checking consistency of "nm-autoptr.h" 2023-02-28 16:33:07 +01:00
Thomas Haller
fdec6a97e8
vapi: add test for consistency of "vapi/NM-1.0.metadata" 2023-02-28 13:05:47 +01:00
Thomas Haller
a259303e1d
ovs: add support for "other_config" settings
See `man ovs-vswitchd.conf.db` for documentation of "other_config" keys.

https://bugzilla.redhat.com/show_bug.cgi?id=2151455
2023-01-11 21:49:36 +01:00
Lubomir Rintel
03813a530a tools/check-docs: more checks for missing includes
We get this wrong *very* often.
2022-11-13 23:36:37 +01:00
Thomas Haller
139f4b4b2e
build: pass both filenames to "tools/check-compare-generated.sh" script
It just feels nicer to be explicit about the filenames and
not rely on a specific naming.

Also, in meson we can directly pass the target as argument, which
expands to the filename but also adds a dependency.
2022-10-31 09:11:30 +01:00
Thomas Haller
ea5cd47bc4
tools: drop unused variables from "tools/generate-docs-nm-property-infos.py"
Found by lgtm.com.
2022-10-25 12:12:44 +02:00
Thomas Haller
70fee1cf46
tools: avoid Python 3 f-string in "generate-docs-nm-property-infos.py"
We also need to build with python2. No f-strings.

Fixes: 8fc7b6df12 ('tools: rework generating documentation from libnm meta data')
2022-10-07 21:08:39 +02:00
Thomas Haller
77e0041b27
tools: sort the settings in "generate-docs-nm-property-infos.py" by name
"nm-setting-ip-config.c" is a base class for IPv4 and IPv6 settings. So
far, any tags there were ignored, which was not obvious. It can be
useful to document common properties there. Well, maybe every property
better has a IPv4/IPv6 specific text, but that should not be a technical
limitation of the tool. So also honor the base file for "ipv4" and
"ipv6" settings.

When doing that, the settings are no longer processed in the order as
they are provided on the command line. Because, one file would be parsed
twice, it wouldn't make much sense. Instead, sort the my setting name.
The advantage is that the generated XML is independent from the order
that make/meson passes to the tool.
2022-10-06 13:40:30 +02:00
Thomas Haller
c1bebdfaa6
tools: don't set empty attributes in "generate-docs-nm-property-infos.py"
If the information is missing, the entire attribute should not be there.
Don't set it to the empty word.

Also, don't alias the "variable" attribute to the "name". It's not clear
what the "variable" fields is supposed to mean, but if it's not
explicitly set, don't make up the information. If a user of that
information cares, the can always fallback to the "name".
2022-10-06 13:40:30 +02:00
Thomas Haller
e56f7f5c2d
tools: don't write empty XML nodes in "generate-docs-nm-property-infos.py"
This generates '<setting name="XXX">\n</setting>' nodes in case there is
no additional data. Don't do that. Just '<setting name="XXX"/>'
2022-10-06 13:40:29 +02:00