launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #15099
[Merge] lp:~rvb/juju-core/mpv-envsetup into lp:~maas-maintainers/juju-core/maas-provider-skeleton
Raphaël Badin has proposed merging lp:~rvb/juju-core/mpv-envsetup into lp:~maas-maintainers/juju-core/maas-provider-skeleton with lp:~jtv/juju-core/mpv-config as a prerequisite.
Commit message:
Add a gomaasapi.MAASObject in the environment and initialize it when the config is set.
Requested reviews:
MAAS Maintainers (maas-maintainers)
For more details, see:
https://code.launchpad.net/~rvb/juju-core/mpv-envsetup/+merge/146655
I used the same pattern as the ec2 provider here: changing the _MAASServerUnlocked object is protected by the ecfgMutex mutex.
--
https://code.launchpad.net/~rvb/juju-core/mpv-envsetup/+merge/146655
Your team MAAS Maintainers is requested to review the proposed merge of lp:~rvb/juju-core/mpv-envsetup into lp:~maas-maintainers/juju-core/maas-provider-skeleton.
=== modified file 'environs/maas/environ.go'
--- environs/maas/environ.go 2013-02-05 15:48:22 +0000
+++ environs/maas/environ.go 2013-02-05 15:48:22 +0000
@@ -2,6 +2,7 @@
import (
"errors"
+ "launchpad.net/gomaasapi"
"launchpad.net/juju-core/environs"
"launchpad.net/juju-core/environs/config"
"launchpad.net/juju-core/log"
@@ -16,7 +17,8 @@
// ecfgMutext protects the *Unlocked fields below.
ecfgMutex sync.Mutex
- ecfgUnlocked *maasEnvironConfig
+ ecfgUnlocked *maasEnvironConfig
+ _MAASServerUnlocked gomaasapi.MAASObject
}
var _ environs.Environ = (*maasEnviron)(nil)
@@ -72,6 +74,12 @@
env.name = cfg.Name()
env.ecfgUnlocked = ecfg
+ authClient, err := gomaasapi.NewAuthenticatedClient(ecfg.MAASServer(), ecfg.MAASOAuth())
+ if err != nil {
+ return err
+ }
+ env._MAASServerUnlocked = gomaasapi.NewMAAS(*authClient)
+
return nil
}
=== added file 'environs/maas/environ_test.go'
--- environs/maas/environ_test.go 1970-01-01 00:00:00 +0000
+++ environs/maas/environ_test.go 2013-02-05 15:48:22 +0000
@@ -0,0 +1,54 @@
+package maas
+
+import (
+ . "launchpad.net/gocheck"
+ "launchpad.net/gomaasapi"
+ "launchpad.net/juju-core/environs/config"
+)
+
+type EnvironTest struct{}
+
+var _ = Suite(new(EnvironTest))
+
+func getTestConfig(name, server, oauth, secret string) *config.Config {
+ ecfg, err := newConfig(map[string]interface{}{
+ "name": name,
+ "maas-server": server,
+ "maas-oauth": oauth,
+ "admin-secret": secret,
+ })
+ if err != nil {
+ panic(err)
+ }
+ return ecfg.Config
+}
+
+func (EnvironTest) TestSetConfigUpdatesConfig(c *C) {
+ cfg := getTestConfig("test env", "maas2.example.com", "a:b:c", "secret")
+ env, err := NewEnviron(cfg)
+ c.Check(err, IsNil)
+ c.Check(env.name, Equals, "test env")
+
+ anotherName := "another name"
+ anotherServer := "maas.example.com"
+ anotherOauth := "c:d:e"
+ anotherSecret := "secret2"
+ cfg2 := getTestConfig(anotherName, anotherServer, anotherOauth, anotherSecret)
+ errSetConfig := env.SetConfig(cfg2)
+ c.Check(errSetConfig, IsNil)
+ c.Check(env.name, Equals, anotherName)
+ authClient, _ := gomaasapi.NewAuthenticatedClient(anotherServer, anotherOauth)
+ maas := gomaasapi.NewMAAS(*authClient)
+ MAASServer := env._MAASServerUnlocked
+ c.Check(MAASServer, DeepEquals, maas)
+}
+
+func (EnvironTest) TestNewEnvironSetsConfig(c *C) {
+ name := "test env"
+ cfg := getTestConfig(name, "maas.example.com", "a:b:c", "secret")
+
+ env, err := NewEnviron(cfg)
+
+ c.Check(err, IsNil)
+ c.Check(env.name, Equals, name)
+}
Follow ups