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
=== 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:22:15 +0000
@@ -28,6 +28,7 @@
28 "launchpad.net/juju-core/provider/common"28 "launchpad.net/juju-core/provider/common"
29 "launchpad.net/juju-core/state"29 "launchpad.net/juju-core/state"
30 "launchpad.net/juju-core/state/api"30 "launchpad.net/juju-core/state/api"
31 "launchpad.net/juju-core/utils"
31 "launchpad.net/juju-core/utils/ssh"32 "launchpad.net/juju-core/utils/ssh"
32 "launchpad.net/juju-core/worker/localstorage"33 "launchpad.net/juju-core/worker/localstorage"
33 "launchpad.net/juju-core/worker/terminationworker"34 "launchpad.net/juju-core/worker/terminationworker"
@@ -218,18 +219,34 @@
218 return e.storage219 return e.storage
219}220}
220221
221var runSSHCommand = func(host string, command []string) (stderr string, err error) {222var runSSHCommand = func(host string, command []string, stdin string) (stderr string, err error) {
222 cmd := ssh.Command(host, command, nil)223 cmd := ssh.Command(host, command, nil)
223 var stderrBuf bytes.Buffer224 var stderrBuf bytes.Buffer
225 cmd.Stdin = strings.NewReader(stdin)
224 cmd.Stderr = &stderrBuf226 cmd.Stderr = &stderrBuf
225 err = cmd.Run()227 err = cmd.Run()
226 return stderrBuf.String(), err228 return stderrBuf.String(), err
227}229}
228230
229func (e *manualEnviron) Destroy() error {231func (e *manualEnviron) Destroy() error {
232 script := `
233set -x
234pkill -%d jujud && exit
235stop juju-db
236rm -f /etc/init/juju*
237rm -f /etc/rsyslog.d/*juju*
238rm -fr %s %s
239exit 0
240`
241 script = fmt.Sprintf(
242 script,
243 terminationworker.TerminationSignal,
244 utils.ShQuote(agent.DefaultDataDir),
245 utils.ShQuote(agent.DefaultLogDir),
246 )
230 stderr, err := runSSHCommand(247 stderr, err := runSSHCommand(
231 "ubuntu@"+e.envConfig().bootstrapHost(),248 "ubuntu@"+e.envConfig().bootstrapHost(),
232 []string{"sudo", "pkill", fmt.Sprintf("-%d", terminationworker.TerminationSignal), "jujud"},249 []string{"sudo", "/bin/bash"}, script,
233 )250 )
234 if err != nil {251 if err != nil {
235 if stderr := strings.TrimSpace(stderr); len(stderr) > 0 {252 if stderr := strings.TrimSpace(stderr); len(stderr) > 0 {
236253
=== 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:22:15 +0000
@@ -84,9 +84,18 @@
84func (s *environSuite) TestDestroy(c *gc.C) {84func (s *environSuite) TestDestroy(c *gc.C) {
85 var resultStderr string85 var resultStderr string
86 var resultErr error86 var resultErr error
87 runSSHCommandTesting := func(host string, command []string) (string, error) {87 runSSHCommandTesting := func(host string, command []string, stdin string) (string, error) {
88 c.Assert(host, gc.Equals, "ubuntu@hostname")88 c.Assert(host, gc.Equals, "ubuntu@hostname")
89 c.Assert(command, gc.DeepEquals, []string{"sudo", "pkill", "-6", "jujud"})89 c.Assert(command, gc.DeepEquals, []string{"sudo", "/bin/bash"})
90 c.Assert(stdin, gc.DeepEquals, `
91set -x
92pkill -6 jujud && exit
93stop juju-db
94rm -f /etc/init/juju*
95rm -f /etc/rsyslog.d/*juju*
96rm -fr '/var/lib/juju' '/var/log/juju'
97exit 0
98`)
90 return resultStderr, resultErr99 return resultStderr, resultErr
91 }100 }
92 s.PatchValue(&runSSHCommand, runSSHCommandTesting)101 s.PatchValue(&runSSHCommand, runSSHCommandTesting)

Subscribers

People subscribed via source and target branches

to status/vote changes: