本文整理汇总了Golang中github.com/juju/juju/environs/testing.UploadFakeTools函数的典型用法代码示例。如果您正苦于以下问题:Golang UploadFakeTools函数的具体用法?Golang UploadFakeTools怎么用?Golang UploadFakeTools使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了UploadFakeTools函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestStartInstanceDistributionParams
func (t *localServerSuite) TestStartInstanceDistributionParams(c *gc.C) {
env := t.Prepare(c)
envtesting.UploadFakeTools(c, env.Storage())
err := bootstrap.Bootstrap(coretesting.Context(c), env, bootstrap.BootstrapParams{})
c.Assert(err, gc.IsNil)
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, gc.IsNil)
c.Assert(mock.group, gc.DeepEquals, expectedInstances)
}
示例2: TestNewAPIState
func (*NewAPIStateSuite) TestNewAPIState(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)
st, err := juju.NewAPIState(env, api.DialOpts{})
c.Assert(st, gc.NotNil)
// the secrets will not be updated, as they already exist
attrs, err := st.Client().EnvironmentGet()
c.Assert(attrs["secret"], gc.Equals, "pork")
c.Assert(st.Close(), gc.IsNil)
}
示例3: TestAddresses
func (t *localServerSuite) TestAddresses(c *gc.C) {
env := t.Prepare(c)
envtesting.UploadFakeTools(c, env.Storage())
err := bootstrap.Bootstrap(coretesting.Context(c), env, bootstrap.BootstrapParams{})
c.Assert(err, gc.IsNil)
inst, _ := testing.AssertStartInstance(c, env, "1")
c.Assert(err, gc.IsNil)
addrs, err := inst.Addresses()
c.Assert(err, gc.IsNil)
// Expected values use Address type but really contain a regexp for
// the value rather than a valid ip or hostname.
expected := []network.Address{{
Value: "*.testing.invalid",
Type: network.HostName,
Scope: network.ScopePublic,
}, {
Value: "*.internal.invalid",
Type: network.HostName,
Scope: network.ScopeCloudLocal,
}, {
Value: "8.0.0.*",
Type: network.IPv4Address,
Scope: network.ScopePublic,
}, {
Value: "127.0.0.*",
Type: network.IPv4Address,
Scope: network.ScopeCloudLocal,
}}
c.Assert(addrs, gc.HasLen, len(expected))
for i, addr := range addrs {
c.Check(addr.Value, gc.Matches, expected[i].Value)
c.Check(addr.Type, gc.Equals, expected[i].Type)
c.Check(addr.Scope, gc.Equals, expected[i].Scope)
}
}
示例4: TestStartInstanceAvailZoneOneConstrained
func (t *localServerSuite) TestStartInstanceAvailZoneOneConstrained(c *gc.C) {
env := t.Prepare(c)
envtesting.UploadFakeTools(c, env.Storage())
err := bootstrap.Bootstrap(coretesting.Context(c), env, bootstrap.BootstrapParams{})
c.Assert(err, gc.IsNil)
mock := mockAvailabilityZoneAllocations{
result: []common.AvailabilityZoneInstances{
{ZoneName: "az1"}, {ZoneName: "az2"},
},
}
t.PatchValue(ec2.AvailabilityZoneAllocations, mock.AvailabilityZoneAllocations)
// The first call to RunInstances fails with an error indicating the AZ
// is constrained. The second attempt succeeds, and so allocates to az2.
var azArgs []string
realRunInstances := *ec2.RunInstances
t.PatchValue(ec2.RunInstances, func(e *amzec2.EC2, ri *amzec2.RunInstances) (*amzec2.RunInstancesResp, error) {
azArgs = append(azArgs, ri.AvailZone)
if len(azArgs) == 1 {
return nil, azConstrainedErr
}
return realRunInstances(e, ri)
})
inst, _ := testing.AssertStartInstance(c, env, "1")
c.Assert(azArgs, gc.DeepEquals, []string{"az1", "az2"})
c.Assert(ec2.InstanceEC2(inst).AvailZone, gc.Equals, "az2")
}
示例5: startServer
func (srv *localServer) startServer(c *gc.C) {
var err error
srv.ec2srv, err = ec2test.NewServer()
if err != nil {
c.Fatalf("cannot start ec2 test server: %v", err)
}
srv.s3srv, err = s3test.NewServer(srv.config)
if err != nil {
c.Fatalf("cannot start s3 test server: %v", err)
}
aws.Regions["test"] = aws.Region{
Name: "test",
EC2Endpoint: srv.ec2srv.URL(),
S3Endpoint: srv.s3srv.URL(),
S3LocationConstraint: true,
Sign: aws.SignV2,
}
s3inst := s3.New(aws.Auth{}, aws.Regions["test"])
storage := ec2.BucketStorage(s3inst.Bucket("juju-dist"))
envtesting.UploadFakeTools(c, storage)
srv.addSpice(c)
zones := make([]amzec2.AvailabilityZoneInfo, 3)
zones[0].Region = "test"
zones[0].Name = "test-available"
zones[0].State = "available"
zones[1].Region = "test"
zones[1].Name = "test-impaired"
zones[1].State = "impaired"
zones[2].Region = "test"
zones[2].Name = "test-unavailable"
zones[2].State = "unavailable"
srv.ec2srv.SetAvailabilityZones(zones)
}
示例6: 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])
}
示例7: 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")
// This data source does not require to contain signed data.
// However, it may still contain it.
// Since we will always try to read signed data first,
// we want to be able to try to read this signed data
// with a user provided key.
// for this test, user provided key is empty.
// Bugs #1542127, #1542131
c.Assert(datasources[0].PublicSigningKey(), gc.Equals, "")
c.Assert(env.instanceConfig, gc.NotNil)
c.Assert(env.instanceConfig.CustomImageMetadata, gc.HasLen, 1)
c.Assert(env.instanceConfig.CustomImageMetadata[0], gc.DeepEquals, metadata[0])
}
示例8: bootstrapEnv
func (s *NewAPIClientSuite) bootstrapEnv(c *gc.C, envName string, store configstore.Storage) {
if store == nil {
store = configstore.NewMem()
}
ctx := envtesting.BootstrapContext(c)
c.Logf("env name: %s", envName)
env, err := environs.PrepareFromName(envName, ctx, store)
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, "released", "released")
err = bootstrap.Bootstrap(ctx, env, bootstrap.BootstrapParams{})
c.Assert(err, jc.ErrorIsNil)
info, err := store.ReadInfo(envName)
c.Assert(err, jc.ErrorIsNil)
creds := info.APICredentials()
creds.User = dummy.AdminUserTag().Name()
c.Logf("set creds: %#v", creds)
info.SetAPICredentials(creds)
err = info.Write()
c.Assert(err, jc.ErrorIsNil)
c.Logf("creds: %#v", info.APICredentials())
info, err = store.ReadInfo(envName)
c.Assert(err, jc.ErrorIsNil)
c.Logf("read creds: %#v", info.APICredentials())
c.Logf("store: %#v", store)
}
示例9: TestNewAPIState
func (cs *NewAPIStateSuite) TestNewAPIState(c *gc.C) {
cfg, err := config.New(config.NoDefaults, dummy.SampleConfig())
c.Assert(err, jc.ErrorIsNil)
ctx := envtesting.BootstrapContext(c)
env, err := environs.Prepare(cfg, ctx, configstore.NewMem())
c.Assert(err, jc.ErrorIsNil)
storageDir := c.MkDir()
cs.PatchValue(&envtools.DefaultBaseURL, storageDir)
stor, err := filestorage.NewFileStorageWriter(storageDir)
c.Assert(err, jc.ErrorIsNil)
envtesting.UploadFakeTools(c, stor, "released", "released")
err = bootstrap.Bootstrap(ctx, env, bootstrap.BootstrapParams{})
c.Assert(err, jc.ErrorIsNil)
cfg = env.Config()
cfg, err = cfg.Apply(map[string]interface{}{
"secret": "fnord",
})
c.Assert(err, jc.ErrorIsNil)
err = env.SetConfig(cfg)
c.Assert(err, jc.ErrorIsNil)
st, err := juju.NewAPIState(dummy.AdminUserTag(), env, api.DialOpts{})
c.Assert(st, gc.NotNil)
// the secrets will not be updated, as they already exist
attrs, err := st.Client().EnvironmentGet()
c.Assert(attrs["secret"], gc.Equals, "pork")
c.Assert(st.Close(), gc.IsNil)
}
示例10: TestBootstrapImageMetadataFromAllSources
// TestBootstrapImageMetadataFromAllSources tests that we are looking for
// image metadata in all data sources available to environment.
// Abandoning look up too soon led to misleading bootstrap failures:
// Juju reported no images available for a particular configuration,
// despite image metadata in other data sources compatible with the same configuration as well.
// Related to bug#1560625.
func (s *bootstrapSuite) TestBootstrapImageMetadataFromAllSources(c *gc.C) {
s.PatchValue(&series.HostSeries, func() string { return "raring" })
s.PatchValue(&arch.HostArch, func() string { return arch.AMD64 })
// Ensure that we can find at least one image metadata
// early on in the image metadata lookup.
// We should continue looking despite it.
metadataDir, _ := createImageMetadata(c)
stor, err := filestorage.NewFileStorageWriter(metadataDir)
c.Assert(err, jc.ErrorIsNil)
envtesting.UploadFakeTools(c, stor, "released", "released")
env := bootstrapEnvironWithRegion{
newEnviron("foo", useDefaultKeys, nil),
simplestreams.CloudSpec{
Region: "region",
Endpoint: "endpoint",
},
}
s.setDummyStorage(c, env.bootstrapEnviron)
bootstrapCons := constraints.MustParse("arch=amd64")
err = bootstrap.Bootstrap(envtesting.BootstrapContext(c), env, bootstrap.BootstrapParams{
BootstrapConstraints: bootstrapCons,
MetadataDir: metadataDir,
})
c.Assert(err, jc.ErrorIsNil)
datasources, err := environs.ImageMetadataSources(env)
c.Assert(err, jc.ErrorIsNil)
for _, source := range datasources {
// make sure we looked in each and all...
c.Assert(c.GetTestLog(), jc.Contains, fmt.Sprintf("image metadata in %s", source.Description()))
}
}
示例11: TestBootstrapMetadataImagesMissing
func (s *bootstrapSuite) TestBootstrapMetadataImagesMissing(c *gc.C) {
environs.UnregisterImageDataSourceFunc("bootstrap metadata")
noImagesDir := c.MkDir()
stor, err := filestorage.NewFileStorageWriter(noImagesDir)
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{
ControllerConfig: coretesting.FakeControllerConfig(),
AdminSecret: "admin-secret",
CAPrivateKey: coretesting.CAKey,
MetadataDir: noImagesDir,
})
c.Assert(err, jc.ErrorIsNil)
c.Assert(env.bootstrapCount, gc.Equals, 1)
datasources, err := environs.ImageMetadataSources(env)
c.Assert(err, jc.ErrorIsNil)
c.Assert(datasources, gc.HasLen, 2)
c.Assert(datasources[0].Description(), gc.Equals, "default cloud images")
c.Assert(datasources[1].Description(), gc.Equals, "default ubuntu cloud images")
}
示例12: bootstrapModel
func (s *NewAPIClientSuite) bootstrapModel(c *gc.C) (environs.Environ, jujuclient.ClientStore) {
const controllerName = "local.my-controller"
store := jujuclienttesting.NewMemStore()
ctx := envtesting.BootstrapContext(c)
env, err := environs.Prepare(ctx, store, environs.PrepareParams{
ControllerName: controllerName,
BaseConfig: dummy.SampleConfig(),
CloudName: "dummy",
})
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, "released", "released")
err = bootstrap.Bootstrap(ctx, env, bootstrap.BootstrapParams{})
c.Assert(err, jc.ErrorIsNil)
return env, store
}
示例13: 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())
}
示例14: testBootstrap
func (s *localJujuTestSuite) testBootstrap(c *gc.C, cfg *config.Config) (env environs.Environ) {
ctx := coretesting.Context(c)
environ, err := local.Provider.Prepare(ctx, cfg)
c.Assert(err, gc.IsNil)
envtesting.UploadFakeTools(c, environ.Storage())
defer environ.Storage().RemoveAll()
err = environ.Bootstrap(ctx, environs.BootstrapParams{})
c.Assert(err, gc.IsNil)
return environ
}
示例15: testStartInstanceAvailZone
func (t *localServerSuite) testStartInstanceAvailZone(c *gc.C, zone string) (instance.Instance, error) {
env := t.Prepare(c)
envtesting.UploadFakeTools(c, env.Storage())
err := bootstrap.Bootstrap(coretesting.Context(c), env, environs.BootstrapParams{})
c.Assert(err, gc.IsNil)
params := environs.StartInstanceParams{Placement: "zone=" + zone}
inst, _, _, err := testing.StartInstanceWithParams(env, "1", params, nil)
return inst, err
}