Skip to content

dbus: Build the copy path correctly #331

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

Merged
merged 3 commits into from
Mar 2, 2023
Merged

Conversation

daniloegea
Copy link
Contributor

@daniloegea daniloegea commented Feb 28, 2023

Dbus Config()/Get() were not working due to a missing / in the destination path.

We still need a nice integration test to catch this issue.

Description

sudo dbus-send --system --print-reply --type=method_call --dest=io.netplan.Netplan /io/netplan/Netplan io.netplan.Netplan.Config

From dbus-monitor:

string "Failed to copy file /etc/netplan/01-network-manager-all.yaml -> /run/netplan/config-1YXM01etc/netplan/01-network-manager-all.yaml: Error opening file “/run/netplan/config-1YXM01etc/netplan/01-network-manager-all.yaml”: No such file or directory

The path is malformed: /run/netplan/config-1YXM01etc/netplan/01-network-manager-all.yaml

Checklist

  • Runs make check successfully.
  • Retains 100% code coverage (make check-coverage).
  • New/changed keys in YAML format are documented.
  • (Optional) Adds example YAML for new feature.
  • (Optional) Closes an open bug in Launchpad.

Dbus Config()/Get() were not working due to a missing / in the
destination path.
Copy link
Collaborator

@slyon slyon left a comment

Choose a reason for hiding this comment

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

Ugh. This should not happen. The fix LGTM!
I assume this is related to LP#1997467 ?

Can we build a test case around it, to avoid such failure in the future?

@daniloegea
Copy link
Contributor Author

I've created a new integration test for dbus at tests/integration/dbus.py with 3 tests. As we need to add it to debian/tests/control to get it running, I also added the test for the bug fixed by this PR in the file integration/regressions.py.

@daniloegea
Copy link
Contributor Author

I think #330 would also be a nice autopkgtest.

@ezeriver94
Copy link

I came across the same issue when creating Config through D-Bus, maybe it's worth adding error control to the _copy_yaml_state method

r = _copy_yaml_state(NETPLAN_ROOT, path, ret_error);  
if (r < 0){  
        return sd_bus_error_setf(ret_error, SD_BUS_ERROR_FAILED,  
                                "Failed to copy yaml structure to'%s': %s\n", path, strerror(errno));  
}

Without this, the execution appears to end up OK (even it shows the path of the new config created) but when you go to the folder it is empty, and that could cause removing the entire netplan of the machine if you apply it

Copy link
Collaborator

@slyon slyon left a comment

Choose a reason for hiding this comment

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

This was initially just a small bug fix, but I still like the idea of adding some more error handling (and unit tests for coverage), while on it. Danilo, could you have a look into that if it's feasible?

Wrt the integration tests, we're checking (and modifying!) the eth0 interface as part of the new dbus tests. We consider eth0 en* to be our management interfaces for the test runner, so we really shouldn't be playing with it inside the tests. It can change in name, depending on the distribution+version this test is being run on, and if we bring down the management interface, our test runners might go down.

Please see tests/integration/base.py:create_devices() and make use of self.dev_e_client (eth42) and/or self.dev_e2_client (eth43) during the tests.

@daniloegea
Copy link
Contributor Author

Thanks for your inputs @ezeriver94 :)

As _copy_yaml_state() was already setting an error code/message, I just changed the callers to propagate it.

Now a call to netplan-bus will fail like this:

$ sudo busctl -j call --system io.netplan.Netplan /io/netplan/Netplan io.netplan.Netplan Config
Call failed: Failed to copy file /etc/netplan/01-network-manager-all.yaml -> /run/netplan/config-08LD11etc/netplan/01-network-manager-all.yaml: Error opening file “/run/netplan/config-08LD11etc/netplan/01-network-manager-all.yaml”: No such file or directory

I also reworked the integration tests to not use eth0 and output the error in case of failures.

Danilo Egea Gondolfo added 2 commits March 2, 2023 15:23
_copy_yaml_state() is setting an error when g_copy_file fails but it
wasn't used by any callers.
This tests can be executed as autopkgtests. They cover netplan get, set
and apply.

There is a copy of test_dbus_config_get() in the file
integration/regressions.py that can be dropped once we adapt the
netplan.io package to run the new test set.
Copy link
Collaborator

@slyon slyon left a comment

Choose a reason for hiding this comment

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

Thank you @daniloegea and @ezeriver94 for your input on this one. I really like the addition of the new dbus integration tests! We'll also rebase #330 on top of this, to make sure it passes, too.

@slyon
Copy link
Collaborator

slyon commented Mar 2, 2023

The new spread tests passed (after some tiny fixes to the tests). So I think this is ready to be merged!

@slyon slyon merged commit 4e89bbf into canonical:main Mar 2, 2023
@mvo5
Copy link
Contributor

mvo5 commented Mar 2, 2023

I think #330 would also be a nice autopkgtest.

Fwiw, it's also easy to run the spread tests as part of autopkgtest (we do this in snapd, see https://github.com/snapcore/snapd/blob/master/packaging/ubuntu-16.04/tests/integrationtests#L57).

@slyon
Copy link
Collaborator

slyon commented Mar 7, 2023

Nice! I think that's something we'd want to do. I think it should also avoid the packaging issue with meson, as we'd use pre-built binary packages to run the autopkgtest.

balabit-sync pushed a commit to balabit-deps/balabit-os-9-netplan.io that referenced this pull request Mar 21, 2023
netplan.io (0.105-0ubuntu2~22.04.3) jammy; urgency=medium

  * Fix and improvements for the DBus integration (LP: #1997467)
    Cherry-picked from upstream: canonical/netplan#331
    - d/p/lp1997467/0009-dbus-Build-the-copy-path-correctly.patch
      Properly build the destination path before copying files in the dbus
      integration and improve error handling
    - d/p/lp1997467/0010-tests-Add-an-integration-test-for-netplan-dbus.patch
      Add an integration test to exercise the code path where the issue was
      addressed.

netplan.io (0.105-0ubuntu2~22.04.2) jammy; urgency=medium

  * d/p/lp1997467: set only specific origin-hint if given (LP: #1997467)
    Cherry-picked from upstream: canonical/netplan#299
    - d/libnetplan0.symbols: Add netplan_parser_load_nullable_overrides() API
    - d/p/0008-src-parse-plug-memory-leaks-in-nullable-handling.patch backport
      upstream commit 40c53bb (memory leak fixup of PR#299)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants