Merge lp:~thumper/juju-core/uniter-context-run-commands into lp:~go-bot/juju-core/trunk
Proposed by
Tim Penhey
Status: | Merged |
---|---|
Approved by: | Tim Penhey |
Approved revision: | no longer in the source branch. |
Merged at revision: | 2143 |
Proposed branch: | lp:~thumper/juju-core/uniter-context-run-commands |
Merge into: | lp:~go-bot/juju-core/trunk |
Prerequisite: | lp:~thumper/juju-core/refactor-uniter-tests |
Diff against target: |
178 lines (+102/-5) 2 files modified
worker/uniter/context.go (+44/-1) worker/uniter/context_test.go (+58/-4) |
To merge this branch: | bzr merge lp:~thumper/juju-core/uniter-context-run-commands |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Juju Engineering | Pending | ||
Review via email: mp+198671@code.launchpad.net |
Commit message
Uniter context run commands.
The uniter.Context gains the ability to run arbitrary commands in a hook
context.
Execute the commands by passing as stdin to "/bin/bash -s".
Description of the change
Uniter context run commands.
The uniter.Context gains the ability to run arbitrary commands in a hook
context.
Execute the commands by passing as stdin to "/bin/bash -s".
To post a comment you must log in.
Reviewers: mp+198671_ code.launchpad. net,
Message:
Please take a look.
Description:
Uniter context run commands.
The uniter.Context gains the ability to run arbitrary commands in a hook
context.
Execute the commands by passing as stdin to "/bin/bash -s".
https:/ /code.launchpad .net/~thumper/ juju-core/ uniter- context- run-commands/ +merge/ 198671
Requires: /code.launchpad .net/~thumper/ juju-core/ refactor- uniter- tests/+ merge/198668
https:/
(do not edit description out of merge proposal)
Please review this at https:/ /codereview. appspot. com/40370047/
Affected files (+99, -0 lines): uniter/ context. go uniter/ context_ test.go
A [revision details]
M worker/
M worker/
Index: [revision details]
=== added file '[revision details]'
--- [revision details] 2012-01-01 00:00:00 +0000
+++ [revision details] 2012-01-01 00:00:00 +0000
@@ -0,0 +1,2 @@
+Old revision: <email address hidden>
+New revision: <email address hidden>
Index: worker/ uniter/ context. go uniter/ context. go' uniter/ context. go 2013-12-12 05:18:00 +0000 uniter/ context. go 2013-12-12 06:14:41 +0000
=== modified file 'worker/
--- worker/
+++ worker/
@@ -5,6 +5,7 @@
import (
"bufio"
+ "bytes"
"fmt"
"io"
"os"
@@ -13,9 +14,11 @@
"sort"
"strings"
"sync"
+ "syscall"
"time"
"launchpad. net/juju- core/charm" net/juju- core/cmd" net/juju- core/state/ api/params" net/juju- core/state/ api/uniter" net/juju- core/worker/ uniter/ debug"
+ "launchpad.
"launchpad.
"launchpad.
unitdebug "launchpad.
@@ -209,6 +212,14 @@
// RunHook executes a hook in an environment which allows it to to call commands, charmDir, toolsDir, ponse, error) { charmDir, toolsDir, socketPath) commands, charmDir, env) text("run commands", err) charmDir, toolsDir, socketPath)
back
// into ctx to execute jujuc tools.
+func (ctx *HookContext) RunCommands(
socketPath string) (*cmd.RemoteRes
+ env := ctx.hookVars(
+ result, err := runCommands(
+ return result, ctx.finalizeCon
+}
+
+// RunHook executes a hook in an environment which allows it to to call
back
+// into ctx to execute jujuc tools.
func (ctx *HookContext) RunHook(hookName, charmDir, toolsDir, socketPath
string) error {
var err error
env := ctx.hookVars(
@@ -253,6 +264,38 @@
return err
}
+func runCommands( commands, charmDir string, env []string) ponse, error) { "/bin/bash" , "-s") String( commands) onse{ ExitError) ; ok && err != nil { .Sys(). (syscall. WaitStatus)
(*cmd.RemoteRes
+ ps := exec.Command(
+ ps.Env = env
+ ps.Dir = charmDir
+ ps.Stdin = bytes.NewBuffer
+
+ stdout := &bytes.Buffer{}
+ stderr := &bytes.Buffer{}
+
+ ps.Stdout = stdout
+ ps.Stderr = stderr
+
+ err := ps.Start()
+ if err == nil {
+ err = ps.Wait()
+ }
+ result := &cmd.RemoteResp
+ Stdout: stdout.Bytes(),
+ Stderr: stderr.Bytes(),
+ }
+ if ee, ok := err.(*exec.
+ status := ee.ProcessState
+ if status.Exited() {
+ // A non-zero return code isn't considered an error here.
+ result.Code = status.ExitStatus()
+ err = nil
+ }
+ logger.Infof("run result: %v", ee)
+ }
+ return result, err
+}
+
type hookLogger struct {
r io.ReadCloser
done chan struct{}
Index: worker/uniter/co...