Beispiel #1
0
func (s *bootstrapSuite) TestSeriesToUpload(c *gc.C) {
	vers := version.Current
	vers.Series = "quantal"
	s.PatchValue(&version.Current, vers)
	env := newEnviron("foo", useDefaultKeys, nil)
	cfg := env.Config()

	prefSeries := config.PreferredSeries(cfg)
	expect := []string{"quantal", prefSeries}
	for _, series := range []string{"precise", "trusty"} {
		if prefSeries != series {
			expect = append(expect, series)
		}
	}
	c.Assert(bootstrap.SeriesToUpload(cfg, nil), jc.SameContents, expect)

	c.Assert(bootstrap.SeriesToUpload(cfg, []string{"quantal"}), jc.SameContents, []string{"quantal"})
	env = newEnviron("foo", useDefaultKeys, map[string]interface{}{"default-series": "lucid"})
	cfg = env.Config()
	c.Assert(bootstrap.SeriesToUpload(cfg, nil), jc.SameContents, []string{"quantal", "precise", "trusty", "lucid"})
}
Beispiel #2
0
// Run changes the version proposed for the juju envtools.
func (c *UpgradeJujuCommand) Run(ctx *cmd.Context) (err error) {
	client, err := c.NewAPIClient()
	if err != nil {
		return err
	}
	defer client.Close()
	defer func() {
		if err == errUpToDate {
			ctx.Infof(err.Error())
			err = nil
		}
	}()

	// Determine the version to upgrade to, uploading tools if necessary.
	attrs, err := client.EnvironmentGet()
	if err != nil {
		return err
	}
	cfg, err := config.New(config.NoDefaults, attrs)
	if err != nil {
		return err
	}
	context, err := c.initVersions(client, cfg)
	if err != nil {
		return err
	}
	if c.UploadTools {
		series := bootstrap.SeriesToUpload(cfg, c.Series)
		if !c.DryRun {
			if err := context.uploadTools(series); err != nil {
				return err
			}
		}
	}
	if err := context.validate(); err != nil {
		return err
	}
	// TODO(fwereade): this list may be incomplete, pending envtools.Upload change.
	ctx.Infof("available tools:\n%s", formatTools(context.tools))
	ctx.Infof("best version:\n    %s", context.chosen)
	if c.DryRun {
		ctx.Infof("upgrade to this version by running\n    juju upgrade-juju --version=\"%s\"\n", context.chosen)
	} else {
		if err := client.SetEnvironAgentVersion(context.chosen); err != nil {
			return err
		}
		logger.Infof("started upgrade to %s", context.chosen)
	}
	return nil
}
Beispiel #3
0
// Run changes the version proposed for the juju envtools.
func (c *UpgradeJujuCommand) Run(_ *cmd.Context) (err error) {
	client, err := juju.NewAPIClientFromName(c.EnvName)
	if err != nil {
		return err
	}
	defer client.Close()
	defer func() {
		if err == errUpToDate {
			logger.Infof(err.Error())
			err = nil
		}
	}()

	// Determine the version to upgrade to, uploading tools if necessary.
	attrs, err := client.EnvironmentGet()
	if err != nil {
		return err
	}
	cfg, err := config.New(config.NoDefaults, attrs)
	if err != nil {
		return err
	}
	context, err := c.initVersions(client, cfg)
	if err != nil {
		return err
	}
	if c.UploadTools {
		series := bootstrap.SeriesToUpload(cfg, c.Series)
		if err := context.uploadTools(series); err != nil {
			return err
		}
	}
	if err := context.validate(); err != nil {
		return err
	}
	logger.Infof("upgrade version chosen: %s", context.chosen)
	// TODO(fwereade): this list may be incomplete, pending envtools.Upload change.
	logger.Infof("available tools: %s", context.tools)

	if err := client.SetEnvironAgentVersion(context.chosen); err != nil {
		return err
	}
	logger.Infof("started upgrade to %s", context.chosen)
	return nil
}