Merge lp:~thumper/juju-core/error-on-empty-jenv-file into lp:~go-bot/juju-core/trunk

Proposed by Tim Penhey
Status: Merged
Approved by: Tim Penhey
Approved revision: no longer in the source branch.
Merged at revision: 2491
Proposed branch: lp:~thumper/juju-core/error-on-empty-jenv-file
Merge into: lp:~go-bot/juju-core/trunk
Diff against target: 67 lines (+27/-1)
3 files modified
cmd/juju/destroyenvironment.go (+5/-0)
cmd/juju/destroyenvironment_test.go (+10/-0)
environs/open.go (+12/-1)
To merge this branch: bzr merge lp:~thumper/juju-core/error-on-empty-jenv-file
Reviewer Review Type Date Requested Status
Juju Engineering Pending
Review via email: mp+212960@code.launchpad.net

Commit message

Have destroy-environment handle empty .jenv file

Have a particular error raised for empty environment
files, that we get when there is an emtpy .jenv file.

If we have an empty file, we currently get this output:

tim@jake:~$ touch .juju/environments/testlocal.jenv
tim@jake:~$ juju status
ERROR Unable to connect to environment "testlocal".
Please check your credentials or use 'juju bootstrap' to create a new environment.

Error details:
environment is not bootstrapped

tim@jake:~$ juju bootstrap
WARNING ignoring environments.yaml: using bootstrap config in file "/home/tim/.juju/environments/testlocal.jenv"
ERROR environment has no bootstrap configuration data

I think this is reasonable, however we also used to get the
error when trying to destroy the environment. Now we get this:

tim@jake:~$ juju destroy-environment -y testlocal
removing empty environment file

https://codereview.appspot.com/80950044/

Description of the change

Have destroy-environment handle empty .jenv file

Have a particular error raised for empty environment
files, that we get when there is an emtpy .jenv file.

If we have an empty file, we currently get this output:

tim@jake:~$ touch .juju/environments/testlocal.jenv
tim@jake:~$ juju status
ERROR Unable to connect to environment "testlocal".
Please check your credentials or use 'juju bootstrap' to create a new environment.

Error details:
environment is not bootstrapped

tim@jake:~$ juju bootstrap
WARNING ignoring environments.yaml: using bootstrap config in file "/home/tim/.juju/environments/testlocal.jenv"
ERROR environment has no bootstrap configuration data

I think this is reasonable, however we also used to get the
error when trying to destroy the environment. Now we get this:

tim@jake:~$ juju destroy-environment -y testlocal
removing empty environment file

https://codereview.appspot.com/80950044/

To post a comment you must log in.
Revision history for this message
Tim Penhey (thumper) wrote :
Download full text (4.1 KiB)

Reviewers: mp+212960_code.launchpad.net,

Message:
Please take a look.

Description:
Have destroy-environment handle empty .jenv file

Have a particular error raised for empty environment
files, that we get when there is an emtpy .jenv file.

If we have an empty file, we currently get this output:

tim@jake:~$ touch .juju/environments/testlocal.jenv
tim@jake:~$ juju status
ERROR Unable to connect to environment "testlocal".
Please check your credentials or use 'juju bootstrap' to create a new
environment.

Error details:
environment is not bootstrapped

tim@jake:~$ juju bootstrap
WARNING ignoring environments.yaml: using bootstrap config in file
"/home/tim/.juju/environments/testlocal.jenv"
ERROR environment has no bootstrap configuration data

I think this is reasonable, however we also used to get the
error when trying to destroy the environment. Now we get this:

tim@jake:~$ juju destroy-environment -y testlocal
removing empty environment file

https://code.launchpad.net/~thumper/juju-core/error-on-empty-jenv-file/+merge/212960

(do not edit description out of merge proposal)

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

Affected files (+29, -1 lines):
   A [revision details]
   M cmd/juju/destroyenvironment.go
   M cmd/juju/destroyenvironment_test.go
   M environs/open.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-20140326171935-rwmkmlytkkvq26d6
+New revision: <email address hidden>

Index: environs/open.go
=== modified file 'environs/open.go'
--- environs/open.go 2014-03-12 10:59:17 +0000
+++ environs/open.go 2014-03-26 22:21:59 +0000
@@ -46,6 +46,17 @@
   ConfigFromEnvirons
  )

+// EmptyConfig indicates the .jenv file is empty.
+type EmptyConfig struct {
+ error
+}
+
+// IsEmptyConfig reports whether err is a EmptyConfig.
+func IsEmptyConfig(err error) bool {
+ _, ok := err.(EmptyConfig)
+ return ok
+}
+
  // ConfigForName returns the configuration for the environment with
  // the given name from the default environments file. If the name is
  // blank, the default environment will be used. If the configuration
@@ -70,7 +81,7 @@
    info, err := store.ReadInfo(name)
    if err == nil {
     if len(info.BootstrapConfig()) == 0 {
- return nil, ConfigFromNowhere, fmt.Errorf("environment has no
bootstrap configuration data")
+ return nil, ConfigFromNowhere, EmptyConfig{fmt.Errorf("environment has
no bootstrap configuration data")}
     }
     logger.Debugf("ConfigForName found bootstrap config %#v",
info.BootstrapConfig())
     cfg, err := config.New(config.NoDefaults, info.BootstrapConfig())

Index: cmd/juju/destroyenvironment.go
=== modified file 'cmd/juju/destroyenvironment.go'
--- cmd/juju/destroyenvironment.go 2014-03-10 20:22:44 +0000
+++ cmd/juju/destroyenvironment.go 2014-03-26 22:21:59 +0000
@@ -54,6 +54,11 @@
   }
   environ, err := environs.NewFromName(c.envName, store)
   if err != nil {
+ if environs.IsEmptyConfig(err) {
+ // Delete the .jenv file and call it done.
+ ctx.Infof("removing empty environ...

Read more...

Revision history for this message
William Reade (fwereade) wrote :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'cmd/juju/destroyenvironment.go'
--- cmd/juju/destroyenvironment.go 2014-03-10 20:22:44 +0000
+++ cmd/juju/destroyenvironment.go 2014-03-26 22:25:49 +0000
@@ -54,6 +54,11 @@
54 }54 }
55 environ, err := environs.NewFromName(c.envName, store)55 environ, err := environs.NewFromName(c.envName, store)
56 if err != nil {56 if err != nil {
57 if environs.IsEmptyConfig(err) {
58 // Delete the .jenv file and call it done.
59 ctx.Infof("removing empty environment file")
60 return environs.DestroyInfo(c.envName, store)
61 }
57 return err62 return err
58 }63 }
59 if !c.assumeYes {64 if !c.assumeYes {
6065
=== modified file 'cmd/juju/destroyenvironment_test.go'
--- cmd/juju/destroyenvironment_test.go 2014-03-24 10:42:51 +0000
+++ cmd/juju/destroyenvironment_test.go 2014-03-26 22:25:49 +0000
@@ -70,6 +70,16 @@
70 c.Assert(err, jc.Satisfies, errors.IsNotFoundError)70 c.Assert(err, jc.Satisfies, errors.IsNotFoundError)
71}71}
7272
73func (s *destroyEnvSuite) TestDestroyEnvironmentCommandEmptyJenv(c *gc.C) {
74 _, err := s.ConfigStore.CreateInfo("emptyenv")
75 c.Assert(err, gc.IsNil)
76
77 context, err := coretesting.RunCommand(c, new(DestroyEnvironmentCommand), []string{"-e", "emptyenv"})
78 c.Assert(err, gc.IsNil)
79
80 c.Assert(coretesting.Stderr(context), gc.Equals, "removing empty environment file\n")
81}
82
73func (s *destroyEnvSuite) TestDestroyEnvironmentCommandBroken(c *gc.C) {83func (s *destroyEnvSuite) TestDestroyEnvironmentCommandBroken(c *gc.C) {
74 oldinfo, err := s.ConfigStore.ReadInfo("dummyenv")84 oldinfo, err := s.ConfigStore.ReadInfo("dummyenv")
75 c.Assert(err, gc.IsNil)85 c.Assert(err, gc.IsNil)
7686
=== modified file 'environs/open.go'
--- environs/open.go 2014-03-12 10:59:17 +0000
+++ environs/open.go 2014-03-26 22:25:49 +0000
@@ -46,6 +46,17 @@
46 ConfigFromEnvirons46 ConfigFromEnvirons
47)47)
4848
49// EmptyConfig indicates the .jenv file is empty.
50type EmptyConfig struct {
51 error
52}
53
54// IsEmptyConfig reports whether err is a EmptyConfig.
55func IsEmptyConfig(err error) bool {
56 _, ok := err.(EmptyConfig)
57 return ok
58}
59
49// ConfigForName returns the configuration for the environment with60// ConfigForName returns the configuration for the environment with
50// the given name from the default environments file. If the name is61// the given name from the default environments file. If the name is
51// blank, the default environment will be used. If the configuration62// blank, the default environment will be used. If the configuration
@@ -70,7 +81,7 @@
70 info, err := store.ReadInfo(name)81 info, err := store.ReadInfo(name)
71 if err == nil {82 if err == nil {
72 if len(info.BootstrapConfig()) == 0 {83 if len(info.BootstrapConfig()) == 0 {
73 return nil, ConfigFromNowhere, fmt.Errorf("environment has no bootstrap configuration data")84 return nil, ConfigFromNowhere, EmptyConfig{fmt.Errorf("environment has no bootstrap configuration data")}
74 }85 }
75 logger.Debugf("ConfigForName found bootstrap config %#v", info.BootstrapConfig())86 logger.Debugf("ConfigForName found bootstrap config %#v", info.BootstrapConfig())
76 cfg, err := config.New(config.NoDefaults, info.BootstrapConfig())87 cfg, err := config.New(config.NoDefaults, info.BootstrapConfig())

Subscribers

People subscribed via source and target branches

to status/vote changes: