// SyncBuiltTools copies to storage a tools tarball and cloned copies for each series. func SyncBuiltTools(stor storage.Storage, builtTools *BuiltTools, fakeSeries ...string) (*coretools.Tools, error) { if err := cloneToolsForSeries(builtTools, fakeSeries...); err != nil { return nil, err } syncContext := &SyncContext{ Source: builtTools.Dir, Target: stor, AllVersions: true, Dev: builtTools.Version.IsDev(), MajorVersion: builtTools.Version.Major, MinorVersion: -1, } logger.Debugf("uploading tools to cloud storage") err := SyncTools(syncContext) if err != nil { return nil, err } url, err := stor.URL(builtTools.StorageName) if err != nil { return nil, err } return &coretools.Tools{ Version: builtTools.Version, URL: url, Size: builtTools.Size, SHA256: builtTools.Sha256Hash, }, nil }
// CreateStateFile creates an empty state file on the given storage, and // returns its URL. func CreateStateFile(stor storage.Storage) (string, error) { err := putState(stor, []byte{}) if err != nil { return "", fmt.Errorf("cannot create initial state file: %v", err) } return stor.URL(StateFile) }
// syncBuiltTools copies to storage a tools tarball and cloned copies for each series. func syncBuiltTools(stor storage.Storage, stream string, builtTools *BuiltAgent, fakeSeries ...string) (*coretools.Tools, error) { if err := cloneToolsForSeries(builtTools, stream, fakeSeries...); err != nil { return nil, err } syncContext := &SyncContext{ Source: builtTools.Dir, TargetToolsFinder: StorageToolsFinder{stor}, TargetToolsUploader: StorageToolsUploader{stor, false, false}, AllVersions: true, Stream: stream, MajorVersion: builtTools.Version.Major, MinorVersion: -1, } logger.Debugf("uploading agent binaries to cloud storage") err := SyncTools(syncContext) if err != nil { return nil, err } url, err := stor.URL(builtTools.StorageName) if err != nil { return nil, err } return &coretools.Tools{ Version: builtTools.Version, URL: url, Size: builtTools.Size, SHA256: builtTools.Sha256Hash, }, nil }
func uploadFakeToolsVersion(stor storage.Storage, toolsDir string, vers version.Binary) (*coretools.Tools, error) { logger.Infof("uploading FAKE tools %s", vers) tgz, checksum := makeFakeTools(vers) size := int64(len(tgz)) name := envtools.StorageName(vers, toolsDir) 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 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 }
// UploadToStorage uploads tools and metadata for the specified versions to storage. func UploadToStorage(c *gc.C, stor storage.Storage, stream string, versions ...version.Binary) map[version.Binary]string { uploaded := map[version.Binary]string{} if len(versions) == 0 { return uploaded } var err error for _, vers := range versions { filename := fmt.Sprintf("tools/%s/tools-%s.tar.gz", stream, vers.String()) // Put a file in images since the dummy storage provider requires a // file to exist before the URL can be found. This is to ensure it behaves // the same way as MAAS. err = stor.Put(filename, strings.NewReader("dummy"), 5) c.Assert(err, jc.ErrorIsNil) uploaded[vers], err = stor.URL(filename) c.Assert(err, jc.ErrorIsNil) } objects := generateMetadata(c, stream, versions...) for _, object := range objects { toolspath := path.Join("tools", object.path) err = stor.Put(toolspath, bytes.NewReader(object.data), int64(len(object.data))) c.Assert(err, jc.ErrorIsNil) } return uploaded }