Commit 563eac74 authored by Iain Lane's avatar Iain Lane Committed by Martin Pitt

lxc, lxd: If we're running systemd, wait until the network is up

We execute `apt-get update' more or less as soon as the container is
started. In some situations this is too early: it can be before network
is fully working.

If we have systemd, use network-online.target to wait until it thinks
networking is up.
Modified-By: Martin Pitt's avatarMartin Pitt <mpitt@debian.org>
  - Add the same approach to LXC
  - Some simplification

LP: #1749736
parent ba52df90
......@@ -122,6 +122,12 @@ setup() {
exit 1
}
# wait until a systemd based container has networking
if ! echo '[ ! -d /run/systemd/system ] || systemctl start network-online.target' | timeout 60 lxc-attach --name=$1 -- sh -e; then
echo "Timed out waiting for container to start network-online.target" >&2
exit 1
fi
# find setup-testbed script
for script in $(dirname $(dirname "$0"))/setup-commands/setup-testbed \
/usr/share/autopkgtest/setup-commands/setup-testbed; do
......
......@@ -81,6 +81,12 @@ setup() {
exit 1
}
# wait until a systemd based container has networking
if ! echo '[ ! -d /run/systemd/system ] || systemctl start network-online.target' | timeout 60 lxc exec "$CONTAINER" -- sh -e; then
echo "Timed out waiting for container to start network-online.target" >&2
exit 1
fi
ARCH=$(lxc exec "$CONTAINER" -- dpkg --print-architecture </dev/null)
DISTRO=$(lxc exec "$CONTAINER" -- sh -ec 'lsb_release -si 2>/dev/null || . /etc/os-release; echo "${NAME% *}"' </dev/null)
CRELEASE=$(lxc exec "$CONTAINER" -- sh -ec 'lsb_release -sc 2>/dev/null || awk "/^deb/ {sub(/\\[.*\\]/, \"\", \$0); print \$3; quit}" /etc/apt/sources.list' </dev/null)
......
......@@ -124,6 +124,8 @@ def wait_booted(lxc_name):
continue
out = out.strip()
if out.split()[-1].isdigit():
adtlog.debug('waiting for network')
VirtSubproc.check_exec(sudoify(['lxc-attach', '--name', lxc_name, '--', 'sh', '-ec', '[ ! -d /run/systemd/system ] || systemctl start network-online.target']), timeout=60)
return
adtlog.debug('wait_booted: runlevel "%s", retrying...' % out)
......
......@@ -100,6 +100,8 @@ def wait_booted():
continue
out = out.strip()
if out.split()[-1].isdigit():
adtlog.debug('waiting for network')
VirtSubproc.check_exec(['lxc', 'exec', container_name, '--', 'sh', '-ec', '[ ! -d /run/systemd/system ] || systemctl start network-online.target'], timeout=60)
return
adtlog.debug('wait_booted: runlevel "%s", retrying...' % out)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment