Merge ~danilogondolfo/netplan/+git/ubuntu:jammy_lp1997467_dbus into ~ubuntu-core-dev/netplan/+git/ubuntu:ubuntu-jammy

Proposed by Danilo Egea Gondolfo
Status: Merged
Approved by: Łukasz Zemczak
Approved revision: d448baeb7ea77415f8f3cb11e2883869d0b86c3e
Merged at revision: d448baeb7ea77415f8f3cb11e2883869d0b86c3e
Proposed branch: ~danilogondolfo/netplan/+git/ubuntu:jammy_lp1997467_dbus
Merge into: ~ubuntu-core-dev/netplan/+git/ubuntu:ubuntu-jammy
Diff against target: 222 lines (+194/-0)
4 files modified
debian/changelog (+13/-0)
debian/patches/lp1997467/0009-dbus-Build-the-copy-path-correctly.patch (+93/-0)
debian/patches/lp1997467/0010-tests-Add-an-integration-test-for-netplan-dbus.patch (+86/-0)
debian/patches/series (+2/-0)
Reviewer Review Type Date Requested Status
Łukasz Zemczak Approve
Review via email: mp+438310@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Łukasz Zemczak (sil2100) wrote :

Looking good, will merge and release. Discussed with Danilo already that I didn't see the tests/integration/dbus.py test added as part of these changes. Not strictly required, but more testing is never a bad thing, even if it makes the diff bigger.

Anyway, let's proceed!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/debian/changelog b/debian/changelog
index 16e5297..f33f8a8 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,16 @@
1netplan.io (0.105-0ubuntu2~22.04.3) jammy; urgency=medium
2
3 * Fix and improvements for the DBus integration (LP: #1997467)
4 Cherry-picked from upstream: https://github.com/canonical/netplan/pull/331
5 - d/p/lp1997467/0009-dbus-Build-the-copy-path-correctly.patch
6 Properly build the destination path before copying files in the dbus
7 integration and improve error handling
8 - d/p/lp1997467/0010-tests-Add-an-integration-test-for-netplan-dbus.patch
9 Add an integration test to exercise the code path where the issue was
10 addressed.
11
12 -- Danilo Egea Gondolfo <danilo.egea.gondolfo@canonical.com> Fri, 03 Mar 2023 13:14:22 +0000
13
1netplan.io (0.105-0ubuntu2~22.04.2) jammy; urgency=medium14netplan.io (0.105-0ubuntu2~22.04.2) jammy; urgency=medium
215
3 * d/p/lp1997467: set only specific origin-hint if given (LP: #1997467)16 * d/p/lp1997467: set only specific origin-hint if given (LP: #1997467)
diff --git a/debian/patches/lp1997467/0009-dbus-Build-the-copy-path-correctly.patch b/debian/patches/lp1997467/0009-dbus-Build-the-copy-path-correctly.patch
4new file mode 10064417new file mode 100644
index 0000000..27d9f23
--- /dev/null
+++ b/debian/patches/lp1997467/0009-dbus-Build-the-copy-path-correctly.patch
@@ -0,0 +1,93 @@
1From: Danilo Egea Gondolfo <danilo.egea.gondolfo@canonical.com>
2Subject: dbus: Build the copy path correctly
3
4This patch fixes a bug in the DBus integration where it was silently failing to
5copy the netplan configuration files due to a malformed file path.
6It also improves the error handling in netplan-dbus by propagating the failure to
7the function callers.
8
9This fix is related to https://github.com/canonical/netplan/pull/299
10
11Origin: upstream, https://github.com/canonical/netplan/commit/2ff1daa9fcdb5779bfb88631a0af1104a0722f1e and https://github.com/canonical/netplan/commit/a76739110da77920f73d467e4102df2eb0d1af2c
12Bug-Ubuntu: https://bugs.launchpad.net/netplan/+bug/1997467
13---
14 src/dbus.c | 21 +++++++++++++--------
15 1 file changed, 13 insertions(+), 8 deletions(-)
16
17diff --git a/src/dbus.c b/src/dbus.c
18index 7f633e6..a5125fc 100644
19--- a/src/dbus.c
20+++ b/src/dbus.c
21@@ -141,7 +141,7 @@ _copy_yaml_state(char *src_root, char *dst_root, sd_bus_error *ret_error)
22 gchar *dest_path = NULL;
23 size_t len = strlen(src_root);
24 for (size_t i = 0; i < gl.gl_pathc; ++i) {
25- dest_path = g_strjoin(NULL, dst_root, (gl.gl_pathv[i])+len, NULL);
26+ dest_path = g_build_path(G_DIR_SEPARATOR_S, dst_root, (gl.gl_pathv[i])+len, NULL);
27 source = g_file_new_for_path(gl.gl_pathv[i]);
28 dest = g_file_new_for_path(dest_path);
29 g_file_copy(source, dest, G_FILE_COPY_OVERWRITE
30@@ -223,8 +223,8 @@ _backup_global_state(sd_bus_error *ret_error)
31 }
32
33 /* Copy main *.yaml files from /{etc,run,lib}/netplan/ to GLOBAL backup dir */
34- _copy_yaml_state(NETPLAN_ROOT, path, ret_error);
35- return 0;
36+ r = _copy_yaml_state(NETPLAN_ROOT, path, ret_error);
37+ return r;
38 }
39
40 /**
41@@ -444,7 +444,8 @@ netplan_try_cancelled_cb(sd_event_source *es, const siginfo_t *si, void* userdat
42 unlink_glob(NETPLAN_ROOT, "/{etc,run,lib}/netplan/*.yaml");
43 /* Restore GLOBAL backup config state to main rootdir */
44 state_dir = g_strdup_printf("%s/run/netplan/config-%s", NETPLAN_ROOT, NETPLAN_GLOBAL_CONFIG);
45- _copy_yaml_state(state_dir, NETPLAN_ROOT, NULL);
46+ r = _copy_yaml_state(state_dir, NETPLAN_ROOT, NULL);
47+ if (r < 0) return r;
48
49 /* Un-invalidate all other current config objects */
50 if (!g_strcmp0(d->handler_id, d->config_dirty))
51@@ -564,7 +565,8 @@ method_config_apply(sd_bus_message *m, void *userdata, sd_bus_error *ret_error)
52 unlink_glob(NETPLAN_ROOT, "/{etc,run,lib}/netplan/*.yaml");
53 /* Copy current config state to GLOBAL */
54 state_dir = g_strdup_printf("%s/run/netplan/config-%s", NETPLAN_ROOT, d->config_id);
55- _copy_yaml_state(state_dir, NETPLAN_ROOT, ret_error);
56+ r = _copy_yaml_state(state_dir, NETPLAN_ROOT, ret_error);
57+ if (r < 0) return r;
58 d->handler_id = g_strdup(d->config_id);
59 }
60
61@@ -639,7 +641,8 @@ method_config_try(sd_bus_message *m, void *userdata, sd_bus_error *ret_error)
62
63 /* Copy current config *.yaml state to main rootdir (i.e. /etc/netplan/) */
64 state_dir = g_strdup_printf("%s/run/netplan/config-%s", NETPLAN_ROOT, d->config_id);
65- _copy_yaml_state(state_dir, NETPLAN_ROOT, ret_error);
66+ r = _copy_yaml_state(state_dir, NETPLAN_ROOT, ret_error);
67+ if (r < 0) return r;
68
69 /* Exec try */
70 r = method_try(m, userdata, ret_error);
71@@ -670,7 +673,8 @@ method_config_cancel(sd_bus_message *m, void *userdata, sd_bus_error *ret_error)
72 unlink_glob(NETPLAN_ROOT, "/{etc,run,lib}/netplan/*.yaml");
73 /* Restore GLOBAL backup config state to main rootdir */
74 state_dir = g_strdup_printf("%s/run/netplan/config-%s", NETPLAN_ROOT, NETPLAN_GLOBAL_CONFIG);
75- _copy_yaml_state(state_dir, NETPLAN_ROOT, ret_error);
76+ r = _copy_yaml_state(state_dir, NETPLAN_ROOT, ret_error);
77+ if (r < 0) return r;
78
79 /* Clear GLOBAL backup and config state */
80 _clear_tmp_state(NETPLAN_GLOBAL_CONFIG, d);
81@@ -754,7 +758,8 @@ method_config(sd_bus_message *m, void *userdata, sd_bus_error *ret_error)
82 }
83
84 /* Copy all *.yaml files from /{etc,run,lib}/netplan/ to temp dir */
85- _copy_yaml_state(NETPLAN_ROOT, path, ret_error);
86+ r = _copy_yaml_state(NETPLAN_ROOT, path, ret_error);
87+ if (r < 0) return r;
88
89 return sd_bus_reply_method_return(m, "o", obj_path);
90 }
91--
922.39.2
93
diff --git a/debian/patches/lp1997467/0010-tests-Add-an-integration-test-for-netplan-dbus.patch b/debian/patches/lp1997467/0010-tests-Add-an-integration-test-for-netplan-dbus.patch
0new file mode 10064494new file mode 100644
index 0000000..3fb9015
--- /dev/null
+++ b/debian/patches/lp1997467/0010-tests-Add-an-integration-test-for-netplan-dbus.patch
@@ -0,0 +1,86 @@
1From: Danilo Egea Gondolfo <danilo.egea.gondolfo@canonical.com>
2Subject: tests: Add an integration test for netplan-dbus
3
4This test exercises the code path where the dbus integration bug was
5addressed.
6
7This fix is related to https://github.com/canonical/netplan/pull/299
8
9Origin: upstream, https://github.com/canonical/netplan/commit/4e89bbf0240d37e662666bec83019cbe3d18edf6
10Bug-Ubuntu: https://bugs.launchpad.net/netplan/+bug/1997467
11---
12 tests/integration/regressions.py | 53 ++++++++++++++++++++++++++++++++
13 1 file changed, 53 insertions(+)
14
15diff --git a/tests/integration/regressions.py b/tests/integration/regressions.py
16index 1a996b4..6e3afd4 100644
17--- a/tests/integration/regressions.py
18+++ b/tests/integration/regressions.py
19@@ -21,6 +21,8 @@
20 # You should have received a copy of the GNU General Public License
21 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22
23+import json
24+import os
25 import sys
26 import signal
27 import subprocess
28@@ -142,4 +144,55 @@ class TestNetworkManager(IntegrationTestsBase, _CommonTests):
29 backend = 'NetworkManager'
30
31
32+class TestDbus(IntegrationTestsBase):
33+ def test_dbus_config_get_lp1997467(self):
34+
35+ NETPLAN_YAML = '''network:
36+ version: 2
37+ ethernets:
38+ %(nic)s:
39+ dhcp4: true
40+'''
41+ BUSCTL_CONFIG = [
42+ 'busctl', '-j', 'call', '--system',
43+ 'io.netplan.Netplan', '/io/netplan/Netplan',
44+ 'io.netplan.Netplan', 'Config']
45+
46+ BUSCTL_CONFIG_GET = [
47+ 'busctl', '-j', 'call', '--system',
48+ 'io.netplan.Netplan', 'PLACEHOLDER',
49+ 'io.netplan.Netplan.Config', 'Get']
50+
51+ # Terminates netplan-dbus if it is running already
52+ cmd = ['ps', '-C', 'netplan-dbus', '-o', 'pid=']
53+ out = subprocess.run(cmd, capture_output=True, universal_newlines=True)
54+ if out.returncode == 0:
55+ pid = out.stdout.strip()
56+ os.kill(int(pid), signal.SIGTERM)
57+
58+ with open(self.config, 'w') as f:
59+ f.write(NETPLAN_YAML % {'nic': self.dev_e_client})
60+
61+ out = subprocess.run(BUSCTL_CONFIG, capture_output=True, universal_newlines=True)
62+ self.assertEqual(out.returncode, 0, msg=f"Busctl Config() failed with error: {out.stderr}")
63+
64+ out_dict = json.loads(out.stdout)
65+ config_path = out_dict.get('data')[0]
66+ self.assertNotEqual(config_path, "", msg="Got an empty response from DBUS")
67+
68+ # The path has the following format: /io/netplan/Netplan/config/WM6X01
69+ BUSCTL_CONFIG_GET[5] = config_path
70+
71+ # Retrieving the config
72+ out = subprocess.run(BUSCTL_CONFIG_GET, capture_output=True, universal_newlines=True)
73+ self.assertEqual(out.returncode, 0, msg=f"Busctl Get() failed with error: {out.stderr}")
74+
75+ out_dict = json.loads(out.stdout)
76+ netplan_data = out_dict.get('data')[0]
77+
78+ self.assertNotEqual(netplan_data, "", msg="Got an empty response from DBUS")
79+ self.assertEqual(netplan_data, NETPLAN_YAML % {'nic': self.dev_e_client},
80+ msg="The original YAML is different from the one returned by DBUS")
81+
82+
83 unittest.main(testRunner=unittest.TextTestRunner(stream=sys.stdout, verbosity=2))
84--
852.39.2
86
diff --git a/debian/patches/series b/debian/patches/series
index 06ed42e..18f0f7f 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -6,3 +6,5 @@ lp1997467/0005-parse-Allow-loading-nullable-origin-hint-overrides-n.patch
6lp1997467/0006-cli-set-fix-origin-hint-handling-LP-1997467.patch6lp1997467/0006-cli-set-fix-origin-hint-handling-LP-1997467.patch
7lp1997467/0007-src-parse-netplan-write-global-renderer-depending-on.patch7lp1997467/0007-src-parse-netplan-write-global-renderer-depending-on.patch
8lp1997467/0008-src-parse-plug-memory-leaks-in-nullable-handling.patch8lp1997467/0008-src-parse-plug-memory-leaks-in-nullable-handling.patch
9lp1997467/0009-dbus-Build-the-copy-path-correctly.patch
10lp1997467/0010-tests-Add-an-integration-test-for-netplan-dbus.patch

Subscribers

People subscribed via source and target branches