Пример #1
0
func (s *restoreSuite) TestRestoreReboostrapBuiltInProvider(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),
		backups.GetRebootstrapParamsFunc("lxd"),
	)
	boostrapped := false
	s.PatchValue(&backups.BootstrapFunc, func(ctx environs.BootstrapContext, environ environs.Environ, args bootstrap.BootstrapParams) error {
		boostrapped = true
		sort.Sort(args.Cloud.AuthTypes)
		c.Assert(args.Cloud, jc.DeepEquals, cloud.Cloud{
			Type:      "lxd",
			AuthTypes: []cloud.AuthType{"empty"},
			Regions:   []cloud.Region{{Name: "localhost"}},
		})
		return nil
	})

	_, err := testing.RunCommand(c, s.command, "restore", "-m", "testing:test1", "--file", "afile", "-b")
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(boostrapped, jc.IsTrue)
}
Пример #2
0
func (s *restoreSuite) TestRestoreReboostrapControllerExists(c *gc.C) {
	fakeEnv := fakeEnviron{controllerInstances: []instance.Id{"1"}}
	s.command = backups.NewRestoreCommandForTest(
		s.store, &mockRestoreAPI{},
		func(string) (backups.ArchiveReader, *params.BackupsMetadataResult, error) {
			return &mockArchiveReader{}, &params.BackupsMetadataResult{}, nil
		},
		backups.GetEnvironFunc(fakeEnv),
		backups.GetRebootstrapParamsFunc("mycloud"),
	)
	_, err := testing.RunCommand(c, s.command, "restore", "--file", "afile", "-b")
	c.Assert(err, gc.ErrorMatches, ".*still seems to exist.*")
}
Пример #3
0
func (s *restoreSuite) TestRestoreReboostrapWritesUpdatedControllerInfo(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),
		backups.GetRebootstrapParamsFunc("mycloud"),
	)
	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-1bad-500d-9000-4b1d0d06f00d",
			"ca-cert":                 testing.CACert,
			"state-port":              1234,
			"api-port":                17777,
			"set-numa-control-policy": false,
		})
		boostrapped = true
		return nil
	})

	intPtr := func(i int) *int {
		return &i
	}

	_, err := testing.RunCommand(c, s.command, "restore", "-m", "testing:test1", "--file", "afile", "-b")
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(boostrapped, jc.IsTrue)
	c.Assert(s.store.Controllers["testing"], jc.DeepEquals, jujuclient.ControllerDetails{
		Cloud:                  "mycloud",
		CloudRegion:            "a-region",
		CACert:                 testing.CACert,
		ControllerUUID:         "deadbeef-1bad-500d-9000-4b1d0d06f00d",
		APIEndpoints:           []string{"10.0.0.1:17777"},
		UnresolvedAPIEndpoints: []string{"10.0.0.1:17777"},
		AgentVersion:           version.Current.String(),
		ModelCount:             intPtr(2),
		MachineCount:           intPtr(1),
		ControllerMachineCount: 1,
	})
}
Пример #4
0
func (s *restoreSuite) TestRestoreReboostrapNoControllers(c *gc.C) {
	fakeEnv := fakeEnviron{}
	s.command = backups.NewRestoreCommandForTest(
		s.store, &mockRestoreAPI{},
		func(string) (backups.ArchiveReader, *params.BackupsMetadataResult, error) {
			return &mockArchiveReader{}, &params.BackupsMetadataResult{
				CACert: testing.CACert,
			}, nil
		},
		backups.GetEnvironFunc(fakeEnv),
		backups.GetRebootstrapParamsFunc("mycloud"),
	)
	s.PatchValue(&backups.BootstrapFunc, func(ctx environs.BootstrapContext, environ environs.Environ, args bootstrap.BootstrapParams) error {
		return errors.New("failed to bootstrap new controller")
	})

	_, err := testing.RunCommand(c, s.command, "restore", "--file", "afile", "-b")
	c.Assert(err, gc.ErrorMatches, ".*failed to bootstrap new controller")
}