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

Proposed by Nate Finch
Status: Rejected
Rejected by: William Reade
Proposed branch: lp:~natefinch/juju-core/juju-core
Merge into: lp:~go-bot/juju-core/trunk
Diff against target: 142 lines (+64/-0) (has conflicts)
5 files modified
juju/api.go (+31/-0)
juju/apiconn_test.go (+20/-0)
juju/export_test.go (+5/-0)
scripts/win-installer/setup.iss (+4/-0)
version/version.go (+4/-0)
Text conflict in juju/api.go
Text conflict in juju/export_test.go
Text conflict in scripts/win-installer/setup.iss
Text conflict in version/version.go
To merge this branch: bzr merge lp:~natefinch/juju-core/juju-core
Reviewer Review Type Date Requested Status
Juju Engineering Pending
Review via email: mp+178288@code.launchpad.net

Description of the change

Show same error for no default env

When you run juju with no default config file, it should give the same error regardless of the command you're running. To do that, I have ReadEnviron wrap the file not found error it used to return in a new type, so that further up the stack we can check for it, and notify the user appropriately.

https://codereview.appspot.com/12347044/

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

Note, this is a proposed fix for https://bugs.launchpad.net/juju-core/+bug/1154938 "juju status should give the same help as juju bootstrap"

Revision history for this message
Dimiter Naydenov (dimitern) wrote :

LGTM, apart from a few trivial suggestions below

https://codereview.appspot.com/12347044/diff/1/cmd/juju/init.go
File cmd/juju/init.go (right):

https://codereview.appspot.com/12347044/diff/1/cmd/juju/init.go#newcode8
cmd/juju/init.go:8: "launchpad.net/gnuflag"
While you're at it, please reformat the imports here:

"fmt"

"launchpad.net/gnuflag"

"launchpad.net/juju-core/..."

We accepted this style of formatting imports some time ago and we should
take the time to fix old code to use the new convention: 1) standard
pacakges, 2) third-parties, 3) juju-core stuff, each group separated
with a blank line from the previous.

https://codereview.appspot.com/12347044/diff/1/environs/config.go
File environs/config.go (right):

https://codereview.appspot.com/12347044/diff/1/environs/config.go#newcode141
environs/config.go:141: if path == "" && os.IsNotExist(err) {
I don't think you need to check path == "" here, because environsPath
will actually handle that and set it to the default.

https://codereview.appspot.com/12347044/diff/1/errors/errors.go
File errors/errors.go (right):

https://codereview.appspot.com/12347044/diff/1/errors/errors.go#newcode68
errors/errors.go:68: // NoEnvError indicates the default environment
config file is missing
s/missing/missing./

https://codereview.appspot.com/12347044/diff/1/errors/errors.go#newcode73
errors/errors.go:73: // IsNoEnv returns true if err is a NoEnvError
By convention, such functions we usually document as "F returns
if/whether/etc ...", no need to say it returns true. Also there should
be a full stop at the end.

https://codereview.appspot.com/12347044/

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

Reviewers: mp+178288_code.launchpad.net, dimitern,

Message:
Fixed dimitern's suggestions, also took rogpeppe's suggestions to remove
the changes to cmd.go and put the error check in each command instead.

Description:
Show same error for no default env

When you run juju with no default config file, it should give the same
error regardless of the command you're running. To do that, I have
ReadEnviron wrap the file not found error it used to return in a new
type, so that further up the stack we can check for it, and notify the
user appropriately.

https://code.launchpad.net/~natefinch/juju-core/juju-core/+merge/178288

(do not edit description out of merge proposal)

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

Affected files:
   A [revision details]
   M cmd/juju/addmachine.go
   M cmd/juju/addrelation.go
   M cmd/juju/addunit.go
   M cmd/juju/bootstrap.go
   M cmd/juju/constraints.go
   M cmd/juju/deploy.go
   M cmd/juju/destroyenvironment.go
   M cmd/juju/destroymachine.go
   M cmd/juju/destroyrelation.go
   M cmd/juju/destroyservice.go
   M cmd/juju/destroyunit.go
   M cmd/juju/environment.go
   M cmd/juju/environmentcommand.go
   M cmd/juju/expose.go
   M cmd/juju/get.go
   M cmd/juju/init.go
   M cmd/juju/publish.go
   M cmd/juju/resolved.go
   M cmd/juju/scp.go
   M cmd/juju/set.go
   M cmd/juju/ssh.go
   M cmd/juju/status.go
   M cmd/juju/unexpose.go
   M cmd/juju/upgradecharm.go
   M cmd/juju/upgradejuju.go
   M environs/config.go
   M errors/errors.go

Revision history for this message
John A Meinel (jameinel) wrote :

Before you get too far, changing all the various places that import should probably be done in a different branch (so it is easier to review).

The other change is that:

 gc "launchpad.net/gocheck"

Is the "standard" way to import gocheck now, because otherwise 'gocheck' everywhere ends up being a bit too verbose.

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

Thanks, I talked to Roger and Dimiter about that on irc just now, too. I'll
change these places over to gc, but definitely should be a separate branch
for the more sweeping changes.

On Thu, Aug 8, 2013 at 1:55 PM, John A Meinel <email address hidden>wrote:

> Before you get too far, changing all the various places that import should
> probably be done in a different branch (so it is easier to review).
>
> The other change is that:
>
> gc "launchpad.net/gocheck"
>
> Is the "standard" way to import gocheck now, because otherwise 'gocheck'
> everywhere ends up being a bit too verbose.
>
> --
> https://code.launchpad.net/~natefinch/juju-core/juju-core/+merge/178288
> You are the owner of lp:~natefinch/juju-core/juju-core.
>

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'juju/api.go'
2--- juju/api.go 2014-04-22 15:00:21 +0000
3+++ juju/api.go 2014-04-24 19:52:39 +0000
4@@ -193,7 +193,15 @@
5 logger.Debugf("no cached API connection settings found")
6 }
7 try.Start(func(stop <-chan struct{}) (io.Closer, error) {
8+<<<<<<< TREE
9 return apiConfigConnect(info, envs, envName, apiOpen, stop, delay)
10+=======
11+ cfg, err := getConfig(info, envs, envName)
12+ if err != nil {
13+ return nil, err
14+ }
15+ return apiConfigConnect(cfg, stop, delay)
16+>>>>>>> MERGE-SOURCE
17 })
18 try.Close()
19 val0, err := try.Result()
20@@ -280,6 +288,7 @@
21 // its endpoint. It only starts the attempt after the given delay,
22 // to allow the faster apiInfoConnect to hopefully succeed first.
23 // It returns nil if there was no configuration information found.
24+<<<<<<< TREE
25 func apiConfigConnect(info configstore.EnvironInfo, envs *environs.Environs, envName string, apiOpen apiOpenFunc, stop <-chan struct{}, delay time.Duration) (apiState, error) {
26 var cfg *config.Config
27 var err error
28@@ -293,6 +302,9 @@
29 } else {
30 return nil, errors.NotFoundf("environment %q", envName)
31 }
32+=======
33+func apiConfigConnect(cfg *config.Config, stop <-chan struct{}, delay time.Duration) (apiState, error) {
34+>>>>>>> MERGE-SOURCE
35 select {
36 case <-time.After(delay):
37 case <-stop:
38@@ -314,6 +326,25 @@
39 return apiStateCachedInfo{st, apiInfo}, nil
40 }
41
42+// getConfig looks for configuration info on the given environment
43+func getConfig(info configstore.EnvironInfo, envs *environs.Environs, envName string) (*config.Config, error) {
44+ if info != nil && len(info.BootstrapConfig()) > 0 {
45+ cfg, err := config.New(config.NoDefaults, info.BootstrapConfig())
46+ if err != nil {
47+ logger.Warningf("failed to parse bootstrap-config: %v", err)
48+ }
49+ return cfg, err
50+ }
51+ if envs != nil {
52+ cfg, err := envs.Config(envName)
53+ if err != nil && !errors.IsNotFoundError(err) {
54+ logger.Warningf("failed to get config for environment %q: %v", envName, err)
55+ }
56+ return cfg, err
57+ }
58+ return nil, errors.NotFoundf("environment %q", envName)
59+}
60+
61 func environAPIInfo(environ environs.Environ) (*api.Info, error) {
62 _, info, err := environ.StateInfo()
63 if err != nil {
64
65=== modified file 'juju/apiconn_test.go'
66--- juju/apiconn_test.go 2014-04-24 02:27:38 +0000
67+++ juju/apiconn_test.go 2014-04-24 19:52:39 +0000
68@@ -299,6 +299,26 @@
69 }
70 }
71
72+type badBootstrapInfo struct {
73+ configstore.EnvironInfo
74+}
75+
76+// BootstrapConfig is returned as a map with real content, but the content
77+// isn't actually valid configuration, causing config.New to fail
78+func (m *badBootstrapInfo) BootstrapConfig() map[string]interface{} {
79+ return map[string]interface{}{"something": "else"}
80+}
81+
82+func (s *NewAPIClientSuite) TestBadConfigDoesntPanic(c *gc.C) {
83+ badInfo := &badBootstrapInfo{}
84+ cfg, err := juju.GetConfig(badInfo, nil, "test")
85+ // The specific error we get depends on what key is invalid, which is a
86+ // bit spurious, but what we care about is that we didn't get a panic,
87+ // but instead got an error
88+ c.Assert(err, gc.ErrorMatches, ".*expected.*got nothing")
89+ c.Assert(cfg, gc.IsNil)
90+}
91+
92 func setEndpointAddress(c *gc.C, store configstore.Storage, envName string, addr string) {
93 // Populate the environment's info with an endpoint
94 // with a known address.
95
96=== modified file 'juju/export_test.go'
97--- juju/export_test.go 2014-04-16 08:07:27 +0000
98+++ juju/export_test.go 2014-04-24 19:52:39 +0000
99@@ -7,6 +7,11 @@
100
101 var (
102 ProviderConnectDelay = &providerConnectDelay
103+<<<<<<< TREE
104+=======
105+ NewAPIFromStore = newAPIFromStore
106+ GetConfig = getConfig
107+>>>>>>> MERGE-SOURCE
108 )
109
110 type APIState apiState
111
112=== modified file 'scripts/win-installer/setup.iss'
113--- scripts/win-installer/setup.iss 2014-04-15 17:15:47 +0000
114+++ scripts/win-installer/setup.iss 2014-04-24 19:52:39 +0000
115@@ -2,7 +2,11 @@
116 ; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
117
118 #define MyAppName "Juju"
119+<<<<<<< TREE
120 #define MyAppVersion "1.19.1"
121+=======
122+#define MyAppVersion "1.18.2"
123+>>>>>>> MERGE-SOURCE
124 #define MyAppPublisher "Canonical, Ltd"
125 #define MyAppURL "http://juju.ubuntu.com/"
126 #define MyAppExeName "juju.exe"
127
128=== modified file 'version/version.go'
129--- version/version.go 2014-04-15 17:15:47 +0000
130+++ version/version.go 2014-04-24 19:52:39 +0000
131@@ -23,7 +23,11 @@
132 // The presence and format of this constant is very important.
133 // The debian/rules build recipe uses this value for the version
134 // number of the release package.
135+<<<<<<< TREE
136 const version = "1.19.1"
137+=======
138+const version = "1.18.2"
139+>>>>>>> MERGE-SOURCE
140
141 // lsbReleaseFile is the name of the file that is read in order to determine
142 // the release version of ubuntu.

Subscribers

People subscribed via source and target branches

to status/vote changes: