本文整理汇总了Golang中github.com/juju/juju/provider/dummy.Listen函数的典型用法代码示例。如果您正苦于以下问题:Golang Listen函数的具体用法?Golang Listen怎么用?Golang Listen使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Listen函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: RunCommand
// RunCommand runs the command and returns channels holding the
// command's operations and errors.
func RunCommand(ctx *cmd.Context, com cmd.Command, args ...string) (opc chan dummy.Operation, errc chan error) {
if ctx == nil {
panic("ctx == nil")
}
errc = make(chan error, 1)
opc = make(chan dummy.Operation, 200)
dummy.Listen(opc)
go func() {
defer func() {
// signal that we're done with this ops channel.
dummy.Listen(nil)
// now that dummy is no longer going to send ops on
// this channel, close it to signal to test cases
// that we are done.
close(opc)
}()
if err := coretesting.InitCommand(com, args); err != nil {
errc <- err
return
}
errc <- com.Run(ctx)
}()
return
}
示例2: TestAllocateAddress
func (s *suite) TestAllocateAddress(c *gc.C) {
e := s.bootstrapTestEnviron(c, false)
defer func() {
err := e.Destroy()
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 := network.NewAddress("0.1.2.1", network.ScopeCloudLocal)
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 = network.NewAddress("0.1.2.2", network.ScopeCloudLocal)
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)
}
示例3: TestSystemKillCallsEnvironDestroyOnHostedEnviron
func (s *cmdControllerSuite) TestSystemKillCallsEnvironDestroyOnHostedEnviron(c *gc.C) {
st := s.Factory.MakeEnvironment(c, &factory.EnvParams{
Name: "foo",
})
defer st.Close()
st.SwitchBlockOn(state.DestroyBlock, "TestBlockDestroyEnvironment")
st.Close()
opc := make(chan dummy.Operation, 200)
dummy.Listen(opc)
conn, err := juju.NewAPIState(s.AdminUserTag(c), s.Environ, api.DialOpts{})
c.Assert(err, jc.ErrorIsNil)
s.AddCleanup(func(*gc.C) { conn.Close() })
client := undertakerapi.NewClient(conn)
startTime := time.Date(2015, time.September, 1, 17, 2, 1, 0, time.UTC)
mClock := testing.NewClock(startTime)
undertaker.NewUndertaker(client, mClock)
store, err := configstore.Default()
_, err = store.ReadInfo("dummyenv")
c.Assert(err, jc.ErrorIsNil)
s.run(c, "kill-controller", "dummyenv", "-y")
// Ensure that Destroy was called on the hosted environment ...
opRecvTimeout(c, st, opc, dummy.OpDestroy{})
// ... and that the configstore was removed.
_, err = store.ReadInfo("dummyenv")
c.Assert(err, jc.Satisfies, errors.IsNotFound)
}
示例4: TestManageModel
func (s *MachineSuite) TestManageModel(c *gc.C) {
usefulVersion := version.Binary{
Number: jujuversion.Current,
Arch: arch.HostArch(),
Series: "quantal", // to match the charm created below
}
envtesting.AssertUploadFakeToolsVersions(c, s.DefaultToolsStorage, s.Environ.Config().AgentStream(), s.Environ.Config().AgentStream(), usefulVersion)
m, _, _ := s.primeAgent(c, state.JobManageModel)
op := make(chan dummy.Operation, 200)
dummy.Listen(op)
a := s.newAgent(c, m)
// Make sure the agent is stopped even if the test fails.
defer a.Stop()
done := make(chan error)
go func() {
done <- a.Run(nil)
}()
c.Logf("started test agent, waiting for workers...")
r0 := s.singularRecord.nextRunner(c)
r0.waitForWorker(c, "txnpruner")
// Check that the provisioner and firewaller are alive by doing
// a rudimentary check that it responds to state changes.
// Create an exposed service, and add a unit.
charm := s.AddTestingCharm(c, "dummy")
svc := s.AddTestingService(c, "test-service", charm)
err := svc.SetExposed()
c.Assert(err, jc.ErrorIsNil)
units, err := juju.AddUnits(s.State, svc, svc.Name(), 1, nil)
c.Assert(err, jc.ErrorIsNil)
// It should be allocated to a machine, which should then be provisioned.
c.Logf("service %q added with 1 unit, waiting for unit %q's machine to be started...", svc.Name(), units[0].Name())
c.Check(opRecvTimeout(c, s.State, op, dummy.OpStartInstance{}), gc.NotNil)
c.Logf("machine hosting unit %q started, waiting for the unit to be deployed...", units[0].Name())
s.waitProvisioned(c, units[0])
// Open a port on the unit; it should be handled by the firewaller.
c.Logf("unit %q deployed, opening port tcp/999...", units[0].Name())
err = units[0].OpenPort("tcp", 999)
c.Assert(err, jc.ErrorIsNil)
c.Check(opRecvTimeout(c, s.State, op, dummy.OpOpenPorts{}), gc.NotNil)
c.Logf("unit %q port tcp/999 opened, cleaning up...", units[0].Name())
err = a.Stop()
c.Assert(err, jc.ErrorIsNil)
select {
case err := <-done:
c.Assert(err, jc.ErrorIsNil)
case <-time.After(coretesting.LongWait):
c.Fatalf("timed out waiting for agent to terminate")
}
c.Logf("test agent stopped successfully.")
}
示例5: TestManageEnviron
func (s *MachineSuite) TestManageEnviron(c *gc.C) {
usefulVersion := version.Current
usefulVersion.Series = "quantal" // to match the charm created below
envtesting.AssertUploadFakeToolsVersions(c, s.Environ.Storage(), usefulVersion)
m, _, _ := s.primeAgent(c, version.Current, state.JobManageEnviron)
op := make(chan dummy.Operation, 200)
dummy.Listen(op)
a := s.newAgent(c, m)
// Make sure the agent is stopped even if the test fails.
defer a.Stop()
done := make(chan error)
go func() {
done <- a.Run(nil)
}()
// Check that the provisioner and firewaller are alive by doing
// a rudimentary check that it responds to state changes.
// Add one unit to a service; it should get allocated a machine
// and then its ports should be opened.
charm := s.AddTestingCharm(c, "dummy")
svc := s.AddTestingService(c, "test-service", charm)
err := svc.SetExposed()
c.Assert(err, gc.IsNil)
units, err := juju.AddUnits(s.State, svc, 1, "")
c.Assert(err, gc.IsNil)
c.Check(opRecvTimeout(c, s.State, op, dummy.OpStartInstance{}), gc.NotNil)
// Wait for the instance id to show up in the state.
s.waitProvisioned(c, units[0])
err = units[0].OpenPort("tcp", 999)
c.Assert(err, gc.IsNil)
c.Check(opRecvTimeout(c, s.State, op, dummy.OpOpenPorts{}), gc.NotNil)
err = a.Stop()
c.Assert(err, gc.IsNil)
select {
case err := <-done:
c.Assert(err, gc.IsNil)
case <-time.After(5 * time.Second):
c.Fatalf("timed out waiting for agent to terminate")
}
c.Assert(s.singularRecord.started(), jc.DeepEquals, []string{
"charm-revision-updater",
"cleaner",
"environ-provisioner",
"firewaller",
"minunitsworker",
"resumer",
})
}
示例6: SetUpTest
func (s *CommonProvisionerSuite) SetUpTest(c *gc.C) {
// Disable the default state policy, because the
// provisioner needs to be able to test pathological
// scenarios where a machine exists in state with
// invalid environment config.
dummy.SetStatePolicy(nil)
s.JujuConnSuite.SetUpTest(c)
// Create the operations channel with more than enough space
// for those tests that don't listen on it.
op := make(chan dummy.Operation, 500)
dummy.Listen(op)
s.op = op
cfg, err := s.State.EnvironConfig()
c.Assert(err, jc.ErrorIsNil)
s.cfg = cfg
// Create a machine for the dummy bootstrap instance,
// so the provisioner doesn't destroy it.
insts, err := s.Environ.Instances([]instance.Id{dummy.BootstrapInstanceId})
c.Assert(err, jc.ErrorIsNil)
addrs, err := insts[0].Addresses()
c.Assert(err, jc.ErrorIsNil)
machine, err := s.State.AddOneMachine(state.MachineTemplate{
Addresses: addrs,
Series: "quantal",
Nonce: agent.BootstrapNonce,
InstanceId: dummy.BootstrapInstanceId,
Jobs: []state.MachineJob{state.JobManageEnviron},
})
c.Assert(err, jc.ErrorIsNil)
c.Assert(machine.Id(), gc.Equals, "0")
current := version.Binary{
Number: version.Current,
Arch: arch.HostArch(),
Series: series.HostSeries(),
}
err = machine.SetAgentVersion(current)
c.Assert(err, jc.ErrorIsNil)
password, err := utils.RandomPassword()
c.Assert(err, jc.ErrorIsNil)
err = machine.SetPassword(password)
c.Assert(err, jc.ErrorIsNil)
s.st = s.OpenAPIAsMachine(c, machine.Tag(), password, agent.BootstrapNonce)
c.Assert(s.st, gc.NotNil)
c.Logf("API: login as %q successful", machine.Tag())
s.provisioner = s.st.Provisioner()
c.Assert(s.provisioner, gc.NotNil)
}
示例7: runCommand
func runCommand(ctx *cmd.Context, com cmd.Command, args ...string) (opc chan dummy.Operation, errc chan error) {
if ctx == nil {
panic("ctx == nil")
}
errc = make(chan error, 1)
opc = make(chan dummy.Operation, 200)
dummy.Listen(opc)
go func() {
// signal that we're done with this ops channel.
defer dummy.Listen(nil)
err := coretesting.InitCommand(com, args)
if err != nil {
errc <- err
return
}
err = com.Run(ctx)
errc <- err
}()
return
}
示例8: SetUpTest
func (s *workerSuite) SetUpTest(c *gc.C) {
s.JujuConnSuite.SetUpTest(c)
// Unbreak dummy provider methods.
s.AssertConfigParameterUpdated(c, "broken", "")
s.APIConnection, _ = s.OpenAPIAsNewMachine(c, state.JobManageModel)
s.API = s.APIConnection.DiscoverSpaces()
s.OpsChan = make(chan dummy.Operation, 10)
dummy.Listen(s.OpsChan)
s.spacesDiscovered = nil
}
示例9: TestListNetworks
func (s *suite) TestListNetworks(c *gc.C) {
e := s.bootstrapTestEnviron(c)
opc := make(chan dummy.Operation, 200)
dummy.Listen(opc)
expectInfo := []network.BasicInfo{
{CIDR: "0.10.0.0/8", ProviderId: "dummy-private"},
{CIDR: "0.20.0.0/24", ProviderId: "dummy-public"},
}
netInfo, err := e.ListNetworks()
c.Assert(err, gc.IsNil)
c.Assert(netInfo, jc.DeepEquals, expectInfo)
assertListNetworks(c, e, opc, expectInfo)
}
示例10: TestDestroyEnvironmentWithContainers
func (s *destroyEnvironmentSuite) TestDestroyEnvironmentWithContainers(c *gc.C) {
ops := make(chan dummy.Operation, 500)
dummy.Listen(ops)
_, nonManager, _ := s.setUpInstances(c)
nonManagerId, _ := nonManager.InstanceId()
err := s.APIState.Client().DestroyEnvironment()
c.Assert(err, gc.IsNil)
for op := range ops {
if op, ok := op.(dummy.OpStopInstances); ok {
c.Assert(op.Ids, jc.SameContents, []instance.Id{nonManagerId})
break
}
}
}
示例11: TestSubnets
func (s *suite) TestSubnets(c *gc.C) {
e := s.bootstrapTestEnviron(c)
defer func() {
err := e.Destroy()
c.Assert(err, jc.ErrorIsNil)
}()
opc := make(chan dummy.Operation, 200)
dummy.Listen(opc)
expectInfo := []network.SubnetInfo{{
CIDR: "0.10.0.0/24",
ProviderId: "dummy-private",
AvailabilityZones: []string{"zone1", "zone2"},
}, {
CIDR: "0.20.0.0/24",
ProviderId: "dummy-public",
}}
ids := []network.Id{"dummy-private", "dummy-public", "foo-bar"}
netInfo, err := e.Subnets("i-foo", ids)
c.Assert(err, jc.ErrorIsNil)
c.Assert(netInfo, jc.DeepEquals, expectInfo)
assertSubnets(c, e, opc, "i-foo", ids, expectInfo)
// Test filtering by id(s).
netInfo, err = e.Subnets("i-foo", nil)
c.Assert(err, jc.ErrorIsNil)
c.Assert(netInfo, jc.DeepEquals, expectInfo)
assertSubnets(c, e, opc, "i-foo", nil, expectInfo)
netInfo, err = e.Subnets("i-foo", ids[0:1])
c.Assert(err, jc.ErrorIsNil)
c.Assert(netInfo, jc.DeepEquals, expectInfo[0:1])
assertSubnets(c, e, opc, "i-foo", ids[0:1], expectInfo[0:1])
netInfo, err = e.Subnets("i-foo", ids[1:])
c.Assert(err, jc.ErrorIsNil)
c.Assert(netInfo, jc.DeepEquals, expectInfo[1:])
assertSubnets(c, e, opc, "i-foo", ids[1:], expectInfo[1:])
// Test we can induce errors.
s.breakMethods(c, e, "Subnets")
netInfo, err = e.Subnets("i-any", nil)
c.Assert(err, gc.ErrorMatches, `dummy\.Subnets is broken`)
c.Assert(netInfo, gc.HasLen, 0)
}
示例12: TestDestroyEnvironmentWithContainers
func (s *destroyEnvironmentSuite) TestDestroyEnvironmentWithContainers(c *gc.C) {
ops := make(chan dummy.Operation, 500)
dummy.Listen(ops)
_, nonManager, _ := s.setUpInstances(c)
nonManagerId, _ := nonManager.InstanceId()
err := common.DestroyEnvironment(s.State, s.State.EnvironTag())
c.Assert(err, jc.ErrorIsNil)
for op := range ops {
if op, ok := op.(dummy.OpStopInstances); ok {
c.Assert(op.Ids, jc.SameContents, []instance.Id{nonManagerId})
break
}
}
s.metricSender.CheckCalls(c, []jtesting.StubCall{{FuncName: "SendMetrics"}})
}
示例13: SetUpTest
func (s *CommonProvisionerSuite) SetUpTest(c *gc.C) {
// Disable the default state policy, because the
// provisioner needs to be able to test pathological
// scenarios where a machine exists in state with
// invalid environment config.
dummy.SetStatePolicy(nil)
s.JujuConnSuite.SetUpTest(c)
// Create the operations channel with more than enough space
// for those tests that don't listen on it.
op := make(chan dummy.Operation, 500)
dummy.Listen(op)
s.op = op
cfg, err := s.State.EnvironConfig()
c.Assert(err, gc.IsNil)
s.cfg = cfg
}
示例14: TestReleaseAddress
func (s *suite) TestReleaseAddress(c *gc.C) {
e := s.bootstrapTestEnviron(c, false)
defer func() {
err := e.Destroy()
c.Assert(err, jc.ErrorIsNil)
}()
inst, _ := jujutesting.AssertStartInstance(c, e, "0")
c.Assert(inst, gc.NotNil)
subnetId := network.Id("net1")
opc := make(chan dummy.Operation, 200)
dummy.Listen(opc)
// Release a couple of addresses.
address := network.NewScopedAddress("0.1.2.1", network.ScopeCloudLocal)
macAddress := "foobar"
hostname := "myhostname"
err := e.ReleaseAddress(inst.Id(), subnetId, address, macAddress, hostname)
c.Assert(err, jc.ErrorIsNil)
assertReleaseAddress(c, e, opc, inst.Id(), subnetId, address, macAddress, hostname)
address = network.NewScopedAddress("0.1.2.2", network.ScopeCloudLocal)
err = e.ReleaseAddress(inst.Id(), subnetId, address, macAddress, hostname)
c.Assert(err, jc.ErrorIsNil)
assertReleaseAddress(c, e, opc, inst.Id(), subnetId, address, macAddress, hostname)
// Test we can induce errors.
s.breakMethods(c, e, "ReleaseAddress")
address = network.NewScopedAddress("0.1.2.3", network.ScopeCloudLocal)
err = e.ReleaseAddress(inst.Id(), subnetId, address, macAddress, hostname)
c.Assert(err, gc.ErrorMatches, `dummy\.ReleaseAddress is broken`)
// Finally, test the method respects the feature flag when
// disabled.
s.SetFeatureFlags() // clear the flags.
err = e.ReleaseAddress(inst.Id(), subnetId, address, macAddress, hostname)
c.Assert(err, gc.ErrorMatches, "address allocation not supported")
c.Assert(err, jc.Satisfies, errors.IsNotSupported)
}
示例15: SetUpTest
func (s *workerSuite) SetUpTest(c *gc.C) {
s.JujuConnSuite.SetUpTest(c)
if s.Enabled {
s.SetFeatureFlags(feature.AddressAllocation)
}
// Unbreak dummy provider methods.
s.AssertConfigParameterUpdated(c, "broken", "")
s.APIConnection, _ = s.OpenAPIAsNewMachine(c, state.JobManageModel)
s.API = s.APIConnection.Addresser()
machineA, err := s.State.AddMachine("quantal", state.JobHostUnits)
s.MachineA = machineA
c.Assert(err, jc.ErrorIsNil)
err = s.MachineA.SetProvisioned("foo", "fake_nonce", nil)
c.Assert(err, jc.ErrorIsNil)
// This machine will be destroyed after address creation to test the
// handling of addresses for machines that have gone.
machineB, err := s.State.AddMachine("quantal", state.JobHostUnits)
s.MachineB = machineB
c.Assert(err, jc.ErrorIsNil)
s.createAddresses(c)
s.State.StartSync()
s.OpsChan = make(chan dummy.Operation, 10)
dummy.Listen(s.OpsChan)
// Start the Addresser worker.
w, err := addresser.NewWorker(s.API)
c.Assert(err, jc.ErrorIsNil)
s.Worker = w
s.waitForInitialDead(c)
}