本文整理汇总了Golang中github.com/juju/juju/provider/maas.NewEnviron函数的典型用法代码示例。如果您正苦于以下问题:Golang NewEnviron函数的具体用法?Golang NewEnviron怎么用?Golang NewEnviron使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewEnviron函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestSetConfigUpdatesConfig
func (*environSuite) TestSetConfigUpdatesConfig(c *gc.C) {
origAttrs := coretesting.Attrs{
"server-name": "http://maas2.testing.invalid",
"maas-oauth": "a:b:c",
"admin-secret": "secret",
}
cfg := getSimpleTestConfig(c, origAttrs)
env, err := maas.NewEnviron(cfg)
c.Check(err, jc.ErrorIsNil)
c.Check(env.Config().Name(), gc.Equals, "testenv")
anotherServer := "http://maas.testing.invalid"
anotherOauth := "c:d:e"
anotherSecret := "secret2"
newAttrs := coretesting.Attrs{
"server-name": anotherServer,
"maas-oauth": anotherOauth,
"admin-secret": anotherSecret,
}
cfg2 := getSimpleTestConfig(c, newAttrs)
errSetConfig := env.SetConfig(cfg2)
c.Check(errSetConfig, gc.IsNil)
c.Check(env.Config().Name(), gc.Equals, "testenv")
authClient, _ := gomaasapi.NewAuthenticatedClient(anotherServer, anotherOauth, maas.APIVersion)
maasClient := gomaasapi.NewMAAS(*authClient)
MAASServer := maas.GetMAASClient(env)
c.Check(MAASServer, gc.DeepEquals, maasClient)
}
示例2: TestSetConfigAllowsEmptyFromNilAgentName
func (*environSuite) TestSetConfigAllowsEmptyFromNilAgentName(c *gc.C) {
// bug #1256179 is that when using an older version of Juju (<1.16.2)
// we didn't include maas-agent-name in the database, so it was 'nil'
// in the OldConfig. However, when setting an environment, we would set
// it to "" (because maasModelConfig.Validate ensures it is a 'valid'
// string). We can't create that from NewEnviron or newConfig because
// both of them Validate the contents. 'cmd/juju/model
// SetEnvironmentCommand' instead uses conn.State.ModelConfig() which
// just reads the content of the database into a map, so we just create
// the map ourselves.
// Even though we use 'nil' here, it actually stores it as "" because
// 1.16.2 already validates the value
baseCfg := getSimpleTestConfig(c, coretesting.Attrs{"maas-agent-name": ""})
c.Check(baseCfg.UnknownAttrs()["maas-agent-name"], gc.Equals, "")
env, err := maas.NewEnviron(baseCfg)
c.Assert(err, jc.ErrorIsNil)
provider := env.Provider()
attrs := coretesting.FakeConfig()
// These are attrs we need to make it a valid Config, but would usually
// be set by other infrastructure
attrs["type"] = "maas"
nilCfg, err := config.New(config.NoDefaults, attrs)
c.Assert(err, jc.ErrorIsNil)
validatedConfig, err := provider.Validate(baseCfg, nilCfg)
c.Assert(err, jc.ErrorIsNil)
c.Check(validatedConfig.UnknownAttrs()["maas-agent-name"], gc.Equals, "")
// However, you can't set it to an actual value if you haven't been using a value
valueCfg := getSimpleTestConfig(c, coretesting.Attrs{"maas-agent-name": "agent-name"})
_, err = provider.Validate(valueCfg, nilCfg)
c.Check(err, gc.ErrorMatches, ".*cannot change maas-agent-name.*")
}
示例3: TestBadEndpointMessageNoMAAS
func (s *badEndpointSuite) TestBadEndpointMessageNoMAAS(c *gc.C) {
cfg := getSimpleTestConfig(c, coretesting.Attrs{})
env, err := maas.NewEnviron(s.cloudSpec, cfg)
c.Assert(env, gc.IsNil)
c.Assert(err, gc.ErrorMatches, `could not connect to MAAS controller - check the endpoint is correct \(it normally ends with /MAAS\)`)
c.Assert(err, jc.Satisfies, errors.IsNotSupported)
}
示例4: TestNewEnvironSetsConfig
func (*environSuite) TestNewEnvironSetsConfig(c *gc.C) {
cfg := getSimpleTestConfig(c, nil)
env, err := maas.NewEnviron(cfg)
c.Check(err, jc.ErrorIsNil)
c.Check(env.Config().Name(), gc.Equals, "testenv")
}
示例5: TestBadEndpointMessageWithMAASAndSlash
func (s *badEndpointSuite) TestBadEndpointMessageWithMAASAndSlash(c *gc.C) {
cfg := getSimpleTestConfig(c, coretesting.Attrs{})
s.cloudSpec.Endpoint += "/MAAS/"
env, err := maas.NewEnviron(s.cloudSpec, cfg)
c.Assert(env, gc.IsNil)
c.Assert(err, gc.ErrorMatches, `could not connect to MAAS controller - check the endpoint is correct`)
c.Assert(err, jc.Satisfies, errors.IsNotSupported)
}
示例6: TestNewCloudinitConfigWithFeatureFlag
func (*environSuite) TestNewCloudinitConfigWithFeatureFlag(c *gc.C) {
cfg := getSimpleTestConfig(c, nil)
env, err := maas.NewEnviron(cfg)
c.Assert(err, jc.ErrorIsNil)
cloudcfg, err := maas.NewCloudinitConfig(env, "testing.invalid", "eth0", "quantal")
c.Assert(err, jc.ErrorIsNil)
c.Assert(cloudcfg.SystemUpdate(), jc.IsTrue)
c.Assert(cloudcfg.RunCmds(), jc.DeepEquals, expectedCloudinitConfig)
}
示例7: TestDestroyWithEmptyAgentName
func (*environSuite) TestDestroyWithEmptyAgentName(c *gc.C) {
// Related bug #1256179, comment as above.
baseCfg := getSimpleTestConfig(c, coretesting.Attrs{"maas-agent-name": ""})
env, err := maas.NewEnviron(baseCfg)
c.Assert(err, jc.ErrorIsNil)
err = env.Destroy()
c.Assert(err, gc.ErrorMatches, "unsafe destruction")
}
示例8: TestSetConfigAllowsChangingNilAgentNameToEmptyString
func (*environSuite) TestSetConfigAllowsChangingNilAgentNameToEmptyString(c *gc.C) {
oldCfg := getSimpleTestConfig(c, nil)
newCfgTwo := getSimpleTestConfig(c, coretesting.Attrs{"maas-agent-name": ""})
env, err := maas.NewEnviron(oldCfg)
c.Assert(err, jc.ErrorIsNil)
err = env.SetConfig(newCfgTwo)
c.Assert(err, jc.ErrorIsNil)
c.Check(maas.MAASAgentName(env), gc.Equals, "")
}
示例9: TestNewCloudinitConfigWithDisabledNetworkManagement
func (*environSuite) TestNewCloudinitConfigWithDisabledNetworkManagement(c *gc.C) {
attrs := coretesting.Attrs{
"disable-network-management": true,
}
cfg := getSimpleTestConfig(c, attrs)
env, err := maas.NewEnviron(cfg)
c.Assert(err, jc.ErrorIsNil)
cloudcfg, err := maas.NewCloudinitConfig(env, "testing.invalid", "eth0", "quantal")
c.Assert(err, jc.ErrorIsNil)
c.Assert(cloudcfg.SystemUpdate(), jc.IsTrue)
c.Assert(cloudcfg.RunCmds(), jc.DeepEquals, expectedCloudinitConfig)
}
示例10: TestNewCloudinitConfig
func (*environSuite) TestNewCloudinitConfig(c *gc.C) {
cfg := getSimpleTestConfig(c, nil)
env, err := maas.NewEnviron(cfg)
c.Assert(err, jc.ErrorIsNil)
modifyNetworkScript := maas.RenderEtcNetworkInterfacesScript()
script := expectedCloudinitConfig
script = append(script, modifyNetworkScript)
cloudcfg, err := maas.NewCloudinitConfig(env, "testing.invalid", "quantal")
c.Assert(err, jc.ErrorIsNil)
c.Assert(cloudcfg.SystemUpdate(), jc.IsTrue)
c.Assert(cloudcfg.RunCmds(), jc.DeepEquals, script)
}
示例11: TestSetConfigValidatesFirst
func (*environSuite) TestSetConfigValidatesFirst(c *gc.C) {
// SetConfig() validates the config change and disallows, for example,
// changes in the environment name.
oldCfg := getSimpleTestConfig(c, coretesting.Attrs{"name": "old-name"})
newCfg := getSimpleTestConfig(c, coretesting.Attrs{"name": "new-name"})
env, err := maas.NewEnviron(oldCfg)
c.Assert(err, jc.ErrorIsNil)
// SetConfig() fails, even though both the old and the new config are
// individually valid.
err = env.SetConfig(newCfg)
c.Assert(err, gc.NotNil)
c.Check(err, gc.ErrorMatches, ".*cannot change name.*")
// The old config is still in place. The new config never took effect.
c.Check(env.Config().Name(), gc.Equals, "old-name")
}
示例12: TestNewCloudinitConfigNoFeatureFlag
func (s *environSuite) TestNewCloudinitConfigNoFeatureFlag(c *gc.C) {
cfg := getSimpleTestConfig(c, nil)
env, err := maas.NewEnviron(cfg)
c.Assert(err, jc.ErrorIsNil)
testCase := func(expectedConfig []string) {
cloudcfg, err := maas.NewCloudinitConfig(env, "testing.invalid", "eth0", "quantal")
c.Assert(err, jc.ErrorIsNil)
c.Assert(cloudcfg.SystemUpdate(), jc.IsTrue)
c.Assert(cloudcfg.RunCmds(), jc.DeepEquals, expectedConfig)
}
// First test the default case (address allocation feature flag on).
testCase(expectedCloudinitConfig)
// Now test with the flag off.
s.SetFeatureFlags() // clear the flags.
testCase(expectedCloudinitConfigWithBridge)
}
示例13: TestSetConfigUpdatesConfig
func (*environSuite) TestSetConfigUpdatesConfig(c *gc.C) {
origAttrs := coretesting.Attrs{
"apt-mirror": "http://testing1.invalid",
}
cfg := getSimpleTestConfig(c, origAttrs)
env, err := maas.NewEnviron(getSimpleCloudSpec(), cfg)
c.Check(err, jc.ErrorIsNil)
c.Check(env.Config().Name(), gc.Equals, "testenv")
newAttrs := coretesting.Attrs{
"apt-mirror": "http://testing2.invalid",
}
cfg2 := getSimpleTestConfig(c, newAttrs)
errSetConfig := env.SetConfig(cfg2)
c.Check(errSetConfig, gc.IsNil)
c.Check(env.Config().Name(), gc.Equals, "testenv")
c.Check(env.Config().AptMirror(), gc.Equals, "http://testing2.invalid")
}
示例14: TestNewCloudinitConfigNoFeatureFlag
func (s *environSuite) TestNewCloudinitConfigNoFeatureFlag(c *gc.C) {
cfg := getSimpleTestConfig(c, nil)
env, err := maas.NewEnviron(cfg)
c.Assert(err, jc.ErrorIsNil)
testCase := func(expectedConfig []string) {
cloudcfg, err := maas.NewCloudinitConfig(env, "testing.invalid", "quantal")
c.Assert(err, jc.ErrorIsNil)
c.Assert(cloudcfg.SystemUpdate(), jc.IsTrue)
c.Assert(cloudcfg.RunCmds(), jc.DeepEquals, expectedConfig)
}
// First test the default case (address allocation feature flag on).
testCase(expectedCloudinitConfig)
// Now test with the flag off.
s.SetFeatureFlags() // clear the flags.
modifyNetworkScript := maas.RenderEtcNetworkInterfacesScript()
script := expectedCloudinitConfig
script = append(script, modifyNetworkScript)
testCase(script)
}
示例15: TestSetConfigRefusesChangingAgentName
func (*environSuite) TestSetConfigRefusesChangingAgentName(c *gc.C) {
oldCfg := getSimpleTestConfig(c, coretesting.Attrs{"maas-agent-name": "agent-one"})
newCfgTwo := getSimpleTestConfig(c, coretesting.Attrs{"maas-agent-name": "agent-two"})
env, err := maas.NewEnviron(oldCfg)
c.Assert(err, jc.ErrorIsNil)
// SetConfig() fails, even though both the old and the new config are
// individually valid.
err = env.SetConfig(newCfgTwo)
c.Assert(err, gc.NotNil)
c.Check(err, gc.ErrorMatches, ".*cannot change maas-agent-name.*")
// The old config is still in place. The new config never took effect.
c.Check(maas.MAASAgentName(env), gc.Equals, "agent-one")
// It also refuses to set it to the empty string:
err = env.SetConfig(getSimpleTestConfig(c, coretesting.Attrs{"maas-agent-name": ""}))
c.Check(err, gc.ErrorMatches, ".*cannot change maas-agent-name.*")
// And to nil
err = env.SetConfig(getSimpleTestConfig(c, nil))
c.Check(err, gc.ErrorMatches, ".*cannot change maas-agent-name.*")
}