207
207
check(m[1], "1", "blahblah", allJobs)
210
func (s *StateSuite) TestAddMachinesEnvironmentLife(c *gc.C) {
210
func (s *StateSuite) TestAddMachinesEnvironmentDying(c *gc.C) {
211
211
_, err := s.State.AddMachine("quantal", state.JobHostUnits)
212
212
c.Assert(err, gc.IsNil)
213
// Check that machines cannot be added if the environment is Dying.
214
213
env, err := s.State.Environment()
215
214
c.Assert(err, gc.IsNil)
216
215
err = env.Destroy()
217
216
c.Assert(err, gc.IsNil)
217
// Check that machines cannot be added if the environment is initially Dying.
218
_, err = s.State.AddMachine("quantal", state.JobHostUnits)
219
c.Assert(err, gc.ErrorMatches, "cannot add a new machine: environment is being destroyed")
222
func (s *StateSuite) TestAddMachinesEnvironmentDyingAfterInitial(c *gc.C) {
223
_, err := s.State.AddMachine("quantal", state.JobHostUnits)
224
c.Assert(err, gc.IsNil)
225
env, err := s.State.Environment()
226
c.Assert(err, gc.IsNil)
227
// Check that machines cannot be added if the environment is initially
228
// Alive but set to Dying immediately before the transaction is run.
229
defer state.SetBeforeHooks(c, s.State, func() {
230
c.Assert(env.Life(), gc.Equals, state.Alive)
231
c.Assert(env.Destroy(), gc.IsNil)
218
233
_, err = s.State.AddMachine("quantal", state.JobHostUnits)
219
234
c.Assert(err, gc.ErrorMatches, "cannot add a new machine: environment is being destroyed")
542
557
c.Assert(ch.URL(), gc.DeepEquals, charm.URL())
545
func (s *StateSuite) TestAddServiceEnvironmentLife(c *gc.C) {
560
func (s *StateSuite) TestAddServiceEnvironmentDying(c *gc.C) {
546
561
charm := s.AddTestingCharm(c, "dummy")
547
562
_, err := s.State.AddService("s0", charm)
548
563
c.Assert(err, gc.IsNil)
550
// Check that services cannot be added if the environment is Dying.
564
// Check that services cannot be added if the environment is initially Dying.
551
565
env, err := s.State.Environment()
552
566
c.Assert(err, gc.IsNil)
553
567
err = env.Destroy()
556
570
c.Assert(err, gc.ErrorMatches, `cannot add service "s1": environment is being destroyed`)
573
func (s *StateSuite) TestAddServiceEnvironmentDyingAfterInitial(c *gc.C) {
574
charm := s.AddTestingCharm(c, "dummy")
575
_, err := s.State.AddService("s0", charm)
576
c.Assert(err, gc.IsNil)
577
env, err := s.State.Environment()
578
c.Assert(err, gc.IsNil)
579
// Check that services cannot be added if the environment is initially
580
// Alive but set to Dying immediately before the transaction is run.
581
defer state.SetBeforeHooks(c, s.State, func() {
582
c.Assert(env.Life(), gc.Equals, state.Alive)
583
c.Assert(env.Destroy(), gc.IsNil)
585
_, err = s.State.AddService("s1", charm)
586
c.Assert(err, gc.ErrorMatches, `cannot add service "s1": environment is being destroyed`)
559
589
func (s *StateSuite) TestServiceNotFound(c *gc.C) {
560
590
_, err := s.State.Service("bummer")
561
591
c.Assert(err, gc.ErrorMatches, `service "bummer" not found`)
1614
1644
tag: "user-arble",
1616
1646
tag: "environment-notauuid",
1617
err: `"environment-notauuid" is not a valid environment tag`,
1647
// TODO(axw) remove backwards compatibility for environment-tag; see lp:1257587
1648
//err: `"environment-notauuid" is not a valid environment tag`,
1620
1651
var entityTypes = map[string]interface{}{
1661
1692
kind, err := names.TagKind(test.tag)
1662
1693
c.Assert(err, gc.IsNil)
1663
1694
c.Assert(e, gc.FitsTypeOf, entityTypes[kind])
1664
c.Assert(e.Tag(), gc.Equals, test.tag)
1695
if kind == "environment" {
1696
// TODO(axw) remove backwards compatibility for environment-tag; see lp:1257587
1697
// We *should* only be able to get the entity with its tag, but
1698
// for backwards-compatibility we accept any non-UUID tag.
1699
c.Assert(e.Tag(), gc.Equals, env.Tag())
1701
c.Assert(e.Tag(), gc.Equals, test.tag)