Example #1
0
// checkNotValid checks that the supplied migrationflag.Config fails to
// Validate, and cannot be used to construct a migrationflag.Worker.
func checkNotValid(c *gc.C, config migrationflag.Config, expect string) {
	check := func(err error) {
		c.Check(err, gc.ErrorMatches, expect)
		c.Check(err, jc.Satisfies, errors.IsNotValid)
	}

	err := config.Validate()
	check(err)

	worker, err := migrationflag.New(config)
	c.Check(worker, gc.IsNil)
	check(err)
}
Example #2
0
func (*WorkerSuite) TestPhaseErrorOnStartup(c *gc.C) {
	stub := &testing.Stub{}
	stub.SetErrors(errors.New("gaah"))
	facade := newMockFacade(stub)
	config := migrationflag.Config{
		Facade: facade,
		Model:  validUUID,
		Check:  panicCheck,
	}
	worker, err := migrationflag.New(config)
	c.Check(worker, gc.IsNil)
	c.Check(err, gc.ErrorMatches, "gaah")
	checkCalls(c, stub, "Phase")
}
Example #3
0
func (*WorkerSuite) TestPhaseErrorWhileRunning(c *gc.C) {
	stub := &testing.Stub{}
	stub.SetErrors(nil, nil, errors.New("glug"))
	facade := newMockFacade(stub, migration.QUIESCE)
	config := migrationflag.Config{
		Facade: facade,
		Model:  validUUID,
		Check:  neverCheck,
	}
	worker, err := migrationflag.New(config)
	c.Assert(err, jc.ErrorIsNil)
	c.Check(worker.Check(), jc.IsFalse)

	err = workertest.CheckKilled(c, worker)
	c.Check(err, gc.ErrorMatches, "glug")
	checkCalls(c, stub, "Phase", "Watch", "Phase")
}
Example #4
0
func (*WorkerSuite) TestSubsequentPhaseChange(c *gc.C) {
	stub := &testing.Stub{}
	facade := newMockFacade(stub,
		migration.ABORT, migration.REAP, migration.QUIESCE,
	)
	config := migrationflag.Config{
		Facade: facade,
		Model:  validUUID,
		Check:  isQuiesce,
	}
	worker, err := migrationflag.New(config)
	c.Assert(err, jc.ErrorIsNil)
	c.Check(worker.Check(), jc.IsFalse)

	err = workertest.CheckKilled(c, worker)
	c.Check(err, gc.Equals, migrationflag.ErrChanged)
	checkCalls(c, stub, "Phase", "Watch", "Phase", "Phase")
}
Example #5
0
func (*WorkerSuite) TestNoRelevantPhaseChange(c *gc.C) {
	stub := &testing.Stub{}
	facade := newMockFacade(stub,
		migration.REAPFAILED,
		migration.DONE,
		migration.ABORT,
		migration.IMPORT,
	)
	config := migrationflag.Config{
		Facade: facade,
		Model:  validUUID,
		Check:  isQuiesce,
	}
	worker, err := migrationflag.New(config)
	c.Assert(err, jc.ErrorIsNil)
	c.Check(worker.Check(), jc.IsFalse)

	workertest.CheckAlive(c, worker)
	workertest.CleanKill(c, worker)
	checkCalls(c, stub, "Phase", "Watch", "Phase", "Phase", "Phase")
}