Skip to content

Commit

Permalink
Fix bug where "use --force" prompt is not displayed
Browse files Browse the repository at this point in the history
For some reason our series selector was not returning an
UnsupportedSeries error when it should have been, instead duplicating
the text of the error and returning a generic error

This means downstream error type checks were failing

Also remove some duplicated code/unnecessary code. It turns out that our
resolver emthods do not return return UnsupportedSeries errors
  • Loading branch information
jack-w-shaw committed Oct 5, 2023
1 parent 3a8220e commit db28f39
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
3 changes: 2 additions & 1 deletion cmd/juju/application/deployer/charm.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/juju/juju/cmd/juju/application/utils"
"github.com/juju/juju/cmd/juju/common"
corebase "github.com/juju/juju/core/base"
corecharm "github.com/juju/juju/core/charm"
"github.com/juju/juju/core/constraints"
"github.com/juju/juju/core/devices"
"github.com/juju/juju/core/instance"
Expand Down Expand Up @@ -440,7 +441,7 @@ func (c *repositoryCharm) PrepareAndDeploy(ctx *cmd.Context, deployAPI DeployerA
}
}

if charm.IsUnsupportedSeriesError(err) {
if corecharm.IsUnsupportedSeriesError(err) {
msg := fmt.Sprintf("%v. Use --force to deploy the charm anyway.", err)
if usingDefaultSeries {
msg += " Used the default-series."
Expand Down
25 changes: 25 additions & 0 deletions cmd/juju/application/deployer/charm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ func (s *charmSuite) TestRepositoryCharmDeployDryRunDefaultSeriesForce(c *gc.C)
dCharm.validateCharmSeriesWithName = func(series, name string, imageStream string) error {
return nil
}

repoCharm := &repositoryCharm{
deployCharm: *dCharm,
userRequestedURL: s.url,
Expand All @@ -129,6 +130,30 @@ func (s *charmSuite) TestRepositoryCharmDeployDryRunDefaultSeriesForce(c *gc.C)
c.Check(output.String(), gc.Equals, "\"testme\" from charm \"testme\", revision -1 on ubuntu@22.04 would be deployed\n")
}

func (s *charmSuite) TestRepositoryCharmDeployDryRunUnsupportedSeries(c *gc.C) {
ctrl := s.setupMocks(c)
defer ctrl.Finish()
s.resolver = mocks.NewMockResolver(ctrl)
s.expectResolveChannel()
s.expectDeployerAPIModelGet(c, corebase.Base{})

dCharm := s.newDeployCharm()
dCharm.dryRun = true
dCharm.validateCharmSeriesWithName = func(series, name string, imageStream string) error {
return nil
}
dCharm.baseFlag = corebase.MustParseBaseFromString("ubuntu@12.04")

repoCharm := &repositoryCharm{
deployCharm: *dCharm,
userRequestedURL: s.url,
clock: clock.WallClock,
}

err := repoCharm.PrepareAndDeploy(s.ctx, s.deployerAPI, s.resolver)
c.Assert(err, gc.ErrorMatches, `series "precise" not supported by charm, .* Use --force to deploy the charm anyway.`)
}

func (s *charmSuite) newDeployCharm() *deployCharm {
return &deployCharm{
configOptions: s.configFlag,
Expand Down
4 changes: 0 additions & 4 deletions cmd/juju/application/deployer/series_selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,6 @@ func (s seriesSelector) userRequested(requestedSeries string) (string, error) {
if supported.IsEmpty() {
return "", errors.NewNotSupported(nil, fmt.Sprintf("series: %s", requestedSeries))
}
return "", errors.Errorf(
"series %q is not supported, supported series are: %s",
requestedSeries, strings.Join(supported.SortedValues(), ","),
)
}
return "", err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/juju/application/deployer/series_selector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func (s *SeriesSelectorSuite) TestCharmSeries(c *gc.C) {
conf: defaultBase{"ubuntu@15.10", true},
supportedJujuSeries: set.NewStrings("bionic", "cosmic"),
},
err: `series "wily" is not supported, supported series are: bionic,cosmic`,
err: `series "wily" not supported by charm, the charm supported series are: bionic,cosmic`,
},
{
title: "juju deploy multiseries # use model series defaults if supported by charm",
Expand Down

0 comments on commit db28f39

Please sign in to comment.