本文整理汇总了Golang中github.com/wallyworld/core/juju/testing.AssertStartInstance函数的典型用法代码示例。如果您正苦于以下问题:Golang AssertStartInstance函数的具体用法?Golang AssertStartInstance怎么用?Golang AssertStartInstance使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了AssertStartInstance函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestStopInstances
func (t *LiveTests) TestStopInstances(c *gc.C) {
// It would be nice if this test was in jujutest, but
// there's no way for jujutest to fabricate a valid-looking
// instance id.
inst0, _ := testing.AssertStartInstance(c, t.Env, "40")
inst1 := ec2.FabricateInstance(inst0, "i-aaaaaaaa")
inst2, _ := testing.AssertStartInstance(c, t.Env, "41")
err := t.Env.StopInstances([]instance.Instance{inst0, inst1, inst2})
c.Check(err, gc.IsNil)
var insts []instance.Instance
// We need the retry logic here because we are waiting
// for Instances to return an error, and it will not retry
// if it succeeds.
gone := false
for a := ec2.ShortAttempt.Start(); a.Next(); {
insts, err = t.Env.Instances([]instance.Id{inst0.Id(), inst2.Id()})
if err == environs.ErrPartialInstances {
// instances not gone yet.
continue
}
if err == environs.ErrNoInstances {
gone = true
break
}
c.Fatalf("error getting instances: %v", err)
}
if !gone {
c.Errorf("after termination, instances remaining: %v", insts)
}
}
示例2: setUpInstances
// setUpInstances adds machines to state backed by instances:
// one manager machine, and one non-manager.
func (s *destroyEnvironmentSuite) setUpInstances(c *gc.C) (m0, m1 *state.Machine) {
m0, err := s.State.AddMachine("precise", state.JobManageEnviron)
c.Assert(err, gc.IsNil)
inst, _ := testing.AssertStartInstance(c, s.APIConn.Environ, m0.Id())
err = m0.SetProvisioned(inst.Id(), "fake_nonce", nil)
c.Assert(err, gc.IsNil)
m1, err = s.State.AddMachine("precise", state.JobHostUnits)
c.Assert(err, gc.IsNil)
inst, _ = testing.AssertStartInstance(c, s.APIConn.Environ, m1.Id())
err = m1.SetProvisioned(inst.Id(), "fake_nonce", nil)
c.Assert(err, gc.IsNil)
return m0, m1
}
示例3: TestStartStop
func (t *Tests) TestStartStop(c *gc.C) {
e := t.Prepare(c)
envtesting.UploadFakeTools(c, e.Storage())
cfg, err := e.Config().Apply(map[string]interface{}{
"agent-version": version.Current.Number.String(),
})
c.Assert(err, gc.IsNil)
err = e.SetConfig(cfg)
c.Assert(err, gc.IsNil)
insts, err := e.Instances(nil)
c.Assert(err, gc.IsNil)
c.Assert(insts, gc.HasLen, 0)
inst0, hc := testing.AssertStartInstance(c, e, "0")
c.Assert(inst0, gc.NotNil)
id0 := inst0.Id()
// Sanity check for hardware characteristics.
c.Assert(hc.Arch, gc.NotNil)
c.Assert(hc.Mem, gc.NotNil)
c.Assert(hc.CpuCores, gc.NotNil)
inst1, _ := testing.AssertStartInstance(c, e, "1")
c.Assert(inst1, gc.NotNil)
id1 := inst1.Id()
insts, err = e.Instances([]instance.Id{id0, id1})
c.Assert(err, gc.IsNil)
c.Assert(insts, gc.HasLen, 2)
c.Assert(insts[0].Id(), gc.Equals, id0)
c.Assert(insts[1].Id(), gc.Equals, id1)
// order of results is not specified
insts, err = e.AllInstances()
c.Assert(err, gc.IsNil)
c.Assert(insts, gc.HasLen, 2)
c.Assert(insts[0].Id(), gc.Not(gc.Equals), insts[1].Id())
err = e.StopInstances([]instance.Instance{inst0})
c.Assert(err, gc.IsNil)
insts, err = e.Instances([]instance.Id{id0, id1})
c.Assert(err, gc.Equals, environs.ErrPartialInstances)
c.Assert(insts[0], gc.IsNil)
c.Assert(insts[1].Id(), gc.Equals, id1)
insts, err = e.AllInstances()
c.Assert(err, gc.IsNil)
c.Assert(insts[0].Id(), gc.Equals, id1)
}
示例4: setupScenario
func (s *workerSuite) setupScenario(c *gc.C) ([]*state.Machine, []instance.Instance) {
var machines []*state.Machine
var insts []instance.Instance
for i := 0; i < 10; i++ {
m, err := s.State.AddMachine("series", state.JobHostUnits)
c.Assert(err, gc.IsNil)
machines = append(machines, m)
inst, _ := testing.AssertStartInstance(c, s.Conn.Environ, m.Id())
insts = append(insts, inst)
}
// Associate the odd-numbered machines with an instance.
for i := 1; i < len(machines); i += 2 {
m := machines[i]
err := m.SetProvisioned(insts[i].Id(), "nonce", nil)
c.Assert(err, gc.IsNil)
}
// Associate the first half of the instances with an address and status.
for i := 0; i < len(machines)/2; i++ {
dummy.SetInstanceAddresses(insts[i], s.addressesForIndex(i))
dummy.SetInstanceStatus(insts[i], "running")
}
// Make sure the second half of the instances have no addresses.
for i := len(machines) / 2; i < len(machines); i++ {
dummy.SetInstanceAddresses(insts[i], nil)
}
return machines, insts
}
示例5: TestStartInstanceWithoutPublicIP
// If the environment is configured not to require a public IP address for nodes,
// bootstrapping and starting an instance should occur without any attempt to
// allocate a public address.
func (s *localServerSuite) TestStartInstanceWithoutPublicIP(c *gc.C) {
cleanup := s.srv.Service.Nova.RegisterControlPoint(
"addFloatingIP",
func(sc hook.ServiceControl, args ...interface{}) error {
return fmt.Errorf("add floating IP should not have been called")
},
)
defer cleanup()
cleanup = s.srv.Service.Nova.RegisterControlPoint(
"addServerFloatingIP",
func(sc hook.ServiceControl, args ...interface{}) error {
return fmt.Errorf("add server floating IP should not have been called")
},
)
defer cleanup()
cfg, err := config.New(config.NoDefaults, s.TestConfig.Merge(coretesting.Attrs{
"use-floating-ip": false,
}))
c.Assert(err, gc.IsNil)
env, err := environs.Prepare(cfg, coretesting.Context(c), s.ConfigStore)
c.Assert(err, gc.IsNil)
err = bootstrap.Bootstrap(coretesting.Context(c), env, environs.BootstrapParams{})
c.Assert(err, gc.IsNil)
inst, _ := testing.AssertStartInstance(c, env, "100")
err = env.StopInstances([]instance.Instance{inst})
c.Assert(err, gc.IsNil)
}
示例6: TestAllocateAddress
func (s *suite) TestAllocateAddress(c *gc.C) {
cfg, err := config.New(config.NoDefaults, s.TestConfig)
c.Assert(err, gc.IsNil)
e, err := environs.Prepare(cfg, testing.Context(c), s.ConfigStore)
c.Assert(err, gc.IsNil, gc.Commentf("preparing environ %#v", s.TestConfig))
c.Assert(e, gc.NotNil)
envtesting.UploadFakeTools(c, e.Storage())
err = bootstrap.EnsureNotBootstrapped(e)
c.Assert(err, gc.IsNil)
err = bootstrap.Bootstrap(testing.Context(c), e, environs.BootstrapParams{})
c.Assert(err, gc.IsNil)
inst, _ := jujutesting.AssertStartInstance(c, e, "0")
c.Assert(inst, gc.NotNil)
netId := network.Id("net1")
opc := make(chan dummy.Operation, 200)
dummy.Listen(opc)
expectAddress := instance.NewAddress("0.1.2.1", instance.NetworkCloudLocal)
address, err := e.AllocateAddress(inst.Id(), netId)
c.Assert(err, gc.IsNil)
c.Assert(address, gc.DeepEquals, expectAddress)
assertAllocateAddress(c, e, opc, inst.Id(), netId, expectAddress)
expectAddress = instance.NewAddress("0.1.2.2", instance.NetworkCloudLocal)
address, err = e.AllocateAddress(inst.Id(), netId)
c.Assert(err, gc.IsNil)
c.Assert(address, gc.DeepEquals, expectAddress)
assertAllocateAddress(c, e, opc, inst.Id(), netId, expectAddress)
}
示例7: primeAgent
// primeAgent adds a new Machine to run the given jobs, and sets up the
// machine agent's directory. It returns the new machine, the
// agent's configuration and the tools currently running.
func (s *commonMachineSuite) primeAgent(
c *gc.C, vers version.Binary,
jobs ...state.MachineJob) (m *state.Machine, config agent.ConfigSetterWriter, tools *tools.Tools) {
// Add a machine and ensure it is provisioned.
m, err := s.State.AddMachine("quantal", jobs...)
c.Assert(err, gc.IsNil)
inst, md := jujutesting.AssertStartInstance(c, s.Conn.Environ, m.Id())
c.Assert(m.SetProvisioned(inst.Id(), state.BootstrapNonce, md), gc.IsNil)
// Add an address for the tests in case the maybeInitiateMongoServer
// codepath is exercised.
s.setFakeMachineAddresses(c, m)
// Set up the new machine.
err = m.SetAgentVersion(vers)
c.Assert(err, gc.IsNil)
err = m.SetPassword(initialMachinePassword)
c.Assert(err, gc.IsNil)
tag := names.MachineTag(m.Id())
if m.IsManager() {
err = m.SetMongoPassword(initialMachinePassword)
c.Assert(err, gc.IsNil)
config, tools = s.agentSuite.primeStateAgent(c, tag, initialMachinePassword, vers)
info, ok := config.StateServingInfo()
c.Assert(ok, jc.IsTrue)
err = s.State.SetStateServingInfo(info)
c.Assert(err, gc.IsNil)
} else {
config, tools = s.agentSuite.primeAgent(c, tag, initialMachinePassword, vers)
}
err = config.Write()
c.Assert(err, gc.IsNil)
return m, config, tools
}
示例8: assertStartInstanceDefaultSecurityGroup
func (s *LiveTests) assertStartInstanceDefaultSecurityGroup(c *gc.C, useDefault bool) {
attrs := s.TestConfig.Merge(coretesting.Attrs{
"name": "sample-" + randomName(),
"control-bucket": "juju-test-" + randomName(),
"use-default-secgroup": useDefault,
})
cfg, err := config.New(config.NoDefaults, attrs)
c.Assert(err, gc.IsNil)
// Set up a test environment.
env, err := environs.New(cfg)
c.Assert(err, gc.IsNil)
c.Assert(env, gc.NotNil)
defer env.Destroy()
// Bootstrap and start an instance.
err = bootstrap.Bootstrap(coretesting.Context(c), env, environs.BootstrapParams{})
c.Assert(err, gc.IsNil)
inst, _ := jujutesting.AssertStartInstance(c, env, "100")
// Check whether the instance has the default security group assigned.
novaClient := openstack.GetNovaClient(env)
groups, err := novaClient.GetServerSecurityGroups(string(inst.Id()))
c.Assert(err, gc.IsNil)
defaultGroupFound := false
for _, group := range groups {
if group.Name == "default" {
defaultGroupFound = true
break
}
}
c.Assert(defaultGroupFound, gc.Equals, useDefault)
}
示例9: TestAddresses
func (t *localServerSuite) TestAddresses(c *gc.C) {
env := t.Prepare(c)
envtesting.UploadFakeTools(c, env.Storage())
err := bootstrap.Bootstrap(coretesting.Context(c), env, environs.BootstrapParams{})
c.Assert(err, gc.IsNil)
inst, _ := testing.AssertStartInstance(c, env, "1")
c.Assert(err, gc.IsNil)
addrs, err := inst.Addresses()
c.Assert(err, gc.IsNil)
// Expected values use Address type but really contain a regexp for
// the value rather than a valid ip or hostname.
expected := []instance.Address{{
Value: "*.testing.invalid",
Type: instance.HostName,
NetworkScope: instance.NetworkPublic,
}, {
Value: "*.internal.invalid",
Type: instance.HostName,
NetworkScope: instance.NetworkCloudLocal,
}, {
Value: "8.0.0.*",
Type: instance.Ipv4Address,
NetworkScope: instance.NetworkPublic,
}, {
Value: "127.0.0.*",
Type: instance.Ipv4Address,
NetworkScope: instance.NetworkCloudLocal,
}}
c.Assert(addrs, gc.HasLen, len(expected))
for i, addr := range addrs {
c.Check(addr.Value, gc.Matches, expected[i].Value)
c.Check(addr.Type, gc.Equals, expected[i].Type)
c.Check(addr.NetworkScope, gc.Equals, expected[i].NetworkScope)
}
}
示例10: TestInstanceStatus
func (s *localServerSuite) TestInstanceStatus(c *gc.C) {
env := s.Prepare(c)
// goose's test service always returns ACTIVE state.
inst, _ := testing.AssertStartInstance(c, env, "100")
c.Assert(inst.Status(), gc.Equals, nova.StatusActive)
err := env.StopInstances([]instance.Instance{inst})
c.Assert(err, gc.IsNil)
}
示例11: TestStartInstance
// If the environment is configured not to require a public IP address for nodes,
// bootstrapping and starting an instance should occur without any attempt to
// allocate a public address.
func (s *localServerSuite) TestStartInstance(c *gc.C) {
env := s.Prepare(c)
envtesting.UploadFakeTools(c, env.Storage())
err := bootstrap.Bootstrap(bootstrapContext(c), env, environs.BootstrapParams{})
c.Assert(err, gc.IsNil)
inst, _ := testing.AssertStartInstance(c, env, "100")
err = env.StopInstances([]instance.Instance{inst})
c.Assert(err, gc.IsNil)
}
示例12: TestStartInstanceHardwareCharacteristics
func (t *localServerSuite) TestStartInstanceHardwareCharacteristics(c *gc.C) {
env := t.Prepare(c)
envtesting.UploadFakeTools(c, env.Storage())
err := bootstrap.Bootstrap(coretesting.Context(c), env, environs.BootstrapParams{})
c.Assert(err, gc.IsNil)
_, hc := testing.AssertStartInstance(c, env, "1")
c.Check(*hc.Arch, gc.Equals, "amd64")
c.Check(*hc.Mem, gc.Equals, uint64(1740))
c.Check(*hc.CpuCores, gc.Equals, uint64(1))
c.Assert(*hc.CpuPower, gc.Equals, uint64(100))
}
示例13: TestStartInstanceNetwork
func (s *localServerSuite) TestStartInstanceNetwork(c *gc.C) {
cfg, err := config.New(config.NoDefaults, s.TestConfig.Merge(coretesting.Attrs{
// A label that corresponds to a nova test service network
"network": "net",
}))
c.Assert(err, gc.IsNil)
env, err := environs.New(cfg)
c.Assert(err, gc.IsNil)
inst, _ := testing.AssertStartInstance(c, env, "100")
err = env.StopInstances([]instance.Instance{inst})
c.Assert(err, gc.IsNil)
}
示例14: TestStartStop
// TestStartStop is similar to Tests.TestStartStop except
// that it does not assume a pristine environment.
func (t *LiveTests) TestStartStop(c *gc.C) {
t.PrepareOnce(c)
envtesting.UploadFakeTools(c, t.Env.Storage())
inst, _ := testing.AssertStartInstance(c, t.Env, "0")
c.Assert(inst, gc.NotNil)
id0 := inst.Id()
insts, err := t.Env.Instances([]instance.Id{id0, id0})
c.Assert(err, gc.IsNil)
c.Assert(insts, gc.HasLen, 2)
c.Assert(insts[0].Id(), gc.Equals, id0)
c.Assert(insts[1].Id(), gc.Equals, id0)
// Asserting on the return of AllInstances makes the test fragile,
// as even comparing the before and after start values can be thrown
// off if other instances have been created or destroyed in the same
// time frame. Instead, just check the instance we created exists.
insts, err = t.Env.AllInstances()
c.Assert(err, gc.IsNil)
found := false
for _, inst := range insts {
if inst.Id() == id0 {
c.Assert(found, gc.Equals, false, gc.Commentf("%v", insts))
found = true
}
}
c.Assert(found, gc.Equals, true, gc.Commentf("expected %v in %v", inst, insts))
dns, err := inst.WaitDNSName()
c.Assert(err, gc.IsNil)
c.Assert(dns, gc.Not(gc.Equals), "")
insts, err = t.Env.Instances([]instance.Id{id0, ""})
c.Assert(err, gc.Equals, environs.ErrPartialInstances)
c.Assert(insts, gc.HasLen, 2)
c.Check(insts[0].Id(), gc.Equals, id0)
c.Check(insts[1], gc.IsNil)
err = t.Env.StopInstances([]instance.Instance{inst})
c.Assert(err, gc.IsNil)
// The machine may not be marked as shutting down
// immediately. Repeat a few times to ensure we get the error.
for a := t.Attempt.Start(); a.Next(); {
insts, err = t.Env.Instances([]instance.Id{id0})
if err != nil {
break
}
}
c.Assert(err, gc.Equals, environs.ErrNoInstances)
c.Assert(insts, gc.HasLen, 0)
}
示例15: TestInstancesGathering
func (s *localServerSuite) TestInstancesGathering(c *gc.C) {
env := s.Prepare(c)
envtesting.UploadFakeTools(c, env.Storage())
inst0, _ := testing.AssertStartInstance(c, env, "100")
id0 := inst0.Id()
inst1, _ := testing.AssertStartInstance(c, env, "101")
id1 := inst1.Id()
c.Logf("id0: %s, id1: %s", id0, id1)
defer func() {
err := env.StopInstances([]instance.Instance{inst0, inst1})
c.Assert(err, gc.IsNil)
}()
for i, test := range instanceGathering {
c.Logf("test %d: find %v -> expect len %d, err: %v", i, test.ids, len(test.ids), test.err)
ids := make([]instance.Id, len(test.ids))
for j, id := range test.ids {
switch id {
case "id0":
ids[j] = id0
case "id1":
ids[j] = id1
}
}
insts, err := env.Instances(ids)
c.Assert(err, gc.Equals, test.err)
if err == environs.ErrNoInstances {
c.Assert(insts, gc.HasLen, 0)
} else {
c.Assert(insts, gc.HasLen, len(test.ids))
}
for j, inst := range insts {
if ids[j] != "" {
c.Assert(inst.Id(), gc.Equals, ids[j])
} else {
c.Assert(inst, gc.IsNil)
}
}
}
}