Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dbus: Allow Set without origin hint #294

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions src/dbus.c
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ method_get(sd_bus_message *m, void *userdata, sd_bus_error *ret_error)
}

static int
method_set(sd_bus_message *m, void *userdata, sd_bus_error *ret_error)
method_set(sd_bus_message *m, void *userdata, sd_bus_error *ret_error, bool full)
{
NetplanData *d = userdata;
g_autoptr(GError) err = NULL;
Expand All @@ -398,8 +398,13 @@ method_set(sd_bus_message *m, void *userdata, sd_bus_error *ret_error)
char *origin_hint = NULL;
guint cur_arg = 0;

if (sd_bus_message_read(m, "ss", &config_delta, &origin_hint) < 0)
if (full && sd_bus_message_read(m, "ss", &config_delta, &origin_hint) < 0)
return sd_bus_error_setf(ret_error, SD_BUS_ERROR_FAILED, "cannot extract config_delta or origin_hint"); // LCOV_EXCL_LINE
else if (!full) {
if (sd_bus_message_read(m, "s", &config_delta) < 0)
return sd_bus_error_setf(ret_error, SD_BUS_ERROR_FAILED, "cannot extract config_delta"); // LCOV_EXCL_LINE
origin_hint = "";
}

if (!!strcmp(origin_hint, "")) {
origin = g_strdup_printf("--origin-hint=%s", origin_hint);
Expand Down Expand Up @@ -593,7 +598,7 @@ method_config_get(sd_bus_message *m, void *userdata, sd_bus_error *ret_error)
}

static int
method_config_set(sd_bus_message *m, void *userdata, sd_bus_error *ret_error)
method_config_set(sd_bus_message *m, void *userdata, sd_bus_error *ret_error, bool full)
{
NetplanData *d = userdata;
/* trim 27 chars (i.e. "/io/netplan/Netplan/config/") from path to get the config ID */
Expand All @@ -602,7 +607,7 @@ method_config_set(sd_bus_message *m, void *userdata, sd_bus_error *ret_error)
if (cd->invalidated)
return sd_bus_error_setf(ret_error, SD_BUS_ERROR_FAILED,
"This config was invalidated by another config object\n");
int r = method_set(m, d, ret_error);
int r = method_set(m, d, ret_error, full);
/* Invalidate all other current config objects */
g_hash_table_foreach(d->config_data, invalidate_other_config, (void*)d->config_id);
d->config_dirty = g_strdup(d->config_id);
Expand All @@ -611,6 +616,18 @@ method_config_set(sd_bus_message *m, void *userdata, sd_bus_error *ret_error)
return r;
}

static int
method_config_set_simple(sd_bus_message *m, void *userdata, sd_bus_error *ret_error)
{
return method_config_set(m, userdata, ret_error, false);
}

static int
method_config_set_full(sd_bus_message *m, void *userdata, sd_bus_error *ret_error)
{
return method_config_set(m, userdata, ret_error, true);
}

static int
method_config_try(sd_bus_message *m, void *userdata, sd_bus_error *ret_error)
{
Expand Down Expand Up @@ -690,7 +707,8 @@ static const sd_bus_vtable config_vtable[] = {
SD_BUS_VTABLE_START(0),
SD_BUS_METHOD("Apply", "", "b", method_config_apply, 0),
SD_BUS_METHOD("Get", "", "s", method_config_get, 0),
SD_BUS_METHOD("Set", "ss", "b", method_config_set, 0),
SD_BUS_METHOD("Set", "s", "b", method_config_set_simple, 0),
SD_BUS_METHOD("Set", "ss", "b", method_config_set_full, 0),
Comment on lines +710 to +711
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There seems to be a conflict in the vtable here, which makes the tests fail...
I'm not sure if we can have two methods using a different signature. Could you please investigate this?

$ NETPLAN_GENERATE_PATH=build/src/generate NETPLAN_DBUS_CMD=build/dbus/netplan-dbus LD_LIBRARY_PATH=build/src PYTHONPATH=. pytest-3 -v tests/dbus/
================================================================= test session starts =================================================================
platform linux -- Python 3.10.6, pytest-6.2.5, py-1.10.0, pluggy-0.13.0 -- /usr/bin/python3
cachedir: .pytest_cache
rootdir: /home/lukas/canonical/netplan
collected 25 items                                                                                                                                    

tests/dbus/test_dbus.py::TestNetplanDBus::test_netplan_apply_in_snap_calls_busctl PASSED                                                        [  4%]
tests/dbus/test_dbus.py::TestNetplanDBus::test_netplan_apply_in_snap_calls_busctl_err PASSED                                                    [  8%]
tests/dbus/test_dbus.py::TestNetplanDBus::test_netplan_apply_in_snap_calls_busctl_ret130 PASSED                                                 [ 12%]
tests/dbus/test_dbus.py::TestNetplanDBus::test_netplan_apply_in_snap_uses_dbus PASSED                                                           [ 16%]
tests/dbus/test_dbus.py::TestNetplanDBus::test_netplan_dbus_config FAILED                                                                       [ 20%]
tests/dbus/test_dbus.py::TestNetplanDBus::test_netplan_dbus_config_apply FAILED                                                                 [ 24%]
tests/dbus/test_dbus.py::TestNetplanDBus::test_netplan_dbus_config_cancel FAILED                                                                [ 28%]
tests/dbus/test_dbus.py::TestNetplanDBus::test_netplan_dbus_config_get FAILED                                                                   [ 32%]
tests/dbus/test_dbus.py::TestNetplanDBus::test_netplan_dbus_config_set FAILED                                                                   [ 36%]
tests/dbus/test_dbus.py::TestNetplanDBus::test_netplan_dbus_config_set_invalidate FAILED                                                        [ 40%]
tests/dbus/test_dbus.py::TestNetplanDBus::test_netplan_dbus_config_set_uninvalidate FAILED                                                      [ 44%]
tests/dbus/test_dbus.py::TestNetplanDBus::test_netplan_dbus_config_set_uninvalidate_timeout FAILED                                              [ 48%]
tests/dbus/test_dbus.py::TestNetplanDBus::test_netplan_dbus_config_try_apply FAILED                                                             [ 52%]
tests/dbus/test_dbus.py::TestNetplanDBus::test_netplan_dbus_config_try_cancel FAILED                                                            [ 56%]
tests/dbus/test_dbus.py::TestNetplanDBus::test_netplan_dbus_config_try_cb FAILED                                                                [ 60%]
tests/dbus/test_dbus.py::TestNetplanDBus::test_netplan_dbus_config_try_config_try FAILED                                                        [ 64%]
tests/dbus/test_dbus.py::TestNetplanDBus::test_netplan_dbus_config_try_no_ready_signal FAILED                                                   [ 68%]
tests/dbus/test_dbus.py::TestNetplanDBus::test_netplan_dbus_generate PASSED                                                                     [ 72%]
tests/dbus/test_dbus.py::TestNetplanDBus::test_netplan_dbus_happy PASSED                                                                        [ 76%]
tests/dbus/test_dbus.py::TestNetplanDBus::test_netplan_dbus_info PASSED                                                                         [ 80%]
tests/dbus/test_dbus.py::TestNetplanDBus::test_netplan_dbus_no_such_command PASSED                                                              [ 84%]
tests/dbus/test_dbus.py::TestNetplanDBus::test_netplan_dbus_noroot PASSED                                                                       [ 88%]
tests/dbus/test_dbus.py::TestNetplanDBus::test_netplan_generate_in_snap_calls_busctl PASSED                                                     [ 92%]
tests/dbus/test_dbus.py::TestNetplanDBus::test_netplan_generate_in_snap_calls_busctl_err PASSED                                                 [ 96%]
tests/dbus/test_dbus.py::TestNetplanDBus::test_netplan_generate_in_snap_calls_busctl_ret130 PASSED                                              [100%]

====================================================================== FAILURES =======================================================================
[...]
=============================================================== short test summary info ===============================================================
FAILED tests/dbus/test_dbus.py::TestNetplanDBus::test_netplan_dbus_config - subprocess.CalledProcessError: Command '['busctl', 'call', '--system', '...
FAILED tests/dbus/test_dbus.py::TestNetplanDBus::test_netplan_dbus_config_apply - subprocess.CalledProcessError: Command '['busctl', 'call', '--syst...
FAILED tests/dbus/test_dbus.py::TestNetplanDBus::test_netplan_dbus_config_cancel - subprocess.CalledProcessError: Command '['busctl', 'call', '--sys...
FAILED tests/dbus/test_dbus.py::TestNetplanDBus::test_netplan_dbus_config_get - subprocess.CalledProcessError: Command '['busctl', 'call', '--system...
FAILED tests/dbus/test_dbus.py::TestNetplanDBus::test_netplan_dbus_config_set - subprocess.CalledProcessError: Command '['busctl', 'call', '--system...
FAILED tests/dbus/test_dbus.py::TestNetplanDBus::test_netplan_dbus_config_set_invalidate - subprocess.CalledProcessError: Command '['busctl', 'call'...
FAILED tests/dbus/test_dbus.py::TestNetplanDBus::test_netplan_dbus_config_set_uninvalidate - subprocess.CalledProcessError: Command '['busctl', 'cal...
FAILED tests/dbus/test_dbus.py::TestNetplanDBus::test_netplan_dbus_config_set_uninvalidate_timeout - subprocess.CalledProcessError: Command '['busct...
FAILED tests/dbus/test_dbus.py::TestNetplanDBus::test_netplan_dbus_config_try_apply - subprocess.CalledProcessError: Command '['busctl', 'call', '--...
FAILED tests/dbus/test_dbus.py::TestNetplanDBus::test_netplan_dbus_config_try_cancel - subprocess.CalledProcessError: Command '['busctl', 'call', '-...
FAILED tests/dbus/test_dbus.py::TestNetplanDBus::test_netplan_dbus_config_try_cb - subprocess.CalledProcessError: Command '['busctl', 'call', '--sys...
FAILED tests/dbus/test_dbus.py::TestNetplanDBus::test_netplan_dbus_config_try_config_try - subprocess.CalledProcessError: Command '['busctl', 'call'...
FAILED tests/dbus/test_dbus.py::TestNetplanDBus::test_netplan_dbus_config_try_no_ready_signal - subprocess.CalledProcessError: Command '['busctl', '...
===================================================== 13 failed, 12 passed, 7 warnings in 28.93s ======================================================

SD_BUS_METHOD("Try", "u", "b", method_config_try, 0),
SD_BUS_METHOD("Cancel", "", "b", method_config_cancel, 0),
SD_BUS_VTABLE_END
Expand Down