~juju-qa/ubuntu/xenial/juju/2.0-rc2

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/cmd/juju/commands/upgradejuju.go

  • Committer: Nicholas Skaggs
  • Date: 2016-09-30 14:39:30 UTC
  • mfrom: (1.8.1)
  • Revision ID: nicholas.skaggs@canonical.com-20160930143930-vwwhrefh6ftckccy
import upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
current model.
39
39
A model's agent version can be shown with `[1:] + "`juju get-model-config agent-\nversion`" + `.
40
40
A version is denoted by: major.minor.patch
41
 
The upgrade candidate will be auto-selected if '--version' is not
 
41
The upgrade candidate will be auto-selected if '--agent-version' is not
42
42
specified:
43
43
 - If the server major version matches the client major version, the
44
44
 version selected is minor+1. If such a minor version is not available then
56
56
 
57
57
Examples:
58
58
    juju upgrade-juju --dry-run
59
 
    juju upgrade-juju --version 2.0.1
 
59
    juju upgrade-juju --agent-version 2.0.1
60
60
    
61
61
See also: 
62
62
    sync-tools`
95
95
 
96
96
func (c *upgradeJujuCommand) SetFlags(f *gnuflag.FlagSet) {
97
97
        c.ModelCommandBase.SetFlags(f)
98
 
        f.StringVar(&c.vers, "version", "", "Upgrade to specific version")
 
98
        f.StringVar(&c.vers, "agent-version", "", "Upgrade to specific version")
99
99
        f.BoolVar(&c.BuildAgent, "build-agent", false, "Build a local version of the agent binary; for development use only")
100
100
        f.BoolVar(&c.DryRun, "dry-run", false, "Don't change anything, just report what would be changed")
101
101
        f.BoolVar(&c.ResetPrevious, "reset-previous-upgrade", false, "Clear the previous (incomplete) upgrade status (use with care)")
111
111
                }
112
112
                if c.BuildAgent && vers.Build != 0 {
113
113
                        // TODO(fwereade): when we start taking versions from actual built
114
 
                        // code, we should disable --version when used with --build-agent.
 
114
                        // code, we should disable --agent-version when used with --build-agent.
115
115
                        // For now, it's the only way to experiment with version upgrade
116
116
                        // behaviour live, so the only restriction is that Build cannot
117
117
                        // be used (because its value needs to be chosen internally so as
259
259
        if c.BuildAgent && c.Version == version.Zero {
260
260
                // Currently, uploading tools assumes the version to be
261
261
                // the same as jujuversion.Current if not specified with
262
 
                // --version.
 
262
                // --agent-version.
263
263
                c.Version = jujuversion.Current
264
264
        }
265
265
        warnCompat := false
292
292
        case c.Version.Major > agentVersion.Major:
293
293
                // User is requesting an upgrade to a new major number
294
294
                // Only upgrade to a different major number if:
295
 
                // 1 - Explicitly requested with --version or using --build-agent, and
 
295
                // 1 - Explicitly requested with --agent-version or using --build-agent, and
296
296
                // 2 - The environment is running a valid version to upgrade from, and
297
297
                // 3 - The upgrade is to a minor version of 0.
298
298
                minVer, ok := c.minMajorUpgradeVersion[c.Version.Major]
321
321
        }
322
322
        // If we're running a custom build or the user has asked for a new agent
323
323
        // to be built, upload a local jujud binary if possible.
324
 
        uploadLocalBinary := isControllerModel && tryImplicitUpload(agentVersion)
 
324
        uploadLocalBinary := isControllerModel && c.Version == version.Zero && tryImplicitUpload(agentVersion)
325
325
        if !warnCompat && (uploadLocalBinary || c.BuildAgent) && !c.DryRun {
326
326
                if err := context.uploadTools(c.BuildAgent); err != nil {
327
327
                        // If we've explicitly asked to build an agent binary, or the upload failed
329
329
                        if err2 := block.ProcessBlockedError(err, block.BlockChange); c.BuildAgent || err2 == cmd.ErrSilent {
330
330
                                return err2
331
331
                        }
332
 
                } else if err == nil {
333
 
                        builtMsg := ""
334
 
                        if c.BuildAgent {
335
 
                                builtMsg = " (built from source)"
336
 
                        }
337
 
                        fmt.Fprintf(ctx.Stdout, "no prepackaged tools available, using local agent binary %v%s\n", context.chosen, builtMsg)
338
 
                }
 
332
                }
 
333
                builtMsg := ""
 
334
                if c.BuildAgent {
 
335
                        builtMsg = " (built from source)"
 
336
                }
 
337
                fmt.Fprintf(ctx.Stdout, "no prepackaged tools available, using local agent binary %v%s\n", context.chosen, builtMsg)
339
338
        }
 
339
 
340
340
        // If there was an error implicitly uploading a binary, we'll still look for any packaged binaries
341
341
        // since there may still be a valid upgrade and the user didn't ask for any local binary.
342
342
        if err := context.validate(); err != nil {
349
349
                fmt.Fprintf(ctx.Stderr, "version %s incompatible with this client (%s)\n", context.chosen, jujuversion.Current)
350
350
        }
351
351
        if c.DryRun {
352
 
                fmt.Fprintf(ctx.Stderr, "upgrade to this version by running\n    juju upgrade-juju --version=\"%s\"\n", context.chosen)
 
352
                fmt.Fprintf(ctx.Stderr, "upgrade to this version by running\n    juju upgrade-juju --agent-version=\"%s\"\n", context.chosen)
353
353
        } else {
354
354
                if c.ResetPrevious {
355
355
                        if ok, err := c.confirmResetPreviousUpgrade(ctx); !ok || err != nil {
531
531
                // agent version and doing major.minor+1.patch=0.
532
532
 
533
533
                // Upgrading across a major release boundary requires that the version
534
 
                // be specified with --version.
 
534
                // be specified with --agent-version.
535
535
                nextVersion := context.agent
536
536
                nextVersion.Minor += 1
537
537
                nextVersion.Patch = 0