File: cloud-init.sh

package info (click to toggle)
netplan.io 1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 4,268 kB
  • sloc: python: 34,640; ansic: 14,096; xml: 4,989; javascript: 2,165; sh: 513; makefile: 118
file content (116 lines) | stat: -rwxr-xr-x 3,751 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/bin/sh
#
# Check that netplan, systemd and cloud-init will properly cooperate
# and run newly generated service units just-in-time.
#
set -eu

if [ ! -x /tmp/autopkgtest-reboot ]; then
    echo "SKIP: Testbed does not support reboot"
    exit 0
fi

# 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=eth0 en*

[Network]
DHCP=yes
KeepConfiguration=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:
      optional: true # ignore in systemd-networkd-wait-online.service to avoid testbed timeouts
      addresses: [10.42.1.1/24]
EOF
        chmod 600 /etc/netplan/00test.yaml
        # Modify a dummy netplan service unit, which will be generated in
        # /run/systemd/generator.late/ during early boot by Netplan's sd-generator
        mkdir -p /etc/systemd/system/netplan-ovs-cleanup.service.d
        cat <<EOF > /etc/systemd/system/netplan-ovs-cleanup.service.d/override.conf
[Unit]
ConditionFileIsExecutable=

[Service]
# Keep it running, so we can verify it was properly started
RemainAfterExit=yes
ExecStart=
ExecStart=echo "Testing. 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
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-ovs-cleanup.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-ovs-cleanup.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 -rf /etc/systemd/system/netplan-ovs-cleanup.service.d/
        rm /etc/systemd/system/cloud-init-dummy.service
        rm /etc/netplan/00test.yaml
        ;;

    *)
        echo "INTERNAL ERROR: autopkgtest marker $AUTOPKGTEST_REBOOT_MARK unexpected" >&2
        exit 1
        ;;
esac