func (s *uploadSuite) TestSyncTools(c *gc.C) { builtTools, err := sync.BuildToolsTarball(nil, "released") c.Assert(err, jc.ErrorIsNil) t, err := sync.SyncBuiltTools(s.targetStorage, "released", builtTools) c.Assert(err, jc.ErrorIsNil) s.assertEqualsCurrentVersion(c, t.Version) c.Assert(t.URL, gc.Not(gc.Equals), "") }
func (s *uploadSuite) TestSyncTools(c *gc.C) { s.PatchValue(&envtools.BundleTools, toolstesting.GetMockBundleTools(c)) builtTools, err := sync.BuildToolsTarball(nil) c.Assert(err, gc.IsNil) t, err := sync.SyncBuiltTools(s.env.Storage(), builtTools) c.Assert(err, gc.IsNil) c.Assert(t.Version, gc.Equals, version.Current) c.Assert(t.URL, gc.Not(gc.Equals), "") }
// populateTools stores uploaded tools in provider storage // and updates the tools metadata. // // TODO(axw) store tools in gridfs, catalogue in state. func (c *BootstrapCommand) populateTools(env environs.Environ) error { agentConfig := c.CurrentConfig() dataDir := agentConfig.DataDir() tools, err := agenttools.ReadTools(dataDir, version.Current) if err != nil { return err } if !strings.HasPrefix(tools.URL, "file://") { // Nothing to do since the tools were not uploaded. return nil } // This is a hack: providers using localstorage (local, manual) // can't use storage during bootstrap as the localstorage worker // isn't running. Use filestorage instead. var stor storage.Storage storageDir := agentConfig.Value(agent.StorageDir) if storageDir != "" { stor, err = filestorage.NewFileStorageWriter(storageDir) if err != nil { return err } } else { stor = env.Storage() } // Create a temporary directory to contain source and cloned tools. tempDir, err := ioutil.TempDir("", "juju-sync-tools") if err != nil { return err } defer os.RemoveAll(tempDir) destTools := filepath.Join(tempDir, filepath.FromSlash(envtools.StorageName(tools.Version))) if err := os.MkdirAll(filepath.Dir(destTools), 0700); err != nil { return err } srcTools := filepath.Join( agenttools.SharedToolsDir(dataDir, version.Current), "tools.tar.gz", ) if err := utils.CopyFile(destTools, srcTools); err != nil { return err } // Until we catalogue tools in state, we clone the tools // for each of the supported series of the same OS. otherSeries := version.OSSupportedSeries(version.Current.OS) _, err = sync.SyncBuiltTools(stor, &sync.BuiltTools{ Version: tools.Version, Dir: tempDir, StorageName: envtools.StorageName(tools.Version), Sha256Hash: tools.SHA256, Size: tools.Size, }, otherSeries...) return err }
func (context *upgradeContext) uploadTools1dot17(builtTools *sync.BuiltTools, series ...string) (*coretools.Tools, error) { logger.Warningf("running upload tools in 1.17 compatibility mode") env, err := environs.New(context.config) if err != nil { return nil, err } return sync.SyncBuiltTools(env.Storage(), builtTools, series...) }
func (s *uploadSuite) TestSyncAndForceVersion(c *gc.C) { vers := jujuversion.Current vers.Patch++ s.patchBundleTools(c, &vers) builtTools, err := sync.BuildAgentTarball(true, &vers, "released") c.Assert(err, jc.ErrorIsNil) t, err := sync.SyncBuiltTools(s.targetStorage, "released", builtTools) c.Assert(err, jc.ErrorIsNil) // Reported version from build call matches the real jujud version. c.Assert(t.Version, gc.Equals, version.Binary{Number: jujuversion.Current, Arch: arch.HostArch(), Series: series.HostSeries()}) }
func (s *uploadSuite) TestSyncToolsFakeSeries(c *gc.C) { seriesToUpload := "precise" if seriesToUpload == version.Current.Series { seriesToUpload = "raring" } builtTools, err := sync.BuildToolsTarball(nil) c.Assert(err, gc.IsNil) t, err := sync.SyncBuiltTools(s.env.Storage(), builtTools, "quantal", seriesToUpload) c.Assert(err, gc.IsNil) s.assertUploadedTools(c, t, seriesToUpload) }
func (s *uploadSuite) TestSyncToolsFakeSeries(c *gc.C) { seriesToUpload := "precise" if seriesToUpload == series.HostSeries() { seriesToUpload = "raring" } builtTools, err := sync.BuildToolsTarball(nil, "testing") c.Assert(err, jc.ErrorIsNil) t, err := sync.SyncBuiltTools(s.targetStorage, "testing", builtTools, "quantal", seriesToUpload) c.Assert(err, jc.ErrorIsNil) s.assertUploadedTools(c, t, []string{seriesToUpload, "quantal", series.HostSeries()}, "testing") }
func (s *uploadSuite) TestSyncAndForceVersion(c *gc.C) { // This test actually tests three things: // the writing of the FORCE-VERSION file; // the reading of the FORCE-VERSION file by the version package; // and the reading of the version from jujud. vers := version.Current vers.Patch++ builtTools, err := sync.BuildToolsTarball(&vers.Number) c.Assert(err, gc.IsNil) t, err := sync.SyncBuiltTools(s.env.Storage(), builtTools) c.Assert(err, gc.IsNil) c.Assert(t.Version, gc.Equals, vers) }
func (s *uploadSuite) TestSyncAndForceVersion(c *gc.C) { // This test actually tests three things: // the writing of the FORCE-VERSION file; // the reading of the FORCE-VERSION file by the version package; // and the reading of the version from jujud. vers := version.Current vers.Patch++ builtTools, err := sync.BuildToolsTarball(&vers, "released") c.Assert(err, jc.ErrorIsNil) t, err := sync.SyncBuiltTools(s.targetStorage, "released", builtTools) c.Assert(err, jc.ErrorIsNil) c.Assert(t.Version, gc.Equals, version.Binary{Number: vers, Arch: arch.HostArch(), Series: series.HostSeries()}) }
// uploadToStorage uploads the tools from the specified directory to environment storage. func (h *toolsHandler) uploadToStorage(uploadedTools *tools.Tools, toolsDir, toolsFilename string, fakeSeries ...string) (*tools.Tools, bool, error) { // SyncTools requires simplestreams metadata to find the tools to upload. stor, err := filestorage.NewFileStorageWriter(toolsDir) if err != nil { return nil, false, fmt.Errorf("cannot create metadata storage: %v", err) } // Generate metadata for the fake series. The URL for each fake series // record points to the same tools tarball. allToolsMetadata := []*tools.Tools{uploadedTools} for _, series := range fakeSeries { vers := uploadedTools.Version vers.Series = series allToolsMetadata = append(allToolsMetadata, &tools.Tools{ Version: vers, URL: uploadedTools.URL, Size: uploadedTools.Size, SHA256: uploadedTools.SHA256, }) } err = envtools.MergeAndWriteMetadata(stor, allToolsMetadata, false) if err != nil { return nil, false, fmt.Errorf("cannot get environment config: %v", err) } // Create the environment so we can get the storage to which we upload the tools. envConfig, err := h.state.EnvironConfig() if err != nil { return nil, false, fmt.Errorf("cannot get environment config: %v", err) } env, err := environs.New(envConfig) if err != nil { return nil, false, fmt.Errorf("cannot access environment: %v", err) } // Now perform the upload. builtTools := &sync.BuiltTools{ Version: uploadedTools.Version, Dir: toolsDir, StorageName: toolsFilename, Size: uploadedTools.Size, Sha256Hash: uploadedTools.SHA256, } uploadedTools, err = sync.SyncBuiltTools(env.Storage(), builtTools, fakeSeries...) if err != nil { return nil, false, err } return uploadedTools, !envConfig.SSLHostnameVerification(), nil }