Skip to content

Commit

Permalink
Validate series error
Browse files Browse the repository at this point in the history
The following ensures that the series we're asked to bootstrap
to is also a valid bootstrap series.
  • Loading branch information
SimonRichardson committed Aug 30, 2019
1 parent 66781fb commit 396d215
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
name = "github.com/juju/naturalsort"

[[constraint]]
revision = "6115736bcd3130ffe464ca312398674a2f626855"
revision = "31722624f15a324ca554ef01285a92e6e89ac7df"
name = "github.com/juju/os"

[[constraint]]
Expand Down
5 changes: 5 additions & 0 deletions environs/bootstrap/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,11 @@ func bootstrapIAAS(
config.PreferredSeries(cfg),
)
if !args.Force && err != nil {
// If the series isn't valid at all, then don't prompt users to use
// the --force flag.
if _, err := series.UbuntuSeriesVersion(requestedBootstrapSeries); err != nil {
return errors.NotValidf("series %q", requestedBootstrapSeries)
}
return errors.Annotatef(err, "use --force to override")
}
bootstrapSeries := &requestedBootstrapSeries
Expand Down
20 changes: 20 additions & 0 deletions environs/bootstrap/bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,26 @@ func (s *bootstrapSuite) TestBootstrapForcedBootstrapSeries(c *gc.C) {
c.Check(env.args.AvailableTools.AllSeries(), jc.SameContents, []string{"xenial"})
}

func (s *bootstrapSuite) TestBootstrapWithInvalidBootstrapSeries(c *gc.C) {
env := newEnviron("foo", useDefaultKeys, nil)
s.setDummyStorage(c, env)
cfg, err := env.Config().Apply(map[string]interface{}{
"default-series": "spock",
})
c.Assert(err, jc.ErrorIsNil)
env.cfg = cfg

err = bootstrap.Bootstrap(envtesting.BootstrapContext(c), env,
s.callContext, bootstrap.BootstrapParams{
ControllerConfig: coretesting.FakeControllerConfig(),
AdminSecret: "admin-secret",
CAPrivateKey: coretesting.CAKey,
BootstrapSeries: "spock",
SupportedBootstrapSeries: supportedJujuSeries,
})
c.Assert(err, gc.ErrorMatches, `series "spock" not valid`)
}

func (s *bootstrapSuite) TestBootstrapSpecifiedPlacement(c *gc.C) {
env := newEnviron("foo", useDefaultKeys, nil)
s.setDummyStorage(c, env)
Expand Down
5 changes: 5 additions & 0 deletions provider/common/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ func BootstrapInstance(
config.PreferredSeries(env.Config()),
)
if !args.Force && err != nil {
// If the series isn't valid at all, then don't prompt users to use
// the --force flag.
if _, err := series.UbuntuSeriesVersion(selectedSeries); err != nil {
return nil, "", nil, errors.NotValidf("series %q", selectedSeries)
}
return nil, "", nil, errors.Annotatef(err, "use --force to override")
}
// The series we're attemptting to bootstrap is empty, show a friendly
Expand Down
2 changes: 1 addition & 1 deletion provider/common/bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func (s *BootstrapSuite) TestBootstrapInvalidSeries(c *gc.C) {
AvailableTools: availableTools,
SupportedBootstrapSeries: coretesting.FakeSupportedJujuSeries,
})
c.Assert(err, gc.ErrorMatches, "use --force to override: spock not supported")
c.Assert(err, gc.ErrorMatches, `series "spock" not valid`)
}

func (s *BootstrapSuite) TestBootstrapFallbackSeries(c *gc.C) {
Expand Down

0 comments on commit 396d215

Please sign in to comment.