本文整理汇总了Golang中github.com/juju/juju/environs/filestorage.NewFileStorageWriter函数的典型用法代码示例。如果您正苦于以下问题:Golang NewFileStorageWriter函数的具体用法?Golang NewFileStorageWriter怎么用?Golang NewFileStorageWriter使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewFileStorageWriter函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: createImageMetadata
func createImageMetadata(c *gc.C) (sourceDir string, destDir string, destStor storage.Storage, metadata *imagemetadata.ImageMetadata) {
destDir = c.MkDir()
var err error
destStor, err = filestorage.NewFileStorageWriter(destDir)
c.Assert(err, gc.IsNil)
// Generate some metadata.
sourceDir = c.MkDir()
im := []*imagemetadata.ImageMetadata{
{
Id: "1234",
Arch: "amd64",
Version: "13.04",
},
}
cloudSpec := &simplestreams.CloudSpec{
Region: "region",
Endpoint: "endpoint",
}
im[0].RegionName = cloudSpec.Region
im[0].Endpoint = cloudSpec.Endpoint
var sourceStor storage.Storage
sourceStor, err = filestorage.NewFileStorageWriter(sourceDir)
c.Assert(err, gc.IsNil)
err = imagemetadata.MergeAndWriteMetadata("raring", im, cloudSpec, sourceStor)
c.Assert(err, gc.IsNil)
return sourceDir, destDir, destStor, im[0]
}
示例2: 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])
}
示例3: 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()))
}
}
示例4: testStorageToolsUploaderWriteMirrors
func (s *uploadSuite) testStorageToolsUploaderWriteMirrors(c *gc.C, writeMirrors envtools.ShouldWriteMirrors) {
storageDir := c.MkDir()
stor, err := filestorage.NewFileStorageWriter(storageDir)
c.Assert(err, jc.ErrorIsNil)
uploader := &sync.StorageToolsUploader{
Storage: stor,
WriteMetadata: true,
WriteMirrors: writeMirrors,
}
err = uploader.UploadTools(
"released",
"released",
&coretools.Tools{
Version: version.Current,
Size: 7,
SHA256: "ed7002b439e9ac845f22357d822bac1444730fbdb6016d3ec9432297b9ec9f73",
}, []byte("content"))
c.Assert(err, jc.ErrorIsNil)
mirrorsPath := simplestreams.MirrorsPath(envtools.StreamsVersionV1) + simplestreams.UnsignedSuffix
r, err := stor.Get(path.Join(storage.BaseToolsPath, mirrorsPath))
if writeMirrors == envtools.WriteMirrors {
c.Assert(err, jc.ErrorIsNil)
data, err := ioutil.ReadAll(r)
r.Close()
c.Assert(err, jc.ErrorIsNil)
c.Assert(string(data), jc.Contains, `"mirrors":`)
} else {
c.Assert(err, jc.Satisfies, errors.IsNotFound)
}
}
示例5: TestWriteIndexRegionOnce
func (s *generateSuite) TestWriteIndexRegionOnce(c *gc.C) {
existingImageMetadata := []*imagemetadata.ImageMetadata{
{
Id: "1234",
Arch: "amd64",
Version: "13.04",
VirtType: "kvm",
},
}
cloudSpec := &simplestreams.CloudSpec{
Region: "region",
Endpoint: "endpoint",
}
dir := c.MkDir()
targetStorage, err := filestorage.NewFileStorageWriter(dir)
c.Assert(err, jc.ErrorIsNil)
err = imagemetadata.MergeAndWriteMetadata("raring", existingImageMetadata, cloudSpec, targetStorage)
c.Assert(err, jc.ErrorIsNil)
newImageMetadata := []*imagemetadata.ImageMetadata{
{
Id: "abcd",
Arch: "amd64",
Version: "13.04",
VirtType: "lxd",
},
}
err = imagemetadata.MergeAndWriteMetadata("raring", newImageMetadata, cloudSpec, targetStorage)
c.Assert(err, jc.ErrorIsNil)
foundIndex, _ := testing.ParseIndexMetadataFromStorage(c, targetStorage)
expectedCloudSpecs := []simplestreams.CloudSpec{*cloudSpec}
c.Assert(foundIndex.Clouds, jc.SameContents, expectedCloudSpecs)
}
示例6: Run
func (c *SyncToolsCommand) Run(ctx *cmd.Context) (resultErr error) {
// Register writer for output on screen.
loggo.RegisterWriter("synctools", cmd.NewCommandLogWriter("juju.environs.sync", ctx.Stdout, ctx.Stderr), loggo.INFO)
defer loggo.RemoveWriter("synctools")
environ, cleanup, err := environFromName(ctx, c.EnvName, &resultErr, "Sync-tools")
if err != nil {
return err
}
defer cleanup()
target := environ.Storage()
if c.localDir != "" {
target, err = filestorage.NewFileStorageWriter(c.localDir)
if err != nil {
return err
}
}
// Prepare syncing.
sctx := &sync.SyncContext{
Target: target,
AllVersions: c.allVersions,
MajorVersion: c.majorVersion,
MinorVersion: c.minorVersion,
DryRun: c.dryRun,
Dev: c.dev,
Public: c.public,
Source: c.source,
}
return syncTools(sctx)
}
示例7: TestReadWriteMetadata
func (*metadataHelperSuite) TestReadWriteMetadata(c *gc.C) {
metadata := []*tools.ToolsMetadata{{
Release: "precise",
Version: "1.2.3",
Arch: "amd64",
Path: "path1",
}, {
Release: "raring",
Version: "1.2.3",
Arch: "amd64",
Path: "path2",
}}
stor, err := filestorage.NewFileStorageWriter(c.MkDir())
c.Assert(err, gc.IsNil)
out, err := tools.ReadMetadata(stor)
c.Assert(out, gc.HasLen, 0)
c.Assert(err, gc.IsNil) // non-existence is not an error
err = tools.WriteMetadata(stor, metadata, tools.DoNotWriteMirrors)
c.Assert(err, gc.IsNil)
out, err = tools.ReadMetadata(stor)
for _, md := range out {
// FullPath is set by ReadMetadata.
c.Assert(md.FullPath, gc.Not(gc.Equals), "")
md.FullPath = ""
}
c.Assert(out, gc.DeepEquals, metadata)
}
示例8: TestWriteMetadataMergeWithExisting
func (s *simplestreamsSuite) TestWriteMetadataMergeWithExisting(c *gc.C) {
dir := c.MkDir()
existingToolsList := coretools.List{
{
Version: version.MustParseBinary("1.2.3-precise-amd64"),
Size: 123,
SHA256: "abc",
}, {
Version: version.MustParseBinary("2.0.1-raring-amd64"),
Size: 456,
SHA256: "xyz",
},
}
writer, err := filestorage.NewFileStorageWriter(dir)
c.Assert(err, gc.IsNil)
err = tools.MergeAndWriteMetadata(writer, existingToolsList, tools.DoNotWriteMirrors)
c.Assert(err, gc.IsNil)
newToolsList := coretools.List{
existingToolsList[0],
{
Version: version.MustParseBinary("2.1.0-raring-amd64"),
Size: 789,
SHA256: "def",
},
}
err = tools.MergeAndWriteMetadata(writer, newToolsList, tools.DoNotWriteMirrors)
c.Assert(err, gc.IsNil)
requiredToolsList := append(existingToolsList, newToolsList[1])
metadata := toolstesting.ParseMetadataFromDir(c, dir, false)
assertMetadataMatches(c, dir, requiredToolsList, metadata)
}
示例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: 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
}
示例11: 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])
}
示例12: 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())
}
示例13: PrimeAgentVersion
// PrimeAgentVersion writes the configuration file and tools with version
// vers for an agent with the given entity name. It returns the agent's
// configuration and the current tools.
func (s *AgentSuite) PrimeAgentVersion(c *gc.C, tag names.Tag, password string, vers version.Binary) (agent.ConfigSetterWriter, *coretools.Tools) {
c.Logf("priming agent %s", tag.String())
stor, err := filestorage.NewFileStorageWriter(c.MkDir())
c.Assert(err, jc.ErrorIsNil)
agentTools := envtesting.PrimeTools(c, stor, s.DataDir(), "released", vers)
err = envtools.MergeAndWriteMetadata(stor, "released", "released", coretools.List{agentTools}, envtools.DoNotWriteMirrors)
tools1, err := agenttools.ChangeAgentTools(s.DataDir(), tag.String(), vers)
c.Assert(err, jc.ErrorIsNil)
c.Assert(tools1, gc.DeepEquals, agentTools)
stateInfo := s.MongoInfo(c)
apiInfo := s.APIInfo(c)
paths := agent.DefaultPaths
paths.DataDir = s.DataDir()
conf, err := agent.NewAgentConfig(
agent.AgentConfigParams{
Paths: paths,
Tag: tag,
UpgradedToVersion: vers.Number,
Password: password,
Nonce: agent.BootstrapNonce,
StateAddresses: stateInfo.Addrs,
APIAddresses: apiInfo.Addrs,
CACert: stateInfo.CACert,
Model: apiInfo.ModelTag,
})
c.Assert(err, jc.ErrorIsNil)
conf.SetPassword(password)
c.Assert(conf.Write(), gc.IsNil)
s.primeAPIHostPorts(c)
return conf, agentTools
}
示例14: makeTools
func makeTools(c *gc.C, metadataDir, stream string, versionStrings []string, withCheckSum bool) coretools.List {
toolsDir := filepath.Join(metadataDir, storage.BaseToolsPath, stream)
c.Assert(os.MkdirAll(toolsDir, 0755), gc.IsNil)
var toolsList coretools.List
for _, versionString := range versionStrings {
binary, err := version.ParseBinary(versionString)
if err != nil {
c.Assert(err, jc.Satisfies, series.IsUnknownOSForSeriesError)
}
path := filepath.Join(toolsDir, fmt.Sprintf("juju-%s.tgz", binary))
data := binary.String()
err = ioutil.WriteFile(path, []byte(data), 0644)
c.Assert(err, jc.ErrorIsNil)
tool := &coretools.Tools{
Version: binary,
URL: path,
}
if withCheckSum {
tool.Size, tool.SHA256 = SHA256sum(c, path)
}
toolsList = append(toolsList, tool)
}
// Write the tools metadata.
stor, err := filestorage.NewFileStorageWriter(metadataDir)
c.Assert(err, jc.ErrorIsNil)
err = tools.MergeAndWriteMetadata(stor, stream, stream, toolsList, false)
c.Assert(err, jc.ErrorIsNil)
return toolsList
}
示例15: TestWriteMetadataNoFetch
func (s *simplestreamsSuite) TestWriteMetadataNoFetch(c *gc.C) {
toolsList := coretools.List{
{
Version: version.MustParseBinary("1.2.3-precise-amd64"),
Size: 123,
SHA256: "abcd",
}, {
Version: version.MustParseBinary("2.0.1-raring-amd64"),
Size: 456,
SHA256: "xyz",
},
}
expected := toolsList
// Add tools with an unknown series. Do not add an entry in the
// expected list as these tools should be ignored.
vers, err := version.ParseBinary("3.2.1-xuanhuaceratops-amd64")
c.Assert(err, jc.Satisfies, series.IsUnknownOSForSeriesError)
toolsList = append(toolsList, &coretools.Tools{
Version: vers,
Size: 456,
SHA256: "wqe",
})
dir := c.MkDir()
writer, err := filestorage.NewFileStorageWriter(dir)
c.Assert(err, jc.ErrorIsNil)
err = tools.MergeAndWriteMetadata(writer, "proposed", "proposed", toolsList, tools.DoNotWriteMirrors)
c.Assert(err, jc.ErrorIsNil)
metadata := toolstesting.ParseMetadataFromDir(c, dir, "proposed", false)
assertMetadataMatches(c, dir, "proposed", expected, metadata)
}