func (s *ModelSuite) assertDyingEnvironTransitionDyingToDead(c *gc.C, st *state.State) { // Add a service to prevent the model from transitioning directly to Dead. // Add the service before getting the Model, otherwise we'll have to run // the transaction twice, and hit the hook point too early. svc := factory.NewFactory(st).MakeService(c, nil) env, err := st.Model() c.Assert(err, jc.ErrorIsNil) // ProcessDyingModel is called by a worker after Destroy is called. To // avoid a race, we jump the gun here and test immediately after the // environement was set to dead. defer state.SetAfterHooks(c, st, func() { c.Assert(env.Refresh(), jc.ErrorIsNil) c.Assert(env.Life(), gc.Equals, state.Dying) err := svc.Destroy() c.Assert(err, jc.ErrorIsNil) c.Assert(st.ProcessDyingModel(), jc.ErrorIsNil) c.Assert(env.Refresh(), jc.ErrorIsNil) c.Assert(env.Life(), gc.Equals, state.Dead) }).Check() c.Assert(env.Destroy(), jc.ErrorIsNil) }
func (s *MinUnitsSuite) TestEnsureMinUnitsDecreaseMinUnitsAfter(c *gc.C) { s.addUnits(c, 2) service := s.service err := service.SetMinUnits(5) c.Assert(err, jc.ErrorIsNil) defer state.SetAfterHooks(c, s.State, func() { err := service.SetMinUnits(3) c.Assert(err, jc.ErrorIsNil) }).Check() c.Assert(service.Refresh(), gc.IsNil) err = service.EnsureMinUnits() c.Assert(err, jc.ErrorIsNil) assertAllUnits(c, service, 3) }
func (s *ModelSuite) TestProcessDyingEnvironWithMachinesAndServicesNoOp(c *gc.C) { st := s.Factory.MakeModel(c, nil) defer st.Close() // calling ProcessDyingModel on a live environ should fail. err := st.ProcessDyingModel() c.Assert(err, gc.ErrorMatches, "model is not dying") // add some machines and services env, err := st.Model() c.Assert(err, jc.ErrorIsNil) _, err = st.AddMachine("quantal", state.JobHostUnits) c.Assert(err, jc.ErrorIsNil) service := s.Factory.MakeService(c, &factory.ServiceParams{Creator: env.Owner()}) ch, _, err := service.Charm() c.Assert(err, jc.ErrorIsNil) args := state.AddServiceArgs{ Name: service.Name(), Owner: service.GetOwnerTag(), Charm: ch, } service, err = st.AddService(args) c.Assert(err, jc.ErrorIsNil) assertEnv := func(life state.Life, expectedMachines, expectedServices int) { c.Assert(env.Refresh(), jc.ErrorIsNil) c.Assert(env.Life(), gc.Equals, life) machines, err := st.AllMachines() c.Assert(err, jc.ErrorIsNil) c.Assert(machines, gc.HasLen, expectedMachines) services, err := st.AllServices() c.Assert(err, jc.ErrorIsNil) c.Assert(services, gc.HasLen, expectedServices) } // Simulate processing a dying envrionment after an envrionment is set to // dying, but before the cleanup has removed machines and services. defer state.SetAfterHooks(c, st, func() { assertEnv(state.Dying, 1, 1) err := st.ProcessDyingModel() c.Assert(err, gc.ErrorMatches, `model not empty, found 1 machine\(s\)`) assertEnv(state.Dying, 1, 1) }).Check() c.Assert(env.Refresh(), jc.ErrorIsNil) c.Assert(env.Destroy(), jc.ErrorIsNil) }
func (s *UpgradeSuite) TestEnsureUpgradeInfoRace(c *gc.C) { v100 := vers("1.0.0") v200 := vers("2.0.0") _, err := s.State.EnsureUpgradeInfo(s.serverIdA, v100, v200) c.Assert(err, jc.ErrorIsNil) defer state.SetAfterHooks(c, s.State, func() { err := s.State.ClearUpgradeInfo() c.Assert(err, jc.ErrorIsNil) }).Check() info, err := s.State.EnsureUpgradeInfo(s.serverIdA, v100, v200) c.Assert(err, gc.ErrorMatches, "current upgrade info not found") c.Assert(err, jc.Satisfies, errors.IsNotFound) c.Assert(info, gc.IsNil) }
func (s *UpgradeSuite) TestEnsureUpgradeInfoMultipleServersRace2(c *gc.C) { serverIdB, serverIdC := s.addControllers(c) s.provision(c, serverIdB, serverIdC) v111 := vers("1.1.1") v123 := vers("1.2.3") _, err := s.State.EnsureUpgradeInfo(s.serverIdA, v111, v123) c.Assert(err, jc.ErrorIsNil) defer state.SetAfterHooks(c, s.State, func() { _, err := s.State.EnsureUpgradeInfo(serverIdC, v111, v123) c.Assert(err, jc.ErrorIsNil) }).Check() info, err := s.State.EnsureUpgradeInfo(serverIdB, v111, v123) c.Assert(err, jc.ErrorIsNil) expectReady := []string{s.serverIdA, serverIdB, serverIdC} c.Assert(info.ControllersReady(), jc.SameContents, expectReady) }
func (s *ModelSuite) assertDyingEnvironTransitionDyingToDead(c *gc.C, st *state.State) { env, err := st.Model() c.Assert(err, jc.ErrorIsNil) // ProcessDyingModel is called by a worker after Destroy is called. To // avoid a race, we jump the gun here and test immediately after the // environement was set to dead. defer state.SetAfterHooks(c, st, func() { c.Assert(env.Refresh(), jc.ErrorIsNil) c.Assert(env.Life(), gc.Equals, state.Dying) c.Assert(st.ProcessDyingModel(), jc.ErrorIsNil) c.Assert(env.Refresh(), jc.ErrorIsNil) c.Assert(env.Life(), gc.Equals, state.Dead) }).Check() c.Assert(env.Destroy(), jc.ErrorIsNil) }
func (s *UpgradeSuite) TestEnsureUpgradeInfoMultipleServersRace4(c *gc.C) { serverIdB, serverIdC := s.addControllers(c) s.provision(c, serverIdB, serverIdC) v111 := vers("1.1.1") v123 := vers("1.2.3") v124 := vers("1.2.4") _, err := s.State.EnsureUpgradeInfo(s.serverIdA, v111, v123) c.Assert(err, jc.ErrorIsNil) defer state.SetAfterHooks(c, s.State, nil, func() { err := s.State.ClearUpgradeInfo() c.Assert(err, jc.ErrorIsNil) _, err = s.State.EnsureUpgradeInfo(serverIdC, v111, v124) c.Assert(err, jc.ErrorIsNil) }).Check() _, err = s.State.EnsureUpgradeInfo(serverIdB, v111, v123) c.Assert(err, gc.ErrorMatches, "current upgrade info mismatch: expected target version 1.2.3, got 1.2.4") }