Merge lp://staging/~natefinch/juju-core/022-destroyer into lp://staging/~go-bot/juju-core/trunk

Proposed by Nate Finch
Status: Merged
Approved by: Nate Finch
Approved revision: no longer in the source branch.
Merged at revision: 2022
Proposed branch: lp://staging/~natefinch/juju-core/022-destroyer
Merge into: lp://staging/~go-bot/juju-core/trunk
Diff against target: 187 lines (+47/-22)
2 files modified
cmd/juju/cmd_test.go (+15/-12)
cmd/juju/destroyenvironment.go (+32/-10)
To merge this branch: bzr merge lp://staging/~natefinch/juju-core/022-destroyer
Reviewer Review Type Date Requested Status
Juju Engineering Pending
Review via email: mp+191501@code.staging.launchpad.net

Commit message

Destroy environment now requires that you always type the name of the environment you're destroying, it will not use the default or current environment. This is to prevent people from accidentally destroying the wrong environment, since no one really reads the warning messages, and destroy environment is pretty cataclysmic.

Description of the change

Add safety belt to destroy-environment

Destroy-environment is dangerous and we should prevent people from shooting themselves in the foot if at all possible. This change removes the -y flag from destroy-environment and changes the "are you sure?" prompt to force the user to type "destroy <environment_name>". The flag is too easy to pass without ththinking, and the y at the prompt is similarly too easy to type in without the user actually thinking about what they're doing. Forcing them to type the environment name will also ensure they don't accidentally destroy the wrong environment by accident.

https://codereview.appspot.com/14502070/

To post a comment you must log in.
Revision history for this message
Nate Finch (natefinch) wrote :
Download full text (7.0 KiB)

Reviewers: mp+191501_code.launchpad.net,

Message:
Please take a look.

Description:
Add safety belt to destroy-environment

Destroy-environment is dangerous and we should prevent people from
shooting themselves in the foot if at all possible. This change removes
the -y flag from destroy-environment and changes the "are you sure?"
prompt to force the user to type "destroy <environment_name>". The flag
is too easy to pass without ththinking, and the y at the prompt is
similarly too easy to type in without the user actually thinking about
what they're doing. Forcing them to type the environment name will also
ensure they don't accidentally destroy the wrong environment by
accident.

https://code.launchpad.net/~natefinch/juju-core/022-destroyer/+merge/191501

(do not edit description out of merge proposal)

Please review this at https://codereview.appspot.com/14502070/

Affected files (+33, -44 lines):
   A [revision details]
   M cmd/juju/cmd_test.go
   M cmd/juju/destroyenvironment.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-20131016154732-13eh4uj8dhsfc1mw
+New revision: <email address hidden>

Index: cmd/juju/cmd_test.go
=== modified file 'cmd/juju/cmd_test.go'
--- cmd/juju/cmd_test.go 2013-10-10 23:17:43 +0000
+++ cmd/juju/cmd_test.go 2013-10-16 20:26:42 +0000
@@ -160,6 +160,10 @@
  }

  func (*CmdSuite) TestDestroyEnvironmentCommand(c *gc.C) {
+ var stdin bytes.Buffer
+ ctx := cmd.DefaultContext()
+ ctx.Stdin = &stdin
+
   // Prepare the environment so we can destroy it.
   store, err := configstore.Default()
   c.Assert(err, gc.IsNil)
@@ -171,7 +175,8 @@
   c.Assert(err, gc.IsNil)

   // normal destroy
- opc, errc := runCommand(nullContext(),
new(DestroyEnvironmentCommand), "--yes")
+ stdin.WriteString("destroy peckham")
+ opc, errc := runCommand(ctx, new(DestroyEnvironmentCommand))
   c.Check(<-errc, gc.IsNil)
   c.Check((<-opc).(dummy.OpDestroy).Env, gc.Equals, "peckham")

@@ -183,26 +188,13 @@
   c.Assert(err, gc.IsNil)

   // destroy with broken environment
- opc, errc = runCommand(nullContext(),
new(DestroyEnvironmentCommand), "--yes", "-e", "brokenenv")
+ stdin.WriteString("destroy brokenenv")
+ opc, errc = runCommand(ctx,
new(DestroyEnvironmentCommand), "-e", "brokenenv")
   c.Check(<-opc, gc.IsNil)
   c.Check(<-errc, gc.ErrorMatches, "dummy.Destroy is broken")
   c.Check(<-opc, gc.IsNil)
  }

-func (*CmdSuite) TestDestroyEnvironmentCommandConfirmationFlag(c *gc.C) {
- com := new(DestroyEnvironmentCommand)
- c.Check(coretesting.InitCommand(com, nil), gc.IsNil)
- c.Check(com.assumeYes, gc.Equals, false)
-
- com = new(DestroyEnvironmentCommand)
- c.Check(coretesting.InitCommand(com, []string{"-y"}), gc.IsNil)
- c.Check(com.assumeYes, gc.Equals, true)
-
- com = new(DestroyEnvironmentCommand)
- c.Check(coretesting.InitCommand(com, []string{"--yes"}), gc.IsNil)
- c.Check(com.assumeYes, gc.Equals, true)
-}
-
  func (*CmdSuite) TestDestroyEnvironmentCommandConfirmation(c *gc.C) {
   var stdin, stdout bytes.Buffer
   ctx := cmd.DefaultContex...

Read more...

Revision history for this message
Roger Peppe (rogpeppe) wrote :

On 2013/10/16 20:50:46, nate.finch wrote:
> Please take a look.

Please no!

I want to be able to use juju easily in scripts. This is
Unix and our target audience are developers and admins. Please
allow us to do dangerous things on the command line.

https://codereview.appspot.com/14502070/

Revision history for this message
Nate Finch (natefinch) wrote :
Revision history for this message
Nate Finch (natefinch) wrote :

I updated the code so that the -y flag is back, but you must always
specify the environment... it'll never take the current or default
environment.

The format of the command is now:

juju destroy-environment <envname> [-y|--yes]

Note, I chose not to use the normal -e environment flag because a flag
implies it's optional (which it's not).

https://codereview.appspot.com/14502070/

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

LGTM

I think this is an overall improvement to the UI. Still scriptable IMO.

https://codereview.appspot.com/14502070/diff/5001/cmd/juju/destroyenvironment.go
File cmd/juju/destroyenvironment.go (right):

https://codereview.appspot.com/14502070/diff/5001/cmd/juju/destroyenvironment.go#newcode54
cmd/juju/destroyenvironment.go:54: scanner :=
bufio.NewScanner(ctx.Stdin)
Just curious, but what benefit do we get over using bufio.NewScanner
over fmt.Fscanln?

https://codereview.appspot.com/14502070/

Revision history for this message
Nate Finch (natefinch) wrote :

On 2013/10/31 22:06:09, thumper wrote:
> LGTM

> I think this is an overall improvement to the UI. Still scriptable
IMO.

https://codereview.appspot.com/14502070/diff/5001/cmd/juju/destroyenvironment.go
> File cmd/juju/destroyenvironment.go (right):

https://codereview.appspot.com/14502070/diff/5001/cmd/juju/destroyenvironment.go#newcode54
> cmd/juju/destroyenvironment.go:54: scanner :=
bufio.NewScanner(ctx.Stdin)
> Just curious, but what benefit do we get over using bufio.NewScanner
over
> fmt.Fscanln?

  fmt.Fscanln actually fails to return the entire string, and returns an
error about no EOL. We were ignoring it, but it bit me when I was
twiddling with the code and tried to get it to read the full line... so
I figured it was better to make the code a good example rather than a
bad example, even if functionally it behaved the same in this particular
case.

https://codereview.appspot.com/14502070/

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
The diff is not available at this time. You can reload the page or download it.

Subscribers

People subscribed via source and target branches

to status/vote changes: