Beispiel #1
0
func (suite *StateSuite) TestRemoveStateInstancesPartial(c *gc.C) {
	storage := suite.newStorage(c)
	state := common.BootstrapState{
		StateInstances: []instance.Id{
			instance.Id("a"),
			instance.Id("b"),
			instance.Id("c"),
		},
	}
	err := common.SaveState(storage, &state)
	c.Assert(err, jc.ErrorIsNil)

	err = common.RemoveStateInstances(
		storage,
		state.StateInstances[0],
		instance.Id("not-there"),
		state.StateInstances[2],
	)
	c.Assert(err, jc.ErrorIsNil)

	storedState, err := common.LoadState(storage)
	c.Assert(storedState, gc.DeepEquals, &common.BootstrapState{
		StateInstances: []instance.Id{
			state.StateInstances[1],
		},
	})
}
Beispiel #2
0
func (suite *StateSuite) TestLoadStateReadsStateFile(c *gc.C) {
	storage, dataDir := suite.newStorageWithDataDir(c)
	state := suite.setUpSavedState(c, dataDir)
	storedState, err := common.LoadState(storage)
	c.Assert(err, jc.ErrorIsNil)
	c.Check(*storedState, gc.DeepEquals, state)
}
Beispiel #3
0
// TODO (wallyworld) - this test was copied from the ec2 provider.
// It should be moved to environs.jujutests.Tests.
func (s *localServerSuite) TestBootstrapInstanceUserDataAndState(c *gc.C) {
	env := s.Prepare(c)
	err := bootstrap.Bootstrap(coretesting.Context(c), env, bootstrap.BootstrapParams{})
	c.Assert(err, gc.IsNil)

	// check that the state holds the id of the bootstrap machine.
	stateData, err := common.LoadState(env.Storage())
	c.Assert(err, gc.IsNil)
	c.Assert(stateData.StateInstances, gc.HasLen, 1)

	insts, err := env.AllInstances()
	c.Assert(err, gc.IsNil)
	c.Assert(insts, gc.HasLen, 1)
	c.Check(insts[0].Id(), gc.Equals, stateData.StateInstances[0])

	addresses, err := insts[0].Addresses()
	c.Assert(err, gc.IsNil)
	c.Assert(addresses, gc.Not(gc.HasLen), 0)

	// TODO(wallyworld) - 2013-03-01 bug=1137005
	// The nova test double needs to be updated to support retrieving instance userData.
	// Until then, we can't check the cloud init script was generated correctly.
	// When we can, we should also check cloudinit for a non-manager node (as in the
	// ec2 tests).
}
Beispiel #4
0
func (suite *StateSuite) TestLoadStateIntegratesWithSaveState(c *gc.C) {
	storage := suite.newStorage(c)
	state := common.BootstrapState{
		StateInstances: []instance.Id{instance.Id("an-instance-id")},
	}
	err := common.SaveState(storage, &state)
	c.Assert(err, jc.ErrorIsNil)
	storedState, err := common.LoadState(storage)
	c.Assert(err, jc.ErrorIsNil)

	c.Check(*storedState, gc.DeepEquals, state)
}
Beispiel #5
0
func (suite *StateSuite) TestRemoveStateInstancesNone(c *gc.C) {
	storage := suite.newStorage(c)
	state := common.BootstrapState{
		StateInstances: []instance.Id{instance.Id("an-instance-id")},
	}
	err := common.SaveState(storage, &state)
	c.Assert(err, jc.ErrorIsNil)

	err = common.RemoveStateInstances(
		storage,
		instance.Id("not-there"),
	)
	c.Assert(err, jc.ErrorIsNil)

	storedState, err := common.LoadState(storage)
	c.Assert(storedState, gc.DeepEquals, &state)
}
Beispiel #6
0
func (suite *StateSuite) TestAddStateInstance(c *gc.C) {
	storage := suite.newStorage(c)
	for _, str := range []string{"a", "b", "c"} {
		id := instance.Id(str)
		err := common.AddStateInstance(storage, instance.Id(id))
		c.Assert(err, jc.ErrorIsNil)
	}

	storedState, err := common.LoadState(storage)
	c.Assert(err, jc.ErrorIsNil)
	c.Check(storedState, gc.DeepEquals, &common.BootstrapState{
		StateInstances: []instance.Id{
			instance.Id("a"),
			instance.Id("b"),
			instance.Id("c"),
		},
	})
}
Beispiel #7
0
func (suite *StateSuite) TestLoadStateMissingFile(c *gc.C) {
	stor := suite.newStorage(c)
	_, err := common.LoadState(stor)
	c.Check(err, gc.Equals, environs.ErrNotBootstrapped)
}