[lxc-devel] [lxd/master] remember the return code in the non wait-for-websocket case

tych0 on Github lxc-bot at linuxcontainers.org
Mon Aug 1 18:57:05 UTC 2016


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 377 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20160801/f933e491/attachment.bin>
-------------- next part --------------
From dec46251f3c22d59156d4d74d358c1bbeca9e60a Mon Sep 17 00:00:00 2001
From: Tycho Andersen <tycho.andersen at canonical.com>
Date: Mon, 1 Aug 2016 12:30:54 -0600
Subject: [PATCH] remember the return code in the non wait-for-websocket case

Closes #2243

Signed-off-by: Tycho Andersen <tycho.andersen at canonical.com>
---
 lxd/container_exec.go | 9 ++++++++-
 test/suites/basic.sh  | 4 ++++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/lxd/container_exec.go b/lxd/container_exec.go
index 71aee79..57b310b 100644
--- a/lxd/container_exec.go
+++ b/lxd/container_exec.go
@@ -14,6 +14,8 @@ import (
 	"github.com/gorilla/websocket"
 
 	"github.com/lxc/lxd/shared"
+
+	log "gopkg.in/inconshreveable/log15.v2"
 )
 
 type commandPostContent struct {
@@ -329,7 +331,12 @@ func containerExecPost(d *Daemon, r *http.Request) Response {
 		}
 		defer nullDev.Close()
 
-		_, cmdErr := c.Exec(post.Command, env, nil, nil, nil)
+		cmdResult, cmdErr := c.Exec(post.Command, env, nil, nil, nil)
+		metadata := shared.Jmap{"return": cmdResult}
+		err = op.UpdateMetadata(metadata)
+		if err != nil {
+			shared.Log.Error("error updating metadata for cmd", log.Ctx{"err": err, "cmd": post.Command})
+		}
 		return cmdErr
 	}
 
diff --git a/test/suites/basic.sh b/test/suites/basic.sh
index b45ef7b..dcbfe21 100644
--- a/test/suites/basic.sh
+++ b/test/suites/basic.sh
@@ -259,6 +259,10 @@ test_basic_usage() {
   lxc exec --env BEST_BAND=meshuggah foo env | grep meshuggah
   lxc exec foo ip link show | grep eth0
 
+  # check that we can get the return code for a non- wait-for-websocket exec
+  op=$(my_curl -X POST "https://${LXD_ADDR}/1.0/containers/foo/exec" -d '{"command": ["sleep", "1"], "environment": {}, "wait-for-websocket": false, "interactive": false}' | jq -r .operation)
+  [ "$(my_curl "https://${LXD_ADDR}${op}/wait" | jq -r .metadata.metadata.return)" != "null" ]
+
   # test file transfer
   echo abc > "${LXD_DIR}/in"
 


More information about the lxc-devel mailing list