Discussion:
[lxc-devel] [lxd/master] Fix "lxd shutdown"
stgraber on Github
2016-12-05 10:28:53 UTC
Permalink
From b18ea31e99b3360410c1298e02381a7fae96d0a4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <***@ubuntu.com>
Date: Mon, 5 Dec 2016 11:09:44 +0100
Subject: [PATCH 1/2] Fix container state recording
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Closes #2686

Signed-off-by: Stéphane Graber <***@ubuntu.com>
---
lxd/containers.go | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/lxd/containers.go b/lxd/containers.go
index 206456c..a002c8e 100644
--- a/lxd/containers.go
+++ b/lxd/containers.go
@@ -167,10 +167,7 @@ func containersShutdown(d *Daemon) error {
}

// Record the current state
- err = c.ConfigKeySet("volatile.last_state.power", c.State())
- if err != nil {
- return err
- }
+ lastState := c.State()

// Stop the container
if c.IsRunning() {
@@ -188,8 +185,12 @@ func containersShutdown(d *Daemon) error {
go func() {
c.Shutdown(time.Second * time.Duration(timeoutSeconds))
c.Stop(false)
+ c.ConfigKeySet("volatile.last_state.power", lastState)
+
wg.Done()
}()
+ } else {
+ c.ConfigKeySet("volatile.last_state.power", lastState)
}
}
wg.Wait()

From 78c8a52f5be897465352c2e453800c6455340092 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <***@ubuntu.com>
Date: Mon, 5 Dec 2016 11:25:45 +0100
Subject: [PATCH 2/2] tests: Test lxd shutdown
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber <***@ubuntu.com>
---
test/suites/basic.sh | 25 +++++++++++++++++++++++--
1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/test/suites/basic.sh b/test/suites/basic.sh
index 9dcd9d3..a0f4674 100644
--- a/test/suites/basic.sh
+++ b/test/suites/basic.sh
@@ -215,8 +215,9 @@ test_basic_usage() {
[ "$(my_curl "https://${LXD_ADDR}/1.0/containers/configtest" | jq -r .metadata.config[\"raw.lxc\"])" = "lxc.hook.clone=/bin/true" ]
lxc delete configtest

- # Test socket activation
+ # Test activateifneeded/shutdown
LXD_ACTIVATION_DIR=$(mktemp -d -p "${TEST_DIR}" XXX)
+ chmod +x "${LXD_ACTIVATION_DIR}"
spawn_lxd "${LXD_ACTIVATION_DIR}"
(
set -e
@@ -230,7 +231,27 @@ test_basic_usage() {
lxd activateifneeded --debug 2>&1 | grep -q -v "activating..."
lxc config set autostart boot.autostart true --force-local
lxd activateifneeded --debug 2>&1 | grep -q "Daemon has auto-started containers, activating..."
- lxc delete autostart --force-local
+
+ lxc config unset autostart boot.autostart --force-local
+ lxd activateifneeded --debug 2>&1 | grep -q -v "activating..."
+
+ lxc start autostart --force-local
+ PID=$(lxc info autostart --force-local | grep ^Pid | awk '{print $2}')
+ lxd shutdown
+ [ -d "/proc/${PID}" ] && false
+
+ lxd activateifneeded --debug 2>&1 | grep -q "Daemon has auto-started containers, activating..."
+
+ # shellcheck disable=SC2086
+ lxd --logfile "${LXD_DIR}/lxd.log" ${DEBUG-} "$@" 2>&1 &
+ LXD_PID=$!
+ echo "${LXD_PID}" > "${LXD_DIR}/lxd.pid"
+ echo "${LXD_DIR}" >> "${TEST_DIR}/daemons"
+ lxd waitready --timeout=300
+
+ lxc list --force-local autostart | grep -q RUNNING
+
+ lxc delete autostart --force --force-local
)
# shellcheck disable=SC2031
LXD_DIR=${LXD_DIR}

Loading...