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
1=== modified file 'cmd/juju/destroyenvironment.go'
2--- cmd/juju/destroyenvironment.go 2014-03-10 20:22:44 +0000
3+++ cmd/juju/destroyenvironment.go 2014-03-26 22:25:49 +0000
4@@ -54,6 +54,11 @@
5 }
6 environ, err := environs.NewFromName(c.envName, store)
7 if err != nil {
8+ if environs.IsEmptyConfig(err) {
9+ // Delete the .jenv file and call it done.
10+ ctx.Infof("removing empty environment file")
11+ return environs.DestroyInfo(c.envName, store)
12+ }
13 return err
14 }
15 if !c.assumeYes {
16
17=== modified file 'cmd/juju/destroyenvironment_test.go'
18--- cmd/juju/destroyenvironment_test.go 2014-03-24 10:42:51 +0000
19+++ cmd/juju/destroyenvironment_test.go 2014-03-26 22:25:49 +0000
20@@ -70,6 +70,16 @@
21 c.Assert(err, jc.Satisfies, errors.IsNotFoundError)
22 }
23
24+func (s *destroyEnvSuite) TestDestroyEnvironmentCommandEmptyJenv(c *gc.C) {
25+ _, err := s.ConfigStore.CreateInfo("emptyenv")
26+ c.Assert(err, gc.IsNil)
27+
28+ context, err := coretesting.RunCommand(c, new(DestroyEnvironmentCommand), []string{"-e", "emptyenv"})
29+ c.Assert(err, gc.IsNil)
30+
31+ c.Assert(coretesting.Stderr(context), gc.Equals, "removing empty environment file\n")
32+}
33+
34 func (s *destroyEnvSuite) TestDestroyEnvironmentCommandBroken(c *gc.C) {
35 oldinfo, err := s.ConfigStore.ReadInfo("dummyenv")
36 c.Assert(err, gc.IsNil)
37
38=== modified file 'environs/open.go'
39--- environs/open.go 2014-03-12 10:59:17 +0000
40+++ environs/open.go 2014-03-26 22:25:49 +0000
41@@ -46,6 +46,17 @@
42 ConfigFromEnvirons
43 )
44
45+// EmptyConfig indicates the .jenv file is empty.
46+type EmptyConfig struct {
47+ error
48+}
49+
50+// IsEmptyConfig reports whether err is a EmptyConfig.
51+func IsEmptyConfig(err error) bool {
52+ _, ok := err.(EmptyConfig)
53+ return ok
54+}
55+
56 // ConfigForName returns the configuration for the environment with
57 // the given name from the default environments file. If the name is
58 // blank, the default environment will be used. If the configuration
59@@ -70,7 +81,7 @@
60 info, err := store.ReadInfo(name)
61 if err == nil {
62 if len(info.BootstrapConfig()) == 0 {
63- return nil, ConfigFromNowhere, fmt.Errorf("environment has no bootstrap configuration data")
64+ return nil, ConfigFromNowhere, EmptyConfig{fmt.Errorf("environment has no bootstrap configuration data")}
65 }
66 logger.Debugf("ConfigForName found bootstrap config %#v", info.BootstrapConfig())
67 cfg, err := config.New(config.NoDefaults, info.BootstrapConfig())

Subscribers

People subscribed via source and target branches

to status/vote changes: