示例#1
0
func copyOne(
	tool *state.Tools, source environs.StorageReader,
	target environs.Storage, ctx *cmd.Context,
) error {
	toolsName := tools.StorageName(tool.Binary)
	fmt.Fprintf(ctx.Stderr, "copying %v", toolsName)
	srcFile, err := source.Get(toolsName)
	if err != nil {
		return err
	}
	defer srcFile.Close()
	// We have to buffer the content, because Put requires the content
	// length, but Get only returns us a ReadCloser
	buf := &bytes.Buffer{}
	nBytes, err := io.Copy(buf, srcFile)
	if err != nil {
		return err
	}
	log.Infof("downloaded %v (%dkB), uploading", toolsName, (nBytes+512)/1024)
	fmt.Fprintf(ctx.Stderr, ", download %dkB, uploading\n", (nBytes+512)/1024)

	if err := target.Put(toolsName, buf, nBytes); err != nil {
		return err
	}
	return nil
}
示例#2
0
func restoreBootstrapVerificationFile(c *C, storage environs.Storage) {
	content := "juju-core storage writing verified: ok\n"
	contentReader := strings.NewReader(content)
	err := storage.Put("bootstrap-verify", contentReader,
		int64(len(content)))
	c.Assert(err, IsNil)
}
示例#3
0
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)
	}
}
示例#4
0
// RemoveTools deletes all tools from the supplied storage.
func RemoveTools(c *C, storage environs.Storage) {
	names, err := storage.List("tools/juju-")
	c.Assert(err, IsNil)
	c.Logf("removing files: %v", names)
	for _, name := range names {
		err = storage.Remove(name)
		c.Check(err, IsNil)
	}
}
示例#5
0
func (suite *StateSuite) setupSavedState(c *C, storage environs.Storage) environs.BootstrapState {
	arch := "amd64"
	state := environs.BootstrapState{
		StateInstances:  []instance.Id{instance.Id("an-instance-id")},
		Characteristics: []instance.HardwareCharacteristics{{Arch: &arch}}}
	content, err := goyaml.Marshal(state)
	c.Assert(err, IsNil)
	err = storage.Put(environs.StateFile, ioutil.NopCloser(bytes.NewReader(content)), int64(len(content)))
	c.Assert(err, IsNil)
	return state
}
示例#6
0
// RemoveFakeTools deletes the fake tools from the supplied storage.
func RemoveFakeTools(c *C, storage environs.Storage) {
	toolsVersion := version.Current
	name := tools.StorageName(toolsVersion)
	err := storage.Remove(name)
	c.Check(err, IsNil)
	if version.Current.Series != config.DefaultSeries {
		toolsVersion.Series = config.DefaultSeries
		name := tools.StorageName(toolsVersion)
		err := storage.Remove(name)
		c.Check(err, IsNil)
	}
}
示例#7
0
func uploadFakeToolsVersion(storage environs.Storage, vers version.Binary) (*state.Tools, error) {
	data := vers.String()
	name := tools.StorageName(vers)
	log.Noticef("environs/testing: uploading FAKE tools %s", vers)
	if err := storage.Put(name, strings.NewReader(data), int64(len(data))); err != nil {
		return nil, err
	}
	url, err := storage.URL(name)
	if err != nil {
		return nil, err
	}
	return &state.Tools{Binary: vers, URL: url}, nil
}
示例#8
0
func storageCopy(source environs.Storage, sourcePath string, target environs.Storage, targetPath string) error {
	rc, err := source.Get(sourcePath)
	if err != nil {
		return err
	}
	var buf bytes.Buffer
	_, err = io.Copy(&buf, rc)
	rc.Close()
	if err != nil {
		return err
	}
	return target.Put(targetPath, &buf, int64(buf.Len()))
}
示例#9
0
func checkRemoveAll(c *C, storage environs.Storage) {
	contents := []byte("File contents.")
	aFile := "a-file.txt"
	err := storage.Put(aFile, bytes.NewBuffer(contents), int64(len(contents)))
	c.Assert(err, IsNil)
	err = storage.Put("empty-file", bytes.NewBuffer(nil), 0)
	c.Assert(err, IsNil)

	err = storage.RemoveAll()
	c.Assert(err, IsNil)

	files, err := storage.List("")
	c.Assert(err, IsNil)
	c.Check(files, HasLen, 0)

	_, err = storage.Get(aFile)
	c.Assert(err, NotNil)
	c.Check(err, ErrorMatches, fmt.Sprintf("file %q not found", aFile))
}