Пример #1
0
func (s *uploadSuite) TestUploadErrors(c *gc.C) {
	destDir := c.MkDir()
	destStor, err := filestorage.NewFileStorageWriter(destDir)
	c.Assert(err, gc.IsNil)
	err = imagemetadata.UploadImageMetadata(destStor, "foo")
	c.Assert(err, jc.Satisfies, os.IsNotExist)
}
Пример #2
0
func (s *uploadSuite) TestUpload(c *gc.C) {
	// Create some metadata.
	sourceDir, destDir, destStor, im := createImageMetadata(c)

	// Ensure it can be uploaded.
	err := imagemetadata.UploadImageMetadata(destStor, sourceDir)
	c.Assert(err, gc.IsNil)
	metadata := testing.ParseMetadataFromDir(c, destDir)
	c.Assert(metadata, gc.HasLen, 1)
	c.Assert(im, gc.DeepEquals, metadata[0])
}
Пример #3
0
func (s *uploadSuite) TestUploadIgnoresNonJsonFiles(c *gc.C) {
	// Create some metadata.
	sourceDir, destDir, destStor, _ := createImageMetadata(c)

	// Add an extra file.
	sourceMetadataPath := filepath.Join(sourceDir, storage.BaseImagesPath, simplestreams.StreamsDir)
	err := ioutil.WriteFile(filepath.Join(sourceMetadataPath, "foo.txt"), []byte("hello"), 0644)
	c.Assert(err, gc.IsNil)

	// Upload the metadata.
	err = imagemetadata.UploadImageMetadata(destStor, sourceDir)
	c.Assert(err, gc.IsNil)

	// Check only json files are uploaded.
	destMetadataPath := filepath.Join(destDir, storage.BaseImagesPath, simplestreams.StreamsDir)
	files, err := ioutil.ReadDir(destMetadataPath)
	c.Assert(err, gc.IsNil)
	c.Assert(files, gc.HasLen, 2)
	for _, f := range files {
		fileName := f.Name()
		c.Assert(strings.HasSuffix(fileName, simplestreams.UnsignedSuffix), jc.IsTrue)
	}
}
Пример #4
0
	if c.UploadTools {
		err = bootstrapFuncs.UploadTools(ctx, environ, c.Constraints.Arch, true, c.Series...)
		if err != nil {
			return err
		}
	}
	return bootstrapFuncs.Bootstrap(ctx, environ, environs.BootstrapParams{
		Constraints: c.Constraints,
		Placement:   c.Placement,
	})
}

var uploadCustomMetadata = func(metadataDir string, env environs.Environ) error {
	logger.Infof("Setting default tools and image metadata sources: %s", metadataDir)
	tools.DefaultBaseURL = metadataDir
	if err := imagemetadata.UploadImageMetadata(env.Storage(), metadataDir); err != nil {
		// Do not error if image metadata directory doesn't exist.
		if !os.IsNotExist(err) {
			return fmt.Errorf("uploading image metadata: %v", err)
		}
	} else {
		logger.Infof("custom image metadata uploaded")
	}
	return nil
}

var validateConstraints = func(cons constraints.Value, env environs.Environ) error {
	validator, err := env.ConstraintsValidator()
	if err != nil {
		return err
	}