Skip to content

Commit

Permalink
Merge pull request juju#17987 from nvinuesa/merge-3.4-3.5-20240828
Browse files Browse the repository at this point in the history
juju#17987

Includes:
- juju#17978

No conflicts.
  • Loading branch information
jujubot authored Aug 28, 2024
2 parents 14011e3 + d401b8c commit 2a05e65
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
6 changes: 5 additions & 1 deletion controller/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -1278,7 +1278,11 @@ func (c Config) validateSpaceConfig(key, topic string) error {
return nil
}
if v, ok := val.(string); ok {
if !names.IsValidSpace(v) {
// NOTE(nvinuesa): We also check for the case where the passed
// value is the empty string, this is needed to un-set the
// controller config value and not added in the regexp to
// validate the space.
if !names.IsValidSpace(v) && v != "" {
return errors.NotValidf("%s space name %q", topic, val)
}
} else {
Expand Down
5 changes: 5 additions & 0 deletions controller/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ var newConfigTests = []struct {
controller.JujuManagementSpace: "\n",
},
expectError: `juju mgmt space name "\\n" not valid`,
}, {
about: "HA space name - empty string OK",
config: controller.Config{
controller.JujuHASpace: "",
},
}, {
about: "invalid HA space name - number",
config: controller.Config{
Expand Down
9 changes: 9 additions & 0 deletions state/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,15 @@ func checkUpdateControllerConfig(name string) error {
// checkSpaceIsAvailableToAllControllers checks if each controller machine has
// at least one address in the input space. If not, an error is returned.
func (st *State) checkSpaceIsAvailableToAllControllers(spaceName string) error {
// TODO(nvinuesa): We should not be checking if the space is empty
// at this point, instead we should be using the `removeAttrs`
// attribute on `UpdateControllerConfig()` to un-set the spaces.
// Unfortunately this is not the case and therefore we must check for
// the empty string (un-setting the space value) as a workaround.
if spaceName == "" {
return nil
}

controllerIds, err := st.ControllerIds()
if err != nil {
return errors.Annotate(err, "cannot get controller info")
Expand Down
23 changes: 23 additions & 0 deletions state/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,29 @@ func (s *ControllerSuite) TestRemovingUnknownName(c *gc.C) {
c.Assert(err, gc.ErrorMatches, `unknown controller config setting "dr-worm"`)
}

func (s *ControllerSuite) TestUpdateControllerConfigAcceptEmptyStringSpace(c *gc.C) {
sp, err := s.State.AddSpace("ha-space", "", nil, false)
c.Assert(err, jc.ErrorIsNil)

m, err := s.State.AddMachine(state.UbuntuBase("12.10"), state.JobManageModel, state.JobHostUnits)
c.Assert(err, jc.ErrorIsNil)

addr := network.NewSpaceAddress("192.168.9.9")
addr.SpaceID = sp.Id()

c.Assert(m.SetProviderAddresses(addr), jc.ErrorIsNil)

err = s.State.UpdateControllerConfig(map[string]interface{}{
controller.JujuHASpace: "ha-space",
}, nil)
c.Assert(err, jc.ErrorIsNil)

err = s.State.UpdateControllerConfig(map[string]interface{}{
controller.JujuHASpace: "",
}, nil)
c.Assert(err, jc.ErrorIsNil)
}

func (s *ControllerSuite) TestUpdateControllerConfigRejectsSpaceWithoutAddresses(c *gc.C) {
_, err := s.State.AddSpace("mgmt-space", "", nil, false)
c.Assert(err, jc.ErrorIsNil)
Expand Down

0 comments on commit 2a05e65

Please sign in to comment.