Code review comment for lp:~axwalk/juju-core/lp1296485-manual-destroy-brokenenv

Revision history for this message
Andrew Wilkins (axwalk) wrote :

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