Reviewers: mp+212610_code.launchpad.net,
Message: Please take a look.
Description: provider/manual: make Destroy handle broken env
If jujud is running, then killing it with SIGABRT is the preferred way of cleaning up. Otherwise, we should fall back to cleaning up manually.
Fixes lp:1296485
https://code.launchpad.net/~axwalk/juju-core/lp1296485-manual-destroy-brokenenv/+merge/212610
(do not edit description out of merge proposal)
Please review this at https://codereview.appspot.com/79720045/
Affected files (+32, -4 lines): A [revision details] M provider/manual/environ.go M provider/manual/environ_test.go
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: tarmac-20140325120745-2lmqgyj0xym54h51 +New revision: <email address hidden>
Index: provider/manual/environ.go === modified file 'provider/manual/environ.go' --- provider/manual/environ.go 2014-03-19 12:16:28 +0000 +++ provider/manual/environ.go 2014-03-25 13:18:46 +0000 @@ -28,6 +28,7 @@ "launchpad.net/juju-core/provider/common" "launchpad.net/juju-core/state" "launchpad.net/juju-core/state/api" + "launchpad.net/juju-core/utils" "launchpad.net/juju-core/utils/ssh" "launchpad.net/juju-core/worker/localstorage" "launchpad.net/juju-core/worker/terminationworker" @@ -218,18 +219,34 @@ return e.storage }
-var runSSHCommand = func(host string, command []string) (stderr string, err error) { +var runSSHCommand = func(host string, command []string, stdin string) (stderr string, err error) { cmd := ssh.Command(host, command, nil) var stderrBuf bytes.Buffer + cmd.Stdin = strings.NewReader(stdin) cmd.Stderr = &stderrBuf err = cmd.Run() return stderrBuf.String(), err }
func (e *manualEnviron) Destroy() error { + script := ` +set -x +pkill -%d jujud && exit +stop juju-db +rm -f /etc/init/juju* +rm -f /etc/rsyslog.d/*juju* +rm -fr %s %s +exit 0 +` + script = fmt.Sprintf( + script, + terminationworker.TerminationSignal, + utils.ShQuote(agent.DefaultDataDir), + utils.ShQuote(agent.DefaultLogDir), + ) stderr, err := runSSHCommand( "ubuntu@"+e.envConfig().bootstrapHost(), - []string{"sudo", "pkill", fmt.Sprintf("-%d", terminationworker.TerminationSignal), "jujud"}, + []string{"sudo", "/bin/bash"}, script, ) if err != nil { if stderr := strings.TrimSpace(stderr); len(stderr) > 0 {
Index: provider/manual/environ_test.go === modified file 'provider/manual/environ_test.go' --- provider/manual/environ_test.go 2014-03-18 01:25:52 +0000 +++ provider/manual/environ_test.go 2014-03-25 13:18:46 +0000 @@ -84,9 +84,18 @@ func (s *environSuite) TestDestroy(c *gc.C) { var resultStderr string var resultErr error - runSSHCommandTesting := func(host string, command []string) (string, error) { + runSSHCommandTesting := func(host string, command []string, stdin string) (string, error) { c.Assert(host, gc.Equals, "ubuntu@hostname") - c.Assert(command, gc.DeepEquals, []string{"sudo", "pkill", "-6", "jujud"}) + c.Assert(command, gc.DeepEquals, []string{"sudo", "/bin/bash"}) + c.Assert(stdin, gc.DeepEquals, ` +set -x +pkill -6 jujud && exit +stop juju-db +rm -f /etc/init/juju* +rm -f /etc/rsyslog.d/*juju* +rm -fr '/var/lib/juju' '/var/log/juju' +exit 0 +`) return resultStderr, resultErr } s.PatchValue(&runSSHCommand, runSSHCommandTesting)
« Back to merge proposal
Reviewers: mp+212610_ code.launchpad. net,
Message:
Please take a look.
Description:
provider/manual: make Destroy handle broken env
If jujud is running, then killing it with SIGABRT
is the preferred way of cleaning up. Otherwise,
we should fall back to cleaning up manually.
Fixes lp:1296485
https:/ /code.launchpad .net/~axwalk/ juju-core/ lp1296485- manual- destroy- brokenenv/ +merge/ 212610
(do not edit description out of merge proposal)
Please review this at https:/ /codereview. appspot. com/79720045/
Affected files (+32, -4 lines): manual/ environ. go manual/ environ_ test.go
A [revision details]
M provider/
M provider/
Index: [revision details] 20140325120745- 2lmqgyj0xym54h5 1
=== 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: tarmac-
+New revision: <email address hidden>
Index: provider/ manual/ environ. go manual/ environ. go' manual/ environ. go 2014-03-19 12:16:28 +0000 manual/ environ. go 2014-03-25 13:18:46 +0000 net/juju- core/provider/ common" net/juju- core/state" net/juju- core/state/ api" net/juju- core/utils" net/juju- core/utils/ ssh" net/juju- core/worker/ localstorage" net/juju- core/worker/ terminationwork er"
=== modified file 'provider/
--- provider/
+++ provider/
@@ -28,6 +28,7 @@
"launchpad.
"launchpad.
"launchpad.
+ "launchpad.
"launchpad.
"launchpad.
"launchpad.
@@ -218,18 +219,34 @@
return e.storage
}
-var runSSHCommand = func(host string, command []string) (stderr string, NewReader( stdin)
err error) {
+var runSSHCommand = func(host string, command []string, stdin string)
(stderr string, err error) {
cmd := ssh.Command(host, command, nil)
var stderrBuf bytes.Buffer
+ cmd.Stdin = strings.
cmd.Stderr = &stderrBuf
err = cmd.Run()
return stderrBuf.String(), err
}
func (e *manualEnviron) Destroy() error { d/*juju* er.TerminationS ignal, agent.DefaultDa taDir), agent.DefaultLo gDir), "+e.envConfig( ).bootstrapHost (), er.TerminationS ignal), "jujud"}, TrimSpace( stderr) ; len(stderr) > 0 {
+ script := `
+set -x
+pkill -%d jujud && exit
+stop juju-db
+rm -f /etc/init/juju*
+rm -f /etc/rsyslog.
+rm -fr %s %s
+exit 0
+`
+ script = fmt.Sprintf(
+ script,
+ terminationwork
+ utils.ShQuote(
+ utils.ShQuote(
+ )
stderr, err := runSSHCommand(
"ubuntu@
- []string{"sudo", "pkill", fmt.Sprintf("-%d",
terminationwork
+ []string{"sudo", "/bin/bash"}, script,
)
if err != nil {
if stderr := strings.
Index: provider/ manual/ environ_ test.go manual/ environ_ test.go' manual/ environ_ test.go 2014-03-18 01:25:52 +0000 manual/ environ_ test.go 2014-03-25 13:18:46 +0000 sting := func(host string, command []string) (string, sting := func(host string, command []string, stdin string) d/*juju* (&runSSHCommand , runSSHCommandTe sting)
=== modified file 'provider/
--- provider/
+++ provider/
@@ -84,9 +84,18 @@
func (s *environSuite) TestDestroy(c *gc.C) {
var resultStderr string
var resultErr error
- runSSHCommandTe
error) {
+ runSSHCommandTe
(string, error) {
c.Assert(host, gc.Equals, "ubuntu@hostname")
- c.Assert(command, gc.DeepEquals,
[]string{"sudo", "pkill", "-6", "jujud"})
+ c.Assert(command, gc.DeepEquals, []string{"sudo", "/bin/bash"})
+ c.Assert(stdin, gc.DeepEquals, `
+set -x
+pkill -6 jujud && exit
+stop juju-db
+rm -f /etc/init/juju*
+rm -f /etc/rsyslog.
+rm -fr '/var/lib/juju' '/var/log/juju'
+exit 0
+`)
return resultStderr, resultErr
}
s.PatchValue