Skip to content

Commit

Permalink
Merge pull request juju#613 from axw/cmd-juju-upgradejuju-series
Browse files Browse the repository at this point in the history
Various cleanups in upgrade-juju

**cmd/juju: remove redundant code from upgrade-juju**

- Ignore/obsolete "--series" as in "juju bootstrap". UploadTools
  now computes the series to send to the API server (for backwards
  compat), and the API server now computes the same.
- Remove old backwards compat code.

Also, change jujud/bootstrap to use new version.OSSupportedSeries.


**state/apiserver: clone uploaded tools for supported series**

Disregard additional series specified by client, and clone for all
supported series of the same OS as the uploaded tools.

**state/api: always "upload" all supported series**

UploadTools no longer accepts a "fakeSeries" parameter; the client just
sends all of the supported series of the same OS as the uploaded tools.
This is to support old API servers.

Also: return a generic error if status code is not 200. We no longer need
to check the "method not supported" error specifically.

**environs/tools: unexpose environs/tools.ToolsLtsSeries**

**version: add OSSupportedSeries**

OSSupportedSeries returns the supported series for the specified OS.
  • Loading branch information
jujubot committed Aug 28, 2014
2 parents 0ec52e7 + cd31d1d commit e338c9e
Show file tree
Hide file tree
Showing 11 changed files with 113 additions and 145 deletions.
67 changes: 9 additions & 58 deletions cmd/juju/upgradejuju.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,11 @@ import (
"strings"

"github.com/juju/cmd"
"github.com/juju/utils/set"
"launchpad.net/gnuflag"

"github.com/juju/juju/cmd/envcmd"
"github.com/juju/juju/environs"
"github.com/juju/juju/environs/config"
"github.com/juju/juju/environs/sync"
envtools "github.com/juju/juju/environs/tools"
"github.com/juju/juju/state/api"
"github.com/juju/juju/state/api/params"
coretools "github.com/juju/juju/tools"
Expand Down Expand Up @@ -80,7 +77,7 @@ func (c *UpgradeJujuCommand) SetFlags(f *gnuflag.FlagSet) {
f.StringVar(&c.vers, "version", "", "upgrade to specific version")
f.BoolVar(&c.UploadTools, "upload-tools", false, "upload local version of tools")
f.BoolVar(&c.DryRun, "dry-run", false, "don't change anything, just report what would change")
f.Var(newSeriesValue(nil, &c.Series), "series", "upload tools for supplied comma-separated series list")
f.Var(newSeriesValue(nil, &c.Series), "series", "upload tools for supplied comma-separated series list (OBSOLETE)")
}

func (c *UpgradeJujuCommand) Init(args []string) error {
Expand Down Expand Up @@ -121,6 +118,10 @@ func formatTools(tools coretools.List) string {

// Run changes the version proposed for the juju envtools.
func (c *UpgradeJujuCommand) Run(ctx *cmd.Context) (err error) {
if len(c.Series) > 0 {
fmt.Fprintln(ctx.Stderr, "Use of --series is obsolete. --upload-tools now expands to all supported series of the same operating system.")
}

client, err := c.NewAPIClient()
if err != nil {
return err
Expand All @@ -147,8 +148,7 @@ func (c *UpgradeJujuCommand) Run(ctx *cmd.Context) (err error) {
return err
}
if c.UploadTools && !c.DryRun {
series := seriesToUpload(cfg, c.Series)
if err := context.uploadTools(series); err != nil {
if err := context.uploadTools(); err != nil {
return err
}
}
Expand Down Expand Up @@ -184,12 +184,6 @@ func (c *UpgradeJujuCommand) initVersions(client *api.Client, cfg *config.Config
}
clientVersion := version.Current.Number
findResult, err := client.FindTools(clientVersion.Major, -1, "", "")
var availableTools coretools.List
if params.IsCodeNotImplemented(err) {
availableTools, err = findTools1dot17(cfg)
} else {
availableTools = findResult.List
}
if err != nil {
return nil, err
}
Expand All @@ -211,23 +205,12 @@ func (c *UpgradeJujuCommand) initVersions(client *api.Client, cfg *config.Config
agent: agent,
client: clientVersion,
chosen: c.Version,
tools: availableTools,
tools: findResult.List,
apiClient: client,
config: cfg,
}, nil
}

// findTools1dot17 allows 1.17.x versions to be upgraded.
func findTools1dot17(cfg *config.Config) (coretools.List, error) {
logger.Warningf("running find tools in 1.17 compatibility mode")
env, err := environs.New(cfg)
if err != nil {
return nil, err
}
clientVersion := version.Current.Number
return envtools.FindTools(env, clientVersion.Major, -1, coretools.Filter{}, envtools.DoNotAllowRetry)
}

// upgradeContext holds the version information for making upgrade decisions.
type upgradeContext struct {
agent version.Number
Expand All @@ -245,7 +228,7 @@ type upgradeContext struct {
// than that of any otherwise-matching available envtools.
// uploadTools resets the chosen version and replaces the available tools
// with the ones just uploaded.
func (context *upgradeContext) uploadTools(series []string) (err error) {
func (context *upgradeContext) uploadTools() (err error) {
// TODO(fwereade): this is kinda crack: we should not assume that
// version.Current matches whatever source happens to be built. The
// ideal would be:
Expand All @@ -272,28 +255,14 @@ func (context *upgradeContext) uploadTools(series []string) (err error) {
var uploaded *coretools.Tools
toolsPath := path.Join(builtTools.Dir, builtTools.StorageName)
logger.Infof("uploading tools %v (%dkB) to Juju state server", builtTools.Version, (builtTools.Size+512)/1024)
uploaded, err = context.apiClient.UploadTools(toolsPath, builtTools.Version, series...)
if params.IsCodeNotImplemented(err) {
uploaded, err = context.uploadTools1dot17(builtTools, series...)
}
uploaded, err = context.apiClient.UploadTools(toolsPath, builtTools.Version)
if err != nil {
return err
}
context.tools = coretools.List{uploaded}
return nil
}

func (context *upgradeContext) uploadTools1dot17(builtTools *sync.BuiltTools,
series ...string) (*coretools.Tools, error) {

logger.Warningf("running upload tools in 1.17 compatibility mode")
env, err := environs.New(context.config)
if err != nil {
return nil, err
}
return sync.SyncBuiltTools(env.Storage(), builtTools, series...)
}

// validate chooses an upgrade version, if one has not already been chosen,
// and ensures the tools list contains no entries that do not have that version.
// If validate returns no error, the environment agent-version can be set to
Expand Down Expand Up @@ -371,21 +340,3 @@ func uploadVersion(vers version.Number, existing coretools.List) version.Number
}
return vers
}

// seriesToUpload returns the supplied series with duplicates removed if
// non-empty; otherwise it returns a default list of series we should
// probably upload, based on cfg.
// TODO(axw) don't use this.
func seriesToUpload(cfg *config.Config, series []string) []string {
unique := set.NewStrings(series...)
if unique.IsEmpty() {
unique.Add(version.Current.Series)
for _, toolsSeries := range envtools.ToolsLtsSeries {
unique.Add(toolsSeries)
}
if series, ok := cfg.DefaultSeries(); ok {
unique.Add(series)
}
}
return unique.SortedValues()
}
17 changes: 3 additions & 14 deletions cmd/jujud/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,20 +319,6 @@ func (c *BootstrapCommand) populateTools(env environs.Environ) error {
stor = env.Storage()
}

// Build a list of other supported series with the same OS.
// Until we catalogue tools in state, we clone the tools
// for each of these series.
var otherSeries []string
for _, series := range version.SupportedSeries() {
os, err := version.GetOSFromSeries(series)
if err != nil {
return err
}
if os == version.Current.OS {
otherSeries = append(otherSeries, series)
}
}

// Create a temporary directory to contain source and cloned tools.
tempDir, err := ioutil.TempDir("", "juju-sync-tools")
if err != nil {
Expand All @@ -351,6 +337,9 @@ func (c *BootstrapCommand) populateTools(env environs.Environ) error {
return err
}

// Until we catalogue tools in state, we clone the tools
// for each of the supported series of the same OS.
otherSeries := version.OSSupportedSeries(version.Current.OS)
_, err = sync.SyncBuiltTools(stor, &sync.BuiltTools{
Version: tools.Version,
Dir: tempDir,
Expand Down
7 changes: 5 additions & 2 deletions environs/testing/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ import (
"github.com/juju/juju/worker/upgrader"
)

// toolsLtsSeries records the known Ubuntu LTS series.
var toolsLtsSeries = []string{"precise", "trusty"}

// ToolsFixture is used as a fixture to stub out the default tools URL so we
// don't hit the real internet during tests.
type ToolsFixture struct {
Expand Down Expand Up @@ -57,7 +60,7 @@ func (s *ToolsFixture) UploadFakeTools(c *gc.C, stor storage.Storage) {
for _, arch := range arches {
v := version.Current
v.Arch = arch
for _, series := range envtools.ToolsLtsSeries {
for _, series := range toolsLtsSeries {
v.Series = series
versions = append(versions, v)
}
Expand Down Expand Up @@ -203,7 +206,7 @@ func MustUploadFakeToolsVersions(stor storage.Storage, versions ...version.Binar
}

func uploadFakeTools(stor storage.Storage) error {
toolsSeries := set.NewStrings(envtools.ToolsLtsSeries...)
toolsSeries := set.NewStrings(toolsLtsSeries...)
toolsSeries.Add(version.Current.Series)
var versions []version.Binary
for _, series := range toolsSeries.Values() {
Expand Down
3 changes: 0 additions & 3 deletions environs/tools/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,3 @@ func convertToolsError(err *error) {
*err = errors.NewNotFound(*err, "")
}
}

// ToolsLtsSeries records the known Ubuntu LTS series.
var ToolsLtsSeries = []string{"precise", "trusty"}
Loading

0 comments on commit e338c9e

Please sign in to comment.