Skip to content

Commit

Permalink
Respond to comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jack-w-shaw committed Aug 25, 2023
1 parent 0c92d4b commit 9b19da2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
14 changes: 7 additions & 7 deletions cmd/juju/application/bundle/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,12 +330,13 @@ func verifyBundle(data *charm.BundleData, bundleDir string, verifyConstraints fu
return err
}

var errs []string
// This method cannot be included within data.Verify because
// to verify corresponding series and base match we need to be
// able to compare them. The charm package, however, treats bases
// and series generically and is unable to do this.
if err := verifyMixedSeriesBasesMatch(data); err != nil {
return errors.Trace(err)
errs = append(errs, err.Error())
}

var verifyError error
Expand All @@ -346,9 +347,8 @@ func verifyBundle(data *charm.BundleData, bundleDir string, verifyConstraints fu
}

if verr, ok := errors.Cause(verifyError).(*charm.VerificationError); ok {
errs := make([]string, len(verr.Errors))
for i, err := range verr.Errors {
errs[i] = err.Error()
for _, err := range verr.Errors {
errs = append(errs, err.Error())
}
return errors.New("the provided bundle has the following errors:\n" + strings.Join(errs, "\n"))
}
Expand All @@ -369,7 +369,7 @@ func verifyMixedSeriesBasesMatch(data *charm.BundleData) error {
return errors.Trace(err)
}
if s != data.Series {
return errors.NewNotValid(nil, fmt.Sprintf("bundle series %q and base %q must match if supplied", data.Series, data.DefaultBase))
return errors.NewNotValid(nil, fmt.Sprintf("bundle series %q and base %q must match if both supplied", data.Series, data.DefaultBase))
}
}

Expand All @@ -384,7 +384,7 @@ func verifyMixedSeriesBasesMatch(data *charm.BundleData) error {
return errors.Trace(err)
}
if s != m.Series {
return errors.NewNotValid(nil, fmt.Sprintf("machine %q series %q and base %q must match if supplied", name, m.Series, m.Base))
return errors.NewNotValid(nil, fmt.Sprintf("machine %q series %q and base %q must match if both supplied", name, m.Series, m.Base))
}
}
}
Expand All @@ -400,7 +400,7 @@ func verifyMixedSeriesBasesMatch(data *charm.BundleData) error {
return errors.Trace(err)
}
if s != app.Series {
return errors.NewNotValid(nil, fmt.Sprintf("application %q series %q and base %q must match if supplied", name, app.Series, app.Base))
return errors.NewNotValid(nil, fmt.Sprintf("application %q series %q and base %q must match if both supplied", name, app.Series, app.Base))
}
}
}
Expand Down
15 changes: 8 additions & 7 deletions cmd/juju/application/bundle/bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,21 +107,21 @@ func (s *buildModelRepSuite) TestBuildModelRepresentationApplicationsWithSubordi
Name: "default",
},
Machines: map[string]params.MachineStatus{
"0": {Base: params.Base{Name: "ubuntu", Channel: "18.04"}},
"1": {Base: params.Base{Name: "ubuntu", Channel: "18.04"}},
"0": {Base: params.Base{Name: "ubuntu", Channel: "22.04"}},
"1": {Base: params.Base{Name: "ubuntu", Channel: "22.04"}},
},
Applications: map[string]params.ApplicationStatus{
"wordpress": {
Charm: "wordpress",
Base: params.Base{Name: "ubuntu", Channel: "18.04"},
Base: params.Base{Name: "ubuntu", Channel: "22.04"},
Life: life.Alive,
Units: map[string]params.UnitStatus{
"0": {Machine: "0"},
},
},
"sub": {
Charm: "sub",
Base: params.Base{Name: "ubuntu", Channel: "18.04"},
Base: params.Base{Name: "ubuntu", Channel: "22.04"},
Life: life.Alive,
SubordinateTo: []string{"wordpress"},
},
Expand Down Expand Up @@ -323,7 +323,7 @@ func (s *composeAndVerifyRepSuite) TestComposeAndVerifyBundleMixingBaseAndSeries
s.expectBasePath()

obtained, _, err := ComposeAndVerifyBundle(s.bundleDataSource, []string{s.overlayFile})
c.Assert(err, gc.ErrorMatches, `application "wordpress" series "jammy" and base "ubuntu@20.04" must match if supplied`)
c.Assert(err, gc.ErrorMatches, `(?s)the provided bundle has the following errors:.*application "wordpress" series "jammy" and base "ubuntu@20.04" must match if both supplied.*invalid constraints.*`)
c.Assert(obtained, gc.IsNil)
}

Expand Down Expand Up @@ -359,12 +359,12 @@ func (s *buildModelRepSuite) TestBuildModelRepresentationApplicationsWithExposed
Name: "default",
},
Machines: map[string]params.MachineStatus{
"0": {Base: params.Base{Name: "ubuntu", Channel: "18.04"}},
"0": {Base: params.Base{Name: "ubuntu", Channel: "22.04"}},
},
Applications: map[string]params.ApplicationStatus{
"wordpress": {
Charm: "wordpress",
Base: params.Base{Name: "ubuntu", Channel: "18.04"},
Base: params.Base{Name: "ubuntu", Channel: "22.04"},
Life: life.Alive,
Units: map[string]params.UnitStatus{
"0": {Machine: "0"},
Expand Down Expand Up @@ -572,6 +572,7 @@ applications:
series: focal
base: ubuntu@20.04
num_units: 1
constraints: image-id=ubuntu-bf2
to:
- "0"
wordpress:
Expand Down

0 comments on commit 9b19da2

Please sign in to comment.