当前位置: 首页>>代码示例>>Golang>>正文


Golang state.SetBeforeHooks函数代码示例

本文整理汇总了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)
	}
}
开发者ID:claudiu-coblis,项目名称:juju,代码行数:34,代码来源:filesystem_test.go

示例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")
}
开发者ID:makyo,项目名称:juju,代码行数:26,代码来源:model_test.go

示例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)
}
开发者ID:claudiu-coblis,项目名称:juju,代码行数:27,代码来源:filesystem_test.go

示例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"})
}
开发者ID:kat-co,项目名称:juju,代码行数:31,代码来源:upgrade_test.go

示例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")
}
开发者ID:bac,项目名称:juju,代码行数:8,代码来源:machineremovals_test.go

示例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)
}
开发者ID:bac,项目名称:juju,代码行数:12,代码来源:restore_test.go

示例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)
}
开发者ID:imoapps,项目名称:juju,代码行数:9,代码来源:minimumunits_test.go

示例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)
}
开发者ID:bac,项目名称:juju,代码行数:9,代码来源:restore_test.go

示例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)
}
开发者ID:bac,项目名称:juju,代码行数:10,代码来源:restore_test.go

示例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`)
}
开发者ID:imoapps,项目名称:juju,代码行数:11,代码来源:minimumunits_test.go

示例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()
}
开发者ID:Pankov404,项目名称:juju,代码行数:11,代码来源:volume_test.go

示例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()
}
开发者ID:Pankov404,项目名称:juju,代码行数:11,代码来源:volume_test.go

示例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")
}
开发者ID:bac,项目名称:juju,代码行数:11,代码来源:modelmigration_test.go

示例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")
}
开发者ID:bac,项目名称:juju,代码行数:11,代码来源:charm_test.go

示例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()
}
开发者ID:claudiu-coblis,项目名称:juju,代码行数:11,代码来源:filesystem_test.go


注:本文中的github.com/juju/juju/state.SetBeforeHooks函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。