Esempio n. 1
0
func (s *destroyEnvironmentSuite) TestBlockDestroyDestroyHostedEnvironment(c *gc.C) {
	otherSt := s.Factory.MakeEnvironment(c, nil)
	defer otherSt.Close()
	info := s.APIInfo(c)
	info.EnvironTag = otherSt.EnvironTag()
	apiState, err := api.Open(info, api.DefaultDialOpts())

	block := commontesting.NewBlockHelper(apiState)
	defer block.Close()

	block.BlockDestroyEnvironment(c, "TestBlockDestroyDestroyEnvironment")
	err = common.DestroyEnvironmentIncludingHosted(s.State, s.State.EnvironTag())
	s.AssertBlocked(c, err, "TestBlockDestroyDestroyEnvironment")
}
Esempio n. 2
0
func (s *destroyTwoEnvironmentsSuite) TestDestroyStateServerAndNonStateServer(c *gc.C) {
	otherFactory := factory.NewFactory(s.otherState)
	otherFactory.MakeMachine(c, nil)
	m := otherFactory.MakeMachine(c, nil)
	otherFactory.MakeMachineNested(c, m.Id(), nil)

	err := common.DestroyEnvironmentIncludingHosted(s.State, s.State.EnvironTag())
	c.Assert(err, jc.ErrorIsNil)

	runAllCleanups(c, s.State)
	runAllCleanups(c, s.otherState)
	assertAllMachinesDeadAndRemove(c, s.otherState)

	// Make sure we can continue to take the hosted environ down while the
	// controller environ is dying.
	c.Assert(s.otherState.ProcessDyingEnviron(), jc.ErrorIsNil)
}
Esempio n. 3
0
// DestroyController will attempt to destroy the controller. If the args
// specify the removal of blocks or the destruction of the environments, this
// method will attempt to do so.
func (s *ControllerAPI) DestroyController(args params.DestroyControllerArgs) error {
	controllerEnv, err := s.state.ControllerEnvironment()
	if err != nil {
		return errors.Trace(err)
	}
	systemTag := controllerEnv.EnvironTag()

	if err = s.ensureNotBlocked(args); err != nil {
		return errors.Trace(err)
	}

	// If we are destroying environments, we need to tolerate living
	// environments but set the controller to dying to prevent new
	// environments sneaking in. If we are not destroying hosted environments,
	// this will fail if any hosted environments are found.
	if args.DestroyEnvironments {
		return errors.Trace(common.DestroyEnvironmentIncludingHosted(s.state, systemTag))
	}
	if err = common.DestroyEnvironment(s.state, systemTag); state.IsHasHostedEnvironsError(err) {
		err = errors.New("controller environment cannot be destroyed before all other environments are destroyed")
	}
	return errors.Trace(err)
}