本文整理汇总了Golang中github.com/juju/core/version.MustParseBinary函数的典型用法代码示例。如果您正苦于以下问题:Golang MustParseBinary函数的具体用法?Golang MustParseBinary怎么用?Golang MustParseBinary使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了MustParseBinary函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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)
}
}
示例2: TestUpgraderUpgradesImmediately
func (s *UpgraderSuite) TestUpgraderUpgradesImmediately(c *gc.C) {
stor := s.Conn.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(),
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)
}
示例3: TestUpgraderRetryAndChanged
func (s *UpgraderSuite) TestUpgraderRetryAndChanged(c *gc.C) {
stor := s.Conn.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)
retryc := make(chan time.Time)
*upgrader.RetryAfter = func() <-chan time.Time {
c.Logf("replacement retry after")
return retryc
}
dummy.Poison(s.Conn.Environ.Storage(), envtools.StorageName(newTools.Version), fmt.Errorf("a non-fatal dose"))
u := s.makeUpgrader()
defer u.Stop()
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, s.Conn.Environ.Storage(), version.MustParseBinary("5.4.6-precise-amd64"))[0]
err = statetesting.SetAgentVersion(s.State, newerTools.Version.Number)
c.Assert(err, gc.IsNil)
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(),
OldTools: oldTools.Version,
NewTools: newerTools.Version,
DataDir: s.DataDir(),
})
case <-time.After(coretesting.LongWait):
c.Fatalf("upgrader did not quit after upgrading")
}
}
示例4: TestUploadFakeSeries
func (s *toolsSuite) TestUploadFakeSeries(c *gc.C) {
// Make some fake tools.
localStorage := c.MkDir()
vers := version.MustParseBinary("1.9.0-quantal-amd64")
versionStrings := []string{vers.String()}
expectedTools := toolstesting.MakeToolsWithCheckSum(c, localStorage, "releases", versionStrings)
// Now try uploading them.
toolsFile := tools.StorageName(vers)
params := "?binaryVersion=" + vers.String() + "&series=precise,trusty"
resp, err := s.uploadRequest(c, s.toolsURI(c, params), true, path.Join(localStorage, toolsFile))
c.Assert(err, gc.IsNil)
// Check the response.
stor := s.Conn.Environ.Storage()
toolsURL, err := stor.URL(tools.StorageName(vers))
c.Assert(err, gc.IsNil)
expectedTools[0].URL = toolsURL
s.assertUploadResponse(c, resp, expectedTools[0])
// Check the contents.
for _, series := range []string{"precise", "quantal", "trusty"} {
toolsVersion := vers
toolsVersion.Series = series
r, err := stor.Get(tools.StorageName(toolsVersion))
c.Assert(err, gc.IsNil)
uploadedData, err := ioutil.ReadAll(r)
c.Assert(err, gc.IsNil)
expectedData, err := ioutil.ReadFile(filepath.Join(localStorage, tools.StorageName(vers)))
c.Assert(err, gc.IsNil)
c.Assert(uploadedData, gc.DeepEquals, expectedData)
}
}
示例5: testAgentTools
func testAgentTools(c *gc.C, obj tooler, agent string) {
// object starts with zero'd tools.
t, err := obj.AgentTools()
c.Assert(t, gc.IsNil)
c.Assert(err, jc.Satisfies, errors.IsNotFound)
err = obj.SetAgentVersion(version.Binary{})
c.Assert(err, gc.ErrorMatches, fmt.Sprintf("cannot set agent version for %s: empty series or arch", agent))
v2 := version.MustParseBinary("7.8.9-foo-bar")
err = obj.SetAgentVersion(v2)
c.Assert(err, gc.IsNil)
t3, err := obj.AgentTools()
c.Assert(err, gc.IsNil)
c.Assert(t3.Version, gc.DeepEquals, v2)
err = obj.Refresh()
c.Assert(err, gc.IsNil)
t3, err = obj.AgentTools()
c.Assert(err, gc.IsNil)
c.Assert(t3.Version, gc.DeepEquals, v2)
testWhenDying(c, obj, noErr, deadErr, func() error {
return obj.SetAgentVersion(v2)
})
}
示例6: makeTools
func makeTools(c *gc.C, metadataDir, subdir string, versionStrings []string, withCheckSum bool) coretools.List {
toolsDir := filepath.Join(metadataDir, storage.BaseToolsPath)
if subdir != "" {
toolsDir = filepath.Join(toolsDir, subdir)
}
c.Assert(os.MkdirAll(toolsDir, 0755), gc.IsNil)
var toolsList coretools.List
for _, versionString := range versionStrings {
binary := version.MustParseBinary(versionString)
path := filepath.Join(toolsDir, fmt.Sprintf("juju-%s.tgz", binary))
data := binary.String()
err := ioutil.WriteFile(path, []byte(data), 0644)
c.Assert(err, gc.IsNil)
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, gc.IsNil)
err = tools.MergeAndWriteMetadata(stor, toolsList, false)
c.Assert(err, gc.IsNil)
return toolsList
}
示例7: runAllowRetriesTest
func (s *BootstrapSuite) runAllowRetriesTest(c *gc.C, test bootstrapRetryTest) {
toolsVersions := envtesting.VAll
if test.version != "" {
useVersion := strings.Replace(test.version, "%LTS%", config.LatestLtsSeries(), 1)
testVersion := version.MustParseBinary(useVersion)
s.PatchValue(&version.Current, testVersion)
if test.addVersionToSource {
toolsVersions = append([]version.Binary{}, toolsVersions...)
toolsVersions = append(toolsVersions, testVersion)
}
}
resetJujuHome(c)
sourceDir := createToolsSource(c, toolsVersions)
s.PatchValue(&envtools.DefaultBaseURL, sourceDir)
var findToolsRetryValues []bool
mockFindTools := func(cloudInst environs.ConfigGetter, majorVersion, minorVersion int,
filter coretools.Filter, allowRetry bool) (list coretools.List, err error) {
findToolsRetryValues = append(findToolsRetryValues, allowRetry)
return nil, errors.NotFoundf("tools")
}
restore := envtools.TestingPatchBootstrapFindTools(mockFindTools)
defer restore()
_, errc := runCommand(nullContext(c), envcmd.Wrap(new(BootstrapCommand)), test.args...)
err := <-errc
c.Check(findToolsRetryValues, gc.DeepEquals, test.expectedAllowRetry)
stripped := strings.Replace(err.Error(), "\n", "", -1)
c.Check(stripped, gc.Matches, test.err)
}
示例8: newTools
func newTools(vers, url string) *tools.Tools {
return &tools.Tools{
Version: version.MustParseBinary(vers),
URL: url,
Size: 10,
SHA256: "1234",
}
}
示例9: TestChangeAgentTools
func (t *ToolsSuite) TestChangeAgentTools(c *gc.C) {
files := []*testing.TarFile{
testing.NewTarFile("jujuc", 0755, "juju executable"),
testing.NewTarFile("jujud", 0755, "jujuc executable"),
}
data, checksum := testing.TarGz(files...)
testTools := &coretest.Tools{
URL: "http://foo/bar1",
Version: version.MustParseBinary("1.2.3-foo-bar"),
Size: int64(len(data)),
SHA256: checksum,
}
err := agenttools.UnpackTools(t.dataDir, testTools, bytes.NewReader(data))
c.Assert(err, gc.IsNil)
gotTools, err := agenttools.ChangeAgentTools(t.dataDir, "testagent", testTools.Version)
c.Assert(err, gc.IsNil)
c.Assert(*gotTools, gc.Equals, *testTools)
assertDirNames(c, t.toolsDir(), []string{"1.2.3-foo-bar", "testagent"})
assertDirNames(c, agenttools.ToolsDir(t.dataDir, "testagent"), []string{"jujuc", "jujud", toolsFile})
// Upgrade again to check that the link replacement logic works ok.
files2 := []*testing.TarFile{
testing.NewTarFile("foo", 0755, "foo content"),
testing.NewTarFile("bar", 0755, "bar content"),
}
data2, checksum2 := testing.TarGz(files2...)
tools2 := &coretest.Tools{
URL: "http://foo/bar2",
Version: version.MustParseBinary("1.2.4-foo-bar"),
Size: int64(len(data2)),
SHA256: checksum2,
}
err = agenttools.UnpackTools(t.dataDir, tools2, bytes.NewReader(data2))
c.Assert(err, gc.IsNil)
gotTools, err = agenttools.ChangeAgentTools(t.dataDir, "testagent", tools2.Version)
c.Assert(err, gc.IsNil)
c.Assert(*gotTools, gc.Equals, *tools2)
assertDirNames(c, t.toolsDir(), []string{"1.2.3-foo-bar", "1.2.4-foo-bar", "testagent"})
assertDirNames(c, agenttools.ToolsDir(t.dataDir, "testagent"), []string{"foo", "bar", toolsFile})
}
示例10: TestReadList
func (s *StorageSuite) TestReadList(c *gc.C) {
store := s.env.Storage()
v001 := version.MustParseBinary("0.0.1-precise-amd64")
v100 := version.MustParseBinary("1.0.0-precise-amd64")
v101 := version.MustParseBinary("1.0.1-precise-amd64")
v111 := version.MustParseBinary("1.1.1-precise-amd64")
agentTools := envtesting.AssertUploadFakeToolsVersions(c, store, v001, v100, v101, v111)
t001 := agentTools[0]
t100 := agentTools[1]
t101 := agentTools[2]
t111 := agentTools[3]
for i, t := range []struct {
majorVersion,
minorVersion int
list coretools.List
}{{
0, 0, coretools.List{t001},
}, {
1, 0, coretools.List{t100, t101},
}, {
1, 1, coretools.List{t111},
}, {
1, -1, coretools.List{t100, t101, t111},
}, {
1, 2, nil,
}, {
2, 0, nil,
}} {
c.Logf("test %d", i)
list, err := envtools.ReadList(store, t.majorVersion, t.minorVersion)
if t.list != nil {
c.Assert(err, gc.IsNil)
// ReadList doesn't set the Size of SHA256, so blank out those attributes.
for _, tool := range t.list {
tool.Size = 0
tool.SHA256 = ""
}
c.Assert(list, gc.DeepEquals, t.list)
} else {
c.Assert(err, gc.Equals, coretools.ErrNoMatches)
}
}
}
示例11: TestWatchAPIVersion
func (s *unitUpgraderSuite) TestWatchAPIVersion(c *gc.C) {
w, err := s.st.WatchAPIVersion(s.rawUnit.Tag())
c.Assert(err, gc.IsNil)
defer statetesting.AssertStop(c, w)
wc := statetesting.NewNotifyWatcherC(c, s.BackingState, w)
// Initial event
wc.AssertOneChange()
vers := version.MustParseBinary("10.20.34-quantal-amd64")
err = s.rawMachine.SetAgentVersion(vers)
c.Assert(err, gc.IsNil)
// One change noticing the new version
wc.AssertOneChange()
vers = version.MustParseBinary("10.20.35-quantal-amd64")
err = s.rawMachine.SetAgentVersion(vers)
c.Assert(err, gc.IsNil)
wc.AssertOneChange()
statetesting.AssertStop(c, w)
wc.AssertClosed()
}
示例12: TestUpgraderRefusesToDowngradeMinorVersions
func (s *UpgraderSuite) TestUpgraderRefusesToDowngradeMinorVersions(c *gc.C) {
stor := s.Conn.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, version.MustParseBinary("5.3.3-precise-amd64"))[0]
err := statetesting.SetAgentVersion(s.State, downgradeTools.Version.Number)
c.Assert(err, gc.IsNil)
u := s.makeUpgrader()
err = u.Stop()
// If the upgrade would have triggered, we would have gotten an
// UpgradeReadyError, since it was skipped, we get no error
c.Check(err, gc.IsNil)
_, err = agenttools.ReadTools(s.DataDir(), downgradeTools.Version)
// TODO: ReadTools *should* be returning some form of errors.NotFound,
// however, it just passes back a fmt.Errorf so we live with it
// c.Assert(err, jc.Satisfies, errors.IsNotFound)
c.Check(err, gc.ErrorMatches, "cannot read tools metadata in tools directory.*no such file or directory")
}
示例13: TestChangeAgentTools
func (s *UpgraderSuite) TestChangeAgentTools(c *gc.C) {
oldTools := &coretools.Tools{
Version: version.MustParseBinary("1.2.3-quantal-amd64"),
}
stor := s.Conn.Environ.Storage()
newTools := envtesting.PrimeTools(c, stor, s.DataDir(), version.MustParseBinary("5.4.3-precise-amd64"))
s.PatchValue(&version.Current, newTools.Version)
err := envtools.MergeAndWriteMetadata(stor, coretools.List{newTools}, envtools.DoNotWriteMirrors)
c.Assert(err, gc.IsNil)
ugErr := &upgrader.UpgradeReadyError{
AgentName: "anAgent",
OldTools: oldTools.Version,
NewTools: newTools.Version,
DataDir: s.DataDir(),
}
err = ugErr.ChangeAgentTools()
c.Assert(err, gc.IsNil)
link, err := os.Readlink(agenttools.ToolsDir(s.DataDir(), "anAgent"))
c.Assert(err, gc.IsNil)
c.Assert(link, gc.Equals, newTools.Version.String())
}
示例14: TestEnsureToolsChecksBeforeDownloading
func (s *UpgraderSuite) TestEnsureToolsChecksBeforeDownloading(c *gc.C) {
stor := s.Conn.Environ.Storage()
newTools := envtesting.PrimeTools(c, stor, s.DataDir(), version.MustParseBinary("5.4.3-precise-amd64"))
s.PatchValue(&version.Current, newTools.Version)
// We've already downloaded the tools, so change the URL to be
// something invalid and ensure we don't actually get an error, because
// it doesn't actually do an HTTP request
u := s.makeUpgrader()
newTools.URL = "http://0.1.2.3/invalid/path/tools.tgz"
err := upgrader.EnsureTools(u, newTools, utils.VerifySSLHostnames)
c.Assert(err, gc.IsNil)
}
示例15: TestUnpackToolsBadChecksum
func (t *ToolsSuite) TestUnpackToolsBadChecksum(c *gc.C) {
data, _ := testing.TarGz(testing.NewTarFile("tools", 0755, "some data"))
testTools := &coretest.Tools{
URL: "http://foo/bar",
Version: version.MustParseBinary("1.2.3-foo-bar"),
Size: int64(len(data)),
SHA256: "1234",
}
err := agenttools.UnpackTools(t.dataDir, testTools, bytes.NewReader(data))
c.Assert(err, gc.ErrorMatches, "tarball sha256 mismatch, expected 1234, got .*")
_, err = os.Stat(t.toolsDir())
c.Assert(err, gc.FitsTypeOf, &os.PathError{})
}