Skip to content

Commit 68be221

Browse files
authored
Merge pull request juju#10348 from hpidcock/1832779-command-fails-no-active-controller
juju#10348 ## Description of change `juju upgrade-controller -c <controller-name>` previously would error when there isn't a current-controller set. Additionally, when upgrading an IAAS controller, it would previously upgrade the current-controller, even though the controller specified in the command was different. ## QA steps Quick test: Bootstrap to an IAAS (not k8s) e.g. `juju bootstrap localhost` Remove the current-controller line from `controllers.yaml`. Run `juju upgrade-controller -c localhost-localhost` It should not error with `ERROR No selected controller.` Additional test: Bootstrap 2 controllers with an old version. Check which controller is the current-controller. `juju upgrade-controller -c <not-the-current-controller>` Check that the current-controller is still using the old version. ## Documentation changes N/A ## Bug reference [https://bugs.launchpad.net/juju/+bug/1832779](https://bugs.launchpad.net/juju/+bug/1832779)
2 parents 7671273 + 3f29cf7 commit 68be221

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

cmd/juju/commands/upgradecontroller.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,13 @@ func (c *upgradeControllerCommand) upgradeIAASController(ctx *cmd.Context) error
268268
}}
269269
jcmd.SetClientStore(c.ClientStore())
270270
wrapped := modelcmd.Wrap(jcmd)
271-
args := append(c.rawArgs, "-m", bootstrap.ControllerModelName)
271+
controllerName, err := c.ControllerName()
272+
if err != nil {
273+
return errors.Trace(err)
274+
}
275+
fullControllerModelName := modelcmd.JoinModelName(controllerName,
276+
bootstrap.ControllerModelName)
277+
args := append(c.rawArgs, "-m", fullControllerModelName)
272278
if c.vers != "" {
273279
args = append(args, "--agent-version", c.vers)
274280
}

cmd/juju/commands/upgradecontroller_test.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
"github.com/juju/cmd"
1111
"github.com/juju/cmd/cmdtesting"
12+
"github.com/juju/errors"
1213
"github.com/juju/os/series"
1314
jc "github.com/juju/testing/checkers"
1415
"github.com/juju/utils/arch"
@@ -23,6 +24,7 @@ import (
2324
"github.com/juju/juju/environs/tools"
2425
jujutesting "github.com/juju/juju/juju/testing"
2526
"github.com/juju/juju/jujuclient"
27+
"github.com/juju/juju/jujuclient/jujuclienttesting"
2628
coretesting "github.com/juju/juju/testing"
2729
jujuversion "github.com/juju/juju/version"
2830
)
@@ -115,6 +117,51 @@ func (s *UpgradeIAASControllerSuite) TestUpgradeWithRealUpload(c *gc.C) {
115117
s.checkToolsUploaded(c, vers, vers.Number)
116118
}
117119

120+
func (s *UpgradeIAASControllerSuite) TestUpgradeCorrectController(c *gc.C) {
121+
badControllerName := "not-the-right-controller"
122+
badControllerSelected := errors.New("bad controller selected")
123+
upgradeCommand := func(minUpgradeVers map[int]version.Number) cmd.Command {
124+
backingStore := s.ControllerStore
125+
store := jujuclienttesting.WrapClientStore(backingStore)
126+
store.ControllerByNameFunc = func(name string) (*jujuclient.ControllerDetails, error) {
127+
if name == badControllerName {
128+
return nil, badControllerSelected
129+
}
130+
return backingStore.ControllerByName(name)
131+
}
132+
store.CurrentControllerFunc = func() (string, error) {
133+
return badControllerName, nil
134+
}
135+
s.ControllerStore = store
136+
cmd := &upgradeControllerCommand{
137+
baseUpgradeCommand: baseUpgradeCommand{minMajorUpgradeVersion: minMajorUpgradeVersion},
138+
}
139+
cmd.SetClientStore(s.ControllerStore)
140+
return modelcmd.WrapController(cmd)
141+
}
142+
143+
tests := []upgradeTest{
144+
{
145+
about: "latest supported stable release with specified controller",
146+
available: []string{"2.1.0-quantal-amd64", "2.1.2-quantal-i386", "2.1.3-quantal-amd64", "2.1-dev1-quantal-amd64"},
147+
currentVersion: "2.0.0-quantal-amd64",
148+
agentVersion: "2.0.0",
149+
expectVersion: "2.1.3",
150+
args: []string{"--controller", "kontroll"},
151+
},
152+
{
153+
about: "latest supported stable release without specified controller",
154+
available: []string{"2.1.0-quantal-amd64", "2.1.2-quantal-i386", "2.1.3-quantal-amd64", "2.1-dev1-quantal-amd64"},
155+
currentVersion: "2.0.0-quantal-amd64",
156+
agentVersion: "2.0.0",
157+
expectVersion: "2.1.3",
158+
expectErr: badControllerSelected.Error(),
159+
},
160+
}
161+
162+
s.assertUpgradeTests(c, tests, upgradeCommand)
163+
}
164+
118165
func (s *UpgradeIAASControllerSuite) TestUpgradeDryRun(c *gc.C) {
119166
s.assertUpgradeDryRun(c, "upgrade-controller", s.upgradeControllerCommand)
120167
}

0 commit comments

Comments
 (0)