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) } } }
// 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) }
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) }
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() } } }
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") }
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") } }
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) }
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) }
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()) }
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) }
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) } }
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: "******", CACert: []byte("CA CERT\n" + testing.CACert), }, APIInfo: &api.Info{ Password: "******", 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) }
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") }
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{}) } }
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) }
func (s *UpgraderSuite) TestDelayedStop(c *C) { defer dummy.SetStorageDelay(0) tools := s.primeTools(c, version.MustParseBinary("2.0.3-foo-bar")) s.uploadTools(c, version.MustParseBinary("2.0.5-foo-bar")) s.uploadTools(c, version.MustParseBinary("2.0.6-foo-bar")) s.uploadTools(c, version.MustParseBinary("2.0.6-foo-bar")) s.uploadTools(c, version.MustParseBinary("2.0.7-foo-bar")) s.poisonVersion(version.MustParseBinary("2.0.7-foo-bar")) for i, test := range delayedStopTests { c.Logf("%d. %v", i, test.about) upgraderKillDelay = test.upgraderKillDelay dummy.SetStorageDelay(test.storageDelay) proposed := version.MustParse(test.propose) s.proposeVersion(c, proposed, true) u := s.startUpgrader(c, tools) t0 := time.Now() err := u.Stop() d := time.Now().Sub(t0) if d > 100*time.Millisecond { c.Errorf("upgrader took took too long: %v", d) } if test.err == "" { c.Check(err, IsNil) } else { c.Check(err, ErrorMatches, test.err) } } }
func (t *ToolsSuite) TestChangeAgentTools(c *gc.C) { files := []*testing.TarFile{ testing.NewTarFile("jujuc", 0755, "juju executable"), testing.NewTarFile("jujud", 0755, "jujuc executable"), } testTools := &tools.Tools{ URL: "http://foo/bar1", Version: version.MustParseBinary("1.2.3-foo-bar"), } err := tools.UnpackTools(t.dataDir, testTools, bytes.NewReader(testing.TarGz(files...))) c.Assert(err, gc.IsNil) gotTools, err := tools.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, tools.ToolsDir(t.dataDir, "testagent"), []string{"jujuc", "jujud", urlFile}) // 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"), } tools2 := &tools.Tools{ URL: "http://foo/bar2", Version: version.MustParseBinary("1.2.4-foo-bar"), } err = tools.UnpackTools(t.dataDir, tools2, bytes.NewReader(testing.TarGz(files2...))) c.Assert(err, gc.IsNil) gotTools, err = tools.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, tools.ToolsDir(t.dataDir, "testagent"), []string{"foo", "bar", urlFile}) }
func (s *UpgraderSuite) TestUpgraderUpgradesImmediately(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) // 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 := upgrader.New(s.state.Upgrader(), s.machine.Tag(), s.DataDir()) err = u.Stop() c.Assert(err, gc.DeepEquals, &upgrader.UpgradeReadyError{ AgentName: s.machine.Tag(), OldTools: oldTools, NewTools: newTools, DataDir: s.DataDir(), }) foundTools, err := tools.ReadTools(s.DataDir(), newTools.Version) c.Assert(err, gc.IsNil) c.Assert(foundTools, gc.DeepEquals, newTools) }
func (suite) TestBinaryMarshalUnmarshal(c *C) { for _, m := range marshallers { c.Logf("encoding %v", m.name) type doc struct { Version version.Binary } v := doc{version.MustParseBinary("1.2.3-foo-bar")} data, err := m.marshal(v) c.Assert(err, IsNil) var nv doc err = m.unmarshal(data, &nv) c.Assert(err, IsNil) c.Assert(v, Equals, nv) } }
func (s *UpgraderSuite) TestUpgraderSetsTools(c *gc.C) { vers := version.MustParseBinary("5.4.3-foo-bar") err := statetesting.SetAgentVersion(s.State, vers.Number) c.Assert(err, gc.IsNil) agentTools := s.primeTools(c, vers) _, err = s.machine.AgentTools() c.Assert(err, jc.Satisfies, errors.IsNotFoundError) u := upgrader.New(s.state.Upgrader(), s.machine.Tag(), s.DataDir()) statetesting.AssertStop(c, u) s.machine.Refresh() gotTools, err := s.machine.AgentTools() c.Assert(err, gc.IsNil) c.Assert(gotTools, gc.DeepEquals, agentTools) }
func StartContainer(c *gc.C, manager lxc.ContainerManager, machineId string) instance.Instance { config := testing.EnvironConfig(c) stateInfo := jujutesting.FakeStateInfo(machineId) apiInfo := jujutesting.FakeAPIInfo(machineId) series := "series" nonce := "fake-nonce" tools := &tools.Tools{ Binary: version.MustParseBinary("2.3.4-foo-bar"), URL: "http://tools.testing.invalid/2.3.4-foo-bar.tgz", } inst, err := manager.StartContainer(machineId, series, nonce, tools, config, stateInfo, apiInfo) c.Assert(err, gc.IsNil) return inst }
func (t *ToolsSuite) TestReadToolsErrors(c *gc.C) { vers := version.MustParseBinary("1.2.3-precise-amd64") testTools, err := tools.ReadTools(t.dataDir, vers) c.Assert(testTools, gc.IsNil) c.Assert(err, gc.ErrorMatches, "cannot read URL in tools directory: .*") dir := tools.SharedToolsDir(t.dataDir, vers) err = os.MkdirAll(dir, 0755) c.Assert(err, gc.IsNil) err = ioutil.WriteFile(filepath.Join(dir, urlFile), []byte(" \t\n"), 0644) c.Assert(err, gc.IsNil) testTools, err = tools.ReadTools(t.dataDir, vers) c.Assert(testTools, gc.IsNil) c.Assert(err, gc.ErrorMatches, "empty URL in tools directory.*") }
func (s *UpgraderSuite) TestUpgraderSetToolsEvenWithNoToolsToRead(c *gc.C) { vers := version.MustParseBinary("5.4.3-foo-bar") s.primeTools(c, vers) err := os.RemoveAll(filepath.Join(s.DataDir(), "tools")) c.Assert(err, gc.IsNil) _, err = s.machine.AgentTools() c.Assert(err, jc.Satisfies, errors.IsNotFoundError) err = statetesting.SetAgentVersion(s.State, vers.Number) c.Assert(err, gc.IsNil) u := upgrader.New(s.state.Upgrader(), s.machine.Tag(), s.DataDir()) statetesting.AssertStop(c, u) s.machine.Refresh() gotTools, err := s.machine.AgentTools() c.Assert(err, gc.IsNil) c.Assert(gotTools, gc.DeepEquals, &tools.Tools{Version: version.Current}) }
func (s *MachineSuite) TestWatchMachine(c *C) { w := s.machine.Watch() defer testing.AssertStop(c, w) // Initial event. wc := testing.NewNotifyWatcherC(c, s.State, w) wc.AssertOneChange() // Make one change (to a separate instance), check one event. machine, err := s.State.Machine(s.machine.Id()) c.Assert(err, IsNil) err = machine.SetProvisioned("m-foo", "fake_nonce", nil) c.Assert(err, IsNil) wc.AssertOneChange() // Make two changes, check one event. err = machine.SetAgentTools(&tools.Tools{ URL: "foo", Binary: version.MustParseBinary("0.0.3-series-arch"), }) c.Assert(err, IsNil) err = machine.Destroy() c.Assert(err, IsNil) wc.AssertOneChange() // Stop, check closed. testing.AssertStop(c, w) wc.AssertClosed() // Remove machine, start new watch, check single event. err = machine.EnsureDead() c.Assert(err, IsNil) err = machine.Remove() c.Assert(err, IsNil) w = s.machine.Watch() defer testing.AssertStop(c, w) testing.NewNotifyWatcherC(c, s.State, w).AssertOneChange() }
"authorized-keys": "i-am-a-key", "ca-cert": testing.CACert, "ca-private-key": "", } for k, v := range attrs { final[k] = v } env, err := environs.NewFromAttrs(final) c.Assert(err, IsNil) s.env = env envtesting.RemoveAllTools(c, s.env) } var ( v100 = version.MustParse("1.0.0") v100p64 = version.MustParseBinary("1.0.0-precise-amd64") v100p32 = version.MustParseBinary("1.0.0-precise-i386") v100p = []version.Binary{v100p64, v100p32} v100q64 = version.MustParseBinary("1.0.0-quantal-amd64") v100q32 = version.MustParseBinary("1.0.0-quantal-i386") v100q = []version.Binary{v100q64, v100q32} v100all = append(v100p, v100q...) v1001 = version.MustParse("1.0.0.1") v1001p64 = version.MustParseBinary("1.0.0.1-precise-amd64") v100Xall = append(v100all, v1001p64) v110 = version.MustParse("1.1.0") v110p64 = version.MustParseBinary("1.1.0-precise-amd64") v110p32 = version.MustParseBinary("1.1.0-precise-i386")
func (s *StorageSuite) TestStorageName(c *gc.C) { vers := version.MustParseBinary("1.2.3-precise-amd64") path := tools.StorageName(vers) c.Assert(path, gc.Equals, "tools/juju-1.2.3-precise-amd64.tgz") }
func mkTools(s string) *tools.Tools { return &tools.Tools{ Version: version.MustParseBinary(s + "-foo-bar"), } }
func mkTools(s string) *state.Tools { return &state.Tools{ Binary: version.MustParseBinary(s + "-foo-bar"), } }
func (s *UpgradeJujuSuite) TestUpgradeJuju(c *C) { oldVersion := version.Current uploadTools = mockUploadTools defer func() { version.Current = oldVersion uploadTools = tools.Upload }() for i, test := range upgradeJujuTests { c.Logf("\ntest %d: %s", i, test.about) s.Reset(c) // Set up apparent CLI version and initialize the command. version.Current = version.MustParseBinary(test.currentVersion) com := &UpgradeJujuCommand{} if err := coretesting.InitCommand(com, test.args); err != nil { if test.expectInitErr != "" { c.Check(err, ErrorMatches, test.expectInitErr) } else { c.Check(err, IsNil) } continue } // Set up state and environ, and run the command. cfg, err := s.State.EnvironConfig() c.Assert(err, IsNil) cfg, err = cfg.Apply(map[string]interface{}{ "agent-version": test.agentVersion, "development": test.development, }) c.Assert(err, IsNil) err = s.State.SetEnvironConfig(cfg) c.Assert(err, IsNil) for _, v := range test.private { vers := version.MustParseBinary(v) envtesting.MustUploadFakeToolsVersion(s.Conn.Environ.Storage(), vers) } for _, v := range test.public { vers := version.MustParseBinary(v) storage := s.Conn.Environ.PublicStorage().(environs.Storage) envtesting.MustUploadFakeToolsVersion(storage, vers) } err = com.Run(coretesting.Context(c)) if test.expectErr != "" { c.Check(err, ErrorMatches, test.expectErr) continue } else if !c.Check(err, IsNil) { continue } // Check expected changes to environ/state. cfg, err = s.State.EnvironConfig() c.Check(err, IsNil) agentVersion, ok := cfg.AgentVersion() c.Check(ok, Equals, true) c.Check(agentVersion, Equals, version.MustParse(test.expectVersion)) c.Check(cfg.Development(), Equals, test.development) for _, uploaded := range test.expectUploaded { vers := version.MustParseBinary(uploaded) r, err := s.Conn.Environ.Storage().Get(tools.StorageName(vers)) if !c.Check(err, IsNil) { continue } data, err := ioutil.ReadAll(r) r.Close() c.Check(err, IsNil) c.Check(string(data), Equals, uploaded) } } }
func newSimpleTools(vers string) *state.Tools { return &state.Tools{ URL: "http://foo.com/tools/juju" + vers + ".tgz", Binary: version.MustParseBinary(vers), } }