Ejemplo n.º 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)
}
Ejemplo n.º 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])
}
Ejemplo n.º 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)
	}
}
Ejemplo n.º 4
0
// Run connects to the environment specified on the command line and bootstraps
// a juju in that environment if none already exists. If there is as yet no environments.yaml file,
// the user is informed how to create one.
func (c *BootstrapCommand) Run(ctx *cmd.Context) (resultErr error) {
	bootstrapFuncs := getBootstrapFuncs()

	if len(c.seriesOld) > 0 {
		fmt.Fprintln(ctx.Stderr, "Use of --series is deprecated. Please use --upload-series instead.")
	}

	environ, cleanup, err := environFromName(ctx, c.EnvName, &resultErr, "Bootstrap")
	if err != nil {
		return err
	}
	validator, err := environ.ConstraintsValidator()
	if err != nil {
		return err
	}
	unsupported, err := validator.Validate(c.Constraints)
	if len(unsupported) > 0 {
		logger.Warningf("unsupported constraints: %v", err)
	} else if err != nil {
		return err
	}

	defer cleanup()
	if err := bootstrapFuncs.EnsureNotBootstrapped(environ); err != nil {
		return err
	}

	// Block interruption during bootstrap. Providers may also
	// register for interrupt notification so they can exit early.
	interrupted := make(chan os.Signal, 1)
	defer close(interrupted)
	ctx.InterruptNotify(interrupted)
	defer ctx.StopInterruptNotify(interrupted)
	go func() {
		for _ = range interrupted {
			ctx.Infof("Interrupt signalled: waiting for bootstrap to exit")
		}
	}()

	// If --metadata-source is specified, override the default tools metadata source so
	// SyncTools can use it, and also upload any image metadata.
	if c.MetadataSource != "" {
		metadataDir := ctx.AbsPath(c.MetadataSource)
		logger.Infof("Setting default tools and image metadata sources: %s", metadataDir)
		tools.DefaultBaseURL = metadataDir
		if err := imagemetadata.UploadImageMetadata(environ.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")
		}
	}
	// TODO (wallyworld): 2013-09-20 bug 1227931
	// We can set a custom tools data source instead of doing an
	// unnecessary upload.
	if environ.Config().Type() == provider.Local {
		c.UploadTools = true
	}
	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,
	})
}