Merge lp:~axwalk/juju-core/lp1296485-manual-destroy-brokenenv into lp:~go-bot/juju-core/trunk

Proposed by Andrew Wilkins
Status: Merged
Approved by: Andrew Wilkins
Approved revision: no longer in the source branch.
Merged at revision: 2480
Proposed branch: lp:~axwalk/juju-core/lp1296485-manual-destroy-brokenenv
Merge into: lp:~go-bot/juju-core/trunk
Diff against target: 73 lines (+30/-4)
2 files modified
provider/manual/environ.go (+19/-2)
provider/manual/environ_test.go (+11/-2)
To merge this branch: bzr merge lp:~axwalk/juju-core/lp1296485-manual-destroy-brokenenv
Reviewer Review Type Date Requested Status
Juju Engineering Pending
Review via email: mp+212610@code.launchpad.net

Commit message

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://codereview.appspot.com/79720045/

Description of the change

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://codereview.appspot.com/79720045/

To post a comment you must log in.
Revision history for this message
Andrew Wilkins (axwalk) wrote :
Download full text (3.4 KiB)

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,...

Read more...

Revision history for this message
Tim Penhey (thumper) wrote :

On 2014/03/25 13:25:48, axw wrote:
> Please take a look.

LGTM

https://codereview.appspot.com/79720045/

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'provider/manual/environ.go'
2--- provider/manual/environ.go 2014-03-19 12:16:28 +0000
3+++ provider/manual/environ.go 2014-03-25 13:22:15 +0000
4@@ -28,6 +28,7 @@
5 "launchpad.net/juju-core/provider/common"
6 "launchpad.net/juju-core/state"
7 "launchpad.net/juju-core/state/api"
8+ "launchpad.net/juju-core/utils"
9 "launchpad.net/juju-core/utils/ssh"
10 "launchpad.net/juju-core/worker/localstorage"
11 "launchpad.net/juju-core/worker/terminationworker"
12@@ -218,18 +219,34 @@
13 return e.storage
14 }
15
16-var runSSHCommand = func(host string, command []string) (stderr string, err error) {
17+var runSSHCommand = func(host string, command []string, stdin string) (stderr string, err error) {
18 cmd := ssh.Command(host, command, nil)
19 var stderrBuf bytes.Buffer
20+ cmd.Stdin = strings.NewReader(stdin)
21 cmd.Stderr = &stderrBuf
22 err = cmd.Run()
23 return stderrBuf.String(), err
24 }
25
26 func (e *manualEnviron) Destroy() error {
27+ script := `
28+set -x
29+pkill -%d jujud && exit
30+stop juju-db
31+rm -f /etc/init/juju*
32+rm -f /etc/rsyslog.d/*juju*
33+rm -fr %s %s
34+exit 0
35+`
36+ script = fmt.Sprintf(
37+ script,
38+ terminationworker.TerminationSignal,
39+ utils.ShQuote(agent.DefaultDataDir),
40+ utils.ShQuote(agent.DefaultLogDir),
41+ )
42 stderr, err := runSSHCommand(
43 "ubuntu@"+e.envConfig().bootstrapHost(),
44- []string{"sudo", "pkill", fmt.Sprintf("-%d", terminationworker.TerminationSignal), "jujud"},
45+ []string{"sudo", "/bin/bash"}, script,
46 )
47 if err != nil {
48 if stderr := strings.TrimSpace(stderr); len(stderr) > 0 {
49
50=== modified file 'provider/manual/environ_test.go'
51--- provider/manual/environ_test.go 2014-03-18 01:25:52 +0000
52+++ provider/manual/environ_test.go 2014-03-25 13:22:15 +0000
53@@ -84,9 +84,18 @@
54 func (s *environSuite) TestDestroy(c *gc.C) {
55 var resultStderr string
56 var resultErr error
57- runSSHCommandTesting := func(host string, command []string) (string, error) {
58+ runSSHCommandTesting := func(host string, command []string, stdin string) (string, error) {
59 c.Assert(host, gc.Equals, "ubuntu@hostname")
60- c.Assert(command, gc.DeepEquals, []string{"sudo", "pkill", "-6", "jujud"})
61+ c.Assert(command, gc.DeepEquals, []string{"sudo", "/bin/bash"})
62+ c.Assert(stdin, gc.DeepEquals, `
63+set -x
64+pkill -6 jujud && exit
65+stop juju-db
66+rm -f /etc/init/juju*
67+rm -f /etc/rsyslog.d/*juju*
68+rm -fr '/var/lib/juju' '/var/log/juju'
69+exit 0
70+`)
71 return resultStderr, resultErr
72 }
73 s.PatchValue(&runSSHCommand, runSSHCommandTesting)

Subscribers

People subscribed via source and target branches

to status/vote changes: