本文整理汇总了Golang中github.com/juju/juju/testing.CustomModelConfig函数的典型用法代码示例。如果您正苦于以下问题:Golang CustomModelConfig函数的具体用法?Golang CustomModelConfig怎么用?Golang CustomModelConfig使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了CustomModelConfig函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestInitializeFromConfig
func (*NetworkSuite) TestInitializeFromConfig(c *gc.C) {
c.Check(network.PreferIPv6(), jc.IsFalse)
envConfig := testing.CustomModelConfig(c, testing.Attrs{
"prefer-ipv6": true,
})
network.SetPreferIPv6(envConfig.PreferIPv6())
c.Check(network.PreferIPv6(), jc.IsTrue)
envConfig = testing.CustomModelConfig(c, testing.Attrs{
"prefer-ipv6": false,
})
network.SetPreferIPv6(envConfig.PreferIPv6())
c.Check(network.PreferIPv6(), jc.IsFalse)
}
示例2: SetUpTest
func (s *Suite) SetUpTest(c *gc.C) {
// Set up InitialConfig with a dummy provider configuration. This
// is required to allow model import test to work.
env, err := environs.Prepare(
modelcmd.BootstrapContext(testing.Context(c)),
jujuclienttesting.NewMemStore(),
environs.PrepareParams{
ControllerName: "dummycontroller",
BaseConfig: dummy.SampleConfig(),
CloudName: "dummy",
},
)
c.Assert(err, jc.ErrorIsNil)
s.InitialConfig = testing.CustomModelConfig(c, env.Config().AllAttrs())
// The call up to StateSuite's SetUpTest uses s.InitialConfig so
// it has to happen here.
s.StateSuite.SetUpTest(c)
s.resources = common.NewResources()
s.AddCleanup(func(*gc.C) { s.resources.StopAll() })
s.authorizer = apiservertesting.FakeAuthorizer{
Tag: s.Owner,
}
}
示例3: ModelConfig
func (sb *stubBackend) ModelConfig() (*config.Config, error) {
sb.MethodCall(sb, "ModelConfig")
if err := sb.NextErr(); err != nil {
return nil, err
}
return coretesting.CustomModelConfig(sb.c, sb.configAttrs), nil
}
示例4: TestNewModelSameUserSameNameFails
func (s *ModelSuite) TestNewModelSameUserSameNameFails(c *gc.C) {
cfg, _ := s.createTestModelConfig(c)
owner := s.Factory.MakeUser(c, nil).UserTag()
// Create the first model.
_, st1, err := s.State.NewModel(state.ModelArgs{
CloudName: "dummy",
CloudRegion: "dummy-region",
Config: cfg,
Owner: owner,
StorageProviderRegistry: storage.StaticProviderRegistry{},
})
c.Assert(err, jc.ErrorIsNil)
defer st1.Close()
// Attempt to create another model with a different UUID but the
// same owner and name as the first.
newUUID, err := utils.NewUUID()
c.Assert(err, jc.ErrorIsNil)
cfg2 := testing.CustomModelConfig(c, testing.Attrs{
"name": cfg.Name(),
"uuid": newUUID.String(),
})
_, _, err = s.State.NewModel(state.ModelArgs{
CloudName: "dummy",
CloudRegion: "dummy-region",
Config: cfg2,
Owner: owner,
StorageProviderRegistry: storage.StaticProviderRegistry{},
})
errMsg := fmt.Sprintf("model %q for %s already exists", cfg2.Name(), owner.Canonical())
c.Assert(err, gc.ErrorMatches, errMsg)
c.Assert(errors.IsAlreadyExists(err), jc.IsTrue)
// Remove the first model.
env1, err := st1.Model()
c.Assert(err, jc.ErrorIsNil)
err = env1.Destroy()
c.Assert(err, jc.ErrorIsNil)
// Destroy only sets the model to dying and RemoveAllModelDocs can
// only be called on a dead model. Normally, the environ's lifecycle
// would be set to dead after machines and services have been cleaned up.
err = state.SetModelLifeDead(st1, env1.ModelTag().Id())
c.Assert(err, jc.ErrorIsNil)
err = st1.RemoveAllModelDocs()
c.Assert(err, jc.ErrorIsNil)
// We should now be able to create the other model.
env2, st2, err := s.State.NewModel(state.ModelArgs{
CloudName: "dummy",
CloudRegion: "dummy-region",
Config: cfg2,
Owner: owner,
StorageProviderRegistry: storage.StaticProviderRegistry{},
})
c.Assert(err, jc.ErrorIsNil)
defer st2.Close()
c.Assert(env2, gc.NotNil)
c.Assert(st2, gc.NotNil)
}
示例5: TestVolumeParamsStorageTags
func (*volumesSuite) TestVolumeParamsStorageTags(c *gc.C) {
volumeTag := names.NewVolumeTag("100")
storageTag := names.NewStorageTag("mystore/0")
unitTag := names.NewUnitTag("mysql/123")
p, err := storagecommon.VolumeParams(
&fakeVolume{tag: volumeTag, params: &state.VolumeParams{
Pool: "loop", Size: 1024,
}},
&fakeStorageInstance{tag: storageTag, owner: unitTag},
testing.CustomModelConfig(c, nil),
&fakePoolManager{},
)
c.Assert(err, jc.ErrorIsNil)
c.Assert(p, jc.DeepEquals, params.VolumeParams{
VolumeTag: "volume-100",
Provider: "loop",
Size: 1024,
Tags: map[string]string{
tags.JujuController: testing.ModelTag.Id(),
tags.JujuModel: testing.ModelTag.Id(),
tags.JujuStorageInstance: "mystore/0",
tags.JujuStorageOwner: "mysql/123",
},
})
}
示例6: MakeModel
// MakeModel creates an model with specified params,
// filling in sane defaults for missing values. If params is nil,
// defaults are used for all values.
//
// By default the new model shares the same owner as the calling
// Factory's model.
func (factory *Factory) MakeModel(c *gc.C, params *ModelParams) *state.State {
if params == nil {
params = new(ModelParams)
}
if params.Name == "" {
params.Name = uniqueString("testenv")
}
if params.Owner == nil {
origEnv, err := factory.st.Model()
c.Assert(err, jc.ErrorIsNil)
params.Owner = origEnv.Owner()
}
// It only makes sense to make an model with the same provider
// as the initial model, or things will break elsewhere.
currentCfg, err := factory.st.ModelConfig()
c.Assert(err, jc.ErrorIsNil)
uuid, err := utils.NewUUID()
c.Assert(err, jc.ErrorIsNil)
cfg := testing.CustomModelConfig(c, testing.Attrs{
"name": params.Name,
"uuid": uuid.String(),
"type": currentCfg.Type(),
"state-port": currentCfg.StatePort(),
"api-port": currentCfg.APIPort(),
}.Merge(params.ConfigAttrs))
_, st, err := factory.st.NewModel(state.ModelArgs{
Config: cfg,
Owner: params.Owner.(names.UserTag),
})
c.Assert(err, jc.ErrorIsNil)
return st
}
示例7: testVolumeParams
func (*volumesSuite) testVolumeParams(c *gc.C, volumeParams *state.VolumeParams, info *state.VolumeInfo) {
tag := names.NewVolumeTag("100")
p, err := storagecommon.VolumeParams(
&fakeVolume{tag: tag, params: volumeParams, info: info},
nil, // StorageInstance
testing.ModelTag.Id(),
testing.ControllerTag.Id(),
testing.CustomModelConfig(c, testing.Attrs{
"resource-tags": "a=b c=",
}),
&fakePoolManager{},
provider.CommonStorageProviders(),
)
c.Assert(err, jc.ErrorIsNil)
c.Assert(p, jc.DeepEquals, params.VolumeParams{
VolumeTag: "volume-100",
Provider: "loop",
Size: 1024,
Tags: map[string]string{
tags.JujuController: testing.ControllerTag.Id(),
tags.JujuModel: testing.ModelTag.Id(),
"a": "b",
"c": "",
},
})
}
示例8: TestNewModelConfigForksControllerValue
func (s *ModelConfigSourceSuite) TestNewModelConfigForksControllerValue(c *gc.C) {
uuid, err := utils.NewUUID()
c.Assert(err, jc.ErrorIsNil)
cfg := testing.CustomModelConfig(c, testing.Attrs{
"name": "another",
"uuid": uuid.String(),
})
owner := names.NewUserTag("[email protected]")
_, st, err := s.State.NewModel(state.ModelArgs{
Config: cfg, Owner: owner, CloudName: "dummy", CloudRegion: "nether-region",
StorageProviderRegistry: storage.StaticProviderRegistry{},
})
c.Assert(err, jc.ErrorIsNil)
defer st.Close()
modelCfg, err := st.ModelConfig()
c.Assert(err, jc.ErrorIsNil)
c.Assert(modelCfg.AllAttrs()["apt-mirror"], gc.Equals, "http://mirror")
// Change the local controller settings and ensure the model setting stays the same.
localCloudSettings, err := s.State.ReadSettings(state.GlobalSettingsC, state.ControllerInheritedSettingsGlobalKey)
c.Assert(err, jc.ErrorIsNil)
localCloudSettings.Set("apt-mirror", "http://anothermirror")
_, err = localCloudSettings.Write()
c.Assert(err, jc.ErrorIsNil)
modelCfg, err = st.ModelConfig()
c.Assert(err, jc.ErrorIsNil)
c.Assert(modelCfg.AllAttrs()["apt-mirror"], gc.Equals, "http://mirror")
}
示例9: SetUpTest
func (s *binaryStorageSuite) SetUpTest(c *gc.C) {
s.ConnSuite.SetUpTest(c)
// Store the controller UUID.
model, err := s.State.ControllerModel()
c.Assert(err, jc.ErrorIsNil)
s.controllerUUID = model.UUID()
// Create a new model and store its UUID.
s.modelUUID = utils.MustNewUUID().String()
cfg := testing.CustomModelConfig(c, testing.Attrs{
"name": "new-model",
"uuid": s.modelUUID,
})
_, s.st, err = s.State.NewModel(state.ModelArgs{
CloudName: "dummy",
CloudRegion: "dummy-region",
Config: cfg,
Owner: names.NewLocalUserTag("test-admin"),
StorageProviderRegistry: storage.StaticProviderRegistry{},
})
c.Assert(err, jc.ErrorIsNil)
s.AddCleanup(func(*gc.C) {
s.st.Close()
})
}
示例10: createTestEnvConfig
// createTestEnvConfig returns a new model config and its UUID for testing.
func (s *ModelSuite) createTestEnvConfig(c *gc.C) (*config.Config, string) {
uuid, err := utils.NewUUID()
c.Assert(err, jc.ErrorIsNil)
return testing.CustomModelConfig(c, testing.Attrs{
"name": "testing",
"uuid": uuid.String(),
}), uuid.String()
}
示例11: newModelConfig
// newModelConfig returns an environment config map with the supplied attrs
// (on top of some default set), or fails the test.
func newModelConfig(c *gc.C, extraAttrs coretesting.Attrs) map[string]interface{} {
attrs := dummy.SampleConfig()
attrs["broken"] = ""
attrs["state-id"] = "42"
for k, v := range extraAttrs {
attrs[k] = v
}
return coretesting.CustomModelConfig(c, attrs).AllAttrs()
}
示例12: TestInstanceTagsUserSpecified
func (*instancecfgSuite) TestInstanceTagsUserSpecified(c *gc.C) {
cfg := testing.CustomModelConfig(c, testing.Attrs{
"resource-tags": "a=b c=",
})
testInstanceTags(c, cfg, nil, map[string]string{
"juju-model-uuid": testing.ModelTag.Id(),
"a": "b",
"c": "",
})
}
示例13: SetUpTest
func (s *ImportSuite) SetUpTest(c *gc.C) {
// Specify the config to use for the controller model before calling
// SetUpTest of the StateSuite, otherwise we get testing.ModelConfig(c).
// The default provider type specified in the testing.ModelConfig function
// is one that isn't registered as a valid provider. For our tests here we
// need a real registered provider, so we use the dummy provider.
// NOTE: make a better test provider.
s.InitialConfig = testing.CustomModelConfig(c, dummy.SampleConfig())
s.StateSuite.SetUpTest(c)
}
示例14: createTestModelConfig
func createTestModelConfig(c *gc.C, controllerUUID string) (*config.Config, string) {
uuid, err := utils.NewUUID()
c.Assert(err, jc.ErrorIsNil)
if controllerUUID == "" {
controllerUUID = uuid.String()
}
return testing.CustomModelConfig(c, testing.Attrs{
"name": "testing",
"uuid": uuid.String(),
}), uuid.String()
}
示例15: NewStateForModelNamed
// NewStateForModelNamed returns an new model with the given modelName, which
// has a unique UUID, and does not need to be closed when the test completes.
func (s *ConnSuite) NewStateForModelNamed(c *gc.C, modelName string) *state.State {
cfg := testing.CustomModelConfig(c, testing.Attrs{
"name": modelName,
"uuid": utils.MustNewUUID().String(),
})
otherOwner := names.NewLocalUserTag("test-admin")
_, otherState, err := s.State.NewModel(cfg, otherOwner)
c.Assert(err, jc.ErrorIsNil)
s.AddCleanup(func(*gc.C) { otherState.Close() })
return otherState
}