func (s *BootstrapSuite) TestSetConstraints(c *gc.C) { bootstrapCons := constraints.Value{Mem: uint64p(4096), CpuCores: uint64p(4)} modelCons := constraints.Value{Mem: uint64p(2048), CpuCores: uint64p(2)} _, cmd, err := s.initBootstrapCommand(c, nil, "--model-config", s.b64yamlControllerModelConfig, "--hosted-model-config", s.b64yamlHostedModelConfig, "--instance-id", string(s.instanceId), "--bootstrap-constraints", bootstrapCons.String(), "--constraints", modelCons.String(), ) c.Assert(err, jc.ErrorIsNil) err = cmd.Run(nil) c.Assert(err, jc.ErrorIsNil) st, err := state.Open(testing.ModelTag, &mongo.MongoInfo{ Info: mongo.Info{ Addrs: []string{gitjujutesting.MgoServer.Addr()}, CACert: testing.CACert, }, Password: testPassword, }, mongotest.DialOpts(), environs.NewStatePolicy()) c.Assert(err, jc.ErrorIsNil) defer st.Close() cons, err := st.ModelConstraints() c.Assert(err, jc.ErrorIsNil) c.Assert(cons, gc.DeepEquals, modelCons) machines, err := st.AllMachines() c.Assert(err, jc.ErrorIsNil) c.Assert(machines, gc.HasLen, 1) cons, err = machines[0].Constraints() c.Assert(err, jc.ErrorIsNil) c.Assert(cons, gc.DeepEquals, bootstrapCons) }
func (s *BootstrapSuite) TestSetConstraints(c *gc.C) { tcons := constraints.Value{Mem: uint64p(2048), CpuCores: uint64p(2)} _, cmd, err := s.initBootstrapCommand(c, nil, "--env-config", s.b64yamlEnvcfg, "--instance-id", string(s.instanceId), "--constraints", tcons.String(), ) c.Assert(err, jc.ErrorIsNil) err = cmd.Run(nil) c.Assert(err, jc.ErrorIsNil) st, err := state.Open(testing.EnvironmentTag, &mongo.MongoInfo{ Info: mongo.Info{ Addrs: []string{gitjujutesting.MgoServer.Addr()}, CACert: testing.CACert, }, Password: testPasswordHash(), }, mongo.DefaultDialOpts(), environs.NewStatePolicy()) c.Assert(err, jc.ErrorIsNil) defer st.Close() cons, err := st.EnvironConstraints() c.Assert(err, jc.ErrorIsNil) c.Assert(cons, gc.DeepEquals, tcons) machines, err := st.AllMachines() c.Assert(err, jc.ErrorIsNil) c.Assert(machines, gc.HasLen, 1) cons, err = machines[0].Constraints() c.Assert(err, jc.ErrorIsNil) c.Assert(cons, gc.DeepEquals, tcons) }
func (s *MigrationImportSuite) assertUnitsMigrated(c *gc.C, cons constraints.Value) { exported, pwd := s.Factory.MakeUnitReturningPassword(c, &factory.UnitParams{ Constraints: cons, }) err := exported.SetMeterStatus("GREEN", "some info") c.Assert(err, jc.ErrorIsNil) err = exported.SetWorkloadVersion("amethyst") c.Assert(err, jc.ErrorIsNil) err = s.State.SetAnnotations(exported, testAnnotations) c.Assert(err, jc.ErrorIsNil) s.primeStatusHistory(c, exported, status.Active, 5) s.primeStatusHistory(c, exported.Agent(), status.Idle, 5) _, newSt := s.importModel(c) importedApplications, err := newSt.AllApplications() c.Assert(err, jc.ErrorIsNil) c.Assert(importedApplications, gc.HasLen, 1) importedUnits, err := importedApplications[0].AllUnits() c.Assert(err, jc.ErrorIsNil) c.Assert(importedUnits, gc.HasLen, 1) imported := importedUnits[0] c.Assert(imported.UnitTag(), gc.Equals, exported.UnitTag()) c.Assert(imported.PasswordValid(pwd), jc.IsTrue) version, err := imported.WorkloadVersion() c.Assert(err, jc.ErrorIsNil) c.Assert(version, gc.Equals, "amethyst") exportedMachineId, err := exported.AssignedMachineId() c.Assert(err, jc.ErrorIsNil) importedMachineId, err := imported.AssignedMachineId() c.Assert(err, jc.ErrorIsNil) c.Assert(importedMachineId, gc.Equals, exportedMachineId) // Confirm machine Principals are set. exportedMachine, err := s.State.Machine(exportedMachineId) c.Assert(err, jc.ErrorIsNil) importedMachine, err := newSt.Machine(importedMachineId) c.Assert(err, jc.ErrorIsNil) s.AssertMachineEqual(c, importedMachine, exportedMachine) meterStatus, err := imported.GetMeterStatus() c.Assert(err, jc.ErrorIsNil) c.Assert(meterStatus, gc.Equals, state.MeterStatus{state.MeterGreen, "some info"}) s.assertAnnotations(c, newSt, imported) s.checkStatusHistory(c, exported, imported, 5) s.checkStatusHistory(c, exported.Agent(), imported.Agent(), 5) s.checkStatusHistory(c, exported.WorkloadVersionHistory(), imported.WorkloadVersionHistory(), 1) newCons, err := imported.Constraints() c.Assert(err, jc.ErrorIsNil) // Can't test the constraints directly, so go through the string repr. c.Assert(newCons.String(), gc.Equals, cons.String()) }