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
1diff --git a/debian/changelog b/debian/changelog
2index 16e5297..f33f8a8 100644
3--- a/debian/changelog
4+++ b/debian/changelog
5@@ -1,3 +1,16 @@
6+netplan.io (0.105-0ubuntu2~22.04.3) jammy; urgency=medium
7+
8+ * Fix and improvements for the DBus integration (LP: #1997467)
9+ Cherry-picked from upstream: https://github.com/canonical/netplan/pull/331
10+ - d/p/lp1997467/0009-dbus-Build-the-copy-path-correctly.patch
11+ Properly build the destination path before copying files in the dbus
12+ integration and improve error handling
13+ - d/p/lp1997467/0010-tests-Add-an-integration-test-for-netplan-dbus.patch
14+ Add an integration test to exercise the code path where the issue was
15+ addressed.
16+
17+ -- Danilo Egea Gondolfo <danilo.egea.gondolfo@canonical.com> Fri, 03 Mar 2023 13:14:22 +0000
18+
19 netplan.io (0.105-0ubuntu2~22.04.2) jammy; urgency=medium
20
21 * d/p/lp1997467: set only specific origin-hint if given (LP: #1997467)
22diff --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
23new file mode 100644
24index 0000000..27d9f23
25--- /dev/null
26+++ b/debian/patches/lp1997467/0009-dbus-Build-the-copy-path-correctly.patch
27@@ -0,0 +1,93 @@
28+From: Danilo Egea Gondolfo <danilo.egea.gondolfo@canonical.com>
29+Subject: dbus: Build the copy path correctly
30+
31+This patch fixes a bug in the DBus integration where it was silently failing to
32+copy the netplan configuration files due to a malformed file path.
33+It also improves the error handling in netplan-dbus by propagating the failure to
34+the function callers.
35+
36+This fix is related to https://github.com/canonical/netplan/pull/299
37+
38+Origin: upstream, https://github.com/canonical/netplan/commit/2ff1daa9fcdb5779bfb88631a0af1104a0722f1e and https://github.com/canonical/netplan/commit/a76739110da77920f73d467e4102df2eb0d1af2c
39+Bug-Ubuntu: https://bugs.launchpad.net/netplan/+bug/1997467
40+---
41+ src/dbus.c | 21 +++++++++++++--------
42+ 1 file changed, 13 insertions(+), 8 deletions(-)
43+
44+diff --git a/src/dbus.c b/src/dbus.c
45+index 7f633e6..a5125fc 100644
46+--- a/src/dbus.c
47++++ b/src/dbus.c
48+@@ -141,7 +141,7 @@ _copy_yaml_state(char *src_root, char *dst_root, sd_bus_error *ret_error)
49+ gchar *dest_path = NULL;
50+ size_t len = strlen(src_root);
51+ for (size_t i = 0; i < gl.gl_pathc; ++i) {
52+- dest_path = g_strjoin(NULL, dst_root, (gl.gl_pathv[i])+len, NULL);
53++ dest_path = g_build_path(G_DIR_SEPARATOR_S, dst_root, (gl.gl_pathv[i])+len, NULL);
54+ source = g_file_new_for_path(gl.gl_pathv[i]);
55+ dest = g_file_new_for_path(dest_path);
56+ g_file_copy(source, dest, G_FILE_COPY_OVERWRITE
57+@@ -223,8 +223,8 @@ _backup_global_state(sd_bus_error *ret_error)
58+ }
59+
60+ /* Copy main *.yaml files from /{etc,run,lib}/netplan/ to GLOBAL backup dir */
61+- _copy_yaml_state(NETPLAN_ROOT, path, ret_error);
62+- return 0;
63++ r = _copy_yaml_state(NETPLAN_ROOT, path, ret_error);
64++ return r;
65+ }
66+
67+ /**
68+@@ -444,7 +444,8 @@ netplan_try_cancelled_cb(sd_event_source *es, const siginfo_t *si, void* userdat
69+ unlink_glob(NETPLAN_ROOT, "/{etc,run,lib}/netplan/*.yaml");
70+ /* Restore GLOBAL backup config state to main rootdir */
71+ state_dir = g_strdup_printf("%s/run/netplan/config-%s", NETPLAN_ROOT, NETPLAN_GLOBAL_CONFIG);
72+- _copy_yaml_state(state_dir, NETPLAN_ROOT, NULL);
73++ r = _copy_yaml_state(state_dir, NETPLAN_ROOT, NULL);
74++ if (r < 0) return r;
75+
76+ /* Un-invalidate all other current config objects */
77+ if (!g_strcmp0(d->handler_id, d->config_dirty))
78+@@ -564,7 +565,8 @@ method_config_apply(sd_bus_message *m, void *userdata, sd_bus_error *ret_error)
79+ unlink_glob(NETPLAN_ROOT, "/{etc,run,lib}/netplan/*.yaml");
80+ /* Copy current config state to GLOBAL */
81+ state_dir = g_strdup_printf("%s/run/netplan/config-%s", NETPLAN_ROOT, d->config_id);
82+- _copy_yaml_state(state_dir, NETPLAN_ROOT, ret_error);
83++ r = _copy_yaml_state(state_dir, NETPLAN_ROOT, ret_error);
84++ if (r < 0) return r;
85+ d->handler_id = g_strdup(d->config_id);
86+ }
87+
88+@@ -639,7 +641,8 @@ method_config_try(sd_bus_message *m, void *userdata, sd_bus_error *ret_error)
89+
90+ /* Copy current config *.yaml state to main rootdir (i.e. /etc/netplan/) */
91+ state_dir = g_strdup_printf("%s/run/netplan/config-%s", NETPLAN_ROOT, d->config_id);
92+- _copy_yaml_state(state_dir, NETPLAN_ROOT, ret_error);
93++ r = _copy_yaml_state(state_dir, NETPLAN_ROOT, ret_error);
94++ if (r < 0) return r;
95+
96+ /* Exec try */
97+ r = method_try(m, userdata, ret_error);
98+@@ -670,7 +673,8 @@ method_config_cancel(sd_bus_message *m, void *userdata, sd_bus_error *ret_error)
99+ unlink_glob(NETPLAN_ROOT, "/{etc,run,lib}/netplan/*.yaml");
100+ /* Restore GLOBAL backup config state to main rootdir */
101+ state_dir = g_strdup_printf("%s/run/netplan/config-%s", NETPLAN_ROOT, NETPLAN_GLOBAL_CONFIG);
102+- _copy_yaml_state(state_dir, NETPLAN_ROOT, ret_error);
103++ r = _copy_yaml_state(state_dir, NETPLAN_ROOT, ret_error);
104++ if (r < 0) return r;
105+
106+ /* Clear GLOBAL backup and config state */
107+ _clear_tmp_state(NETPLAN_GLOBAL_CONFIG, d);
108+@@ -754,7 +758,8 @@ method_config(sd_bus_message *m, void *userdata, sd_bus_error *ret_error)
109+ }
110+
111+ /* Copy all *.yaml files from /{etc,run,lib}/netplan/ to temp dir */
112+- _copy_yaml_state(NETPLAN_ROOT, path, ret_error);
113++ r = _copy_yaml_state(NETPLAN_ROOT, path, ret_error);
114++ if (r < 0) return r;
115+
116+ return sd_bus_reply_method_return(m, "o", obj_path);
117+ }
118+--
119+2.39.2
120+
121diff --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
122new file mode 100644
123index 0000000..3fb9015
124--- /dev/null
125+++ b/debian/patches/lp1997467/0010-tests-Add-an-integration-test-for-netplan-dbus.patch
126@@ -0,0 +1,86 @@
127+From: Danilo Egea Gondolfo <danilo.egea.gondolfo@canonical.com>
128+Subject: tests: Add an integration test for netplan-dbus
129+
130+This test exercises the code path where the dbus integration bug was
131+addressed.
132+
133+This fix is related to https://github.com/canonical/netplan/pull/299
134+
135+Origin: upstream, https://github.com/canonical/netplan/commit/4e89bbf0240d37e662666bec83019cbe3d18edf6
136+Bug-Ubuntu: https://bugs.launchpad.net/netplan/+bug/1997467
137+---
138+ tests/integration/regressions.py | 53 ++++++++++++++++++++++++++++++++
139+ 1 file changed, 53 insertions(+)
140+
141+diff --git a/tests/integration/regressions.py b/tests/integration/regressions.py
142+index 1a996b4..6e3afd4 100644
143+--- a/tests/integration/regressions.py
144++++ b/tests/integration/regressions.py
145+@@ -21,6 +21,8 @@
146+ # You should have received a copy of the GNU General Public License
147+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
148+
149++import json
150++import os
151+ import sys
152+ import signal
153+ import subprocess
154+@@ -142,4 +144,55 @@ class TestNetworkManager(IntegrationTestsBase, _CommonTests):
155+ backend = 'NetworkManager'
156+
157+
158++class TestDbus(IntegrationTestsBase):
159++ def test_dbus_config_get_lp1997467(self):
160++
161++ NETPLAN_YAML = '''network:
162++ version: 2
163++ ethernets:
164++ %(nic)s:
165++ dhcp4: true
166++'''
167++ BUSCTL_CONFIG = [
168++ 'busctl', '-j', 'call', '--system',
169++ 'io.netplan.Netplan', '/io/netplan/Netplan',
170++ 'io.netplan.Netplan', 'Config']
171++
172++ BUSCTL_CONFIG_GET = [
173++ 'busctl', '-j', 'call', '--system',
174++ 'io.netplan.Netplan', 'PLACEHOLDER',
175++ 'io.netplan.Netplan.Config', 'Get']
176++
177++ # Terminates netplan-dbus if it is running already
178++ cmd = ['ps', '-C', 'netplan-dbus', '-o', 'pid=']
179++ out = subprocess.run(cmd, capture_output=True, universal_newlines=True)
180++ if out.returncode == 0:
181++ pid = out.stdout.strip()
182++ os.kill(int(pid), signal.SIGTERM)
183++
184++ with open(self.config, 'w') as f:
185++ f.write(NETPLAN_YAML % {'nic': self.dev_e_client})
186++
187++ out = subprocess.run(BUSCTL_CONFIG, capture_output=True, universal_newlines=True)
188++ self.assertEqual(out.returncode, 0, msg=f"Busctl Config() failed with error: {out.stderr}")
189++
190++ out_dict = json.loads(out.stdout)
191++ config_path = out_dict.get('data')[0]
192++ self.assertNotEqual(config_path, "", msg="Got an empty response from DBUS")
193++
194++ # The path has the following format: /io/netplan/Netplan/config/WM6X01
195++ BUSCTL_CONFIG_GET[5] = config_path
196++
197++ # Retrieving the config
198++ out = subprocess.run(BUSCTL_CONFIG_GET, capture_output=True, universal_newlines=True)
199++ self.assertEqual(out.returncode, 0, msg=f"Busctl Get() failed with error: {out.stderr}")
200++
201++ out_dict = json.loads(out.stdout)
202++ netplan_data = out_dict.get('data')[0]
203++
204++ self.assertNotEqual(netplan_data, "", msg="Got an empty response from DBUS")
205++ self.assertEqual(netplan_data, NETPLAN_YAML % {'nic': self.dev_e_client},
206++ msg="The original YAML is different from the one returned by DBUS")
207++
208++
209+ unittest.main(testRunner=unittest.TextTestRunner(stream=sys.stdout, verbosity=2))
210+--
211+2.39.2
212+
213diff --git a/debian/patches/series b/debian/patches/series
214index 06ed42e..18f0f7f 100644
215--- a/debian/patches/series
216+++ b/debian/patches/series
217@@ -6,3 +6,5 @@ lp1997467/0005-parse-Allow-loading-nullable-origin-hint-overrides-n.patch
218 lp1997467/0006-cli-set-fix-origin-hint-handling-LP-1997467.patch
219 lp1997467/0007-src-parse-netplan-write-global-renderer-depending-on.patch
220 lp1997467/0008-src-parse-plug-memory-leaks-in-nullable-handling.patch
221+lp1997467/0009-dbus-Build-the-copy-path-correctly.patch
222+lp1997467/0010-tests-Add-an-integration-test-for-netplan-dbus.patch

Subscribers

People subscribed via source and target branches