本文整理汇总了Golang中github.com/juju/juju/environs/testing.BootstrapContext函数的典型用法代码示例。如果您正苦于以下问题:Golang BootstrapContext函数的具体用法?Golang BootstrapContext怎么用?Golang BootstrapContext使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了BootstrapContext函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestBootstrapAsRoot
func (s *configSuite) TestBootstrapAsRoot(c *gc.C) {
s.PatchValue(local.CheckIfRoot, func() bool { return true })
env, err := local.Provider.PrepareForBootstrap(envtesting.BootstrapContext(c), minimalConfig(c))
c.Assert(err, jc.ErrorIsNil)
_, err = env.Bootstrap(envtesting.BootstrapContext(c), environs.BootstrapParams{})
c.Assert(err, gc.ErrorMatches, "bootstrapping a local environment must not be done as root")
}
示例2: TestBootstrapNeedsSettings
func (s *bootstrapSuite) TestBootstrapNeedsSettings(c *gc.C) {
env := newEnviron("bar", noKeysDefined, nil)
s.setDummyStorage(c, env)
err := bootstrap.Bootstrap(envtesting.BootstrapContext(c), env, bootstrap.BootstrapParams{
ControllerConfig: coretesting.FakeControllerConfig(),
CAPrivateKey: coretesting.CAKey,
})
c.Assert(err, gc.ErrorMatches, "validating bootstrap parameters: admin-secret is empty")
controllerCfg := coretesting.FakeControllerConfig()
delete(controllerCfg, "ca-cert")
err = bootstrap.Bootstrap(envtesting.BootstrapContext(c), env, bootstrap.BootstrapParams{
ControllerConfig: controllerCfg,
AdminSecret: "admin-secret",
CAPrivateKey: coretesting.CAKey,
})
c.Assert(err, gc.ErrorMatches, "validating bootstrap parameters: controller configuration has no ca-cert")
controllerCfg = coretesting.FakeControllerConfig()
err = bootstrap.Bootstrap(envtesting.BootstrapContext(c), env, bootstrap.BootstrapParams{
ControllerConfig: controllerCfg,
AdminSecret: "admin-secret",
})
c.Assert(err, gc.ErrorMatches, "validating bootstrap parameters: empty ca-private-key")
err = bootstrap.Bootstrap(envtesting.BootstrapContext(c), env, bootstrap.BootstrapParams{
ControllerConfig: controllerCfg,
AdminSecret: "admin-secret",
CAPrivateKey: coretesting.CAKey,
})
c.Assert(err, jc.ErrorIsNil)
}
示例3: TestBootstrapNeedsSettings
func (s *bootstrapSuite) TestBootstrapNeedsSettings(c *gc.C) {
env := newEnviron("bar", noKeysDefined, nil)
s.setDummyStorage(c, env)
fixEnv := func(key string, value interface{}) {
cfg, err := env.Config().Apply(map[string]interface{}{
key: value,
})
c.Assert(err, jc.ErrorIsNil)
env.cfg = cfg
}
err := bootstrap.Bootstrap(envtesting.BootstrapContext(c), env, bootstrap.BootstrapParams{})
c.Assert(err, gc.ErrorMatches, "model configuration has no admin-secret")
fixEnv("admin-secret", "whatever")
err = bootstrap.Bootstrap(envtesting.BootstrapContext(c), env, bootstrap.BootstrapParams{})
c.Assert(err, gc.ErrorMatches, "model configuration has no ca-cert")
fixEnv("ca-cert", coretesting.CACert)
err = bootstrap.Bootstrap(envtesting.BootstrapContext(c), env, bootstrap.BootstrapParams{})
c.Assert(err, gc.ErrorMatches, "model configuration has no ca-private-key")
fixEnv("ca-private-key", coretesting.CAKey)
err = bootstrap.Bootstrap(envtesting.BootstrapContext(c), env, bootstrap.BootstrapParams{})
c.Assert(err, jc.ErrorIsNil)
}
示例4: bootstrapTestEnviron
func (s *suite) bootstrapTestEnviron(c *gc.C) environs.NetworkingEnviron {
env, err := bootstrap.Prepare(
envtesting.BootstrapContext(c),
s.ControllerStore,
bootstrap.PrepareParams{
ControllerConfig: testing.FakeControllerConfig(),
ModelConfig: s.TestConfig,
ControllerName: s.TestConfig["name"].(string),
Cloud: dummy.SampleCloudSpec(),
AdminSecret: AdminSecret,
},
)
c.Assert(err, gc.IsNil, gc.Commentf("preparing environ %#v", s.TestConfig))
c.Assert(env, gc.NotNil)
netenv, supported := environs.SupportsNetworking(env)
c.Assert(supported, jc.IsTrue)
err = bootstrap.Bootstrap(envtesting.BootstrapContext(c), netenv, bootstrap.BootstrapParams{
ControllerConfig: testing.FakeControllerConfig(),
CloudName: "dummy",
Cloud: cloud.Cloud{
Type: "dummy",
AuthTypes: []cloud.AuthType{cloud.EmptyAuthType},
},
AdminSecret: AdminSecret,
CAPrivateKey: testing.CAKey,
})
c.Assert(err, jc.ErrorIsNil)
return netenv
}
示例5: TestBootstrap
func (t *Tests) TestBootstrap(c *gc.C) {
credential := t.Credential
if credential.AuthType() == "" {
credential = cloud.NewEmptyCredential()
}
var regions []cloud.Region
if t.CloudRegion != "" {
regions = []cloud.Region{{
Name: t.CloudRegion,
Endpoint: t.CloudEndpoint,
}}
}
args := bootstrap.BootstrapParams{
ControllerConfig: coretesting.FakeControllerConfig(),
CloudName: t.TestConfig["type"].(string),
Cloud: cloud.Cloud{
Type: t.TestConfig["type"].(string),
AuthTypes: []cloud.AuthType{credential.AuthType()},
Regions: regions,
Endpoint: t.CloudEndpoint,
},
CloudRegion: t.CloudRegion,
CloudCredential: &credential,
CloudCredentialName: "credential",
AdminSecret: AdminSecret,
CAPrivateKey: coretesting.CAKey,
}
e := t.Prepare(c)
err := bootstrap.Bootstrap(envtesting.BootstrapContext(c), e, args)
c.Assert(err, jc.ErrorIsNil)
controllerInstances, err := e.ControllerInstances(t.ControllerUUID)
c.Assert(err, jc.ErrorIsNil)
c.Assert(controllerInstances, gc.Not(gc.HasLen), 0)
e2 := t.Open(c, e.Config())
controllerInstances2, err := e2.ControllerInstances(t.ControllerUUID)
c.Assert(err, jc.ErrorIsNil)
c.Assert(controllerInstances2, gc.Not(gc.HasLen), 0)
c.Assert(controllerInstances2, jc.SameContents, controllerInstances)
err = environs.Destroy(e2.Config().Name(), e2, t.ControllerStore)
c.Assert(err, jc.ErrorIsNil)
// Prepare again because Destroy invalidates old environments.
e3 := t.Prepare(c)
err = bootstrap.Bootstrap(envtesting.BootstrapContext(c), e3, args)
c.Assert(err, jc.ErrorIsNil)
err = environs.Destroy(e3.Config().Name(), e3, t.ControllerStore)
c.Assert(err, jc.ErrorIsNil)
}
示例6: TestBootstrapWithDefaultSeries
func (t *LiveTests) TestBootstrapWithDefaultSeries(c *gc.C) {
if !t.HasProvisioner {
c.Skip("HasProvisioner is false; cannot test deployment")
}
current := version.Binary{
Number: jujuversion.Current,
Arch: arch.HostArch(),
Series: series.HostSeries(),
}
other := current
other.Series = "quantal"
if current == other {
other.Series = "precise"
}
dummyCfg := dummy.SampleConfig().Merge(coretesting.Attrs{
"controller": false,
"name": "dummy storage",
})
args := t.prepareForBootstrapParams(c)
args.BaseConfig = dummyCfg
dummyenv, err := environs.Prepare(envtesting.BootstrapContext(c),
jujuclienttesting.NewMemStore(),
args,
)
c.Assert(err, jc.ErrorIsNil)
defer dummyenv.Destroy()
t.Destroy(c)
attrs := t.TestConfig.Merge(coretesting.Attrs{
"name": "livetests",
"default-series": other.Series,
})
args.BaseConfig = attrs
env, err := environs.Prepare(envtesting.BootstrapContext(c),
t.ControllerStore,
args)
c.Assert(err, jc.ErrorIsNil)
defer environs.Destroy("livetests", env, t.ControllerStore)
err = bootstrap.Bootstrap(envtesting.BootstrapContext(c), env, bootstrap.BootstrapParams{})
c.Assert(err, jc.ErrorIsNil)
st := t.Env.(jujutesting.GetStater).GetStateInAPIServer()
// Wait for machine agent to come up on the bootstrap
// machine and ensure it deployed the proper series.
m0, err := st.Machine("0")
c.Assert(err, jc.ErrorIsNil)
mw0 := newMachineToolWaiter(m0)
defer mw0.Stop()
waitAgentTools(c, mw0, other)
}
示例7: 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, jc.ErrorIsNil)
_, err = manual.ProviderInstance.PrepareForBootstrap(envtesting.BootstrapContext(c), testConfig)
c.Assert(err, gc.ErrorMatches, "use-sshstorage must not be specified")
minimal["use-sshstorage"] = true
testConfig, err = config.New(config.UseDefaults, minimal)
c.Assert(err, jc.ErrorIsNil)
_, err = manual.ProviderInstance.PrepareForBootstrap(envtesting.BootstrapContext(c), testConfig)
c.Assert(err, jc.ErrorIsNil)
}
示例8: TestAllocateAddressFailureToFindNetworkInterface
func (t *localServerSuite) TestAllocateAddressFailureToFindNetworkInterface(c *gc.C) {
env := t.prepareEnviron(c)
err := bootstrap.Bootstrap(envtesting.BootstrapContext(c), env, bootstrap.BootstrapParams{})
c.Assert(err, jc.ErrorIsNil)
instanceIds, err := env.StateServerInstances()
c.Assert(err, jc.ErrorIsNil)
instId := instanceIds[0]
addr := network.Address{Value: "8.0.0.4"}
// Invalid instance found
err = env.AllocateAddress(instId+"foo", "", &addr, "foo", "bar")
c.Assert(err, gc.ErrorMatches, ".*InvalidInstanceID.NotFound.*")
// No network interface
err = env.AllocateAddress(instId, "", &addr, "foo", "bar")
c.Assert(errors.Cause(err), gc.ErrorMatches, "unexpected AWS response: network interface not found")
// Nil or empty address given.
err = env.AllocateAddress(instId, "", nil, "foo", "bar")
c.Assert(errors.Cause(err), gc.ErrorMatches, "invalid address: nil or empty")
err = env.AllocateAddress(instId, "", &network.Address{Value: ""}, "foo", "bar")
c.Assert(errors.Cause(err), gc.ErrorMatches, "invalid address: nil or empty")
}
示例9: TestBootstrap
func (s *environSuite) TestBootstrap(c *gc.C) {
defer envtesting.DisableFinishBootstrap()()
ctx := envtesting.BootstrapContext(c)
env := prepareForBootstrap(c, ctx, s.provider, &s.sender)
s.sender = s.initResourceGroupSenders()
s.sender = append(s.sender, s.startInstanceSenders(true)...)
s.requests = nil
result, err := env.Bootstrap(
ctx, environs.BootstrapParams{
ControllerConfig: testing.FakeControllerConfig(),
AvailableTools: makeToolsList("quantal"),
BootstrapSeries: "quantal",
},
)
c.Assert(err, jc.ErrorIsNil)
c.Assert(result.Arch, gc.Equals, "amd64")
c.Assert(result.Series, gc.Equals, "quantal")
c.Assert(len(s.requests), gc.Equals, numExpectedStartInstanceRequests+1)
s.vmTags[tags.JujuIsController] = to.StringPtr("true")
s.assertStartInstanceRequests(c, s.requests[1:], assertStartInstanceRequestsParams{
availabilitySetName: "juju-controller",
imageReference: &quantalImageReference,
diskSizeGB: 32,
osProfile: &linuxOsProfile,
})
}
示例10: testBootstrap
func (s *localJujuTestSuite) testBootstrap(c *gc.C, cfg *config.Config) environs.Environ {
ctx := envtesting.BootstrapContext(c)
environ, err := local.Provider.PrepareForBootstrap(ctx, cfg)
c.Assert(err, jc.ErrorIsNil)
availableTools := coretools.List{&coretools.Tools{
Version: version.Binary{
Number: version.Current,
Arch: arch.HostArch(),
Series: series.HostSeries(),
},
URL: "http://testing.invalid/tools.tar.gz",
}}
result, err := environ.Bootstrap(ctx, environs.BootstrapParams{
AvailableTools: availableTools,
})
c.Assert(err, jc.ErrorIsNil)
icfg, err := instancecfg.NewBootstrapInstanceConfig(
constraints.Value{}, constraints.Value{}, "quantal", "",
)
c.Assert(err, jc.ErrorIsNil)
icfg.Tools = availableTools[0]
err = result.Finalize(ctx, icfg)
c.Assert(err, jc.ErrorIsNil)
return environ
}
示例11: TestStartInstanceDistributionParams
func (t *localServerSuite) TestStartInstanceDistributionParams(c *gc.C) {
env := t.Prepare(c)
err := bootstrap.Bootstrap(envtesting.BootstrapContext(c), env, bootstrap.BootstrapParams{})
c.Assert(err, jc.ErrorIsNil)
mock := mockAvailabilityZoneAllocations{
result: []common.AvailabilityZoneInstances{{ZoneName: "az1"}},
}
t.PatchValue(ec2.AvailabilityZoneAllocations, mock.AvailabilityZoneAllocations)
// no distribution group specified
testing.AssertStartInstance(c, env, "1")
c.Assert(mock.group, gc.HasLen, 0)
// distribution group specified: ensure it's passed through to AvailabilityZone.
expectedInstances := []instance.Id{"i-0", "i-1"}
params := environs.StartInstanceParams{
DistributionGroup: func() ([]instance.Id, error) {
return expectedInstances, nil
},
}
_, err = testing.StartInstanceWithParams(env, "1", params, nil)
c.Assert(err, jc.ErrorIsNil)
c.Assert(mock.group, gc.DeepEquals, expectedInstances)
}
示例12: setupBootstrapSpecificVersion
func (s *bootstrapSuite) setupBootstrapSpecificVersion(c *gc.C, clientMajor, clientMinor int, toolsVersion *version.Number) (error, int, version.Number) {
currentVersion := version.Current
currentVersion.Major = clientMajor
currentVersion.Minor = clientMinor
currentVersion.Tag = ""
s.PatchValue(&version.Current, currentVersion)
s.PatchValue(&series.HostSeries, func() string { return "trusty" })
s.PatchValue(&arch.HostArch, func() string { return arch.AMD64 })
env := newEnviron("foo", useDefaultKeys, nil)
s.setDummyStorage(c, env)
envtools.RegisterToolsDataSourceFunc("local storage", func(environs.Environ) (simplestreams.DataSource, error) {
return storage.NewStorageSimpleStreamsDataSource("test datasource", env.storage, "tools", simplestreams.CUSTOM_CLOUD_DATA, false), nil
})
defer envtools.UnregisterToolsDataSourceFunc("local storage")
toolsBinaries := []version.Binary{
version.MustParseBinary("10.11.12-trusty-amd64"),
version.MustParseBinary("10.11.13-trusty-amd64"),
version.MustParseBinary("10.11-beta1-trusty-amd64"),
}
stream := "released"
if toolsVersion != nil && toolsVersion.Tag != "" {
stream = "devel"
currentVersion.Tag = toolsVersion.Tag
}
_, err := envtesting.UploadFakeToolsVersions(env.storage, stream, stream, toolsBinaries...)
c.Assert(err, jc.ErrorIsNil)
err = bootstrap.Bootstrap(envtesting.BootstrapContext(c), env, bootstrap.BootstrapParams{
AgentVersion: toolsVersion,
})
vers, _ := env.cfg.AgentVersion()
return err, env.bootstrapCount, vers
}
示例13: TestBootstrapMetadata
func (s *bootstrapSuite) TestBootstrapMetadata(c *gc.C) {
environs.UnregisterImageDataSourceFunc("bootstrap metadata")
metadataDir, metadata := createImageMetadata(c)
stor, err := filestorage.NewFileStorageWriter(metadataDir)
c.Assert(err, jc.ErrorIsNil)
envtesting.UploadFakeTools(c, stor, "released", "released")
env := newEnviron("foo", useDefaultKeys, nil)
s.setDummyStorage(c, env)
err = bootstrap.Bootstrap(envtesting.BootstrapContext(c), env, bootstrap.BootstrapParams{
MetadataDir: metadataDir,
})
c.Assert(err, jc.ErrorIsNil)
c.Assert(env.bootstrapCount, gc.Equals, 1)
c.Assert(envtools.DefaultBaseURL, gc.Equals, metadataDir)
datasources, err := environs.ImageMetadataSources(env)
c.Assert(err, jc.ErrorIsNil)
c.Assert(datasources, gc.HasLen, 3)
c.Assert(datasources[0].Description(), gc.Equals, "bootstrap metadata")
c.Assert(env.instanceConfig, gc.NotNil)
c.Assert(env.instanceConfig.CustomImageMetadata, gc.HasLen, 1)
c.Assert(env.instanceConfig.CustomImageMetadata[0], gc.DeepEquals, metadata[0])
}
示例14: TestUpdateEnvInfo
func (s *OpenSuite) TestUpdateEnvInfo(c *gc.C) {
store := jujuclienttesting.NewMemStore()
ctx := envtesting.BootstrapContext(c)
uuid := utils.MustNewUUID().String()
cfg, err := config.New(config.UseDefaults, map[string]interface{}{
"type": "dummy",
"name": "admin-model",
"uuid": uuid,
})
c.Assert(err, jc.ErrorIsNil)
controllerCfg := testing.FakeControllerConfig()
_, err = bootstrap.Prepare(ctx, store, bootstrap.PrepareParams{
ControllerConfig: controllerCfg,
ControllerName: "controller-name",
ModelConfig: cfg.AllAttrs(),
Cloud: dummy.SampleCloudSpec(),
AdminSecret: "admin-secret",
})
c.Assert(err, jc.ErrorIsNil)
foundController, err := store.ControllerByName("controller-name")
c.Assert(err, jc.ErrorIsNil)
c.Assert(foundController.ControllerUUID, gc.Not(gc.Equals), "")
c.Assert(foundController.CACert, gc.Not(gc.Equals), "")
foundModel, err := store.ModelByName("controller-name", "admin/admin-model")
c.Assert(err, jc.ErrorIsNil)
c.Assert(foundModel, jc.DeepEquals, &jujuclient.ModelDetails{
ModelUUID: cfg.UUID(),
})
}
示例15: TestNewDummyEnviron
func (s *OpenSuite) TestNewDummyEnviron(c *gc.C) {
s.PatchValue(&jujuversion.Current, testing.FakeVersionNumber)
// matches *Settings.Map()
cfg, err := config.New(config.NoDefaults, dummySampleConfig())
c.Assert(err, jc.ErrorIsNil)
ctx := envtesting.BootstrapContext(c)
cache := jujuclienttesting.NewMemStore()
controllerCfg := testing.FakeControllerConfig()
env, err := bootstrap.Prepare(ctx, cache, bootstrap.PrepareParams{
ControllerConfig: controllerCfg,
ControllerName: cfg.Name(),
ModelConfig: cfg.AllAttrs(),
Cloud: dummy.SampleCloudSpec(),
AdminSecret: "admin-secret",
})
c.Assert(err, jc.ErrorIsNil)
storageDir := c.MkDir()
s.PatchValue(&envtools.DefaultBaseURL, storageDir)
stor, err := filestorage.NewFileStorageWriter(storageDir)
c.Assert(err, jc.ErrorIsNil)
envtesting.UploadFakeTools(c, stor, cfg.AgentStream(), cfg.AgentStream())
err = bootstrap.Bootstrap(ctx, env, bootstrap.BootstrapParams{
ControllerConfig: controllerCfg,
AdminSecret: "admin-secret",
CAPrivateKey: testing.CAKey,
})
c.Assert(err, jc.ErrorIsNil)
// New controller should have been added to collection.
foundController, err := cache.ControllerByName(cfg.Name())
c.Assert(err, jc.ErrorIsNil)
c.Assert(foundController.ControllerUUID, gc.DeepEquals, controllerCfg.ControllerUUID())
}