// Run changes the version proposed for the juju tools. func (c *UpgradeJujuCommand) Run(_ *cmd.Context) error { var err error c.conn, err = juju.NewConnFromName(c.EnvName) if err != nil { return err } defer c.conn.Close() cfg, err := c.conn.State.EnvironConfig() if err != nil { return err } c.agentVersion = cfg.AgentVersion() c.toolsList, err = environs.ListTools(c.conn.Environ, c.agentVersion.Major) if err != nil { return err } if c.UploadTools { var forceVersion *version.Number if c.BumpVersion { vers := c.bumpedVersion() forceVersion = &vers.Number c.Version = vers.Number } tools, err := putTools(c.conn.Environ.Storage(), forceVersion) if err != nil { return err } c.toolsList.Private = append(c.toolsList.Private, tools) } if c.Version == (version.Number{}) { c.Version, err = c.newestVersion() if err != nil { return fmt.Errorf("cannot find newest version: %v", err) } } if c.Version.Major != c.agentVersion.Major { return fmt.Errorf("cannot upgrade major versions yet") } if c.Version == c.agentVersion && c.Development == cfg.Development() { return nil } return SetAgentVersion(c.conn.State, c.Version, c.Development) }
func (t *ToolsSuite) TestListTools(c *C) { testList := []string{ "foo", "tools/.tgz", "tools/juju-1.2.3-precise-i386.tgz", "tools/juju-2.2.3-precise-amd64.tgz", "tools/juju-2.2.3-precise-i386.tgz", "tools/juju-2.2.4-precise-i386.tgz", "tools/juju-2.2-precise-amd64.tgz", "tools/juju-3.2.1-quantal-amd64.tgz", "xtools/juju-2.2.3-precise-amd64.tgz", } // dummy always populates the tools set with version.Current. // Remove any tools in the public storage to ensure they don't // conflict with the list of tools we expect. ps := t.env.PublicStorage().(environs.Storage) tools, err := ps.List("") c.Assert(err, IsNil) for _, tool := range tools { ps.Remove(tool) } putNames(c, t.env, testList, testList) for i, test := range listToolsTests { c.Logf("test %d", i) toolsList, err := environs.ListTools(t.env, test.major) c.Assert(err, IsNil) c.Assert(toolsList.Private, HasLen, len(test.expect)) c.Assert(toolsList.Public, HasLen, len(test.expect)) for i, t := range toolsList.Private { vers := binaryVersion(test.expect[i]) c.Assert(t.Binary, Equals, vers) assertURLContents(c, t.URL, environs.ToolsStoragePath(vers)) } for i, t := range toolsList.Public { vers := binaryVersion(test.expect[i]) c.Assert(t.Binary, Equals, vers) assertURLContents(c, t.URL, "public-"+environs.ToolsStoragePath(vers)) } } }