Skip to content

Commit

Permalink
Merge pull request #7442 from wallyworld/restore-controller-config
Browse files Browse the repository at this point in the history
Ensure any missing controller config is added when restoring from backup

## Description of change

When restoring a system originally bootstrapped with an older Juju, there may be new controller config attributes not originally present in the older Juju. This caused a panic. Restore now ensures any necessary default controller attributes are filled in as needed.

## QA steps

Follow steps in bug.
Deploy Juju 2.1.3
Upgrade to 2.2
Take backup
Kill controller
Restore from backup

## Bug reference

https://bugs.launchpad.net/juju/+bug/1688635
  • Loading branch information
jujubot committed Jun 2, 2017
2 parents ec9eac9 + f5dfc80 commit 6d55ec8
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
10 changes: 6 additions & 4 deletions cmd/juju/backups/restore.go
Expand Up @@ -203,12 +203,14 @@ func (c *restoreCommand) getRebootstrapParams(
return nil, errors.Annotatef(err, "cannot enable provisioner-safe-mode")
}

controllerCfg := make(controller.Config)
controllerCfgAttrs := make(map[string]interface{})
for k, v := range config.ControllerConfig {
controllerCfg[k] = v
controllerCfgAttrs[k] = v
}
controllerCfg, err := controller.NewConfig(controllerDetails.ControllerUUID, meta.CACert, controllerCfgAttrs)
if err != nil {
return nil, errors.Annotatef(err, "cannot create controller config")
}
controllerCfg[controller.ControllerUUIDKey] = controllerDetails.ControllerUUID
controllerCfg[controller.CACertKey] = meta.CACert

return &restoreBootstrapParams{
controllerCfg,
Expand Down
36 changes: 36 additions & 0 deletions cmd/juju/backups/restore_test.go
Expand Up @@ -263,6 +263,42 @@ func (s *restoreSuite) TestRestoreReboostrapWritesUpdatedControllerInfo(c *gc.C)
})
}

func (s *restoreSuite) TestRestoreReboostrapControllerConfigDefaults(c *gc.C) {
metadata := params.BackupsMetadataResult{
CACert: testing.CACert,
CAPrivateKey: testing.CAKey,
}
fakeEnv := fakeEnviron{}
s.command = backups.NewRestoreCommandForTest(
s.store, &mockRestoreAPI{},
func(string) (backups.ArchiveReader, *params.BackupsMetadataResult, error) {
return &mockArchiveReader{}, &metadata, nil
},
backups.GetEnvironFunc(fakeEnv),
nil,
)
boostrapped := false
s.PatchValue(&backups.BootstrapFunc, func(ctx environs.BootstrapContext, environ environs.Environ, args bootstrap.BootstrapParams) error {
c.Assert(args.ControllerConfig, jc.DeepEquals, controller.Config{
"controller-uuid": "deadbeef-0bad-400d-8000-5b1d0d06f00d",
"ca-cert": testing.CACert,
"state-port": 37017,
"api-port": 17070,
"set-numa-control-policy": false,
"max-logs-age": "72h",
"max-logs-size": "4096M",
"max-txn-log-size": "10M",
"auditing-enabled": false,
})
boostrapped = true
return nil
})

_, err := cmdtesting.RunCommand(c, s.command, "restore", "-m", "testing:test1", "--file", "afile", "-b")
c.Assert(err, jc.ErrorIsNil)
c.Assert(boostrapped, jc.IsTrue)
}

func (s *restoreSuite) TestRestoreReboostrapBuiltInProvider(c *gc.C) {
metadata := params.BackupsMetadataResult{
CACert: testing.CACert,
Expand Down

0 comments on commit 6d55ec8

Please sign in to comment.