Merge lp:~rvb/juju-core/fix-maas-pvd-conf into lp:~juju/juju-core/trunk

Proposed by Raphaël Badin
Status: Rejected
Rejected by: Dimiter Naydenov
Proposed branch: lp:~rvb/juju-core/fix-maas-pvd-conf
Merge into: lp:~juju/juju-core/trunk
Diff against target: 45 lines (+26/-1)
2 files modified
environs/maas/environprovider.go (+5/-1)
environs/maas/environprovider_test.go (+21/-0)
To merge this branch: bzr merge lp:~rvb/juju-core/fix-maas-pvd-conf
Reviewer Review Type Date Requested Status
Dimiter Naydenov (community) Approve
Review via email: mp+158938@code.launchpad.net

Commit message

Fix maasEnvironProvider.Open() so that it returns a nil object when it fails.

Description of the change

[Note: I did not use rietveld because I ran into errors like: http://paste.ubuntu.com/5710470/ when trying to use lbox propose]

This branch fixes a problem we saw happening in the MAAS lab while testing the MAAS provider. The symptom was that, after having installed the bootstrap node ok, Juju was unable to deploy any service. The error found in the bootstrap node's logs: http://paste.ubuntu.com/5709878/.

The problem is that, from this code in cmd/jujud/upgrade.go: http://paste.ubuntu.com/5710182/, environs/maas/environ.go:SetConfig ends up being called on a nil object. After investigating the problem, I found that environs/maas/environprovider.go:Open(), when the config is invalid, returns a interface that has a nil value but a non-nil type (http://golang.org/doc/faq#nil_error) and thus, in cmd/jujud/upgrade.go (see snippet above), 'environ.SetConfig(cfg)' gets called on a nil 'environ'.

To post a comment you must log in.
Revision history for this message
Dimiter Naydenov (dimitern) wrote :

LGTM

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

[0] env, err := NewEnviron(cfg)

This deserves a comment. But otherwise LGTM trivial.

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

Due to the problems rvba had with lbox, he asked to land this for him.
It was proposed as https://codereview.appspot.com/8772043
So I'm setting this as Rejected and the one above will be merged.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'environs/maas/environprovider.go'
2--- environs/maas/environprovider.go 2013-04-12 09:45:01 +0000
3+++ environs/maas/environprovider.go 2013-04-15 14:31:30 +0000
4@@ -19,7 +19,11 @@
5
6 func (maasEnvironProvider) Open(cfg *config.Config) (environs.Environ, error) {
7 log.Debugf("environs/maas: opening environment %q.", cfg.Name())
8- return NewEnviron(cfg)
9+ env, err := NewEnviron(cfg)
10+ if err != nil {
11+ return nil, err
12+ }
13+ return env, nil
14 }
15
16 // Boilerplate config YAML. Don't mess with the indentation or add newlines!
17
18=== modified file 'environs/maas/environprovider_test.go'
19--- environs/maas/environprovider_test.go 2013-04-11 10:33:21 +0000
20+++ environs/maas/environprovider_test.go 2013-04-15 14:31:30 +0000
21@@ -92,3 +92,24 @@
22 c.Assert(err, IsNil)
23 c.Check(privateAddress, Equals, hostname)
24 }
25+
26+func (suite *EnvironProviderSuite) TestOpenReturnsNilInterfaceUponFailure(c *C) {
27+ testJujuHome := c.MkDir()
28+ defer config.SetJujuHome(config.SetJujuHome(testJujuHome))
29+ const oauth = "wrongly-formatted-oauth-string"
30+ attrs := map[string]interface{}{
31+ "maas-oauth": oauth,
32+ "maas-server": "http://maas.example.com/maas/",
33+ "name": "wheee",
34+ "type": "maas",
35+ "authorized-keys": "I-am-not-a-real-key",
36+ }
37+ config, err := config.New(attrs)
38+ c.Assert(err, IsNil)
39+ env, err := suite.environ.Provider().Open(config)
40+ // When Open() fails (i.e. returns a non-nil error), it returns an
41+ // environs.Environ interface object with a nil value and a nil
42+ // type.
43+ c.Check(env, Equals, nil)
44+ c.Check(err, ErrorMatches, ".*malformed maas-oauth.*")
45+}

Subscribers

People subscribed via source and target branches