Пример #1
0
func (s *assignCleanSuite) TestAssignUsingConstraintsToMachine(c *C) {
	for i, t := range assignUsingConstraintsTests {
		c.Logf("test %d", i)
		cons := constraints.MustParse(t.unitConstraints)
		err := s.State.SetEnvironConstraints(cons)
		c.Assert(err, IsNil)

		unit, err := s.wordpress.AddUnit()
		c.Assert(err, IsNil)

		m, err := s.State.AddMachine("series", state.JobHostUnits)
		c.Assert(err, IsNil)
		if t.hardwareCharacteristics != "none" {
			hc := instance.MustParseHardware(t.hardwareCharacteristics)
			err = m.SetProvisioned("inst-id", "fake_nonce", &hc)
			c.Assert(err, IsNil)
		}

		um, err := s.assignUnit(unit)
		if t.assignOk {
			c.Assert(err, IsNil)
			c.Assert(um.Id(), Equals, m.Id())
		} else {
			c.Assert(um, IsNil)
			c.Assert(err, ErrorMatches, eligibleMachinesInUse)
			// Destroy the machine so it can't be used for the next test.
			err = m.Destroy()
			c.Assert(err, IsNil)
		}
	}
}
Пример #2
0
// TODO (wallyworld) - this test was copied from the ec2 provider.
// It should be moved to environs.jujutests.Tests.
func (s *localServerSuite) TestBootstrapInstanceUserDataAndState(c *C) {
	err := environs.Bootstrap(s.env, constraints.Value{})
	c.Assert(err, IsNil)

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

	expectedHardware := instance.MustParseHardware("arch=amd64 cpu-cores=1 mem=512M")
	insts, err := s.env.AllInstances()
	c.Assert(err, IsNil)
	c.Assert(insts, HasLen, 1)
	c.Check(insts[0].Id(), Equals, stateData.StateInstances[0])
	c.Check(expectedHardware, DeepEquals, stateData.Characteristics[0])

	info, apiInfo, err := s.env.StateInfo()
	c.Assert(err, IsNil)
	c.Assert(info, NotNil)

	bootstrapDNS, err := insts[0].DNSName()
	c.Assert(err, IsNil)
	c.Assert(bootstrapDNS, Not(Equals), "")

	// 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.

	// check that a new instance will be started with a machine agent,
	// and without a provisioning agent.
	series := s.env.Config().DefaultSeries()
	info.Tag = "machine-1"
	apiInfo.Tag = "machine-1"
	inst1, _, err := s.env.StartInstance("1", "fake_nonce", series, constraints.Value{}, info, apiInfo)
	c.Assert(err, IsNil)

	err = s.env.Destroy(append(insts, inst1))
	c.Assert(err, IsNil)

	_, err = environs.LoadState(s.env.Storage())
	c.Assert(err, NotNil)
}
Пример #3
0
func (t *localServerSuite) TestBootstrapInstanceUserDataAndState(c *C) {
	envtesting.UploadFakeTools(c, t.env.Storage())
	err := environs.Bootstrap(t.env, constraints.Value{})
	c.Assert(err, IsNil)

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

	expectedHardware := instance.MustParseHardware("arch=amd64 cpu-cores=1 cpu-power=100 mem=1740M")
	insts, err := t.env.AllInstances()
	c.Assert(err, IsNil)
	c.Assert(insts, HasLen, 1)
	c.Check(insts[0].Id(), Equals, bootstrapState.StateInstances[0])
	c.Check(expectedHardware, DeepEquals, bootstrapState.Characteristics[0])

	info, apiInfo, err := t.env.StateInfo()
	c.Assert(err, IsNil)
	c.Assert(info, NotNil)

	// check that the user data is configured to start zookeeper
	// and the machine and provisioning agents.
	inst := t.srv.ec2srv.Instance(string(insts[0].Id()))
	c.Assert(inst, NotNil)
	bootstrapDNS, err := insts[0].DNSName()
	c.Assert(err, IsNil)
	c.Assert(bootstrapDNS, Not(Equals), "")

	userData, err := utils.Gunzip(inst.UserData)
	c.Assert(err, IsNil)
	c.Logf("first instance: UserData: %q", userData)
	var x map[interface{}]interface{}
	err = goyaml.Unmarshal(userData, &x)
	c.Assert(err, IsNil)
	CheckPackage(c, x, "git", true)
	CheckScripts(c, x, "jujud bootstrap-state", true)
	// TODO check for provisioning agent
	// TODO check for machine agent

	// check that a new instance will be started without
	// zookeeper, with a machine agent, and without a
	// provisioning agent.
	series := t.env.Config().DefaultSeries()
	info.Tag = "machine-1"
	apiInfo.Tag = "machine-1"
	inst1, hc, err := t.env.StartInstance("1", "fake_nonce", series, constraints.Value{}, info, apiInfo)
	c.Assert(err, IsNil)
	c.Check(*hc.Arch, Equals, "amd64")
	c.Check(*hc.Mem, Equals, uint64(1740))
	c.Check(*hc.CpuCores, Equals, uint64(1))
	c.Assert(*hc.CpuPower, Equals, uint64(100))
	inst = t.srv.ec2srv.Instance(string(inst1.Id()))
	c.Assert(inst, NotNil)
	userData, err = utils.Gunzip(inst.UserData)
	c.Assert(err, IsNil)
	c.Logf("second instance: UserData: %q", userData)
	x = nil
	err = goyaml.Unmarshal(userData, &x)
	c.Assert(err, IsNil)
	CheckPackage(c, x, "zookeeperd", false)
	// TODO check for provisioning agent
	// TODO check for machine agent

	err = t.env.Destroy(append(insts, inst1))
	c.Assert(err, IsNil)

	_, err = environs.LoadState(t.env.Storage())
	c.Assert(err, NotNil)
}