[Merge] ~slyon/netplan/+git/ubuntu:slyon/0100-fix-nova-ssh-access into ~ubuntu-core-dev/netplan/+git/ubuntu:ubuntu/master

Dimitri John Ledkov launchpad at surgut.co.uk
Wed Sep 16 08:35:57 UTC 2020


I like using "netplan-foo.service" and "cloud-init-foo.service" to simulate the behavior. This is really nice.

Diff comments:

> diff --git a/debian/tests/cloud-init b/debian/tests/cloud-init
> new file mode 100755
> index 0000000..927b64f
> --- /dev/null
> +++ b/debian/tests/cloud-init
> @@ -0,0 +1,115 @@
> +#!/bin/sh
> +#
> +# Check that netplan and systemd/networkd will properly cooperate and run
> +# out generator at boot.

Is there a typpo here? did you mean "run our generator at boot"?

> +#
> +set -eu
> +
> +if [ ! -x /tmp/autopkgtest-reboot ]; then
> +    echo "SKIP: Testbed does not support reboot"
> +    exit 0
> +fi
> +
> +trap 'rm -f /etc/netplan/00test.yaml' EXIT INT QUIT PIPE TERM
> +
> +# parameters: service expect_running
> +assert_is_running() {
> +    if [ "$2" = 1 ] && ! systemctl --quiet is-active "$1"; then
> +        echo "ERROR: expected $1 to have started, but it was not" >&2
> +        systemctl --no-pager status "$1"
> +        exit 1
> +    elif [ "$2" = 0 ] && systemctl --quiet is-active "$1"; then
> +        echo "ERROR: expected $1 to not have started, but it was" >&2
> +        systemctl --no-pager status "$1"
> +        exit 1
> +    else
> +        systemctl --no-pager status "$1" || true
> +    fi
> +}
> +
> +# Always try to keep the management interface up and running
> +mkdir -p /etc/systemd/network
> +cat <<EOF > /etc/systemd/network/20-mgmt.network
> +[Match]
> +Name=en*
> +
> +[Network]
> +DHCP=yes
> +EOF
> +
> +case "${AUTOPKGTEST_REBOOT_MARK:-}" in
> +    '')
> +        echo "INFO: Preparing configuration"
> +        mkdir -p /etc/netplan
> +        # Any netplan YAML config
> +        cat <<EOF > /etc/netplan/00test.yaml
> +network:
> +  version: 2
> +  bridges:
> +    brtest00:
> +      addresses: [10.42.1.1/24]
> +EOF
> +        # Prepare a dummy netplan service unit, which will be moved to /run/systemd/system/
> +        # during early boot, as if it would have been created by 'netplan generate'
> +        cat <<EOF > /netplan-dummy.service
> +[Unit]
> +Description=Check if this dummy is properly started by systemd
> +
> +[Service]
> +Type=oneshot
> +# Keep it running, so we can verify it was properly started
> +RemainAfterExit=yes
> +ExecStart=echo "Doing nothing ..."
> +EOF
> +        # A service simulating cloud-init, calling 'netplan generate' during early boot
> +        # at the 'initialization' phase of systemd (before basic.target is reached).
> +        cat <<EOF > /etc/systemd/system/cloud-init-dummy.service
> +[Unit]
> +Description=Simulating cloud-init's 'netplan generate' call during early boot
> +DefaultDependencies=no
> +Before=basic.target
> +Before=network.target
> +After=sysinit.target
> +
> +[Install]
> +RequiredBy=basic.target
> +
> +[Service]
> +Type=oneshot
> +# Keep it running, so we can verify it was properly started
> +RemainAfterExit=yes
> +# Simulate creating a new service unit (i.e. netplan-wpa-*.service / netplan-ovs-*.service)
> +ExecStart=/bin/mv /netplan-dummy.service /run/systemd/system/
> +ExecStart=/usr/sbin/netplan generate
> +EOF
> +
> +        # right after installation systemd-networkd may or may not be started
> +        assert_is_running systemd-networkd.service status
> +
> +        systemctl disable systemd-networkd.service
> +        systemctl enable cloud-init-dummy.service
> +        echo "INFO: Configuration written, rebooting..."
> +        /tmp/autopkgtest-reboot config
> +        ;;
> +
> +    config)
> +        sleep 5  # Give some time for systemd to finish the boot transaction
> +        echo "INFO: Validate that systemd-networkd, cloud-init-dummy.service and netplan-dummy.service are running and our test bridge exists..."
> +        assert_is_running systemd-networkd.service 1
> +        assert_is_running cloud-init-dummy.service 1
> +        assert_is_running netplan-dummy.service 1
> +        ip a show dev brtest00
> +        echo "OK: Test bridge is configured and just-in-time services running."
> +
> +        # Cleanup
> +        systemctl enable systemd-networkd.service
> +        systemctl disable cloud-init-dummy.service
> +        rm /run/systemd/system/netplan-dummy.service
> +        rm /etc/systemd/system/cloud-init-dummy.service
> +        ;;
> +
> +    *)
> +        echo "INTERNAL ERROR: autopkgtest marker $AUTOPKGTEST_REBOOT_MARK unexpected" >&2
> +        exit 1
> +        ;;
> +esac


-- 
https://code.launchpad.net/~slyon/netplan/+git/ubuntu/+merge/390813
Your team Ubuntu Core Development Team is subscribed to branch ~ubuntu-core-dev/netplan/+git/ubuntu:ubuntu/master.



More information about the Ubuntu-reviews mailing list