本文整理汇总了Golang中github.com/juju/juju/version.MustParseBinary函数的典型用法代码示例。如果您正苦于以下问题:Golang MustParseBinary函数的具体用法?Golang MustParseBinary怎么用?Golang MustParseBinary使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了MustParseBinary函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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
}
示例2: 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)
}
示例3: TestAutoUploadAfterFailedSync
func (s *BootstrapSuite) TestAutoUploadAfterFailedSync(c *gc.C) {
s.PatchValue(&version.Current.Series, config.LatestLtsSeries())
otherSeries := "quantal"
env := s.setupAutoUploadTest(c, "1.7.3", otherSeries)
// Run command and check for that upload has been run for tools matching the current juju version.
opc, errc := runCommand(nullContext(c), envcmd.Wrap(new(BootstrapCommand)))
c.Assert(<-errc, gc.IsNil)
c.Assert((<-opc).(dummy.OpPutFile).Env, gc.Equals, "peckham")
list, err := envtools.FindTools(env, version.Current.Major, version.Current.Minor, coretools.Filter{}, false)
c.Assert(err, gc.IsNil)
c.Logf("found: " + list.String())
urls := list.URLs()
// We expect:
// supported LTS series precise, trusty,
// the specified series (quantal),
// and the environment's default series (raring).
expectedVers := []version.Binary{
version.MustParseBinary(fmt.Sprintf("1.7.3.1-%s-%s", "quantal", version.Current.Arch)),
version.MustParseBinary(fmt.Sprintf("1.7.3.1-%s-%s", "raring", version.Current.Arch)),
version.MustParseBinary(fmt.Sprintf("1.7.3.1-%s-%s", "precise", version.Current.Arch)),
version.MustParseBinary(fmt.Sprintf("1.7.3.1-%s-%s", "trusty", version.Current.Arch)),
}
c.Assert(urls, gc.HasLen, len(expectedVers))
for _, vers := range expectedVers {
c.Logf("seeking: " + vers.String())
_, found := urls[vers]
c.Check(found, gc.Equals, true)
}
}
示例4: 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)
}
示例5: TestMetadataFromTools
func (*metadataHelperSuite) TestMetadataFromTools(c *gc.C) {
metadata := tools.MetadataFromTools(nil, "proposed")
c.Assert(metadata, gc.HasLen, 0)
toolsList := coretools.List{{
Version: version.MustParseBinary("1.2.3-precise-amd64"),
Size: 123,
SHA256: "abc",
}, {
Version: version.MustParseBinary("2.0.1-raring-amd64"),
URL: "file:///tmp/proposed/juju-2.0.1-raring-amd64.tgz",
Size: 456,
SHA256: "xyz",
}}
metadata = tools.MetadataFromTools(toolsList, "proposed")
c.Assert(metadata, gc.HasLen, len(toolsList))
for i, t := range toolsList {
md := metadata[i]
c.Assert(md.Release, gc.Equals, t.Version.Series)
c.Assert(md.Version, gc.Equals, t.Version.Number.String())
c.Assert(md.Arch, gc.Equals, t.Version.Arch)
// FullPath is only filled out when reading tools using simplestreams.
// It's not needed elsewhere and requires a URL() call.
c.Assert(md.FullPath, gc.Equals, "")
c.Assert(md.Path, gc.Equals, tools.StorageName(t.Version, "proposed")[len("tools/"):])
c.Assert(md.FileType, gc.Equals, "tar.gz")
c.Assert(md.Size, gc.Equals, t.Size)
c.Assert(md.SHA256, gc.Equals, t.SHA256)
}
}
示例6: assertWriteMetadata
func (s *simplestreamsSuite) assertWriteMetadata(c *gc.C, withMirrors bool) {
var versionStrings = []string{
"1.2.3-precise-amd64",
"2.0.1-raring-amd64",
}
dir := c.MkDir()
toolstesting.MakeTools(c, dir, "proposed", versionStrings)
toolsList := coretools.List{
{
// If sha256/size is already known, do not recalculate
Version: version.MustParseBinary("1.2.3-precise-amd64"),
Size: 123,
SHA256: "abcd",
}, {
Version: version.MustParseBinary("2.0.1-raring-amd64"),
// The URL is not used for generating metadata.
URL: "bogus://",
},
}
writer, err := filestorage.NewFileStorageWriter(dir)
c.Assert(err, jc.ErrorIsNil)
writeMirrors := tools.DoNotWriteMirrors
if withMirrors {
writeMirrors = tools.WriteMirrors
}
err = tools.MergeAndWriteMetadata(writer, "proposed", "proposed", toolsList, writeMirrors)
c.Assert(err, jc.ErrorIsNil)
metadata := toolstesting.ParseMetadataFromDir(c, dir, "proposed", withMirrors)
assertMetadataMatches(c, dir, "proposed", toolsList, metadata)
// No release stream generated so there will not be a legacy index file created.
_, err = writer.Get("tools/streams/v1/index.json")
c.Assert(err, gc.NotNil)
}
示例7: TestUpgraderUpgradesImmediately
func (s *UpgraderSuite) TestUpgraderUpgradesImmediately(c *gc.C) {
stor := s.Environ.Storage()
oldTools := envtesting.PrimeTools(c, stor, s.DataDir(), version.MustParseBinary("5.4.3-precise-amd64"))
s.PatchValue(&version.Current, oldTools.Version)
newTools := envtesting.AssertUploadFakeToolsVersions(
c, stor, version.MustParseBinary("5.4.5-precise-amd64"))[0]
err := statetesting.SetAgentVersion(s.State, newTools.Version.Number)
c.Assert(err, gc.IsNil)
// Make the download take a while so that we verify that
// the download happens before the upgrader checks if
// it's been stopped.
dummy.SetStorageDelay(coretesting.ShortWait)
u := s.makeUpgrader()
err = u.Stop()
envtesting.CheckUpgraderReadyError(c, err, &upgrader.UpgradeReadyError{
AgentName: s.machine.Tag().String(),
OldTools: oldTools.Version,
NewTools: newTools.Version,
DataDir: s.DataDir(),
})
foundTools, err := agenttools.ReadTools(s.DataDir(), newTools.Version)
c.Assert(err, gc.IsNil)
envtesting.CheckTools(c, foundTools, newTools)
}
示例8: TestUpgraderAllowsDowngradeToOrigVersionIfUpgradeInProgress
func (s *UpgraderSuite) TestUpgraderAllowsDowngradeToOrigVersionIfUpgradeInProgress(c *gc.C) {
// note: otherwise illegal version jump
downgradeVersion := version.MustParseBinary("5.3.0-precise-amd64")
s.confVersion = downgradeVersion.Number
s.upgradeRunning = true
stor := s.Environ.Storage()
origTools := envtesting.PrimeTools(c, stor, s.DataDir(), version.MustParseBinary("5.4.3-precise-amd64"))
s.PatchValue(&version.Current, origTools.Version)
downgradeTools := envtesting.AssertUploadFakeToolsVersions(c, stor, downgradeVersion)[0]
err := statetesting.SetAgentVersion(s.State, downgradeVersion.Number)
c.Assert(err, gc.IsNil)
dummy.SetStorageDelay(coretesting.ShortWait)
u := s.makeUpgrader(c)
err = u.Stop()
envtesting.CheckUpgraderReadyError(c, err, &upgrader.UpgradeReadyError{
AgentName: s.machine.Tag().String(),
OldTools: origTools.Version,
NewTools: downgradeVersion,
DataDir: s.DataDir(),
})
foundTools, err := agenttools.ReadTools(s.DataDir(), downgradeTools.Version)
c.Assert(err, gc.IsNil)
downgradeTools.URL = fmt.Sprintf("https://%s/environment/90168e4c-2f10-4e9c-83c2-feedfacee5a9/tools/5.3.0-precise-amd64", s.APIState.Addr())
envtesting.CheckTools(c, foundTools, downgradeTools)
}
示例9: TestMockBuildTools
func (s *uploadSuite) TestMockBuildTools(c *gc.C) {
s.PatchValue(&version.Current, version.MustParseBinary("1.9.1-trusty-amd64"))
buildToolsFunc := toolstesting.GetMockBuildTools(c)
builtTools, err := buildToolsFunc(nil)
c.Assert(err, gc.IsNil)
builtTools.Dir = ""
expectedBuiltTools := &sync.BuiltTools{
StorageName: "name",
Version: version.Current,
Size: 127,
Sha256Hash: "6a19d08ca4913382ca86508aa38eb8ee5b9ae2d74333fe8d862c0f9e29b82c39",
}
c.Assert(builtTools, gc.DeepEquals, expectedBuiltTools)
vers := version.MustParseBinary("1.5.3-trusty-amd64")
builtTools, err = buildToolsFunc(&vers.Number)
c.Assert(err, gc.IsNil)
builtTools.Dir = ""
expectedBuiltTools = &sync.BuiltTools{
StorageName: "name",
Version: vers,
Size: 127,
Sha256Hash: "cad8ccedab8f26807ff379ddc2f2f78d9a7cac1276e001154cee5e39b9ddcc38",
}
c.Assert(builtTools, gc.DeepEquals, expectedBuiltTools)
}
示例10: TestMockBuildTools
func (s *uploadSuite) TestMockBuildTools(c *gc.C) {
current := version.MustParseBinary("1.9.1-trusty-amd64")
s.PatchValue(&version.Current, current.Number)
s.PatchValue(&arch.HostArch, func() string { return current.Arch })
s.PatchValue(&series.HostSeries, func() string { return current.Series })
buildToolsFunc := toolstesting.GetMockBuildTools(c)
builtTools, err := buildToolsFunc(nil, "released")
c.Assert(err, jc.ErrorIsNil)
builtTools.Dir = ""
expectedBuiltTools := &sync.BuiltTools{
StorageName: "name",
Version: current,
Size: 127,
Sha256Hash: "6a19d08ca4913382ca86508aa38eb8ee5b9ae2d74333fe8d862c0f9e29b82c39",
}
c.Assert(builtTools, gc.DeepEquals, expectedBuiltTools)
vers := version.MustParseBinary("1.5.3-trusty-amd64")
builtTools, err = buildToolsFunc(&vers.Number, "released")
c.Assert(err, jc.ErrorIsNil)
builtTools.Dir = ""
expectedBuiltTools = &sync.BuiltTools{
StorageName: "name",
Version: vers,
Size: 127,
Sha256Hash: "cad8ccedab8f26807ff379ddc2f2f78d9a7cac1276e001154cee5e39b9ddcc38",
}
c.Assert(builtTools, gc.DeepEquals, expectedBuiltTools)
}
示例11: 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.Series = "trusty"
currentVersion.Arch = "amd64"
s.PatchValue(&version.Current, currentVersion)
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"), nil
})
defer envtools.UnregisterToolsDataSourceFunc("local storage")
toolsBinaries := []version.Binary{
version.MustParseBinary("10.11.12-trusty-amd64"),
version.MustParseBinary("10.11.13-trusty-amd64"),
}
_, err := envtesting.UploadFakeToolsVersions(env.storage, "released", "released", 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
}
示例12: TestUpgradeJuju
func (s *UpgradeJujuSuite) TestUpgradeJuju(c *gc.C) {
for i, test := range upgradeJujuTests {
c.Logf("\ntest %d: %s", i, test.about)
s.Reset(c)
tools.DefaultBaseURL = ""
// Set up apparent CLI version and initialize the command.
s.PatchValue(&version.Current, version.MustParseBinary(test.currentVersion))
com := &UpgradeJujuCommand{}
if err := coretesting.InitCommand(envcmd.Wrap(com), test.args); err != nil {
if test.expectInitErr != "" {
c.Check(err, gc.ErrorMatches, test.expectInitErr)
} else {
c.Check(err, jc.ErrorIsNil)
}
continue
}
// Set up state and environ, and run the command.
toolsDir := c.MkDir()
updateAttrs := map[string]interface{}{
"agent-version": test.agentVersion,
"agent-metadata-url": "file://" + toolsDir + "/tools",
}
err := s.State.UpdateEnvironConfig(updateAttrs, nil, nil)
c.Assert(err, jc.ErrorIsNil)
versions := make([]version.Binary, len(test.tools))
for i, v := range test.tools {
versions[i] = version.MustParseBinary(v)
}
if len(versions) > 0 {
stor, err := filestorage.NewFileStorageWriter(toolsDir)
c.Assert(err, jc.ErrorIsNil)
envtesting.MustUploadFakeToolsVersions(stor, s.Environ.Config().AgentStream(), versions...)
}
err = com.Run(coretesting.Context(c))
if test.expectErr != "" {
c.Check(err, gc.ErrorMatches, test.expectErr)
continue
} else if !c.Check(err, jc.ErrorIsNil) {
continue
}
// Check expected changes to environ/state.
cfg, err := s.State.EnvironConfig()
c.Check(err, jc.ErrorIsNil)
agentVersion, ok := cfg.AgentVersion()
c.Check(ok, jc.IsTrue)
c.Check(agentVersion, gc.Equals, version.MustParse(test.expectVersion))
for _, uploaded := range test.expectUploaded {
// Substitute latest LTS for placeholder in expected series for uploaded tools
uploaded = strings.Replace(uploaded, "%LTS%", config.LatestLtsSeries(), 1)
vers := version.MustParseBinary(uploaded)
s.checkToolsUploaded(c, vers, agentVersion)
}
}
}
示例13: TestSetBootstrapTools
func (s *bootstrapSuite) TestSetBootstrapTools(c *gc.C) {
availableVersions := []version.Binary{
version.MustParseBinary("1.18.0-trusty-arm64"),
version.MustParseBinary("1.18.1-trusty-arm64"),
version.MustParseBinary("1.18.1.1-trusty-arm64"),
version.MustParseBinary("1.18.1.2-trusty-arm64"),
version.MustParseBinary("1.18.1.3-trusty-arm64"),
}
availableTools := make(tools.List, len(availableVersions))
for i, v := range availableVersions {
availableTools[i] = &tools.Tools{Version: v}
}
type test struct {
currentVersion version.Number
expectedTools version.Number
expectedAgentVersion version.Number
}
tests := []test{{
currentVersion: version.MustParse("1.18.0"),
expectedTools: version.MustParse("1.18.0"),
expectedAgentVersion: version.MustParse("1.18.1.3"),
}, {
currentVersion: version.MustParse("1.18.1.4"),
expectedTools: version.MustParse("1.18.1.3"),
expectedAgentVersion: version.MustParse("1.18.1.3"),
}, {
// build number is ignored unless major/minor don't
// match the latest.
currentVersion: version.MustParse("1.18.1.2"),
expectedTools: version.MustParse("1.18.1.3"),
expectedAgentVersion: version.MustParse("1.18.1.3"),
}, {
// If the current patch level exceeds whatever's in
// the tools source (e.g. when bootstrapping from trunk)
// then the latest available tools will be chosen.
currentVersion: version.MustParse("1.18.2"),
expectedTools: version.MustParse("1.18.1.3"),
expectedAgentVersion: version.MustParse("1.18.1.3"),
}}
env := newEnviron("foo", useDefaultKeys, nil)
for i, t := range tests {
c.Logf("test %d: %+v", i, t)
cfg, err := env.Config().Remove([]string{"agent-version"})
c.Assert(err, gc.IsNil)
err = env.SetConfig(cfg)
c.Assert(err, gc.IsNil)
s.PatchValue(&version.Current.Number, t.currentVersion)
bootstrapTools, err := bootstrap.SetBootstrapTools(env, availableTools)
c.Assert(err, gc.IsNil)
c.Assert(bootstrapTools, gc.HasLen, 1)
c.Assert(bootstrapTools[0].Version.Number, gc.Equals, t.expectedTools)
agentVersion, _ := env.Config().AgentVersion()
c.Assert(agentVersion, gc.Equals, t.expectedAgentVersion)
}
}
示例14: TestUpgraderRetryAndChanged
func (s *UpgraderSuite) TestUpgraderRetryAndChanged(c *gc.C) {
stor := s.DefaultToolsStorage
oldTools := envtesting.PrimeTools(c, stor, s.DataDir(), s.Environ.Config().AgentStream(), version.MustParseBinary("5.4.3-precise-amd64"))
s.PatchValue(&version.Current, oldTools.Version)
newTools := envtesting.AssertUploadFakeToolsVersions(
c, stor, s.Environ.Config().AgentStream(), s.Environ.Config().AgentStream(), version.MustParseBinary("5.4.5-precise-amd64"))[0]
err := statetesting.SetAgentVersion(s.State, newTools.Version.Number)
c.Assert(err, jc.ErrorIsNil)
retryc := make(chan time.Time)
*upgrader.RetryAfter = func() <-chan time.Time {
c.Logf("replacement retry after")
return retryc
}
err = stor.Remove(envtools.StorageName(newTools.Version, "released"))
c.Assert(err, jc.ErrorIsNil)
u := s.makeUpgrader(c)
defer u.Stop()
s.expectUpgradeChannelNotClosed(c)
for i := 0; i < 3; i++ {
select {
case retryc <- time.Now():
case <-time.After(coretesting.LongWait):
c.Fatalf("upgrader did not retry (attempt %d)", i)
}
}
// Make it upgrade to some newer tools that can be
// downloaded ok; it should stop retrying, download
// the newer tools and exit.
newerTools := envtesting.AssertUploadFakeToolsVersions(
c, stor, s.Environ.Config().AgentStream(), s.Environ.Config().AgentStream(), version.MustParseBinary("5.4.6-precise-amd64"))[0]
err = statetesting.SetAgentVersion(s.State, newerTools.Version.Number)
c.Assert(err, jc.ErrorIsNil)
s.BackingState.StartSync()
done := make(chan error)
go func() {
done <- u.Wait()
}()
select {
case err := <-done:
envtesting.CheckUpgraderReadyError(c, err, &upgrader.UpgradeReadyError{
AgentName: s.machine.Tag().String(),
OldTools: oldTools.Version,
NewTools: newerTools.Version,
DataDir: s.DataDir(),
})
case <-time.After(coretesting.LongWait):
c.Fatalf("upgrader did not quit after upgrading")
}
}
示例15: TestFindToolsExactInStorage
func (s *toolsSuite) TestFindToolsExactInStorage(c *gc.C) {
mockToolsStorage := &mockToolsStorage{
metadata: []toolstorage.Metadata{
{Version: version.MustParseBinary("1.22-beta1-trusty-amd64")},
{Version: version.MustParseBinary("1.22.0-trusty-amd64")},
},
}
s.PatchValue(&arch.HostArch, func() string { return arch.AMD64 })
s.PatchValue(&version.Current, version.MustParseBinary("1.22-beta1-trusty-amd64"))
s.testFindToolsExact(c, mockToolsStorage, true, true)
s.PatchValue(&version.Current, version.MustParseBinary("1.22.0-trusty-amd64"))
s.testFindToolsExact(c, mockToolsStorage, true, false)
}