예제 #1
0
파일: restore_test.go 프로젝트: bac/juju
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) 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
		},
		func(string, *params.BackupsMetadataResult) (environs.Environ, error) {
			return fakeEnv, nil
		})
	s.PatchValue(&backups.BootstrapFunc, func(ctx environs.BootstrapContext, environ environs.Environ, args bootstrap.BootstrapParams) error {
		return nil
	})

	_, err := testing.RunCommand(c, s.command, "restore", "-m", "testing:test1", "--file", "afile", "-b")
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(s.store.Controllers["testing"], jc.DeepEquals, jujuclient.ControllerDetails{
		CACert:                 testing.CACert,
		ControllerUUID:         "deadbeef-0bad-400d-8000-4b1d0d06f00d",
		APIEndpoints:           []string{"10.0.0.1:100"},
		UnresolvedAPIEndpoints: []string{"10.0.0.1:100"},
	})
}
예제 #3
0
파일: restore_test.go 프로젝트: bac/juju
func (s *restoreSuite) TestFailedRestoreReboostrapMaintainsControllerInfo(c *gc.C) {
	metadata := params.BackupsMetadataResult{
		CACert:       testing.CACert,
		CAPrivateKey: testing.CAKey,
	}
	s.command = backups.NewRestoreCommandForTest(
		s.store, &mockRestoreAPI{},
		func(string) (backups.ArchiveReader, *params.BackupsMetadataResult, error) {
			return &mockArchiveReader{}, &metadata, nil
		},
		nil,
		backups.GetRebootstrapParamsFuncWithError(),
	)
	s.PatchValue(&backups.BootstrapFunc, func(ctx environs.BootstrapContext, environ environs.Environ, args bootstrap.BootstrapParams) error {
		// We should not call bootstrap.
		c.Fail()
		return nil
	})

	_, err := testing.RunCommand(c, s.command, "restore", "-m", "testing:test1", "--file", "afile", "-b")
	c.Assert(err, gc.ErrorMatches, "failed")
	// The details below are as per what was done in test setup, so no changes.
	c.Assert(s.store.Controllers["testing"], jc.DeepEquals, jujuclient.ControllerDetails{
		Cloud:                  "mycloud",
		CloudRegion:            "a-region",
		CACert:                 testing.CACert,
		ControllerUUID:         "deadbeef-0bad-400d-8000-5b1d0d06f00d",
		APIEndpoints:           []string{"10.0.1.1:17777"},
		UnresolvedAPIEndpoints: []string{"10.0.1.1:17777"},
	})
}
예제 #4
0
func (s *restoreSuite) TestRestoreArgs(c *gc.C) {
	s.command = backups.NewRestoreCommandForTest(s.store, nil, nil, nil)
	_, err := testing.RunCommand(c, s.command, "restore")
	c.Assert(err, gc.ErrorMatches, "you must specify either a file or a backup id.")

	_, err = testing.RunCommand(c, s.command, "restore", "--id", "anid", "--file", "afile")
	c.Assert(err, gc.ErrorMatches, "you must specify either a file or a backup id but not both.")

	_, err = testing.RunCommand(c, s.command, "restore", "--id", "anid", "-b")
	c.Assert(err, gc.ErrorMatches, "it is not possible to rebootstrap and restore from an id.")
}
예제 #5
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
		},
		func(string, *params.BackupsMetadataResult) (environs.Environ, error) {
			return fakeEnv, nil
		})
	_, err := testing.RunCommand(c, s.command, "restore", "--file", "afile", "-b")
	c.Assert(err, gc.ErrorMatches, ".*still seems to exist.*")
}
예제 #6
0
파일: restore_test.go 프로젝트: bac/juju
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,
	})
}
예제 #7
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{}, nil
		},
		func(string, *params.BackupsMetadataResult) (environs.Environ, error) {
			return fakeEnv, nil
		})
	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")
}
예제 #8
0
func (s *restoreSuite) TestRestoreReboostrapReadsMetadata(c *gc.C) {
	metadata := params.BackupsMetadataResult{
		CACert:       testing.CACert,
		CAPrivateKey: testing.CAKey,
	}
	s.command = backups.NewRestoreCommandForTest(
		s.store, &mockRestoreAPI{},
		func(string) (backups.ArchiveReader, *params.BackupsMetadataResult, error) {
			return &mockArchiveReader{}, &metadata, nil
		},
		nil)
	s.PatchValue(&backups.BootstrapFunc, func(ctx environs.BootstrapContext, environ environs.Environ, args bootstrap.BootstrapParams) error {
		attr := environ.Config().AllAttrs()
		c.Assert(attr["ca-cert"], gc.Equals, testing.CACert)
		return errors.New("failed to bootstrap new controller")
	})

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