Skip to content

Commit

Permalink
Upgrade step to set enable-disk-uuid to false
Browse files Browse the repository at this point in the history
This maintains current behaviour for existing models, although new
models will default to true.
  • Loading branch information
babbageclunk committed Nov 19, 2018
1 parent cfbfcc5 commit 53feba4
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 0 deletions.
24 changes: 24 additions & 0 deletions state/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -1819,3 +1819,27 @@ func MigrateAddModelPermissions(pool *StatePool) error {
}
return nil
}

// SetEnableDiskUUIDOnVsphere updates the settings for all vsphere
// models to have enable-disk-uuid=false. The new default is true, but
// this maintains the previous behaviour for upgraded models.
func SetEnableDiskUUIDOnVsphere(pool *StatePool) error {
return errors.Trace(applyToAllModelSettings(pool.SystemState(), func(doc *settingsDoc) (bool, error) {
typeVal, found := doc.Settings["type"]
if !found {
return false, nil
}
typeStr, ok := typeVal.(string)
if !ok || typeStr != "vsphere" {
return false, nil
}
_, found = doc.Settings["enable-disk-uuid"]
if found {
// If the config option's already been set don't change
// it.
return false, nil
}
doc.Settings["enable-disk-uuid"] = false
return true, nil
}))
}
70 changes: 70 additions & 0 deletions state/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2830,6 +2830,76 @@ func (s *upgradesSuite) TestMigrateAddModelPermissions(c *gc.C) {
s.assertUpgradedData(c, MigrateAddModelPermissions, expectUpgradedData{permissionsColl, expected})
}

func (s *upgradesSuite) TestSetEnableDiskUUIDOnVsphere(c *gc.C) {
coll, closer := s.state.db().GetRawCollection(settingsC)
defer closer()

_, err := coll.RemoveAll(nil)
c.Assert(err, jc.ErrorIsNil)

m1 := s.makeModel(c, "m1", coretesting.Attrs{
"type": "someprovider",
})
defer m1.Close()
m2 := s.makeModel(c, "m2", coretesting.Attrs{
"type": "vsphere",
})
defer m2.Close()
m3 := s.makeModel(c, "m3", coretesting.Attrs{
"type": "vsphere",
"enable-disk-uuid": true,
})
defer m3.Close()

err = coll.Insert(bson.M{
"_id": "someothersettingshouldnotbetouched",
// non-model setting: should not be touched
"settings": bson.M{"key": "value"},
})
c.Assert(err, jc.ErrorIsNil)

getAttrs := func(st *State) map[string]interface{} {
model, err := st.Model()
c.Assert(err, jc.ErrorIsNil)
cfg, err := model.ModelConfig()
c.Assert(err, jc.ErrorIsNil)
attrs := cfg.AllAttrs()
attrs["resource-tags"] = ""
return attrs
}

expected1 := getAttrs(m1)
expected2 := getAttrs(m2)
expected2["enable-disk-uuid"] = false

expected3 := getAttrs(m3)

expectedSettings := bsonMById{
{
"_id": m1.ModelUUID() + ":e",
"settings": bson.M(expected1),
"model-uuid": m1.ModelUUID(),
}, {
"_id": m2.ModelUUID() + ":e",
"settings": bson.M(expected2),
"model-uuid": m2.ModelUUID(),
}, {
"_id": m3.ModelUUID() + ":e",
"settings": bson.M(expected3),
"model-uuid": m3.ModelUUID(),
}, {
"_id": "someothersettingshouldnotbetouched",
"settings": bson.M{"key": "value"},
},
}
sort.Sort(expectedSettings)

c.Logf(pretty.Sprint(expectedSettings))
s.assertUpgradedData(c, SetEnableDiskUUIDOnVsphere,
expectUpgradedData{coll, expectedSettings},
)
}

type docById []bson.M

func (d docById) Len() int { return len(d) }
Expand Down
5 changes: 5 additions & 0 deletions upgrades/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ type StateBackend interface {
MigrateStorageMachineIdFields() error
MigrateAddModelPermissions() error
LegacyLeases(time.Time) (map[lease.Key]lease.Info, error)
SetEnableDiskUUIDOnVsphere() error
}

// Model is an interface providing access to the details of a model within the
Expand Down Expand Up @@ -214,3 +215,7 @@ func (s stateBackend) LeaseNotifyTarget(w io.Writer, logger raftleasestore.Logge
func (s stateBackend) LegacyLeases(localTime time.Time) (map[lease.Key]lease.Info, error) {
return state.LegacyLeases(s.pool, localTime)
}

func (s stateBackend) SetEnableDiskUUIDOnVsphere() error {
return state.SetEnableDiskUUIDOnVsphere(s.pool)
}
7 changes: 7 additions & 0 deletions upgrades/steps_25.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,12 @@ func stateStepsFor25() []Step {
return context.State().MigrateAddModelPermissions()
},
},
&upgradeStep{
description: "set enable-disk-uuid (if on vsphere)",
targets: []Target{DatabaseMaster},
run: func(context Context) error {
return context.State().SetEnableDiskUUIDOnVsphere()
},
},
}
}
6 changes: 6 additions & 0 deletions upgrades/steps_25_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,9 @@ func (s *steps25Suite) TestMigrateAddModelPermissions(c *gc.C) {
// Logic for step itself is tested in state package.
c.Assert(step.Targets(), jc.DeepEquals, []upgrades.Target{upgrades.DatabaseMaster})
}

func (s *steps25Suite) TestSetEnableDiskUUIDOnVsphere(c *gc.C) {
step := findStateStep(c, v25, `set enable-disk-uuid (if on vsphere)`)
// Logic for step itself is tested in state package.
c.Assert(step.Targets(), jc.DeepEquals, []upgrades.Target{upgrades.DatabaseMaster})
}

0 comments on commit 53feba4

Please sign in to comment.