本文整理汇总了Golang中github.com/juju/juju/state.SetBeforeHooks函数的典型用法代码示例。如果您正苦于以下问题:Golang SetBeforeHooks函数的具体用法?Golang SetBeforeHooks怎么用?Golang SetBeforeHooks使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SetBeforeHooks函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: testFilesystemAttachmentParamsConcurrent
func (s *FilesystemStateSuite) testFilesystemAttachmentParamsConcurrent(c *gc.C, locBefore, locAfter, expectErr string) {
machine, err := s.State.AddMachine("quantal", state.JobHostUnits)
c.Assert(err, jc.ErrorIsNil)
storage := map[string]state.StorageConstraints{
"data": makeStorageCons("rootfs", 1024, 1),
}
deploy := func(rev int, location, serviceName string) error {
ch := s.createStorageCharmRev(c, "storage-filesystem", charm.Storage{
Name: "data",
Type: charm.StorageFilesystem,
CountMin: 1,
CountMax: 1,
Location: location,
}, rev)
service := s.AddTestingServiceWithStorage(c, serviceName, ch, storage)
unit, err := service.AddUnit()
c.Assert(err, jc.ErrorIsNil)
return unit.AssignToMachine(machine)
}
defer state.SetBeforeHooks(c, s.State, func() {
err := deploy(1, locBefore, "storage-filesystem-before")
c.Assert(err, jc.ErrorIsNil)
}).Check()
err = deploy(2, locAfter, "storage-filesystem-after")
if expectErr != "" {
c.Assert(err, gc.ErrorMatches, expectErr)
} else {
c.Assert(err, jc.ErrorIsNil)
}
}
示例2: TestDestroyControllerRemoveEmptyAddNonEmptyModel
func (s *ModelSuite) TestDestroyControllerRemoveEmptyAddNonEmptyModel(c *gc.C) {
st2 := s.Factory.MakeModel(c, nil)
defer st2.Close()
// Simulate an empty model being removed, and a new non-empty
// model being added, just before the remove txn is called.
defer state.SetBeforeHooks(c, s.State, func() {
// Destroy the empty model, which should move it right
// along to Dead, and then remove it.
model, err := st2.Model()
c.Assert(err, jc.ErrorIsNil)
c.Assert(model.Destroy(), jc.ErrorIsNil)
err = st2.RemoveAllModelDocs()
c.Assert(err, jc.ErrorIsNil)
// Add a new, non-empty model. This should still prevent
// the controller from being destroyed.
st3 := s.Factory.MakeModel(c, nil)
defer st3.Close()
factory.NewFactory(st3).MakeService(c, nil)
}).Check()
env, err := s.State.Model()
c.Assert(err, jc.ErrorIsNil)
c.Assert(env.Destroy(), gc.ErrorMatches, "failed to destroy model: hosting 1 other models")
}
示例3: TestFilesystemAttachmentParamsConcurrentRemove
func (s *FilesystemStateSuite) TestFilesystemAttachmentParamsConcurrentRemove(c *gc.C) {
// this creates a filesystem mounted at "/srv".
filesystem, machine := s.setupFilesystemAttachment(c, "rootfs")
ch := s.createStorageCharm(c, "storage-filesystem", charm.Storage{
Name: "data",
Type: charm.StorageFilesystem,
CountMin: 1,
CountMax: 1,
Location: "/not/in/srv",
})
service := s.AddTestingService(c, "storage-filesystem", ch)
unit, err := service.AddUnit()
c.Assert(err, jc.ErrorIsNil)
defer state.SetBeforeHooks(c, s.State, func() {
err := s.State.DetachFilesystem(machine.MachineTag(), filesystem.FilesystemTag())
c.Assert(err, jc.ErrorIsNil)
err = s.State.RemoveFilesystemAttachment(
machine.MachineTag(), filesystem.FilesystemTag(),
)
c.Assert(err, jc.ErrorIsNil)
}).Check()
err = unit.AssignToMachine(machine)
c.Assert(err, jc.ErrorIsNil)
}
示例4: TestSetControllerDoneMultipleServersRace
func (s *UpgradeSuite) TestSetControllerDoneMultipleServersRace(c *gc.C) {
v100 := vers("1.0.0")
v200 := vers("2.0.0")
serverIdB, serverIdC := s.addControllers(c)
s.provision(c, serverIdB, serverIdC)
info, err := s.State.EnsureUpgradeInfo(s.serverIdA, v100, v200)
c.Assert(err, jc.ErrorIsNil)
_, err = s.State.EnsureUpgradeInfo(serverIdB, v100, v200)
c.Assert(err, jc.ErrorIsNil)
_, err = s.State.EnsureUpgradeInfo(serverIdC, v100, v200)
c.Assert(err, jc.ErrorIsNil)
s.setToFinishing(c, info)
// Interrupt the transaction for controller A twice with calls
// from the other machines.
defer state.SetBeforeHooks(c, s.State, func() {
err = info.SetControllerDone(serverIdB)
c.Assert(err, jc.ErrorIsNil)
}, func() {
err = info.SetControllerDone(serverIdC)
c.Assert(err, jc.ErrorIsNil)
}).Check()
err = info.SetControllerDone(s.serverIdA)
c.Assert(err, jc.ErrorIsNil)
s.assertUpgrading(c, false)
info = s.getOneUpgradeInfo(c)
c.Assert(info.Status(), gc.Equals, state.UpgradeComplete)
c.Assert(info.ControllersDone(), jc.SameContents, []string{"0", "1", "2"})
}
示例5: TestMarkForRemovalAssertsMachineStillExists
func (s *MachineRemovalSuite) TestMarkForRemovalAssertsMachineStillExists(c *gc.C) {
m := s.makeMachine(c, true)
defer state.SetBeforeHooks(c, s.State, func() {
c.Assert(m.Remove(), gc.IsNil)
}).Check()
err := m.MarkForRemoval()
c.Assert(err, gc.ErrorMatches, "cannot remove machine 0: machine 0 not found")
}
示例6: TestInsertRaceHarmless
//--------------------------------------
// Whitebox race tests to trigger different paths through the SetStatus
// code; use arbitrary sample transitions, full set of valid transitions
// are checked further down.
func (s *RestoreInfoSuite) TestInsertRaceHarmless(c *gc.C) {
defer state.SetBeforeHooks(
c, s.State, func() {
s.checkSetStatus(c, state.RestorePending)
},
).Check()
s.checkSetStatus(c, state.RestorePending)
}
示例7: testEnsureMinUnitsBefore
func (s *MinUnitsSuite) testEnsureMinUnitsBefore(c *gc.C, f func(), minUnits, expectedUnits int) {
service := s.service
err := service.SetMinUnits(minUnits)
c.Assert(err, jc.ErrorIsNil)
defer state.SetBeforeHooks(c, s.State, f).Check()
err = service.EnsureMinUnits()
c.Assert(err, jc.ErrorIsNil)
assertAllUnits(c, service, expectedUnits)
}
示例8: TestUpdateRaceHarmless
func (s *RestoreInfoSuite) TestUpdateRaceHarmless(c *gc.C) {
s.setupInProgress(c)
defer state.SetBeforeHooks(
c, s.State, func() {
s.checkSetStatus(c, state.RestoreFinished)
},
).Check()
s.checkSetStatus(c, state.RestoreFinished)
}
示例9: TestInsertRaceFailure
func (s *RestoreInfoSuite) TestInsertRaceFailure(c *gc.C) {
defer state.SetBeforeHooks(
c, s.State, func() {
s.checkSetStatus(c, state.RestorePending)
s.checkSetStatus(c, state.RestoreInProgress)
},
).Check()
s.checkBadSetStatus(c, state.RestorePending)
s.checkStatus(c, state.RestoreInProgress)
}
示例10: TestEnsureMinUnitsDestroyServiceBefore
func (s *MinUnitsSuite) TestEnsureMinUnitsDestroyServiceBefore(c *gc.C) {
s.addUnits(c, 1)
err := s.service.SetMinUnits(42)
c.Assert(err, jc.ErrorIsNil)
defer state.SetBeforeHooks(c, s.State, func() {
err := s.service.Destroy()
c.Assert(err, jc.ErrorIsNil)
}).Check()
c.Assert(s.service.EnsureMinUnits(), gc.ErrorMatches,
`cannot ensure minimum units for service "dummy-service": service is not alive`)
}
示例11: TestDetachVolume
func (s *VolumeStateSuite) TestDetachVolume(c *gc.C) {
volume, machine := s.setupVolumeAttachment(c)
assertDetach := func() {
err := s.State.DetachVolume(machine.MachineTag(), volume.VolumeTag())
c.Assert(err, jc.ErrorIsNil)
attachment := s.volumeAttachment(c, machine.MachineTag(), volume.VolumeTag())
c.Assert(attachment.Life(), gc.Equals, state.Dying)
}
defer state.SetBeforeHooks(c, s.State, assertDetach).Check()
assertDetach()
}
示例12: TestDestroyVolume
func (s *VolumeStateSuite) TestDestroyVolume(c *gc.C) {
volume, _ := s.setupVolumeAttachment(c)
assertDestroy := func() {
err := s.State.DestroyVolume(volume.VolumeTag())
c.Assert(err, jc.ErrorIsNil)
volume = s.volume(c, volume.VolumeTag())
c.Assert(volume.Life(), gc.Equals, state.Dying)
}
defer state.SetBeforeHooks(c, s.State, assertDestroy).Check()
assertDestroy()
}
示例13: TestCreateMigrationRace
func (s *MigrationSuite) TestCreateMigrationRace(c *gc.C) {
defer state.SetBeforeHooks(c, s.State2, func() {
mig, err := s.State2.CreateMigration(s.stdSpec)
c.Assert(mig, gc.Not(gc.IsNil))
c.Assert(err, jc.ErrorIsNil)
}).Check()
mig, err := s.State2.CreateMigration(s.stdSpec)
c.Check(mig, gc.IsNil)
c.Check(err, gc.ErrorMatches, "failed to create migration: already in progress")
}
示例14: TestDestroyReferencedCharmRace
func (s *CharmSuite) TestDestroyReferencedCharmRace(c *gc.C) {
defer state.SetBeforeHooks(c, s.State, func() {
s.Factory.MakeApplication(c, &factory.ApplicationParams{
Charm: s.charm,
})
}).Check()
err := s.charm.Destroy()
c.Check(err, gc.ErrorMatches, "charm in use")
}
示例15: TestDestroyFilesystem
func (s *FilesystemStateSuite) TestDestroyFilesystem(c *gc.C) {
filesystem, _ := s.setupFilesystemAttachment(c, "rootfs")
assertDestroy := func() {
err := s.State.DestroyFilesystem(filesystem.FilesystemTag())
c.Assert(err, jc.ErrorIsNil)
filesystem = s.filesystem(c, filesystem.FilesystemTag())
c.Assert(filesystem.Life(), gc.Equals, state.Dying)
}
defer state.SetBeforeHooks(c, s.State, assertDestroy).Check()
assertDestroy()
}