本文整理汇总了Golang中launchpad/net/juju-core/version.MustParseBinary函数的典型用法代码示例。如果您正苦于以下问题:Golang MustParseBinary函数的具体用法?Golang MustParseBinary怎么用?Golang MustParseBinary使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了MustParseBinary函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestReadList
func (s *StorageSuite) TestReadList(c *gc.C) {
store := s.env.Storage()
v001 := version.MustParseBinary("0.0.1-precise-amd64")
t001 := envtesting.UploadFakeToolsVersion(c, store, v001)
v100 := version.MustParseBinary("1.0.0-precise-amd64")
t100 := envtesting.UploadFakeToolsVersion(c, store, v100)
v101 := version.MustParseBinary("1.0.1-precise-amd64")
t101 := envtesting.UploadFakeToolsVersion(c, store, v101)
for i, t := range []struct {
majorVersion int
list tools.List
}{{
0, tools.List{t001},
}, {
1, tools.List{t100, t101},
}, {
2, nil,
}} {
c.Logf("test %d", i)
list, err := tools.ReadList(store, t.majorVersion)
if t.list != nil {
c.Assert(err, gc.IsNil)
c.Assert(list, gc.DeepEquals, t.list)
} else {
c.Assert(err, gc.Equals, tools.ErrNoMatches)
}
}
}
示例2: TestUnpackToolsContents
// Copied from environs/agent/tools_test.go
func (s *DiskManagerSuite) TestUnpackToolsContents(c *gc.C) {
files := []*coretesting.TarFile{
coretesting.NewTarFile("bar", 0755, "bar contents"),
coretesting.NewTarFile("foo", 0755, "foo contents"),
}
t1 := &tools.Tools{
URL: "http://foo/bar",
Version: version.MustParseBinary("1.2.3-foo-bar"),
}
err := s.manager.UnpackTools(t1, bytes.NewReader(coretesting.TarGz(files...)))
c.Assert(err, gc.IsNil)
assertDirNames(c, s.toolsDir(), []string{"1.2.3-foo-bar"})
s.assertToolsContents(c, t1, files)
// Try to unpack the same version of tools again - it should succeed,
// leaving the original version around.
t2 := &tools.Tools{
URL: "http://arble",
Version: version.MustParseBinary("1.2.3-foo-bar"),
}
files2 := []*coretesting.TarFile{
coretesting.NewTarFile("bar", 0755, "bar2 contents"),
coretesting.NewTarFile("x", 0755, "x contents"),
}
err = s.manager.UnpackTools(t2, bytes.NewReader(coretesting.TarGz(files2...)))
c.Assert(err, gc.IsNil)
assertDirNames(c, s.toolsDir(), []string{"1.2.3-foo-bar"})
s.assertToolsContents(c, t1, files)
}
示例3: TestUnpackToolsContents
func (t *ToolsSuite) TestUnpackToolsContents(c *gc.C) {
files := []*testing.TarFile{
testing.NewTarFile("bar", 0755, "bar contents"),
testing.NewTarFile("foo", 0755, "foo contents"),
}
testTools := &tools.Tools{
URL: "http://foo/bar",
Version: version.MustParseBinary("1.2.3-foo-bar"),
}
err := tools.UnpackTools(t.dataDir, testTools, bytes.NewReader(testing.TarGz(files...)))
c.Assert(err, gc.IsNil)
assertDirNames(c, t.toolsDir(), []string{"1.2.3-foo-bar"})
t.assertToolsContents(c, testTools, files)
// Try to unpack the same version of tools again - it should succeed,
// leaving the original version around.
tools2 := &tools.Tools{
URL: "http://arble",
Version: version.MustParseBinary("1.2.3-foo-bar"),
}
files2 := []*testing.TarFile{
testing.NewTarFile("bar", 0755, "bar2 contents"),
testing.NewTarFile("x", 0755, "x contents"),
}
err = tools.UnpackTools(t.dataDir, tools2, bytes.NewReader(testing.TarGz(files2...)))
c.Assert(err, gc.IsNil)
assertDirNames(c, t.toolsDir(), []string{"1.2.3-foo-bar"})
t.assertToolsContents(c, testTools, files)
}
示例4: TestUpgradeJuju
func (s *UpgradeJujuSuite) TestUpgradeJuju(c *C) {
oldVersion := version.Current
putTools = testPutTools
defer func() {
version.Current = oldVersion
putTools = environs.PutTools
}()
for i, test := range upgradeJujuTests {
c.Logf("%d. %s", i, test.about)
// Set up the test preconditions.
s.Reset(c)
for _, v := range test.private {
upload(s.Conn.Environ.Storage(), v)
}
for _, v := range test.public {
storage := s.Conn.Environ.PublicStorage().(environs.Storage)
upload(storage, v)
}
version.Current = version.MustParseBinary(test.currentVersion)
err := SetAgentVersion(s.State, version.MustParse(test.agentVersion), false)
c.Assert(err, IsNil)
// Run the command
com := &UpgradeJujuCommand{}
err = com.Init(newFlagSet(), test.args)
if test.expectInitErr != "" {
c.Check(err, ErrorMatches, test.expectInitErr)
continue
}
err = com.Run(&cmd.Context{c.MkDir(), nil, ioutil.Discard, ioutil.Discard})
if test.expectErr != "" {
c.Check(err, ErrorMatches, test.expectErr)
continue
}
c.Assert(err, IsNil)
cfg, err := s.State.EnvironConfig()
c.Check(err, IsNil)
c.Check(cfg.AgentVersion(), Equals, version.MustParse(test.expectVersion))
c.Check(cfg.Development(), Equals, test.expectDevelopment)
if test.expectUploaded != "" {
p := environs.ToolsStoragePath(version.MustParseBinary(test.expectUploaded))
r, err := s.Conn.Environ.Storage().Get(p)
c.Assert(err, IsNil)
data, err := ioutil.ReadAll(r)
c.Check(err, IsNil)
c.Check(string(data), Equals, test.expectUploaded)
r.Close()
}
}
}
示例5: TestUpgraderReadyErrorUpgrade
func (s *UpgraderSuite) TestUpgraderReadyErrorUpgrade(c *C) {
currentTools := s.primeTools(c, version.MustParseBinary("2.0.2-foo-bar"))
ug := &UpgradeReadyError{
AgentName: "foo",
OldTools: &state.Tools{Binary: version.MustParseBinary("2.0.0-foo-bar")},
NewTools: currentTools,
DataDir: s.DataDir(),
}
err := ug.ChangeAgentTools()
c.Assert(err, IsNil)
d := environs.AgentToolsDir(s.DataDir(), "foo")
data, err := ioutil.ReadFile(filepath.Join(d, "jujud"))
c.Assert(err, IsNil)
c.Assert(string(data), Equals, "jujud contents 2.0.2-foo-bar")
}
示例6: TestUpgraderRetryAndChanged
func (s *UpgraderSuite) TestUpgraderRetryAndChanged(c *gc.C) {
oldTools := s.primeTools(c, version.MustParseBinary("5.4.3-foo-bar"))
newTools := s.uploadTools(c, version.MustParseBinary("5.4.5-foo-bar"))
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(), tools.StorageName(newTools.Version), fmt.Errorf("a non-fatal dose"))
u := upgrader.New(s.state.Upgrader(), s.machine.Tag(), s.DataDir())
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 := s.uploadTools(c, version.MustParseBinary("5.4.6-foo-bar"))
err = statetesting.SetAgentVersion(s.State, newerTools.Version.Number)
c.Assert(err, gc.IsNil)
s.BackingState.Sync()
done := make(chan error)
go func() {
done <- u.Wait()
}()
select {
case err := <-done:
c.Assert(err, gc.DeepEquals, &upgrader.UpgradeReadyError{
AgentName: s.machine.Tag(),
OldTools: oldTools,
NewTools: newerTools,
DataDir: s.DataDir(),
})
case <-time.After(coretesting.LongWait):
c.Fatalf("upgrader did not quit after upgrading")
}
}
示例7: TestMachineRefresh
func (s *MachineSuite) TestMachineRefresh(c *C) {
m0, err := s.State.AddMachine("series", state.JobHostUnits)
c.Assert(err, IsNil)
oldTools, _ := m0.AgentTools()
m1, err := s.State.Machine(m0.Id())
c.Assert(err, IsNil)
err = m0.SetAgentTools(&tools.Tools{
URL: "foo",
Binary: version.MustParseBinary("0.0.3-series-arch"),
})
c.Assert(err, IsNil)
newTools, _ := m0.AgentTools()
m1Tools, _ := m1.AgentTools()
c.Assert(m1Tools, DeepEquals, oldTools)
err = m1.Refresh()
c.Assert(err, IsNil)
m1Tools, _ = m1.AgentTools()
c.Assert(*m1Tools, Equals, *newTools)
err = m0.EnsureDead()
c.Assert(err, IsNil)
err = m0.Remove()
c.Assert(err, IsNil)
err = m0.Refresh()
c.Assert(err, checkers.Satisfies, errors.IsNotFoundError)
}
示例8: TestBootstrapConfig
func (suite) TestBootstrapConfig(c *C) {
defer makeFakeHome(c, "bladaam").restore()
cfg, err := config.New(map[string]interface{}{
"name": "bladaam",
"type": "dummy",
"state-server": false,
"admin-secret": "highly",
"secret": "um",
"authorized-keys": "i-am-a-key",
"ca-cert": testing.CACert,
"ca-private-key": testing.CAKey,
})
c.Assert(err, IsNil)
provider, err := environs.Provider(cfg.Type())
c.Assert(err, IsNil)
tools := &state.Tools{
URL: "http://x",
Binary: version.MustParseBinary("1.2.3-foo-bar"),
}
cfg1, err := environs.BootstrapConfig(provider, cfg, tools)
c.Assert(err, IsNil)
expect := cfg.AllAttrs()
delete(expect, "secret")
expect["admin-secret"] = ""
expect["ca-private-key"] = ""
expect["agent-version"] = "1.2.3"
c.Assert(cfg1.AllAttrs(), DeepEquals, expect)
}
示例9: TestChangeAgentTools
func (s *UpgraderSuite) TestChangeAgentTools(c *gc.C) {
oldTools := &tools.Tools{
Version: version.MustParseBinary("1.2.3-arble-bletch"),
}
newTools := s.primeTools(c, version.MustParseBinary("5.4.3-foo-bar"))
ugErr := &upgrader.UpgradeReadyError{
AgentName: "anAgent",
OldTools: oldTools,
NewTools: newTools,
DataDir: s.DataDir(),
}
err := ugErr.ChangeAgentTools()
c.Assert(err, gc.IsNil)
link, err := os.Readlink(tools.ToolsDir(s.DataDir(), "anAgent"))
c.Assert(err, gc.IsNil)
c.Assert(link, gc.Equals, newTools.Version.String())
}
示例10: SetUpTest
func (s *lxcBrokerSuite) SetUpTest(c *gc.C) {
s.lxcSuite.SetUpTest(c)
tools := &tools.Tools{
Version: version.MustParseBinary("2.3.4-foo-bar"),
URL: "http://tools.testing.invalid/2.3.4-foo-bar.tgz",
}
s.broker = provisioner.NewLxcBroker(coretesting.EnvironConfig(c), tools)
}
示例11: upload
func upload(s environs.Storage, v string) {
vers := version.MustParseBinary(v)
p := environs.ToolsStoragePath(vers)
err := s.Put(p, strings.NewReader(v), int64(len(v)))
if err != nil {
panic(err)
}
}
示例12: TestUserData
func (*CloudInitSuite) TestUserData(c *C) {
testJujuHome := c.MkDir()
defer config.SetJujuHome(config.SetJujuHome(testJujuHome))
tools := &tools.Tools{
URL: "http://foo.com/tools/juju1.2.3-linux-amd64.tgz",
Binary: version.MustParseBinary("1.2.3-linux-amd64"),
}
envConfig, err := config.New(map[string]interface{}{
"type": "maas",
"name": "foo",
"default-series": "series",
"authorized-keys": "keys",
"ca-cert": testing.CACert,
})
c.Assert(err, IsNil)
cfg := &cloudinit.MachineConfig{
MachineId: "10",
MachineNonce: "5432",
Tools: tools,
StateServerCert: []byte(testing.ServerCert),
StateServerKey: []byte(testing.ServerKey),
StateInfo: &state.Info{
Password: "pw1",
CACert: []byte("CA CERT\n" + testing.CACert),
},
APIInfo: &api.Info{
Password: "pw2",
CACert: []byte("CA CERT\n" + testing.CACert),
},
DataDir: environs.DataDir,
Config: envConfig,
StatePort: envConfig.StatePort(),
APIPort: envConfig.APIPort(),
StateServer: true,
ProviderType: "dummy",
}
script1 := "script1"
script2 := "script2"
scripts := []string{script1, script2}
result, err := environs.ComposeUserData(cfg, scripts...)
c.Assert(err, IsNil)
unzipped, err := utils.Gunzip(result)
c.Assert(err, IsNil)
config := make(map[interface{}]interface{})
err = goyaml.Unmarshal(unzipped, &config)
c.Assert(err, IsNil)
// Just check that the cloudinit config looks good.
c.Check(config["apt_upgrade"], Equals, true)
// The scripts given to userData where added as the first
// commands to be run.
runCmd := config["runcmd"].([]interface{})
c.Check(runCmd[0], Equals, script1)
c.Check(runCmd[1], Equals, script2)
}
示例13: TestSetToolPrefix
func (s *StorageSuite) TestSetToolPrefix(c *gc.C) {
vers := version.MustParseBinary("1.2.3-precise-amd64")
tools.SetToolPrefix("test_prefix/juju-")
path := tools.StorageName(vers)
c.Assert(path, gc.Equals, "test_prefix/juju-1.2.3-precise-amd64.tgz")
tools.SetToolPrefix(tools.DefaultToolPrefix)
path = tools.StorageName(vers)
c.Assert(path, gc.Equals, "tools/juju-1.2.3-precise-amd64.tgz")
}
示例14: TestUnpackToolsBadData
func (t *ToolsSuite) TestUnpackToolsBadData(c *gc.C) {
for i, test := range unpackToolsBadDataTests {
c.Logf("test %d", i)
testTools := &tools.Tools{
URL: "http://foo/bar",
Version: version.MustParseBinary("1.2.3-foo-bar"),
}
err := tools.UnpackTools(t.dataDir, testTools, bytes.NewReader(test.data))
c.Assert(err, gc.ErrorMatches, test.err)
assertDirNames(c, t.toolsDir(), []string{})
}
}
示例15: TestBinaryBSON
func (suite) TestBinaryBSON(c *C) {
type doc struct {
Version version.Binary
}
v := doc{version.MustParseBinary("1.2.3-foo-bar")}
data, err := bson.Marshal(v)
c.Assert(err, IsNil)
var nv doc
err = bson.Unmarshal(data, &nv)
c.Assert(err, IsNil)
c.Assert(v, Equals, nv)
}