Merge ~slyon/snappy-hwe-snaps/+git/network-manager:slyon/drop-vendorized-netplan into ~snappy-hwe-team/snappy-hwe-snaps/+git/network-manager:snap-20

Proposed by Lukas Märdian
Status: Merged
Approved by: Alfonso Sanchez-Beato
Approved revision: b30293022f595124fe8cebd6e6ac3f17f3ea84d8
Merged at revision: ecc97bad2af908d74162d16b0efc2e67b4b1d01a
Proposed branch: ~slyon/snappy-hwe-snaps/+git/network-manager:slyon/drop-vendorized-netplan
Merge into: ~snappy-hwe-team/snappy-hwe-snaps/+git/network-manager:snap-20
Diff against target: 537 lines (+70/-211)
3 files modified
dev/null (+0/-83)
snap-patch/networkmanager/0002-nm-netplan-keyfile.patch (+63/-93)
snap/snapcraft.yaml (+7/-35)
Reviewer Review Type Date Requested Status
System Enablement Bot continuous-integration Approve
Alfonso Sanchez-Beato Approve
Review via email: mp+412634@code.launchpad.net

Commit message

Drop vendorized netplan

All required changes landed:
- https://github.com/snapcore/snapd/pull/10212
- https://github.com/canonical/netplan/pull/208
- https://bugs.launchpad.net/snappy/+bug/1926442

Refresh 0002-nm-netplan-keyfile.patch

netplan 0.103 compat changes are now integrated with the original patch, as
that version landed in UC20, changes to NM's unit-tests are not needed anymore.

Also, avoid calling into the netplan_generate() libnetplan API, this would just
execute the 'netplan generate' CLI, which would then call the
io.netplan.Netplan.Generate() DBus API in snap environments.
We can avoid this additional redirection and be independent from deprecation
or changes that are incompatible with the snap environment in the
netplan_generate() API, by calling the 'netplan generate' CLI directly.
Ideally, in the future we would avoid this redirection as well and call into
the io.netplan.Netplan.Generate() DBus method directly. But we need to pass a
--root-dir argument during the execution of NM's unit-tests, that is currently
not supported by the DBus method, so let's stick with the CLI for now.

This depends on the snapd snap to be >= 2.53.2+git864.g5823952 (currently in snapd/edge).

Description of the change

Drop vendorized netplan

All required changes landed:
- https://github.com/snapcore/snapd/pull/10212
- https://github.com/canonical/netplan/pull/208
- https://bugs.launchpad.net/snappy/+bug/1926442

Refresh 0002-nm-netplan-keyfile.patch

netplan 0.103 compat changes are now integrated with the original patch, as
that version landed in UC20, changes to NM's unit-tests are not needed anymore.

Also, avoid calling into the netplan_generate() libnetplan API, this would just
execute the 'netplan generate' CLI, which would then call the
io.netplan.Netplan.Generate() DBus API in snap environments.
We can avoid this additional redirection and be independent from deprecation
or changes that are incompatible with the snap environment in the
netplan_generate() API, by calling the 'netplan generate' CLI directly.
Ideally, in the future we would avoid this redirection as well and call into
the io.netplan.Netplan.Generate() DBus method directly. But we need to pass a
--root-dir argument during the execution of NM's unit-tests, that is currently
not supported by the DBus method, so let's stick with the CLI for now.

This depends on the snapd snap to be >= 2.53.2+git864.g5823952 (currently in snapd/edge).

To post a comment you must log in.
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Alfonso Sanchez-Beato (alfonsosanchezbeato) wrote :

Awesome, thanks for this! However, before merging we need to add a dependency so newer versions of the NM snap can be installed only for snapd with the interface change, like:

assumes:
  - snapd<version>

But we cannot really do this until snapd with the change has landed in the stable channel. Meanwhile, I'm marking this as WIP to avoid accidental merges.

Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Lukas Märdian (slyon) wrote :

snapd 2.54.2 landed in the stable channel and the test is passing now!

May I ask for another review/merge, Alfonso?

I'm not adding the "assumes:" stanza as that will be part of this other MP and I'd like to avoid a merge conflict:
https://code.launchpad.net/~alfonsosanchezbeato/snappy-hwe-snaps/+git/network-manager/+merge/414094

Revision history for this message
Alfonso Sanchez-Beato (alfonsosanchezbeato) wrote :

Thanks for this!

Thinking about netplan/libnetplan, is there any dependency on a newer core20 version added due to the changes in the NM netplan patch? If that is the case we would need an assumes also for core20.

For the removed "software-properties-common" build dep, there was a comment related to "package-repositories:". Does that mean that the comments at the beginning of snapcraft.yaml need to be removed too? I mean:

# Some packages might land in the ubuntu-image PPA for making their way
# into a Ubuntu Core base image and only later land in a LTS release.
# Enable ubuntu-image PPA once the --enable-experimental-package-repositories
# flag is not needed anymore
# package-repositories:
# - type: apt
# ppa: canonical-foundations/ubuntu-image

Revision history for this message
Alfonso Sanchez-Beato (alfonsosanchezbeato) wrote :

I was also thinking, is the NM netplan patch stored in some git repo also? It would be nice to know where to get history for it.

Revision history for this message
Lukas Märdian (slyon) wrote :

Thank you, those are some good comments!

I've now added the "assumes" dependencies on snapd and core20 as both are needed to access the "io.netplan.Netplan.Generate()" DBus API.

I was thinking about leaving that comment about the extra ubuntu-image PPA as is, in case it might be needed in the future. But no strong opinion about that; it's not needed currently, so I removed it now.

The link to the NM netplan patch git repository is listed in snapcraft.yaml, but I've now also added it to the patch header itself, for better visibility. There is not a lot of history on that repository, though, as all changes are squashed into a single commit. That is because carrying all the "overhead" (patch headers and description of individual commits) produces a very big patch, which was criticized in the past.

Revision history for this message
Alfonso Sanchez-Beato (alfonsosanchezbeato) wrote :

Ah, I had not seen the link to the repo in the snapcraft.yaml. Thanks for your changes!

review: Approve
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Alfonso Sanchez-Beato (alfonsosanchezbeato) wrote :

@slyon, I've been asking in snappy channel, and "assumes" is actually not valid for base snaps. The suggestion is to ship the library inside NM if there is such a dependency. Does that make sense?

Revision history for this message
Alfonso Sanchez-Beato (alfonsosanchezbeato) wrote :

Also, I've tried the snap and fails on installation, most probably that is causing the CI issues.

Revision history for this message
Lukas Märdian (slyon) wrote :

Alright!
So let me remove the 'assumes:' stanza again, and let's pull in the snapd dependency via your MR#414094, while renouncing the core20 dependency.

Shipping libnetplan inside the NM snap isn't really an option for two reasons:
1/ 'netplan generate' accesses systemd files that are outside of the confinement and snapd didn't want to allow-list them. (See history on https://github.com/snapcore/snapd/pull/10212 – we've been working on this since April'21) So the only option is the hack that we currently have, vendorizing a patched version of netplan, that is reduced in functionality. But that needs to be updated (and patches refreshed) with each netplan SRU, while still not providing the full netplan functionality.

2/ The netplan configuration read from /etc/netplan is also used by the system (e.g. on bootup), so if we ship a different version of netplan inside the snap than we have in the outside system, the outside system might be happily creating and using new configuration settings, while the (potentially outdated) version inside the snap would fail to process those very same config files. As already happening in https://bugs.launchpad.net/rochester/+bug/1957828

So I guess we just have to expect the core snap to be up-to-date, containing a version of netplan that provides the io.netplan.Netplan.Generate() DBus API (that has been backported down to Bionic), without defining any dependency. This is the same way that we expected it to provide the io.netplan.Netplan.Apply() DBus API ever since.

Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Alfonso Sanchez-Beato (alfonsosanchezbeato) wrote :

@slyon ok, what you say makes sense. Maybe what we need to do is just that NM does not fail catastrophically is an older core20 is present. What would happen if we install this NM with an old core20?

Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Lukas Märdian (slyon) wrote :

From my understanding of the code in `nms-keyfile-utils.c -> generate_netplan()` if the .Generate() DBus API would not be available on an older version of core20, NM would still be able to successfully produce new YAML (or modify existing YAML) in /etc/netplan but would then fail to generate the corresponding keyfile data out of that. So the NM state would basically not be updated, but the old configuration still in place. After a reboot (or 'netplan apply' call from the outside system) the current state would be visible to NM.

I don't have access to older versions of core20 (that would not provide the .Generate() API), so I could not test it in the real environment, but tested it inside a normal ("classic") Ubuntu Focal installation, where the modified NetworkManager is installed; that confirmed my assumption from above:

# nmcli con add type ethernet
[...]
Error: Failed to add 'ethernet' connection: failure adding connection: settings plugin does not support adding connections

# nmcli con mod ethernet con-name abc
[...]
Error: Failed to modify connection 'abc': failed to update connection: keyfile writer produces an invalid connection: cannot access file: No such file or directory

# nmcli con reload
Call failed: Unknown method Generate or interface io.netplan.Netplan.
Traceback (most recent call last):
  File "/usr/sbin/netplan", line 23, in <module>
    netplan.main()
  File "/usr/share/netplan/netplan/cli/core.py", line 50, in main
    self.run_command()
  File "/usr/share/netplan/netplan/cli/utils.py", line 310, in run_command
    self.func()
  File "/usr/share/netplan/netplan/cli/commands/generate.py", line 46, in run
    self.run_command()
  File "/usr/share/netplan/netplan/cli/utils.py", line 310, in run_command
    self.func()
  File "/usr/share/netplan/netplan/cli/commands/generate.py", line 73, in command_generate
    raise RuntimeError(
RuntimeError: failed to communicate with dbus service: error 1

All operations display a similar error message as the "nmcli con reload" command: "Call failed: Unknown method Generate or interface io.netplan.Netplan" / "RuntimeError: failed to communicate with dbus service: error 1"

Deleting of connection profiles via NM even works (but also prints the error message about the missing DBus API):
# nmcli con del abc
[...]
Connection 'abc' (6d8d8b90-5874-458f-b6c9-e1857f3e7b06) successfully deleted.

NetworkManager keeps running at all times (does not crash) and handles the latest configuration after reboot or 'netplan apply' was executed from the outside system. I'd say this qualifies for "NM does not fail catastrophically" and we should be good to go.

Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/snap-patch/netplan.patch b/snap-patch/netplan.patch
0deleted file mode 1006440deleted file mode 100644
index 96d35e2..0000000
--- a/snap-patch/netplan.patch
+++ /dev/null
@@ -1,103 +0,0 @@
1From a989fcd2e08c6aa207f2bde2fab1bb7ea273ccf6 Mon Sep 17 00:00:00 2001
2From: =?UTF-8?q?Lukas=20M=C3=A4rdian?= <lukas.maerdian@canonical.com>
3Date: Wed, 5 May 2021 17:07:57 +0200
4Subject: [PATCH] generate: disable generation of non-NM config
5
6---
7 src/generate.c | 28 +++++++++++++++-------------
8 1 file changed, 15 insertions(+), 13 deletions(-)
9
10diff --git a/src/generate.c b/src/generate.c
11index d820f35..5424316 100644
12--- a/src/generate.c
13+++ b/src/generate.c
14@@ -36,7 +36,7 @@
15 static gchar* rootdir;
16 static gchar** files;
17 static gboolean any_networkd;
18-static gboolean any_sriov;
19+//static gboolean any_sriov;
20 static gchar* mapping_iface;
21
22 static GOptionEntry options[] = {
23@@ -46,12 +46,14 @@ static GOptionEntry options[] = {
24 {NULL}
25 };
26
27+/*
28 static void
29 reload_udevd(void)
30 {
31 const gchar *argv[] = { "/sbin/udevadm", "control", "--reload", NULL };
32 g_spawn_sync(NULL, (gchar**)argv, NULL, G_SPAWN_STDERR_TO_DEV_NULL, NULL, NULL, NULL, NULL, NULL, NULL);
33 };
34+*/
35
36 // LCOV_EXCL_START
37 /* covered via 'cloud-init' integration test */
38@@ -85,13 +87,13 @@ static void
39 nd_iterator_list(gpointer value, gpointer user_data)
40 {
41 NetplanNetDefinition* def = (NetplanNetDefinition*) value;
42- if (write_networkd_conf(def, (const char*) user_data))
43- any_networkd = TRUE;
44+ //if (write_networkd_conf(def, (const char*) user_data))
45+ // any_networkd = TRUE;
46
47- write_ovs_conf(def, (const char*) user_data);
48+ //write_ovs_conf(def, (const char*) user_data);
49 write_nm_conf(def, (const char*) user_data);
50- if (def->sriov_explicit_vf_count < G_MAXUINT || def->sriov_link)
51- any_sriov = TRUE;
52+ //if (def->sriov_explicit_vf_count < G_MAXUINT || def->sriov_link)
53+ // any_sriov = TRUE;
54 }
55
56
57@@ -223,28 +225,28 @@ int main(int argc, char** argv)
58 }
59
60 /* Clean up generated config from previous runs */
61- cleanup_networkd_conf(rootdir);
62+ //cleanup_networkd_conf(rootdir);
63 cleanup_nm_conf(rootdir);
64- cleanup_ovs_conf(rootdir);
65- cleanup_sriov_conf(rootdir);
66+ //cleanup_ovs_conf(rootdir);
67+ //cleanup_sriov_conf(rootdir);
68
69 if (mapping_iface && netdefs)
70 return find_interface(mapping_iface);
71
72 /* Generate backend specific configuration files from merged data. */
73- write_ovs_conf_finish(rootdir); // OVS cleanup unit is always written
74+ //write_ovs_conf_finish(rootdir); // OVS cleanup unit is always written
75 if (netdefs) {
76 g_debug("Generating output files..");
77 g_list_foreach (netdefs_ordered, nd_iterator_list, rootdir);
78 write_nm_conf_finish(rootdir);
79- if (any_sriov) write_sriov_conf_finish(rootdir);
80+ //if (any_sriov) write_sriov_conf_finish(rootdir);
81 /* We may have written .rules & .link files, thus we must
82 * invalidate udevd cache of its config as by default it only
83 * invalidates cache at most every 3 seconds. Not sure if this
84 * should live in `generate' or `apply', but it is confusing
85 * when udevd ignores just-in-time created rules files.
86 */
87- reload_udevd();
88+ //reload_udevd();
89 }
90
91 /* Disable /usr/lib/NetworkManager/conf.d/10-globally-managed-devices.conf
92@@ -262,7 +264,7 @@ int main(int argc, char** argv)
93 FILE* f = fopen(generator_run_stamp, "w");
94 g_assert(f != NULL);
95 fclose(f);
96- } else if (check_called_just_in_time()) {
97+ } else if (FALSE && check_called_just_in_time()) {
98 /* netplan-feature: generate-just-in-time */
99 /* When booting with cloud-init, network configuration
100 * might be provided just-in-time. Specifically after
101--
1022.30.2
103
diff --git a/snap-patch/networkmanager/0002-nm-netplan-keyfile.patch b/snap-patch/networkmanager/0002-nm-netplan-keyfile.patch
index a9fa763..6dbaf2a 100644
--- a/snap-patch/networkmanager/0002-nm-netplan-keyfile.patch
+++ b/snap-patch/networkmanager/0002-nm-netplan-keyfile.patch
@@ -1,7 +1,7 @@
1From e5d3bc03eb28ee09351f947670b3b6608786491e Mon Sep 17 00:00:00 20011From 58fd964ae79bfb635928b839f5788e1face8ddfb Mon Sep 17 00:00:00 2001
2From: Lukas Märdian <lukas.maerdian@canonical.com>2From: Lukas Märdian <lukas.maerdian@canonical.com>
3Date: Tue, 2 Feb 2021 15:52:05 +01003Date: Tue, 2 Feb 2021 15:52:05 +0100
4Subject: [PATCH 1/2] netplan: make use of libnetplan for YAML backend4Subject: [PATCH] netplan: make use of libnetplan for YAML backend
55
6This patch modifies NetworkManager's nms-keyfile-plugin in a way to6This patch modifies NetworkManager's nms-keyfile-plugin in a way to
7write YAML connections (according to the netplan spec) to7write YAML connections (according to the netplan spec) to
@@ -27,16 +27,19 @@ Each time the YAML data was modified, NetworkManager calls
27netplan generator can be used as intended (no need for duplicated27netplan generator can be used as intended (no need for duplicated
28keyfile export functionality) and the nms-keyfile-writer can be re-used28keyfile export functionality) and the nms-keyfile-writer can be re-used
29without any patching needed.29without any patching needed.
30
31Current upstream repository/branch:
32https://github.com/slyon/NetworkManager/tree/slyon/backend-1.22.10
30---33---
31 Makefile.am | 5 +-34 Makefile.am | 5 +-
32 meson.build | 3 +35 meson.build | 3 +
33 src/meson.build | 2 +36 src/meson.build | 2 +
34 .../plugins/keyfile/nms-keyfile-plugin.c | 19 ++++37 .../plugins/keyfile/nms-keyfile-plugin.c | 19 +++
35 .../plugins/keyfile/nms-keyfile-utils.c | 41 ++++++++38 .../plugins/keyfile/nms-keyfile-utils.c | 57 +++++++++
36 .../plugins/keyfile/nms-keyfile-utils.h | 2 +39 .../plugins/keyfile/nms-keyfile-utils.h | 4 +
37 .../plugins/keyfile/nms-keyfile-writer.c | 97 +++++++++++++++++++40 .../plugins/keyfile/nms-keyfile-writer.c | 108 ++++++++++++++++++
38 .../keyfile/tests/test-keyfile-settings.c | 45 +++++++--41 .../keyfile/tests/test-keyfile-settings.c | 45 ++++++--
39 8 files changed, 205 insertions(+), 9 deletions(-)42 8 files changed, 234 insertions(+), 9 deletions(-)
4043
41diff --git a/Makefile.am b/Makefile.am44diff --git a/Makefile.am b/Makefile.am
42index b37aa4e712311cb23a675af70ec1287fcd3d63f5..2e4e146412de6102068bb953c38cb8091e7f010a 10064445index b37aa4e712311cb23a675af70ec1287fcd3d63f5..2e4e146412de6102068bb953c38cb8091e7f010a 100644
@@ -89,7 +92,7 @@ index 748fa519bc56305bfe485b9ea1207942fe5b5874..398efb3c69c37bd1d6214602d194dfad
89 92
90 if enable_wext93 if enable_wext
91diff --git a/src/settings/plugins/keyfile/nms-keyfile-plugin.c b/src/settings/plugins/keyfile/nms-keyfile-plugin.c94diff --git a/src/settings/plugins/keyfile/nms-keyfile-plugin.c b/src/settings/plugins/keyfile/nms-keyfile-plugin.c
92index fdb88d2a6d6218460fe191d7bc5be08b492886f5..548eda536354c9aa3a305540038bf4a03be8fcb6 10064495index fdb88d2a6d6218460fe191d7bc5be08b492886f5..60b8490fdaa7cbf1ffae3dc89f19289bc842acad 100644
93--- a/src/settings/plugins/keyfile/nms-keyfile-plugin.c96--- a/src/settings/plugins/keyfile/nms-keyfile-plugin.c
94+++ b/src/settings/plugins/keyfile/nms-keyfile-plugin.c97+++ b/src/settings/plugins/keyfile/nms-keyfile-plugin.c
95@@ -12,6 +12,7 @@98@@ -12,6 +12,7 @@
@@ -115,7 +118,7 @@ index fdb88d2a6d6218460fe191d7bc5be08b492886f5..548eda536354c9aa3a305540038bf4a0
115 nm_auto_clear_sett_util_storages NMSettUtilStorages storages_new = NM_SETT_UTIL_STORAGES_INIT (storages_new, nms_keyfile_storage_destroy);118 nm_auto_clear_sett_util_storages NMSettUtilStorages storages_new = NM_SETT_UTIL_STORAGES_INIT (storages_new, nms_keyfile_storage_destroy);
116 int i;119 int i;
117 120
118+ netplan_generate(NULL);121+ generate_netplan(NULL);
119+ _fix_netplan_interface_name(NULL);122+ _fix_netplan_interface_name(NULL);
120 _load_dir (self, NMS_KEYFILE_STORAGE_TYPE_RUN, priv->dirname_run, &storages_new);123 _load_dir (self, NMS_KEYFILE_STORAGE_TYPE_RUN, priv->dirname_run, &storages_new);
121 if (priv->dirname_etc)124 if (priv->dirname_etc)
@@ -140,14 +143,14 @@ index fdb88d2a6d6218460fe191d7bc5be08b492886f5..548eda536354c9aa3a305540038bf4a0
140 143
141+ g_autofree gchar* netplan_id = netplan_get_id_from_nm_filename(previous_filename, ssid);144+ g_autofree gchar* netplan_id = netplan_get_id_from_nm_filename(previous_filename, ssid);
142+ netplan_delete_connection(netplan_id, NULL);145+ netplan_delete_connection(netplan_id, NULL);
143+ netplan_generate(NULL);146+ generate_netplan(NULL);
144+ _fix_netplan_interface_name(NULL);147+ _fix_netplan_interface_name(NULL);
145+148+
146 _LOGT ("commit: deleted \"%s\", %s %s (%s%s%s%s)",149 _LOGT ("commit: deleted \"%s\", %s %s (%s%s%s%s)",
147 previous_filename,150 previous_filename,
148 storage->is_meta_data ? "meta-data" : "profile",151 storage->is_meta_data ? "meta-data" : "profile",
149diff --git a/src/settings/plugins/keyfile/nms-keyfile-utils.c b/src/settings/plugins/keyfile/nms-keyfile-utils.c152diff --git a/src/settings/plugins/keyfile/nms-keyfile-utils.c b/src/settings/plugins/keyfile/nms-keyfile-utils.c
150index f03c601a56a6548c947f1b7cc6d4cd6b441e5b1d..44edabd37599187ee00da2dfea4c3a09fcb2cb9d 100644153index f03c601a56a6548c947f1b7cc6d4cd6b441e5b1d..20c3d949b284ba64de0d01794795a1bb6367ba4c 100644
151--- a/src/settings/plugins/keyfile/nms-keyfile-utils.c154--- a/src/settings/plugins/keyfile/nms-keyfile-utils.c
152+++ b/src/settings/plugins/keyfile/nms-keyfile-utils.c155+++ b/src/settings/plugins/keyfile/nms-keyfile-utils.c
153@@ -9,6 +9,7 @@156@@ -9,6 +9,7 @@
@@ -205,8 +208,28 @@ index f03c601a56a6548c947f1b7cc6d4cd6b441e5b1d..44edabd37599187ee00da2dfea4c3a09
205 const char *208 const char *
206 nms_keyfile_nmmeta_check_filename (const char *filename,209 nms_keyfile_nmmeta_check_filename (const char *filename,
207 guint *out_uuid_len)210 guint *out_uuid_len)
211@@ -366,3 +407,19 @@ nms_keyfile_utils_check_file_permissions (NMSKeyfileFiletype filetype,
212 NM_SET_OUT (out_st, st);
213 return TRUE;
214 }
215+
216+gboolean
217+generate_netplan(const char* rootdir)
218+{
219+ /* TODO: call the io.netplan.Netplan.Generate() DBus method directly, after
220+ * finding a way to pass the --root-dir parameter via DBus, to make it work
221+ * inside NM's unit-tests where netplan needs to read & generate outside of
222+ * /etc/netplan and /run/{systemd,NetworkManager} */
223+ const gchar *argv[] = { "netplan", "generate", NULL , NULL, NULL };
224+ if (rootdir) {
225+ argv[2] = "--root-dir";
226+ argv[3] = rootdir;
227+ }
228+ return g_spawn_sync(NULL, (gchar**)argv, NULL, G_SPAWN_SEARCH_PATH,
229+ NULL, NULL, NULL, NULL, NULL, NULL);
230+}
208diff --git a/src/settings/plugins/keyfile/nms-keyfile-utils.h b/src/settings/plugins/keyfile/nms-keyfile-utils.h231diff --git a/src/settings/plugins/keyfile/nms-keyfile-utils.h b/src/settings/plugins/keyfile/nms-keyfile-utils.h
209index f943d65ca6834efd2bc243397d122243d906712e..f9c29899990ffd70ca4aba50f42284fa2277440f 100644232index f943d65ca6834efd2bc243397d122243d906712e..4803135d3f60cdfae4a23640cefcbe6d4f4f1de4 100644
210--- a/src/settings/plugins/keyfile/nms-keyfile-utils.h233--- a/src/settings/plugins/keyfile/nms-keyfile-utils.h
211+++ b/src/settings/plugins/keyfile/nms-keyfile-utils.h234+++ b/src/settings/plugins/keyfile/nms-keyfile-utils.h
212@@ -30,6 +30,8 @@ NMS_KEYFILE_STORAGE_TYPE_LIB (guint run_idx)235@@ -30,6 +30,8 @@ NMS_KEYFILE_STORAGE_TYPE_LIB (guint run_idx)
@@ -218,8 +241,15 @@ index f943d65ca6834efd2bc243397d122243d906712e..f9c29899990ffd70ca4aba50f42284fa
218 const char *nms_keyfile_nmmeta_check_filename (const char *filename,241 const char *nms_keyfile_nmmeta_check_filename (const char *filename,
219 guint *out_uuid_len);242 guint *out_uuid_len);
220 243
244@@ -71,4 +73,6 @@ gboolean nms_keyfile_utils_check_file_permissions (NMSKeyfileFiletype filetype,
245 struct stat *out_st,
246 GError **error);
247
248+gboolean generate_netplan(const char* rootdir);
249+
250 #endif /* __NMS_KEYFILE_UTILS_H__ */
221diff --git a/src/settings/plugins/keyfile/nms-keyfile-writer.c b/src/settings/plugins/keyfile/nms-keyfile-writer.c251diff --git a/src/settings/plugins/keyfile/nms-keyfile-writer.c b/src/settings/plugins/keyfile/nms-keyfile-writer.c
222index fa95198c0084ac6b907f7ffa7ba826a1cca6a025..fb1c0437a45ac0eae9a9fbb6d140abf7ad49bb00 100644252index fa95198c0084ac6b907f7ffa7ba826a1cca6a025..53d8f929921181adbe2b0349ee80d1b93939e829 100644
223--- a/src/settings/plugins/keyfile/nms-keyfile-writer.c253--- a/src/settings/plugins/keyfile/nms-keyfile-writer.c
224+++ b/src/settings/plugins/keyfile/nms-keyfile-writer.c254+++ b/src/settings/plugins/keyfile/nms-keyfile-writer.c
225@@ -11,6 +11,10 @@255@@ -11,6 +11,10 @@
@@ -241,7 +271,7 @@ index fa95198c0084ac6b907f7ffa7ba826a1cca6a025..fb1c0437a45ac0eae9a9fbb6d140abf7
241 GError **error)271 GError **error)
242 {272 {
243 gs_unref_keyfile GKeyFile *kf_file = NULL;273 gs_unref_keyfile GKeyFile *kf_file = NULL;
244@@ -364,6 +369,92 @@ _internal_write_connection (NMConnection *connection,274@@ -364,6 +369,103 @@ _internal_write_connection (NMConnection *connection,
245 && !nm_streq (path, existing_path))275 && !nm_streq (path, existing_path))
246 unlink (existing_path);276 unlink (existing_path);
247 277
@@ -278,7 +308,7 @@ index fa95198c0084ac6b907f7ffa7ba826a1cca6a025..fb1c0437a45ac0eae9a9fbb6d140abf7
278+ * we've written the /etc/netplan/*.yaml file instead. */308+ * we've written the /etc/netplan/*.yaml file instead. */
279+ unlink(path);309+ unlink(path);
280+ g_free(path);310+ g_free(path);
281+ if (!netplan_generate(rootdir)) {311+ if (!generate_netplan(rootdir)) {
282+ g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED,312+ g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED,
283+ "netplan generate failed");313+ "netplan generate failed");
284+ return FALSE;314+ return FALSE;
@@ -296,6 +326,17 @@ index fa95198c0084ac6b907f7ffa7ba826a1cca6a025..fb1c0437a45ac0eae9a9fbb6d140abf7
296+ else326+ else
297+ path = g_strdup_printf("%s/run/NetworkManager/system-connections/netplan-NM-%s.nmconnection",327+ path = g_strdup_printf("%s/run/NetworkManager/system-connections/netplan-NM-%s.nmconnection",
298+ rootdir ?: "", nm_connection_get_uuid (connection));328+ rootdir ?: "", nm_connection_get_uuid (connection));
329+
330+ // Since netplan v0.103 logical interfaces (bridge/bond/vlan/...) use the interface name as ID
331+ if (!g_file_test(path, G_FILE_TEST_EXISTS)) {
332+ g_free(path);
333+ if (escaped_ssid)
334+ path = g_strdup_printf("%s/run/NetworkManager/system-connections/netplan-%s-%s.nmconnection",
335+ rootdir ?: "", (char *)netdef_id, escaped_ssid);
336+ else
337+ path = g_strdup_printf("%s/run/NetworkManager/system-connections/netplan-%s.nmconnection",
338+ rootdir ?: "", (char *)netdef_id);
339+ }
299+ }340+ }
300+341+
301+ /* re-read again: this time the connection profile newly generated by netplan in /run/... */342+ /* re-read again: this time the connection profile newly generated by netplan in /run/... */
@@ -334,7 +375,7 @@ index fa95198c0084ac6b907f7ffa7ba826a1cca6a025..fb1c0437a45ac0eae9a9fbb6d140abf7
334 NM_SET_OUT (out_reread, g_steal_pointer (&reread));375 NM_SET_OUT (out_reread, g_steal_pointer (&reread));
335 NM_SET_OUT (out_reread_same, reread_same);376 NM_SET_OUT (out_reread_same, reread_same);
336 NM_SET_OUT (out_path, g_steal_pointer (&path));377 NM_SET_OUT (out_path, g_steal_pointer (&path));
337@@ -407,6 +498,7 @@ nms_keyfile_writer_connection (NMConnection *connection,378@@ -407,6 +509,7 @@ nms_keyfile_writer_connection (NMConnection *connection,
338 out_path,379 out_path,
339 out_reread,380 out_reread,
340 out_reread_same,381 out_reread_same,
@@ -342,7 +383,7 @@ index fa95198c0084ac6b907f7ffa7ba826a1cca6a025..fb1c0437a45ac0eae9a9fbb6d140abf7
342 error);383 error);
343 }384 }
344 385
345@@ -420,6 +512,10 @@ nms_keyfile_writer_test_connection (NMConnection *connection,386@@ -420,6 +523,10 @@ nms_keyfile_writer_test_connection (NMConnection *connection,
346 gboolean *out_reread_same,387 gboolean *out_reread_same,
347 GError **error)388 GError **error)
348 {389 {
@@ -353,7 +394,7 @@ index fa95198c0084ac6b907f7ffa7ba826a1cca6a025..fb1c0437a45ac0eae9a9fbb6d140abf7
353 return _internal_write_connection (connection,394 return _internal_write_connection (connection,
354 FALSE,395 FALSE,
355 FALSE,396 FALSE,
356@@ -438,5 +534,6 @@ nms_keyfile_writer_test_connection (NMConnection *connection,397@@ -438,5 +545,6 @@ nms_keyfile_writer_test_connection (NMConnection *connection,
357 out_path,398 out_path,
358 out_reread,399 out_reread,
359 out_reread_same,400 out_reread_same,
@@ -470,74 +511,3 @@ index d2da09da71c45226a8fb5e9f46e376deb5a48be8..fd2aa1424a218ea6a61369da56b9044d
470-- 511--
4712.32.05122.32.0
472513
473
474From 99bd17f98438acb4e9263ef7c1b43b78d955cbcb Mon Sep 17 00:00:00 2001
475From: Lukas Märdian <slyon@ubuntu.com>
476Date: Tue, 5 Oct 2021 11:42:19 +0200
477Subject: [PATCH 2/2] netplan: v0.103 compatibility
478
479---
480 src/settings/plugins/keyfile/nms-keyfile-writer.c | 11 +++++++++++
481 .../plugins/keyfile/tests/test-keyfile-settings.c | 11 ++++++++---
482 2 files changed, 19 insertions(+), 3 deletions(-)
483
484diff --git a/src/settings/plugins/keyfile/nms-keyfile-writer.c b/src/settings/plugins/keyfile/nms-keyfile-writer.c
485index fb1c0437a45ac0eae9a9fbb6d140abf7ad49bb00..1bc761c4c92ba8df341705630b35a429749b4853 100644
486--- a/src/settings/plugins/keyfile/nms-keyfile-writer.c
487+++ b/src/settings/plugins/keyfile/nms-keyfile-writer.c
488@@ -420,6 +420,17 @@ _internal_write_connection (NMConnection *connection,
489 else
490 path = g_strdup_printf("%s/run/NetworkManager/system-connections/netplan-NM-%s.nmconnection",
491 rootdir ?: "", nm_connection_get_uuid (connection));
492+
493+ // Since netplan v0.103 logical interfaces (bridge/bond/vlan/...) use the interface name as ID
494+ if (!g_file_test(path, G_FILE_TEST_EXISTS)) {
495+ g_free(path);
496+ if (escaped_ssid)
497+ path = g_strdup_printf("%s/run/NetworkManager/system-connections/netplan-%s-%s.nmconnection",
498+ rootdir ?: "", (char *)netdef_id, escaped_ssid);
499+ else
500+ path = g_strdup_printf("%s/run/NetworkManager/system-connections/netplan-%s.nmconnection",
501+ rootdir ?: "", (char *)netdef_id);
502+ }
503 }
504
505 /* re-read again: this time the connection profile newly generated by netplan in /run/... */
506diff --git a/src/settings/plugins/keyfile/tests/test-keyfile-settings.c b/src/settings/plugins/keyfile/tests/test-keyfile-settings.c
507index fd2aa1424a218ea6a61369da56b9044d75232cac..84c7081e941cab54c2027231e1d55065f18633ef 100644
508--- a/src/settings/plugins/keyfile/tests/test-keyfile-settings.c
509+++ b/src/settings/plugins/keyfile/tests/test-keyfile-settings.c
510@@ -461,7 +461,9 @@ test_write_wired_connection (void)
511 /* Routes */
512 add_one_ip_route (s_ip4, route1, route1_nh, 24, 3);
513 add_one_ip_route (s_ip4, route2, route2_nh, 8, 1);
514- add_one_ip_route (s_ip4, route3, route3_nh, 7, -1);
515+ /* XXX: netplan 0.103 requires "to" and "via" for unicast routes,
516+ * but NM drops the "via"/nh field if metric is not defined. */
517+ add_one_ip_route (s_ip4, route3, route3_nh, 7, 0);
518
519 rt = nm_ip_route_new (AF_INET, route4, 6, route4_nh, 4, &error);
520 g_assert_no_error (error);
521@@ -492,14 +494,17 @@ test_write_wired_connection (void)
522 add_one_ip_route (s_ip6, route6_1, route6_1_nh, 64, 3);
523 add_one_ip_route (s_ip6, route6_2, route6_2_nh, 56, 1);
524 add_one_ip_route (s_ip6, route6_3, route6_3_nh, 63, 5);
525- add_one_ip_route (s_ip6, route6_4, route6_4_nh, 62, -1);
526+ /* XXX: netplan 0.103 requires "to" and "via" for unicast routes,
527+ * but NM drops the "via"/nh field if metric is not defined. */
528+ add_one_ip_route (s_ip6, route6_4, route6_4_nh, 62, 0);
529
530 /* DNS servers */
531 nm_setting_ip_config_add_dns (s_ip6, dns6_1);
532 nm_setting_ip_config_add_dns (s_ip6, dns6_2);
533
534 /* DNS searches */
535- nm_setting_ip_config_add_dns_search (s_ip6, "wallaceandgromit.com");
536+ //XXX: netplan cannot differentiate between IPv4/6 search domains
537+ //nm_setting_ip_config_add_dns_search (s_ip6, "wallaceandgromit.com");
538
539 write_test_connection_and_reread (connection, FALSE);
540 }
541--
5422.32.0
543
diff --git a/snap-patch/networkmanager/0005-netplan-use-vendorized-generate-binary.patch b/snap-patch/networkmanager/0005-netplan-use-vendorized-generate-binary.patch
544deleted file mode 100644514deleted file mode 100644
index 7359624..0000000
--- a/snap-patch/networkmanager/0005-netplan-use-vendorized-generate-binary.patch
+++ /dev/null
@@ -1,83 +0,0 @@
1From ba8d280149cccfd24c7cbb78e8f301edaf4a0cfb Mon Sep 17 00:00:00 2001
2From: Lukas Märdian <slyon@ubuntu.com>
3Date: Thu, 6 May 2021 15:05:33 +0200
4Subject: [PATCH] netplan: use vendorized generate binary
5
6---
7 src/settings/plugins/keyfile/nms-keyfile-plugin.c | 4 ++--
8 src/settings/plugins/keyfile/nms-keyfile-utils.c | 14 ++++++++++++++
9 src/settings/plugins/keyfile/nms-keyfile-utils.h | 2 ++
10 src/settings/plugins/keyfile/nms-keyfile-writer.c | 2 +-
11 4 files changed, 19 insertions(+), 3 deletions(-)
12
13diff --git a/src/settings/plugins/keyfile/nms-keyfile-plugin.c b/src/settings/plugins/keyfile/nms-keyfile-plugin.c
14index 548eda536..83bcdb857 100644
15--- a/src/settings/plugins/keyfile/nms-keyfile-plugin.c
16+++ b/src/settings/plugins/keyfile/nms-keyfile-plugin.c
17@@ -561,7 +561,7 @@ reload_connections (NMSettingsPlugin *plugin,
18 nm_auto_clear_sett_util_storages NMSettUtilStorages storages_new = NM_SETT_UTIL_STORAGES_INIT (storages_new, nms_keyfile_storage_destroy);
19 int i;
20
21- netplan_generate(NULL);
22+ _netplan_generate(NULL);
23 _fix_netplan_interface_name(NULL);
24 _load_dir (self, NMS_KEYFILE_STORAGE_TYPE_RUN, priv->dirname_run, &storages_new);
25 if (priv->dirname_etc)
26@@ -1027,7 +1027,7 @@ delete_connection (NMSettingsPlugin *plugin,
27
28 g_autofree gchar* netplan_id = netplan_get_id_from_nm_filename(previous_filename, ssid);
29 netplan_delete_connection(netplan_id, NULL);
30- netplan_generate(NULL);
31+ _netplan_generate(NULL);
32 _fix_netplan_interface_name(NULL);
33
34 _LOGT ("commit: deleted \"%s\", %s %s (%s%s%s%s)",
35diff --git a/src/settings/plugins/keyfile/nms-keyfile-utils.c b/src/settings/plugins/keyfile/nms-keyfile-utils.c
36index 44edabd37..e2030ec5c 100644
37--- a/src/settings/plugins/keyfile/nms-keyfile-utils.c
38+++ b/src/settings/plugins/keyfile/nms-keyfile-utils.c
39@@ -407,3 +407,17 @@ nms_keyfile_utils_check_file_permissions (NMSKeyfileFiletype filetype,
40 NM_SET_OUT (out_st, st);
41 return TRUE;
42 }
43+
44+gboolean
45+_netplan_generate(const char* rootdir)
46+{
47+ /* Use 'netplan_generate()' from libnetplan once that is fixed to not be
48+ * DENIED by apparmor via snapd's 'network-setup-control' interface.
49+ * This needs https://github.com/snapcore/snapd/pull/10212 to be landed. */
50+ const gchar *argv[] = { "/snap/network-manager/current/lib/netplan/generate", NULL , NULL, NULL };
51+ if (rootdir) {
52+ argv[1] = "--root-dir";
53+ argv[2] = rootdir;
54+ }
55+ return g_spawn_sync(NULL, (gchar**)argv, NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL);
56+}
57diff --git a/src/settings/plugins/keyfile/nms-keyfile-utils.h b/src/settings/plugins/keyfile/nms-keyfile-utils.h
58index f9c298999..16b965ffd 100644
59--- a/src/settings/plugins/keyfile/nms-keyfile-utils.h
60+++ b/src/settings/plugins/keyfile/nms-keyfile-utils.h
61@@ -73,4 +73,6 @@ gboolean nms_keyfile_utils_check_file_permissions (NMSKeyfileFiletype filetype,
62 struct stat *out_st,
63 GError **error);
64
65+gboolean _netplan_generate(const char* rootdir);
66+
67 #endif /* __NMS_KEYFILE_UTILS_H__ */
68diff --git a/src/settings/plugins/keyfile/nms-keyfile-writer.c b/src/settings/plugins/keyfile/nms-keyfile-writer.c
69index 1bc761c4c..022eebce9 100644
70--- a/src/settings/plugins/keyfile/nms-keyfile-writer.c
71+++ b/src/settings/plugins/keyfile/nms-keyfile-writer.c
72@@ -402,7 +402,7 @@ _internal_write_connection (NMConnection *connection,
73 * we've written the /etc/netplan/*.yaml file instead. */
74 unlink(path);
75 g_free(path);
76- if (!netplan_generate(rootdir)) {
77+ if (!_netplan_generate(rootdir)) {
78 g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED,
79 "netplan generate failed");
80 return FALSE;
81--
822.32.0
83
diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml
index b214e02..f5701f3 100644
--- a/snap/snapcraft.yaml
+++ b/snap/snapcraft.yaml
@@ -23,14 +23,6 @@ grade: stable
23# will be adjusted accordingly.23# will be adjusted accordingly.
24epoch: 124epoch: 1
2525
26# Some packages might land in the ubuntu-image PPA for making their way
27# into a Ubuntu Core base image and only later land in a LTS release.
28# Enable ubuntu-image PPA once the --enable-experimental-package-repositories
29# flag is not needed anymore
30# package-repositories:
31# - type: apt
32# ppa: canonical-foundations/ubuntu-image
33
34slots:26slots:
35 service: network-manager27 service: network-manager
3628
@@ -152,29 +144,6 @@ parts:
152 prime:144 prime:
153 - $binaries145 - $binaries
154146
155 netplan:
156 after: [ stack-snaps-tools ]
157 plugin: make
158 source: https://git.launchpad.net/ubuntu/+source/netplan.io
159 source-type: git
160 source-tag: applied/0.102-0ubuntu1_20.04.2
161 build-packages:
162 - build-essential
163 - libyaml-dev
164 - libglib2.0-dev
165 - uuid-dev
166 - libsystemd-dev
167 - pandoc
168 override-build: |
169 set -ex
170 git apply "$SNAPCRAFT_PROJECT_DIR"/snap-patch/netplan.patch
171 snapcraftctl build
172 filesets:
173 binaries:
174 - lib/netplan/generate
175 prime:
176 - $binaries
177
178 networkmanager:147 networkmanager:
179 after: [ stack-snaps-tools ]148 after: [ stack-snaps-tools ]
180 plugin: autotools149 plugin: autotools
@@ -220,7 +189,6 @@ parts:
220 - libnetplan-dev189 - libnetplan-dev
221 - netplan.io190 - netplan.io
222 - libyaml-dev191 - libyaml-dev
223 - software-properties-common # Can be removed once "package-repositories:" is working
224 autotools-configure-parameters:192 autotools-configure-parameters:
225 - --prefix=/usr193 - --prefix=/usr
226 - --sysconfdir=/etc194 - --sysconfdir=/etc
@@ -280,11 +248,15 @@ parts:
280 ./autogen.sh248 ./autogen.sh
281 snapcraftctl build249 snapcraftctl build
282250
283 # Simulate vendorized netplan generator binary to pass tests
284 mkdir -p /snap/network-manager/current/lib/netplan
285 ln -sf /lib/netplan/generate /snap/network-manager/current/lib/netplan/generate
286 # Run all tests NetworkManager ships by default251 # Run all tests NetworkManager ships by default
252 # Hide the $SNAP env variable during testing, to prevent the netplan CLI
253 # from using the snap fallback io.netplan.Netplan.Generate() DBus API as
254 # that does not allow to pass a --root-dir argument, needed for testing
255 _SNAP=$SNAP
256 unset SNAP
287 make check257 make check
258 SNAP=$_SNAP
259 unset _SNAP
288 stage-packages:260 stage-packages:
289 - iputils-arping261 - iputils-arping
290 - libasn1-8-heimdal262 - libasn1-8-heimdal

Subscribers

People subscribed via source and target branches