本文整理汇总了Golang中github.com/wallyworld/core/environs/config.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了New函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestValidateAcceptsUnchangedConfig
func (*configSuite) TestValidateAcceptsUnchangedConfig(c *gc.C) {
attrs := makeAzureConfigMap(c)
provider := azureEnvironProvider{}
oldConfig, err := config.New(config.NoDefaults, attrs)
c.Assert(err, gc.IsNil)
newConfig, err := config.New(config.NoDefaults, attrs)
c.Assert(err, gc.IsNil)
result, err := provider.Validate(newConfig, oldConfig)
c.Assert(err, gc.IsNil)
c.Check(result.Name(), gc.Equals, attrs["name"])
}
开发者ID:jameinel,项目名称:core,代码行数:11,代码来源:config_test.go
示例2: TestValidateChecksConfigChanges
func (*configSuite) TestValidateChecksConfigChanges(c *gc.C) {
provider := azureEnvironProvider{}
oldConfig, err := config.New(config.NoDefaults, makeConfigMap(nil))
c.Assert(err, gc.IsNil)
newAttrs := makeConfigMap(map[string]interface{}{
"name": "different-name",
})
newConfig, err := config.New(config.NoDefaults, newAttrs)
c.Assert(err, gc.IsNil)
_, err = provider.Validate(newConfig, oldConfig)
c.Check(err, gc.NotNil)
}
开发者ID:jameinel,项目名称:core,代码行数:12,代码来源:config_test.go
示例3: TestValidateParsesAzureConfig
func (*configSuite) TestValidateParsesAzureConfig(c *gc.C) {
location := "location"
managementSubscriptionId := "subscription-id"
certificate := "certificate content"
storageAccountName := "account-name"
forceImageName := "force-image-name"
unknownFutureSetting := "preserved"
azureConfig := map[string]interface{}{
"location": location,
"management-subscription-id": managementSubscriptionId,
"management-certificate": certificate,
"storage-account-name": storageAccountName,
"force-image-name": forceImageName,
"unknown-future-setting": unknownFutureSetting,
}
attrs := makeConfigMap(azureConfig)
provider := azureEnvironProvider{}
config, err := config.New(config.NoDefaults, attrs)
c.Assert(err, gc.IsNil)
azConfig, err := provider.newConfig(config)
c.Assert(err, gc.IsNil)
c.Check(azConfig.Name(), gc.Equals, attrs["name"])
c.Check(azConfig.location(), gc.Equals, location)
c.Check(azConfig.managementSubscriptionId(), gc.Equals, managementSubscriptionId)
c.Check(azConfig.managementCertificate(), gc.Equals, certificate)
c.Check(azConfig.storageAccountName(), gc.Equals, storageAccountName)
c.Check(azConfig.forceImageName(), gc.Equals, forceImageName)
c.Check(azConfig.UnknownAttrs()["unknown-future-setting"], gc.Equals, unknownFutureSetting)
}
开发者ID:jameinel,项目名称:core,代码行数:29,代码来源:config_test.go
示例4: NewFromAttrs
// NewFromAttrs returns a new environment based on the provided configuration
// attributes.
// TODO(rog) remove this function - it's almost always wrong to use it.
func NewFromAttrs(attrs map[string]interface{}) (Environ, error) {
cfg, err := config.New(config.NoDefaults, attrs)
if err != nil {
return nil, err
}
return New(cfg)
}
开发者ID:jameinel,项目名称:core,代码行数:10,代码来源:open.go
示例5: assertGetImageMetadataSources
func (t *ProviderSuite) assertGetImageMetadataSources(c *gc.C, stream, officialSourcePath string) {
// Make an env configured with the stream.
envAttrs := localConfigAttrs
if stream != "" {
envAttrs = envAttrs.Merge(coretesting.Attrs{
"image-stream": stream,
})
}
cfg, err := config.New(config.NoDefaults, envAttrs)
c.Assert(err, gc.IsNil)
env, err := environs.Prepare(cfg, coretesting.Context(c), configstore.NewMem())
c.Assert(err, gc.IsNil)
c.Assert(env, gc.NotNil)
sources, err := imagemetadata.GetMetadataSources(env)
c.Assert(err, gc.IsNil)
c.Assert(len(sources), gc.Equals, 2)
var urls = make([]string, len(sources))
for i, source := range sources {
url, err := source.URL("")
c.Assert(err, gc.IsNil)
urls[i] = url
}
// The control bucket URL contains the bucket name.
c.Check(strings.Contains(urls[0], ec2.ControlBucketName(env)+"/images"), jc.IsTrue)
c.Assert(urls[1], gc.Equals, fmt.Sprintf("http://cloud-images.ubuntu.com/%s/", officialSourcePath))
}
开发者ID:jameinel,项目名称:core,代码行数:27,代码来源:local_test.go
示例6: TestFirewallMode
func (s *ConfigSuite) TestFirewallMode(c *gc.C) {
for i, test := range firewallModeTests {
c.Logf("test %d: %s", i, test.configFirewallMode)
attrs := dummy.SampleConfig()
if test.configFirewallMode != "" {
attrs = attrs.Merge(testing.Attrs{
"firewall-mode": test.configFirewallMode,
})
}
cfg, err := config.New(config.NoDefaults, attrs)
if err != nil {
c.Assert(err, gc.ErrorMatches, test.errorMsg)
continue
}
ctx := testing.Context(c)
env, err := environs.Prepare(cfg, ctx, configstore.NewMem())
if test.errorMsg != "" {
c.Assert(err, gc.ErrorMatches, test.errorMsg)
continue
}
c.Assert(err, gc.IsNil)
defer env.Destroy()
firewallMode := env.Config().FirewallMode()
c.Assert(firewallMode, gc.Equals, test.firewallMode)
s.TearDownTest(c)
}
}
开发者ID:jameinel,项目名称:core,代码行数:29,代码来源:config_test.go
示例7: 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 maasEnvironConfig.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/environment
// SetEnvironmentCommand' instead uses conn.State.EnvironConfig() 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, gc.IsNil)
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, gc.IsNil)
validatedConfig, err := provider.Validate(baseCfg, nilCfg)
c.Assert(err, gc.IsNil)
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.*")
}
开发者ID:jameinel,项目名称:core,代码行数:33,代码来源:environ_test.go
示例8: TestDestroy
func (*OpenSuite) TestDestroy(c *gc.C) {
cfg, err := config.New(config.NoDefaults, dummy.SampleConfig().Merge(
testing.Attrs{
"state-server": false,
"name": "erewhemos",
},
))
c.Assert(err, gc.IsNil)
store := configstore.NewMem()
// Prepare the environment and sanity-check that
// the config storage info has been made.
ctx := testing.Context(c)
e, err := environs.Prepare(cfg, ctx, store)
c.Assert(err, gc.IsNil)
_, err = store.ReadInfo(e.Name())
c.Assert(err, gc.IsNil)
err = environs.Destroy(e, store)
c.Assert(err, gc.IsNil)
// Check that the environment has actually been destroyed
// and that the config info has been destroyed too.
_, _, err = e.StateInfo()
c.Assert(err, gc.ErrorMatches, "environment has been destroyed")
_, err = store.ReadInfo(e.Name())
c.Assert(err, jc.Satisfies, errors.IsNotFound)
}
开发者ID:jameinel,项目名称:core,代码行数:28,代码来源:open_test.go
示例9: TestPrepareGeneratesDifferentAdminSecrets
func (*OpenSuite) TestPrepareGeneratesDifferentAdminSecrets(c *gc.C) {
baselineAttrs := dummy.SampleConfig().Merge(testing.Attrs{
"state-server": false,
"name": "erewhemos",
}).Delete(
"admin-secret",
)
cfg, err := config.New(config.NoDefaults, baselineAttrs)
c.Assert(err, gc.IsNil)
ctx := testing.Context(c)
env0, err := environs.Prepare(cfg, ctx, configstore.NewMem())
c.Assert(err, gc.IsNil)
adminSecret0 := env0.Config().AdminSecret()
c.Assert(adminSecret0, gc.HasLen, 32)
c.Assert(adminSecret0, gc.Matches, "^[0-9a-f]*$")
env1, err := environs.Prepare(cfg, ctx, configstore.NewMem())
c.Assert(err, gc.IsNil)
adminSecret1 := env1.Config().AdminSecret()
c.Assert(adminSecret1, gc.HasLen, 32)
c.Assert(adminSecret1, gc.Matches, "^[0-9a-f]*$")
c.Assert(adminSecret1, gc.Not(gc.Equals), adminSecret0)
}
开发者ID:jameinel,项目名称:core,代码行数:25,代码来源:open_test.go
示例10: assertGetImageMetadataSources
func (suite *environSuite) assertGetImageMetadataSources(c *gc.C, stream, officialSourcePath string) {
// Make an env configured with the stream.
testAttrs := maasEnvAttrs
testAttrs = testAttrs.Merge(coretesting.Attrs{
"maas-server": suite.testMAASObject.TestServer.URL,
})
if stream != "" {
testAttrs = testAttrs.Merge(coretesting.Attrs{
"image-stream": stream,
})
}
attrs := coretesting.FakeConfig().Merge(testAttrs)
cfg, err := config.New(config.NoDefaults, attrs)
c.Assert(err, gc.IsNil)
env, err := NewEnviron(cfg)
c.Assert(err, gc.IsNil)
// Add a dummy file to storage so we can use that to check the
// obtained source later.
data := makeRandomBytes(10)
stor := NewStorage(env)
err = stor.Put("images/filename", bytes.NewBuffer([]byte(data)), int64(len(data)))
c.Assert(err, gc.IsNil)
sources, err := imagemetadata.GetMetadataSources(env)
c.Assert(err, gc.IsNil)
c.Assert(len(sources), gc.Equals, 2)
assertSourceContents(c, sources[0], "filename", data)
url, err := sources[1].URL("")
c.Assert(err, gc.IsNil)
c.Assert(url, gc.Equals, fmt.Sprintf("http://cloud-images.ubuntu.com/%s/", officialSourcePath))
}
开发者ID:jameinel,项目名称:core,代码行数:31,代码来源:environ_whitebox_test.go
示例11: TestStartInstanceWithoutPublicIP
// If the environment is configured not to require a public IP address for nodes,
// bootstrapping and starting an instance should occur without any attempt to
// allocate a public address.
func (s *localServerSuite) TestStartInstanceWithoutPublicIP(c *gc.C) {
cleanup := s.srv.Service.Nova.RegisterControlPoint(
"addFloatingIP",
func(sc hook.ServiceControl, args ...interface{}) error {
return fmt.Errorf("add floating IP should not have been called")
},
)
defer cleanup()
cleanup = s.srv.Service.Nova.RegisterControlPoint(
"addServerFloatingIP",
func(sc hook.ServiceControl, args ...interface{}) error {
return fmt.Errorf("add server floating IP should not have been called")
},
)
defer cleanup()
cfg, err := config.New(config.NoDefaults, s.TestConfig.Merge(coretesting.Attrs{
"use-floating-ip": false,
}))
c.Assert(err, gc.IsNil)
env, err := environs.Prepare(cfg, coretesting.Context(c), s.ConfigStore)
c.Assert(err, gc.IsNil)
err = bootstrap.Bootstrap(coretesting.Context(c), env, environs.BootstrapParams{})
c.Assert(err, gc.IsNil)
inst, _ := testing.AssertStartInstance(c, env, "100")
err = env.StopInstances([]instance.Instance{inst})
c.Assert(err, gc.IsNil)
}
开发者ID:jameinel,项目名称:core,代码行数:31,代码来源:local_test.go
示例12: TestNewConn
func (*NewAPIConnSuite) TestNewConn(c *gc.C) {
cfg, err := config.New(config.NoDefaults, dummy.SampleConfig())
c.Assert(err, gc.IsNil)
ctx := coretesting.Context(c)
env, err := environs.Prepare(cfg, ctx, configstore.NewMem())
c.Assert(err, gc.IsNil)
envtesting.UploadFakeTools(c, env.Storage())
err = bootstrap.Bootstrap(ctx, env, environs.BootstrapParams{})
c.Assert(err, gc.IsNil)
cfg = env.Config()
cfg, err = cfg.Apply(map[string]interface{}{
"secret": "fnord",
})
c.Assert(err, gc.IsNil)
err = env.SetConfig(cfg)
c.Assert(err, gc.IsNil)
conn, err := juju.NewAPIConn(env, api.DefaultDialOpts())
c.Assert(err, gc.IsNil)
c.Assert(conn.Environ, gc.Equals, env)
c.Assert(conn.State, gc.NotNil)
// the secrets will not be updated, as they already exist
attrs, err := conn.State.Client().EnvironmentGet()
c.Assert(attrs["secret"], gc.Equals, "pork")
c.Assert(conn.Close(), gc.IsNil)
}
开发者ID:jameinel,项目名称:core,代码行数:30,代码来源:apiconn_test.go
示例13: MakeConfig
// MakeConfig creates a functional environConfig for a test.
func MakeConfig(c *gc.C, attrs testing.Attrs) *environConfig {
cfg, err := config.New(config.NoDefaults, attrs)
c.Assert(err, gc.IsNil)
env, err := environs.Prepare(cfg, testing.Context(c), configstore.NewMem())
c.Assert(err, gc.IsNil)
return env.(*joyentEnviron).Ecfg()
}
开发者ID:jameinel,项目名称:core,代码行数:8,代码来源:export_test.go
示例14: getEnvironConfig
func getEnvironConfig(c *gc.C, attrs map[string]interface{}) *environConfig {
testConfig, err := config.New(config.UseDefaults, attrs)
c.Assert(err, gc.IsNil)
envConfig, err := manualProvider{}.validate(testConfig, nil)
c.Assert(err, gc.IsNil)
return envConfig
}
开发者ID:jameinel,项目名称:core,代码行数:7,代码来源:config_test.go
示例15: loop
func (w *EnvironConfigWatcher) loop() (err error) {
sw := w.st.watchSettings(environGlobalKey)
defer sw.Stop()
out := w.out
out = nil
cfg := &config.Config{}
for {
select {
case <-w.st.watcher.Dead():
return stateWatcherDeadError(w.st.watcher.Err())
case <-w.tomb.Dying():
return tomb.ErrDying
case settings, ok := <-sw.Changes():
if !ok {
return watcher.MustErr(sw)
}
cfg, err = config.New(config.NoDefaults, settings.Map())
if err == nil {
out = w.out
} else {
out = nil
}
case out <- cfg:
out = nil
}
}
}
开发者ID:jameinel,项目名称:core,代码行数:27,代码来源:watcher.go
示例16: TestAllocateAddress
func (s *suite) TestAllocateAddress(c *gc.C) {
cfg, err := config.New(config.NoDefaults, s.TestConfig)
c.Assert(err, gc.IsNil)
e, err := environs.Prepare(cfg, testing.Context(c), s.ConfigStore)
c.Assert(err, gc.IsNil, gc.Commentf("preparing environ %#v", s.TestConfig))
c.Assert(e, gc.NotNil)
envtesting.UploadFakeTools(c, e.Storage())
err = bootstrap.EnsureNotBootstrapped(e)
c.Assert(err, gc.IsNil)
err = bootstrap.Bootstrap(testing.Context(c), e, environs.BootstrapParams{})
c.Assert(err, gc.IsNil)
inst, _ := jujutesting.AssertStartInstance(c, e, "0")
c.Assert(inst, gc.NotNil)
netId := network.Id("net1")
opc := make(chan dummy.Operation, 200)
dummy.Listen(opc)
expectAddress := instance.NewAddress("0.1.2.1", instance.NetworkCloudLocal)
address, err := e.AllocateAddress(inst.Id(), netId)
c.Assert(err, gc.IsNil)
c.Assert(address, gc.DeepEquals, expectAddress)
assertAllocateAddress(c, e, opc, inst.Id(), netId, expectAddress)
expectAddress = instance.NewAddress("0.1.2.2", instance.NetworkCloudLocal)
address, err = e.AllocateAddress(inst.Id(), netId)
c.Assert(err, gc.IsNil)
c.Assert(address, gc.DeepEquals, expectAddress)
assertAllocateAddress(c, e, opc, inst.Id(), netId, expectAddress)
}
开发者ID:jameinel,项目名称:core,代码行数:33,代码来源:environs_test.go
示例17: assertStartInstanceDefaultSecurityGroup
func (s *LiveTests) assertStartInstanceDefaultSecurityGroup(c *gc.C, useDefault bool) {
attrs := s.TestConfig.Merge(coretesting.Attrs{
"name": "sample-" + randomName(),
"control-bucket": "juju-test-" + randomName(),
"use-default-secgroup": useDefault,
})
cfg, err := config.New(config.NoDefaults, attrs)
c.Assert(err, gc.IsNil)
// Set up a test environment.
env, err := environs.New(cfg)
c.Assert(err, gc.IsNil)
c.Assert(env, gc.NotNil)
defer env.Destroy()
// Bootstrap and start an instance.
err = bootstrap.Bootstrap(coretesting.Context(c), env, environs.BootstrapParams{})
c.Assert(err, gc.IsNil)
inst, _ := jujutesting.AssertStartInstance(c, env, "100")
// Check whether the instance has the default security group assigned.
novaClient := openstack.GetNovaClient(env)
groups, err := novaClient.GetServerSecurityGroups(string(inst.Id()))
c.Assert(err, gc.IsNil)
defaultGroupFound := false
for _, group := range groups {
if group.Name == "default" {
defaultGroupFound = true
break
}
}
c.Assert(defaultGroupFound, gc.Equals, useDefault)
}
开发者ID:jameinel,项目名称:core,代码行数:30,代码来源:live_test.go
示例18: testingEnvConfig
func testingEnvConfig(c *gc.C) *config.Config {
cfg, err := config.New(config.NoDefaults, dummy.SampleConfig())
c.Assert(err, gc.IsNil)
env, err := environs.Prepare(cfg, testing.Context(c), configstore.NewMem())
c.Assert(err, gc.IsNil)
return env.Config()
}
开发者ID:jameinel,项目名称:core,代码行数:7,代码来源:environwatcher_test.go
示例19: ConfigForName
// 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
// is not found, an errors.NotFoundError is returned. If the given
// store contains an entry for the environment and it has associated
// bootstrap config, that configuration will be returned.
// ConfigForName also returns where the configuration was sourced from
// (this is also valid even when there is an error.
func ConfigForName(name string, store configstore.Storage) (*config.Config, ConfigSource, error) {
envs, err := ReadEnvirons("")
if err != nil {
return nil, ConfigFromNowhere, err
}
if name == "" {
name = envs.Default
}
// TODO(rog) 2013-10-04 https://bugs.github.com/wallyworld/core/+bug/1235217
// Don't fall back to reading from environments.yaml
// when we can be sure that everyone has a
// .jenv file for their currently bootstrapped environments.
if name != "" {
info, err := store.ReadInfo(name)
if err == nil {
if len(info.BootstrapConfig()) == 0 {
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())
return cfg, ConfigFromInfo, err
}
if err != nil && !errors.IsNotFound(err) {
return nil, ConfigFromInfo, fmt.Errorf("cannot read environment info for %q: %v", name, err)
}
}
cfg, err := envs.Config(name)
return cfg, ConfigFromEnvirons, err
}
开发者ID:jameinel,项目名称:core,代码行数:37,代码来源:open.go
示例20: TestPrepareUseSSHStorage
func (s *providerSuite) TestPrepareUseSSHStorage(c *gc.C) {
minimal := manual.MinimalConfigValues()
minimal["use-sshstorage"] = false
testConfig, err := config.New(config.UseDefaults, minimal)
c.Assert(err, gc.IsNil)
_, err = manual.ProviderInstance.Prepare(coretesting.Context(c), testConfig)
c.Assert(err, gc.ErrorMatches, "use-sshstorage must not be specified")
s.PatchValue(manual.NewSSHStorage, func(sshHost, storageDir, storageTmpdir string) (storage.Storage, error) {
return nil, fmt.Errorf("newSSHStorage failed")
})
minimal["use-sshstorage"] = true
testConfig, err = config.New(config.UseDefaults, minimal)
c.Assert(err, gc.IsNil)
_, err = manual.ProviderInstance.Prepare(coretesting.Context(c), testConfig)
c.Assert(err, gc.ErrorMatches, "initialising SSH storage failed: newSSHStorage failed")
}
开发者ID:jameinel,项目名称:core,代码行数:17,代码来源:provider_test.go
注:本文中的github.com/wallyworld/core/environs/config.New函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论