func (trivialSuite) TestCompression(c *C) { cdata := trivial.Gzip(data) c.Assert(len(cdata) < len(data), Equals, true) data1, err := trivial.Gunzip(cdata) c.Assert(err, IsNil) c.Assert(data1, DeepEquals, data) data1, err = trivial.Gunzip(compressedData) c.Assert(err, IsNil) c.Assert(data1, DeepEquals, data) }
func (t *localServerSuite) TestBootstrapInstanceUserDataAndState(c *C) { policy := t.env.AssignmentPolicy() c.Assert(policy, Equals, state.AssignUnused) err := environs.Bootstrap(t.env, true, panicWrite) c.Assert(err, IsNil) // check that the state holds the id of the bootstrap machine. state, err := ec2.LoadState(t.env) c.Assert(err, IsNil) c.Assert(state.StateInstances, HasLen, 1) insts, err := t.env.Instances(state.StateInstances) c.Assert(err, IsNil) c.Assert(insts, HasLen, 1) c.Check(insts[0].Id(), Equals, state.StateInstances[0]) info, 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 := trivial.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. info.EntityName = "machine-1" inst1, err := t.env.StartInstance("1", info, nil) c.Assert(err, IsNil) inst = t.srv.ec2srv.Instance(string(inst1.Id())) c.Assert(inst, NotNil) userData, err = trivial.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 p := t.env.Provider() addr, err := p.PublicAddress() c.Assert(err, IsNil) c.Assert(addr, Equals, "public.dummy.address.example.com") addr, err = p.PrivateAddress() c.Assert(err, IsNil) c.Assert(addr, Equals, "private.dummy.address.example.com") err = t.env.Destroy(append(insts, inst1)) c.Assert(err, IsNil) _, err = ec2.LoadState(t.env) c.Assert(err, NotNil) }