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) } }
// RemoveFakeTools deletes the fake tools from the supplied storage. func RemoveFakeTools(c *gc.C, stor storage.Storage) { c.Logf("removing fake tools") toolsVersion := version.Current name := envtools.StorageName(toolsVersion) err := stor.Remove(name) c.Check(err, gc.IsNil) defaultSeries := coretesting.FakeDefaultSeries if version.Current.Series != defaultSeries { toolsVersion.Series = defaultSeries name := envtools.StorageName(toolsVersion) err := stor.Remove(name) c.Check(err, gc.IsNil) } RemoveFakeToolsMetadata(c, stor) }
func (s *bootstrapSuite) TestBootstrapToolsFileURL(c *gc.C) { storageName := tools.StorageName(version.Current) sftpURL, err := s.env.Storage().URL(storageName) c.Assert(err, gc.IsNil) fileURL := fmt.Sprintf("file://%s/%s", s.env.storageDir, storageName) s.testBootstrapToolsURL(c, sftpURL, fileURL) }
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") } }
func uploadFakeToolsVersion(stor storage.Storage, vers version.Binary) (*coretools.Tools, error) { logger.Infof("uploading FAKE tools %s", vers) tgz, checksum := coretesting.TarGz( coretesting.NewTarFile("jujud", 0777, "jujud contents "+vers.String())) size := int64(len(tgz)) name := envtools.StorageName(vers) if err := stor.Put(name, bytes.NewReader(tgz), size); err != nil { return nil, err } url, err := stor.URL(name) if err != nil { return nil, err } return &coretools.Tools{URL: url, Version: vers, Size: size, SHA256: checksum}, nil }
func (s *StorageSuite) TestStorageName(c *gc.C) { vers := version.MustParseBinary("1.2.3-precise-amd64") path := envtools.StorageName(vers) c.Assert(path, gc.Equals, "tools/releases/juju-1.2.3-precise-amd64.tgz") }
func (t *LiveTests) TestBootstrapWithDefaultSeries(c *gc.C) { if !t.HasProvisioner { c.Skip("HasProvisioner is false; cannot test deployment") } current := version.Current other := current other.Series = "quantal" if current == other { other.Series = "precise" } dummyCfg, err := config.New(config.NoDefaults, dummy.SampleConfig().Merge(coretesting.Attrs{ "state-server": false, "name": "dummy storage", })) dummyenv, err := environs.Prepare(dummyCfg, coretesting.Context(c), configstore.NewMem()) c.Assert(err, gc.IsNil) defer dummyenv.Destroy() t.Destroy(c) attrs := t.TestConfig.Merge(coretesting.Attrs{"default-series": other.Series}) cfg, err := config.New(config.NoDefaults, attrs) c.Assert(err, gc.IsNil) env, err := environs.Prepare(cfg, coretesting.Context(c), t.ConfigStore) c.Assert(err, gc.IsNil) defer environs.Destroy(env, t.ConfigStore) currentName := envtools.StorageName(current) otherName := envtools.StorageName(other) envStorage := env.Storage() dummyStorage := dummyenv.Storage() defer envStorage.Remove(otherName) _, err = sync.Upload(dummyStorage, ¤t.Number) c.Assert(err, gc.IsNil) // This will only work while cross-compiling across releases is safe, // which depends on external elements. Tends to be safe for the last // few releases, but we may have to refactor some day. err = storageCopy(dummyStorage, currentName, envStorage, otherName) c.Assert(err, gc.IsNil) err = bootstrap.Bootstrap(coretesting.Context(c), env, environs.BootstrapParams{}) c.Assert(err, gc.IsNil) conn, err := juju.NewConn(env) c.Assert(err, gc.IsNil) defer conn.Close() // Wait for machine agent to come up on the bootstrap // machine and ensure it deployed the proper series. m0, err := conn.State.Machine("0") c.Assert(err, gc.IsNil) mw0 := newMachineToolWaiter(m0) defer mw0.Stop() waitAgentTools(c, mw0, other) }