Skip to content

Commit

Permalink
Remove some redundant upgrade validations
Browse files Browse the repository at this point in the history
Note it is only possibe to upgrade to 4.x from 3.x

It is impossible to deploy a charmstor charm to 3.x, so we don't need to
check for them when uprading

It is also impossible to deploy to a windows machine in 3.x, so we don't
need to check for that either
  • Loading branch information
jack-w-shaw committed Aug 23, 2023
1 parent 257c615 commit 43de7ac
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 116 deletions.
2 changes: 0 additions & 2 deletions upgrades/upgradevalidation/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ func ValidatorsForModelMigrationSource(
) []Validator {
return []Validator{
getCheckUpgradeSeriesLockForModel(false),
checkNoWinMachinesForModel,
checkForDeprecatedUbuntuSeriesForModel,
getCheckForLXDVersion(cloudspec),
checkForCharmStoreCharms,
}
}
2 changes: 0 additions & 2 deletions upgrades/upgradevalidation/package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@ func TestAll(t *stdtesting.T) {

var (
CheckForDeprecatedUbuntuSeriesForModel = checkForDeprecatedUbuntuSeriesForModel
CheckNoWinMachinesForModel = checkNoWinMachinesForModel
GetCheckUpgradeSeriesLockForModel = getCheckUpgradeSeriesLockForModel
GetCheckTargetVersionForModel = getCheckTargetVersionForModel
CheckModelMigrationModeForControllerUpgrade = checkModelMigrationModeForControllerUpgrade
CheckMongoStatusForControllerUpgrade = checkMongoStatusForControllerUpgrade
CheckMongoVersionForControllerModel = checkMongoVersionForControllerModel
GetCheckForLXDVersion = getCheckForLXDVersion
CheckForCharmStoreCharms = checkForCharmStoreCharms
)
12 changes: 0 additions & 12 deletions upgrades/upgradevalidation/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,18 @@ func ValidatorsForControllerUpgrade(
getCheckTargetVersionForControllerModel(targetVersion),
checkMongoStatusForControllerUpgrade,
checkMongoVersionForControllerModel,
checkNoWinMachinesForModel,
checkForDeprecatedUbuntuSeriesForModel,
getCheckForLXDVersion(cloudspec),
}
if targetVersion.Major == 3 && targetVersion.Minor >= 1 {
validators = append(validators, checkForCharmStoreCharms)
}
return validators
}

validators := []Validator{
getCheckTargetVersionForModel(targetVersion, UpgradeControllerAllowed),
checkModelMigrationModeForControllerUpgrade,
checkNoWinMachinesForModel,
checkForDeprecatedUbuntuSeriesForModel,
getCheckForLXDVersion(cloudspec),
}
if targetVersion.Major == 3 && targetVersion.Minor >= 1 {
validators = append(validators, checkForCharmStoreCharms)
}
return validators
}

Expand All @@ -50,12 +42,8 @@ func ValidatorsForModelUpgrade(
) []Validator {
validators := []Validator{
getCheckUpgradeSeriesLockForModel(force),
checkNoWinMachinesForModel,
checkForDeprecatedUbuntuSeriesForModel,
getCheckForLXDVersion(cloudspec),
}
if targetVersion.Major == 3 && targetVersion.Minor >= 1 {
validators = append(validators, checkForCharmStoreCharms)
}
return validators
}
58 changes: 0 additions & 58 deletions upgrades/upgradevalidation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import (
"sort"
"strings"

"github.com/juju/charm/v11"
"github.com/juju/collections/set"
"github.com/juju/errors"
jujuhttp "github.com/juju/http/v2"
"github.com/juju/replicaset/v3"
Expand Down Expand Up @@ -154,29 +152,6 @@ func getCheckUpgradeSeriesLockForModel(force bool) Validator {
}
}

var windowsSeries = []string{
"win2008r2", "win2012", "win2012hv", "win2012hvr2", "win2012r2", "win2012r2",
"win2016", "win2016hv", "win2019", "win7", "win8", "win81", "win10",
}

func checkNoWinMachinesForModel(_ string, _ StatePool, st State, _ Model) (*Blocker, error) {
windowsBases := make([]state.Base, len(windowsSeries))
for i, s := range windowsSeries {
windowsBases[i] = state.Base{OS: "windows", Channel: s}
}
result, err := st.MachineCountForBase(windowsBases...)
if err != nil {
return nil, errors.Annotate(err, "cannot count windows machines")
}
if len(result) > 0 {
return NewBlocker(
"the model hosts deprecated windows machine(s): %s",
stringifyMachineCounts(result),
), nil
}
return nil, nil
}

func stringifyMachineCounts(result map[string]int) string {
var keys []string
for k := range result {
Expand Down Expand Up @@ -217,39 +192,6 @@ func checkForDeprecatedUbuntuSeriesForModel(
return nil, nil
}

func checkForCharmStoreCharms(_ string, _ StatePool, st State, _ Model) (*Blocker, error) {
curls, err := st.AllCharmURLs()
if errors.Is(err, errors.NotFound) {
return nil, nil
}
if err != nil {
return nil, err
}
result := set.NewStrings()
for _, curlStr := range curls {
if curlStr == nil {
return nil, errors.New("malformed charm in database with no URL")
}
curl, err := charm.ParseURL(*curlStr)
if err != nil {
logger.Errorf("error from ParseURL: %s", err)
return nil, errors.New(fmt.Sprintf("malformed charm url in database: %q", *curlStr))
}
// TODO 6-dec-2022
// Update check once charm's ValidateSchema rejects charm store charms.
if !charm.CharmHub.Matches(curl.Schema) && !charm.Local.Matches(curl.Schema) {
c := curl.WithSeries("").WithArchitecture("")
result.Add(c.String())
}
}
if !result.IsEmpty() {
return NewBlocker("the model hosts deprecated charm store charms(s): %s",
strings.Join(result.SortedValues(), ", "),
), nil
}
return nil, nil
}

func getCheckTargetVersionForControllerModel(
targetVersion version.Number,
) Validator {
Expand Down
42 changes: 0 additions & 42 deletions upgrades/upgradevalidation/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,25 +110,6 @@ func (s *upgradeValidationSuite) TestModelUpgradeCheck(c *gc.C) {
- unexpected upgrade series lock found`[1:])
}

func (s *upgradeValidationSuite) TestCheckNoWinMachinesForModel(c *gc.C) {
ctrl := gomock.NewController(c)
defer ctrl.Finish()

st := mocks.NewMockState(ctrl)
gomock.InOrder(
st.EXPECT().MachineCountForBase(makeBases("windows", winVersions)).Return(nil, nil),
st.EXPECT().MachineCountForBase(makeBases("windows", winVersions)).Return(map[string]int{"win10": 1, "win7": 2}, nil),
)

blocker, err := upgradevalidation.CheckNoWinMachinesForModel("", nil, st, nil)
c.Assert(err, jc.ErrorIsNil)
c.Assert(blocker, gc.IsNil)

blocker, err = upgradevalidation.CheckNoWinMachinesForModel("", nil, st, nil)
c.Assert(err, jc.ErrorIsNil)
c.Assert(blocker.Error(), gc.Equals, `the model hosts deprecated windows machine(s): win10(1) win7(2)`)
}

func (s *upgradeValidationSuite) TestCheckForDeprecatedUbuntuSeriesForModel(c *gc.C) {
ctrl := gomock.NewController(c)
defer ctrl.Finish()
Expand Down Expand Up @@ -401,26 +382,3 @@ func (s *upgradeValidationSuite) TestGetCheckForLXDVersionFailed(c *gc.C) {
c.Assert(blocker, gc.NotNil)
c.Assert(blocker.Error(), gc.Equals, `LXD version has to be at least "5.0.0", but current version is only "4.0.0"`)
}

func (s *upgradeValidationSuite) TestCheckForCharmStoreCharmsNotFound(c *gc.C) {
ctrl := gomock.NewController(c)
defer ctrl.Finish()

st := mocks.NewMockState(ctrl)
st.EXPECT().AllCharmURLs().Return([]*string{}, errors.NotFoundf("charm urls"))

blocker, err := upgradevalidation.CheckForCharmStoreCharms("", nil, st, nil)
c.Assert(err, jc.ErrorIsNil)
c.Assert(blocker, gc.IsNil)
}

func (s *upgradeValidationSuite) TestCheckForCharmStoreCharmsError(c *gc.C) {
ctrl := gomock.NewController(c)
defer ctrl.Finish()

st := mocks.NewMockState(ctrl)
st.EXPECT().AllCharmURLs().Return([]*string{}, errors.BadRequestf("charm urls"))

_, err := upgradevalidation.CheckForCharmStoreCharms("", nil, st, nil)
c.Assert(errors.Is(err, errors.BadRequest), jc.IsTrue)
}

0 comments on commit 43de7ac

Please sign in to comment.