From bb77e219f14e030f2ab9bb20ef59d893b42ab06c Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 28 Feb 2023 16:35:38 +0100 Subject: [PATCH 1/3] tests: add new spread based snapd integration test These tests integrate into the GH workflow and run snapd and dbus based integration tests. --- .github/workflows/spread.yml | 21 +++++++++++ spread.yaml | 46 +++++++++++++++++++++++ tests/spread/dbus/task.yaml | 31 ++++++++++++++++ tests/spread/snapd-integration/task.yaml | 47 ++++++++++++++++++++++++ 4 files changed, 145 insertions(+) create mode 100644 .github/workflows/spread.yml create mode 100644 spread.yaml create mode 100644 tests/spread/dbus/task.yaml create mode 100644 tests/spread/snapd-integration/task.yaml diff --git a/.github/workflows/spread.yml b/.github/workflows/spread.yml new file mode 100644 index 000000000..9016bc0da --- /dev/null +++ b/.github/workflows/spread.yml @@ -0,0 +1,21 @@ +name: Run spread + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + spread: + runs-on: ubuntu-latest + steps: + - uses: canonical/setup-lxd@ea57509243d3cf39f8ab926e021bb353947b01b5 + - uses: actions/checkout@v2 + - name: Install spread + run: | + go install github.com/snapcore/spread/cmd/spread@latest + - name: Run the spread test inside LXD + run: | + ~/go/bin/spread -v lxd: + diff --git a/spread.yaml b/spread.yaml new file mode 100644 index 000000000..0eaa9315a --- /dev/null +++ b/spread.yaml @@ -0,0 +1,46 @@ +project: netplan + +backends: + lxd: + systems: [ubuntu-22.04] + qemu: + systems: + - ubuntu-22.04-64: + username: ubuntu + password: ubuntu + +suites: + tests/spread/: + summary: integration tests + +path: /home/tests + +prepare: | + # FIXME: remove after legacy symlink in 107 gets dropped (see meson.build) + # This is needed as the git netplan puts a symlink to /lib/netplan/generate + # but the package has the real generate there + rm -f /lib/netplan/generate + # FIXME: having the debian packging available would allow "apt + # build-dep -y ./" would make this easier :) + apt update -qq + apt install -y build-essential meson pkg-config libyaml-dev \ + libglib2.0-dev uuid-dev python3 libsystemd-dev pandoc python3-pytest \ + python3-coverage libcmocka-dev python3-rich + # install, a bit ugly but this is a container (did I mention the packaging?) + meson setup build --prefix=/usr + meson compile -C build + # FIXME: enable, this crashes right now with: + # https://paste.ubuntu.com/p/qRnJvjyddN/ + #meson test -C build --verbose + meson install -C build --destdir=/ + # set some defaults for the tests + cat > /etc/netplan/0-snapd-defaults.yaml <<'EOF' + network: + version: 2 + bridges: + br54: + dhcp4: true + EOF + chmod 0600 /etc/netplan/0-snapd-defaults.yaml + echo "Precondition check, the basics work" + netplan get bridges.br54.dhcp4 | MATCH true diff --git a/tests/spread/dbus/task.yaml b/tests/spread/dbus/task.yaml new file mode 100644 index 000000000..be1f201b2 --- /dev/null +++ b/tests/spread/dbus/task.yaml @@ -0,0 +1,31 @@ +summary: Check that the dbus integration works + +debug: | + netplan get + +execute: | + # see the basics work + netplan get bridges.br54.dhcp4 | MATCH true + # TODO: actually use busctl + obj_path=$(dbus-send --system --print-reply --type=method_call \ + --dest=io.netplan.Netplan /io/netplan/Netplan \ + io.netplan.Netplan.Config|tail -1 | sed 's/.*"\(.*\)".*/\1/' ) + dbus-send --print-reply --system --type=method_call \ + --dest=io.netplan.Netplan "$obj_path" \ + io.netplan.Netplan.Config.Get | MATCH "version: 2" + # and updating via dbus netplan works + dbus-send --print-reply --system --type=method_call \ + --dest=io.netplan.Netplan "$obj_path" \ + io.netplan.Netplan.Config.Set \ + string:bridges.br54.dhcp4=false string:90-test + # not applied yet + test ! -e /etc/netplan/90-test.yaml + netplan get bridges.br54.dhcp4 | MATCH true + # apply + dbus-send --print-reply --system --type=method_call \ + --dest=io.netplan.Netplan "$obj_path" \ + io.netplan.Netplan.Config.Apply + # and now it's active + test -e /etc/netplan/90-test.yaml + netplan get bridges.br54.dhcp4 | MATCH false + diff --git a/tests/spread/snapd-integration/task.yaml b/tests/spread/snapd-integration/task.yaml new file mode 100644 index 000000000..264f1238a --- /dev/null +++ b/tests/spread/snapd-integration/task.yaml @@ -0,0 +1,47 @@ +summary: Check that the snapd/netplan integration works + +prepare: | + # put snapd in debug mode for good logs + mkdir -p /etc/systemd/system/snapd.service.d + cat < /etc/systemd/system/snapd.service.d/local.conf + [Service] + Environment=SNAPD_DEBUG=1 + EOF + systemctl daemon-reload + # install snapd if needed (should be installed on most lxd images) + if ! dpkg -l snapd >/dev/null; then + apt install -y snapd + echo "apt autoremove -y snapd" >> defered.cleanup + fi + # fake running on core (netplan only enabled on ubuntu core) + # FIXME: find a more offical way, this if fugly + cp /etc/os-release /etc/os-release.save + sed -i s/ID=ubuntu/ID=ubuntu-core/ /etc/os-release + M=/var/lib/snapd/assertions/asserts-v0/model/16/generic/generic-classic/active + cp "$M" model.save + sed -i 's/classic: true/architecture: amd64\ngadget: pc\nkernel: pc-kernel/g' "$M" + # restart snapd + systemctl restart snapd + +restore: | + mv /etc/os-release.save /etc/os-release + mv model.save /var/lib/snapd/assertions/asserts-v0/model/16/generic/generic-classic/active + sudo systemctl restart snapd + if [ -e defered.cleanup ]; then + sh -ex defered.cleanup + fi + rm -f model.* + +debug: | + journalctl -u snapd + snap get system -d + snap version + +execute: | + # see the basics work + netplan get bridges.br54.dhcp4 | MATCH true + snap get system system.network.netplan.network.bridges.br54.dhcp4 | MATCH true + # and updating netplan works + snap set system system.network.netplan.network.bridges.br54.dhcp4=false + netplan get bridges.br54.dhcp4 | MATCH false + snap get system system.network.netplan.network.bridges.br54.dhcp4 | MATCH false From 1afd4d38fad1c0fd0575570fb6f1485d2f88f8e8 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 6 Mar 2023 09:29:25 +0100 Subject: [PATCH 2/3] spread.yaml: restore /etc/netplan for each test This is archived by moving using the "restore-each" stanza and just restoring /etc/netplan in there. This avoids the need to have two br54,br55 (or N for N tests). --- spread.yaml | 9 ++++++++- tests/spread/dbus/task.yaml | 3 ++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/spread.yaml b/spread.yaml index 0eaa9315a..03c3bb737 100644 --- a/spread.yaml +++ b/spread.yaml @@ -33,7 +33,7 @@ prepare: | # https://paste.ubuntu.com/p/qRnJvjyddN/ #meson test -C build --verbose meson install -C build --destdir=/ - # set some defaults for the tests + # set some defaults cat > /etc/netplan/0-snapd-defaults.yaml <<'EOF' network: version: 2 @@ -44,3 +44,10 @@ prepare: | chmod 0600 /etc/netplan/0-snapd-defaults.yaml echo "Precondition check, the basics work" netplan get bridges.br54.dhcp4 | MATCH true + # keep original config around + tar cvf "$SPREAD_PATH"/etc-netplan.tar.gz /etc/netplan/ + +restore-each: | + # restore original netplan dir + rm -rf /etc/netplan/* + (cd / && tar xvf "$SPREAD_PATH"/etc-netplan.tar.gz) diff --git a/tests/spread/dbus/task.yaml b/tests/spread/dbus/task.yaml index be1f201b2..49a69b57c 100644 --- a/tests/spread/dbus/task.yaml +++ b/tests/spread/dbus/task.yaml @@ -13,7 +13,8 @@ execute: | dbus-send --print-reply --system --type=method_call \ --dest=io.netplan.Netplan "$obj_path" \ io.netplan.Netplan.Config.Get | MATCH "version: 2" - # and updating via dbus netplan works + # and updating via dbus netplan works (use 90-test origin hint for + # easier test cleanup) dbus-send --print-reply --system --type=method_call \ --dest=io.netplan.Netplan "$obj_path" \ io.netplan.Netplan.Config.Set \ From ae8641568ccef66c23018c52826bed01955331d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20M=C3=A4rdian?= Date: Thu, 23 Mar 2023 15:13:43 +0100 Subject: [PATCH 3/3] meson: fix installation of legacy /lib/netplan/generate symlink --- src/meson.build | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/meson.build b/src/meson.build index 3b2c3ce3e..1636fbc54 100644 --- a/src/meson.build +++ b/src/meson.build @@ -39,8 +39,6 @@ meson.add_install_script(meson_make_symlink, join_paths(systemd_generator_dir, 'netplan')) # FIXME: Drop legacy symlink after 0.107 is released: # It's only around for legacy reasons, see netplan/cli/utils.py: get_generator_path() -install_symlink( - 'generate', - pointing_to: join_paths('..', '..') + join_paths(get_option('prefix'), libexec_netplan, 'generate'), - install_dir: join_paths('/', 'lib', 'netplan')) - +meson.add_install_script(meson_make_symlink, + join_paths(get_option('prefix'), libexec_netplan, 'generate'), + join_paths('/', 'lib', 'netplan', 'generate'))