From 6bc57ff5e38d45d343be1b9c7f340138eb748aa8 Mon Sep 17 00:00:00 2001 From: Enrique Llorente Date: Wed, 1 Mar 2023 14:37:26 +0100 Subject: [PATCH] networking-tools: Add nmstate As discussed at [1] the nmstatectl tool is going to be added to FCOS, it will allow to declare the network configuration at boot time [1] https://github.com/coreos/fedora-coreos-tracker/issues/1175 Signed-off-by: Enrique Llorente --- manifest-lock.overrides.yaml | 5 ++++ manifests/networking-tools.yaml | 3 +++ .../systemd/system-preset/40-coreos.preset | 3 +++ .../networking/nmstate/data/nmstate-common.sh | 23 ++++++++++++++++++ .../kola/networking/nmstate/policy/config.bu | 24 +++++++++++++++++++ .../nmstate/policy/data/commonlib.sh | 1 + .../nmstate/policy/data/nmstate-common.sh | 1 + tests/kola/networking/nmstate/policy/test.sh | 11 +++++++++ tests/kola/networking/nmstate/state/config.bu | 17 +++++++++++++ .../nmstate/state/data/commonlib.sh | 1 + .../nmstate/state/data/nmstate-common.sh | 1 + tests/kola/networking/nmstate/state/test.sh | 11 +++++++++ 12 files changed, 101 insertions(+) create mode 100755 tests/kola/networking/nmstate/data/nmstate-common.sh create mode 100644 tests/kola/networking/nmstate/policy/config.bu create mode 120000 tests/kola/networking/nmstate/policy/data/commonlib.sh create mode 120000 tests/kola/networking/nmstate/policy/data/nmstate-common.sh create mode 100755 tests/kola/networking/nmstate/policy/test.sh create mode 100644 tests/kola/networking/nmstate/state/config.bu create mode 120000 tests/kola/networking/nmstate/state/data/commonlib.sh create mode 120000 tests/kola/networking/nmstate/state/data/nmstate-common.sh create mode 100755 tests/kola/networking/nmstate/state/test.sh diff --git a/manifest-lock.overrides.yaml b/manifest-lock.overrides.yaml index ea2ae3b8a7..60abf0d581 100644 --- a/manifest-lock.overrides.yaml +++ b/manifest-lock.overrides.yaml @@ -34,3 +34,8 @@ packages: metadata: reason: https://github.com/coreos/fedora-coreos-tracker/issues/1441 type: pin + nmstate: + evr: 2.2.8-2.fc37 + metadata: + bodhi: https://bodhi.fedoraproject.org/updates/FEDORA-2023-59543876eb + type: fast-track diff --git a/manifests/networking-tools.yaml b/manifests/networking-tools.yaml index ffb51ee70d..c5c66336e2 100644 --- a/manifests/networking-tools.yaml +++ b/manifests/networking-tools.yaml @@ -19,3 +19,6 @@ packages: - iptables nftables # Interactive network tools for admins - socat net-tools bind-utils + # Declarative network configuration + # https://github.com/coreos/fedora-coreos-tracker/issues/1175 + - nmstate diff --git a/overlay.d/05core/usr/lib/systemd/system-preset/40-coreos.preset b/overlay.d/05core/usr/lib/systemd/system-preset/40-coreos.preset index f4577d8fe9..17c9d4051f 100644 --- a/overlay.d/05core/usr/lib/systemd/system-preset/40-coreos.preset +++ b/overlay.d/05core/usr/lib/systemd/system-preset/40-coreos.preset @@ -32,3 +32,6 @@ enable rtas_errd.service enable clevis-luks-askpass.path # Provide status information about the Ignition run enable coreos-ignition-write-issues.service +# Apply network configuration from /etc/nmstate/*.yml +# We can drop this after merging https://src.fedoraproject.org/rpms/fedora-release/pull-request/255 +enable nmstate.service diff --git a/tests/kola/networking/nmstate/data/nmstate-common.sh b/tests/kola/networking/nmstate/data/nmstate-common.sh new file mode 100755 index 0000000000..ca8293fa8d --- /dev/null +++ b/tests/kola/networking/nmstate/data/nmstate-common.sh @@ -0,0 +1,23 @@ +. $KOLA_EXT_DATA/commonlib.sh + +main() { + nmstatectl show + journalctl -u nmstate + + local prefix="first boot" + if [ "${AUTOPKGTEST_REBOOT_MARK:-}" == rebooted ]; then + prefix="second boot" + fi + + if ! nmcli c show br-ex; then + fatal "${prefix}: bridge not configured" + fi + + if ! ls /etc/nmstate/*applied; then + fatal "${prefix}: nmstate yamls files not marked as applied" + fi + + if [ "${AUTOPKGTEST_REBOOT_MARK:-}" == "" ]; then + /tmp/autopkgtest-reboot rebooted + fi +} diff --git a/tests/kola/networking/nmstate/policy/config.bu b/tests/kola/networking/nmstate/policy/config.bu new file mode 100644 index 0000000000..a3862363c0 --- /dev/null +++ b/tests/kola/networking/nmstate/policy/config.bu @@ -0,0 +1,24 @@ +variant: fcos +version: 1.4.0 +storage: + files: + - path: /etc/nmstate/br-ex-policy.yml + contents: + inline: | + capture: + default-gw-route: routes.running.destination=="::/0" + default-gw-iface: interfaces.name==capture.default-gw-route.routes.running.0.next-hop-interface + desiredState: + interfaces: + - name: "{{ capture.default-gw-iface.interfaces.0.name }}" + type: ethernet + state: up + - name: br-ex + type: linux-bridge + copy-mac-from: "{{ capture.default-gw-iface.interfaces.0.name }}" + state: up + ipv4: "{{ capture.default-gw-iface.interfaces.0.ipv4 }}" + ipv6: "{{ capture.default-gw-iface.interfaces.0.ipv6 }}" + bridge: + port: + - name: "{{ capture.default-gw-iface.interfaces.0.name }}" diff --git a/tests/kola/networking/nmstate/policy/data/commonlib.sh b/tests/kola/networking/nmstate/policy/data/commonlib.sh new file mode 120000 index 0000000000..b8dcbdca1a --- /dev/null +++ b/tests/kola/networking/nmstate/policy/data/commonlib.sh @@ -0,0 +1 @@ +../../../data/commonlib.sh \ No newline at end of file diff --git a/tests/kola/networking/nmstate/policy/data/nmstate-common.sh b/tests/kola/networking/nmstate/policy/data/nmstate-common.sh new file mode 120000 index 0000000000..fe39f3bae7 --- /dev/null +++ b/tests/kola/networking/nmstate/policy/data/nmstate-common.sh @@ -0,0 +1 @@ +../../data/nmstate-common.sh \ No newline at end of file diff --git a/tests/kola/networking/nmstate/policy/test.sh b/tests/kola/networking/nmstate/policy/test.sh new file mode 100755 index 0000000000..490d629731 --- /dev/null +++ b/tests/kola/networking/nmstate/policy/test.sh @@ -0,0 +1,11 @@ +#!/bin/bash +## kola: +## tags: "platform-independent" +# +# Configure a DHCP linux bridge using butane and nmstate service with policy + +set -xeuo pipefail + +. $KOLA_EXT_DATA/nmstate-common.sh + +main diff --git a/tests/kola/networking/nmstate/state/config.bu b/tests/kola/networking/nmstate/state/config.bu new file mode 100644 index 0000000000..d2d7e834b5 --- /dev/null +++ b/tests/kola/networking/nmstate/state/config.bu @@ -0,0 +1,17 @@ +variant: fcos +version: 1.4.0 +storage: + files: + - path: /etc/nmstate/br-ex.yml + contents: + inline: | + interfaces: + - name: br-ex + type: linux-bridge + state: up + ipv4: + enabled: false + ipv6: + enabled: false + bridge: + port: [] diff --git a/tests/kola/networking/nmstate/state/data/commonlib.sh b/tests/kola/networking/nmstate/state/data/commonlib.sh new file mode 120000 index 0000000000..b8dcbdca1a --- /dev/null +++ b/tests/kola/networking/nmstate/state/data/commonlib.sh @@ -0,0 +1 @@ +../../../data/commonlib.sh \ No newline at end of file diff --git a/tests/kola/networking/nmstate/state/data/nmstate-common.sh b/tests/kola/networking/nmstate/state/data/nmstate-common.sh new file mode 120000 index 0000000000..fe39f3bae7 --- /dev/null +++ b/tests/kola/networking/nmstate/state/data/nmstate-common.sh @@ -0,0 +1 @@ +../../data/nmstate-common.sh \ No newline at end of file diff --git a/tests/kola/networking/nmstate/state/test.sh b/tests/kola/networking/nmstate/state/test.sh new file mode 100755 index 0000000000..6a069e6049 --- /dev/null +++ b/tests/kola/networking/nmstate/state/test.sh @@ -0,0 +1,11 @@ +#!/bin/bash +## kola: +## tags: "platform-independent" +# +# Configure a DHCP linux bridge using butane and nmstate service with state + +set -xeuo pipefail + +. $KOLA_EXT_DATA/nmstate-common.sh + +main