func (s *UnitSuite) TestUpgrade(c *gc.C) { machine, unit, _, currentTools := s.primeAgent(c) agent := s.newAgent(c, unit) newVers := version.Binary{ Number: version.Current, Arch: arch.HostArch(), Series: series.HostSeries(), } newVers.Patch++ envtesting.AssertUploadFakeToolsVersions( c, s.DefaultToolsStorage, s.Environ.Config().AgentStream(), s.Environ.Config().AgentStream(), newVers) // The machine agent downloads the tools; fake this by // creating downloaded-tools.txt in data-dir/tools/<version>. toolsDir := agenttools.SharedToolsDir(s.DataDir(), newVers) err := os.MkdirAll(toolsDir, 0755) c.Assert(err, jc.ErrorIsNil) toolsPath := filepath.Join(toolsDir, "downloaded-tools.txt") testTools := tools.Tools{Version: newVers, URL: "http://testing.invalid/tools"} data, err := json.Marshal(testTools) c.Assert(err, jc.ErrorIsNil) err = ioutil.WriteFile(toolsPath, data, 0644) c.Assert(err, jc.ErrorIsNil) // Set the machine agent version to trigger an upgrade. err = machine.SetAgentVersion(newVers) c.Assert(err, jc.ErrorIsNil) err = runWithTimeout(agent) envtesting.CheckUpgraderReadyError(c, err, &upgrader.UpgradeReadyError{ AgentName: unit.Tag().String(), OldTools: currentTools.Version, NewTools: newVers, DataDir: s.DataDir(), }) }
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) }
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.DefaultToolsStorage origTools := envtesting.PrimeTools(c, stor, s.DataDir(), s.Environ.Config().AgentStream(), version.MustParseBinary("5.4.3-precise-amd64")) s.PatchValue(&version.Current, origTools.Version) downgradeTools := envtesting.AssertUploadFakeToolsVersions( c, stor, s.Environ.Config().AgentStream(), s.Environ.Config().AgentStream(), downgradeVersion)[0] err := statetesting.SetAgentVersion(s.State, downgradeVersion.Number) c.Assert(err, jc.ErrorIsNil) dummy.SetStorageDelay(coretesting.ShortWait) u := s.makeUpgrader(c) err = u.Stop() s.expectUpgradeChannelNotClosed(c) 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, jc.ErrorIsNil) downgradeTools.URL = fmt.Sprintf("https://%s/environment/%s/tools/5.3.0-precise-amd64", s.APIState.Addr(), coretesting.EnvironmentTag.Id()) envtesting.CheckTools(c, foundTools, downgradeTools) }
func (s *UpgraderSuite) TestUpgraderUpgradesImmediately(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) // 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(c) err = u.Stop() s.expectUpgradeChannelNotClosed(c) 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, jc.ErrorIsNil) newTools.URL = fmt.Sprintf("https://%s/environment/%s/tools/5.4.5-precise-amd64", s.APIState.Addr(), coretesting.EnvironmentTag.Id()) envtesting.CheckTools(c, foundTools, newTools) }
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") } }
func (s *MachineSuite) testUpgradeRequest(c *gc.C, agent runner, tag string, currentTools *tools.Tools) { newVers := version.Current newVers.Patch++ newTools := envtesting.AssertUploadFakeToolsVersions(c, s.Environ.Storage(), newVers)[0] err := s.State.SetEnvironAgentVersion(newVers.Number) c.Assert(err, gc.IsNil) err = runWithTimeout(agent) envtesting.CheckUpgraderReadyError(c, err, &upgrader.UpgradeReadyError{ AgentName: tag, OldTools: currentTools.Version, NewTools: newTools.Version, DataDir: s.DataDir(), }) }
func (s *UnitSuite) TestUpgrade(c *gc.C) { machine, unit, _, currentTools := s.primeAgent(c) agent := s.newAgent(c, unit) newVers := version.Current newVers.Patch++ envtesting.AssertUploadFakeToolsVersions(c, s.Environ.Storage(), newVers) // Set the machine agent version to trigger an upgrade. err := machine.SetAgentVersion(newVers) c.Assert(err, gc.IsNil) err = runWithTimeout(agent) envtesting.CheckUpgraderReadyError(c, err, &upgrader.UpgradeReadyError{ AgentName: unit.Tag().String(), OldTools: currentTools.Version, NewTools: newVers, DataDir: s.DataDir(), }) }
func (s *MachineSuite) testUpgradeRequest(c *gc.C, agent runner, tag string, currentTools *tools.Tools) { newVers := version.Binary{ Number: jujuversion.Current, Arch: arch.HostArch(), Series: series.HostSeries(), } newVers.Patch++ newTools := envtesting.AssertUploadFakeToolsVersions( c, s.DefaultToolsStorage, s.Environ.Config().AgentStream(), s.Environ.Config().AgentStream(), newVers)[0] err := s.State.SetModelAgentVersion(newVers.Number) c.Assert(err, jc.ErrorIsNil) err = runWithTimeout(agent) envtesting.CheckUpgraderReadyError(c, err, &upgrader.UpgradeReadyError{ AgentName: tag, OldTools: currentTools.Version, NewTools: newTools.Version, DataDir: s.DataDir(), }) }
func (s *UpgraderSuite) TestUpgraderAllowsDowngradingPatchVersions(c *gc.C) { 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, version.MustParseBinary("5.4.2-precise-amd64"))[0] err := statetesting.SetAgentVersion(s.State, downgradeTools.Version.Number) c.Assert(err, gc.IsNil) dummy.SetStorageDelay(coretesting.ShortWait) u := s.makeUpgrader() err = u.Stop() envtesting.CheckUpgraderReadyError(c, err, &upgrader.UpgradeReadyError{ AgentName: s.machine.Tag().String(), OldTools: origTools.Version, NewTools: downgradeTools.Version, DataDir: s.DataDir(), }) foundTools, err := agenttools.ReadTools(s.DataDir(), downgradeTools.Version) c.Assert(err, gc.IsNil) envtesting.CheckTools(c, foundTools, downgradeTools) }
func (s *UpgraderSuite) TestUsesAlreadyDownloadedToolsIfAvailable(c *gc.C) { oldVersion := version.MustParseBinary("1.2.3-quantal-amd64") s.PatchValue(&version.Current, oldVersion) newVersion := version.MustParseBinary("5.4.3-quantal-amd64") err := statetesting.SetAgentVersion(s.State, newVersion.Number) c.Assert(err, gc.IsNil) // Install tools matching the new version in the data directory // but *not* in environment storage. The upgrader should find the // downloaded tools without looking in environment storage. envtesting.InstallFakeDownloadedTools(c, s.DataDir(), newVersion) u := s.makeUpgrader(c) err = u.Stop() envtesting.CheckUpgraderReadyError(c, err, &upgrader.UpgradeReadyError{ AgentName: s.machine.Tag().String(), OldTools: oldVersion, NewTools: newVersion, DataDir: s.DataDir(), }) }
func (s *UpgraderSuite) TestUpgraderAllowsDowngradingPatchVersions(c *gc.C) { stor := s.DefaultToolsStorage origTools := envtesting.PrimeTools(c, stor, s.DataDir(), s.Environ.Config().AgentStream(), version.MustParseBinary("5.4.3-precise-amd64")) s.patchVersion(origTools.Version) downgradeTools := envtesting.AssertUploadFakeToolsVersions( c, stor, s.Environ.Config().AgentStream(), s.Environ.Config().AgentStream(), version.MustParseBinary("5.4.2-precise-amd64"))[0] err := statetesting.SetAgentVersion(s.State, downgradeTools.Version.Number) c.Assert(err, jc.ErrorIsNil) u := s.makeUpgrader(c) err = u.Stop() s.expectInitialUpgradeCheckNotDone(c) envtesting.CheckUpgraderReadyError(c, err, &upgrader.UpgradeReadyError{ AgentName: s.machine.Tag().String(), OldTools: origTools.Version, NewTools: downgradeTools.Version, DataDir: s.DataDir(), }) foundTools, err := agenttools.ReadTools(s.DataDir(), downgradeTools.Version) c.Assert(err, jc.ErrorIsNil) downgradeTools.URL = fmt.Sprintf("https://%s/model/%s/tools/5.4.2-precise-amd64", s.APIState.Addr(), coretesting.ModelTag.Id()) envtesting.CheckTools(c, foundTools, downgradeTools) }
func (s *UpgraderSuite) TestUpgraderUpgradesImmediately(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.patchVersion(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) u := s.makeUpgrader(c) err = u.Stop() s.expectUpgradeChannelNotClosed(c) 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, jc.ErrorIsNil) newTools.URL = fmt.Sprintf("https://%s/environment/%s/tools/5.4.5-precise-amd64", s.APIState.Addr(), coretesting.EnvironmentTag.Id()) envtesting.CheckTools(c, foundTools, newTools) }