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


Golang constraints.MustParse函数代码示例

本文整理汇总了Golang中launchpad/net/juju-core/constraints.MustParse函数的典型用法代码示例。如果您正苦于以下问题:Golang MustParse函数的具体用法?Golang MustParse怎么用?Golang MustParse使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了MustParse函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestDeployForceMachineIdWithContainer

func (s *DeployLocalSuite) TestDeployForceMachineIdWithContainer(c *C) {
	machine, err := s.State.AddMachine("series", state.JobHostUnits)
	c.Assert(err, IsNil)
	c.Assert(machine.Id(), Equals, "0")
	cons := constraints.MustParse("mem=2G")
	err = s.State.SetEnvironConstraints(cons)
	c.Assert(err, IsNil)
	serviceCons := constraints.MustParse("cpu-cores=2")
	service, err := s.Conn.DeployService(juju.DeployServiceParams{
		ServiceName:   "bob",
		Charm:         s.charm,
		Constraints:   serviceCons,
		NumUnits:      1,
		ToMachineSpec: fmt.Sprintf("%s:0", instance.LXC),
	})
	c.Assert(err, IsNil)
	s.assertConstraints(c, service, serviceCons)
	units, err := service.AllUnits()
	c.Assert(err, IsNil)
	c.Assert(units, HasLen, 1)

	// The newly created container will use the constraints.
	id, err := units[0].AssignedMachineId()
	c.Assert(err, IsNil)
	machine, err = s.State.Machine(id)
	c.Assert(err, IsNil)
	expectedCons, err := machine.Constraints()
	c.Assert(err, IsNil)
	c.Assert(cons, DeepEquals, expectedCons)
}
开发者ID:rif,项目名称:golang-stuff,代码行数:30,代码来源:conn_test.go

示例2: TestAssignUnitToNewMachineSetsConstraints

func (s *AssignSuite) TestAssignUnitToNewMachineSetsConstraints(c *C) {
	// Set up constraints.
	scons := constraints.MustParse("mem=2G cpu-power=400")
	err := s.wordpress.SetConstraints(scons)
	c.Assert(err, IsNil)
	econs := constraints.MustParse("mem=4G cpu-cores=2")
	err = s.State.SetEnvironConstraints(econs)
	c.Assert(err, IsNil)

	// Unit will take combined service/environ constraints on creation.
	unit, err := s.wordpress.AddUnit()
	c.Assert(err, IsNil)

	// Change service/env constraints before assigning, to verify this.
	scons = constraints.MustParse("mem=6G cpu-power=800")
	err = s.wordpress.SetConstraints(scons)
	c.Assert(err, IsNil)
	econs = constraints.MustParse("cpu-cores=4")
	err = s.State.SetEnvironConstraints(econs)
	c.Assert(err, IsNil)

	// The new machine takes the original combined unit constraints.
	err = unit.AssignToNewMachine()
	c.Assert(err, IsNil)
	err = unit.Refresh()
	c.Assert(err, IsNil)
	mid, err := unit.AssignedMachineId()
	c.Assert(err, IsNil)
	machine, err := s.State.Machine(mid)
	c.Assert(err, IsNil)
	mcons, err := machine.Constraints()
	c.Assert(err, IsNil)
	expect := constraints.MustParse("mem=2G cpu-cores=2 cpu-power=400")
	c.Assert(mcons, DeepEquals, expect)
}
开发者ID:rif,项目名称:golang-stuff,代码行数:35,代码来源:assign_test.go

示例3: TestConstraintsFromEnvironment

func (s *MachineSuite) TestConstraintsFromEnvironment(c *C) {
	econs1 := constraints.MustParse("mem=1G")
	econs2 := constraints.MustParse("mem=2G")

	// A newly-created machine gets a copy of the environment constraints.
	err := s.State.SetEnvironConstraints(econs1)
	c.Assert(err, IsNil)
	machine1, err := s.State.AddMachine("series", state.JobHostUnits)
	c.Assert(err, IsNil)
	mcons1, err := machine1.Constraints()
	c.Assert(err, IsNil)
	c.Assert(mcons1, DeepEquals, econs1)

	// Change environment constraints and add a new machine.
	err = s.State.SetEnvironConstraints(econs2)
	c.Assert(err, IsNil)
	machine2, err := s.State.AddMachine("series", state.JobHostUnits)
	c.Assert(err, IsNil)
	mcons2, err := machine2.Constraints()
	c.Assert(err, IsNil)
	c.Assert(mcons2, DeepEquals, econs2)

	// Check the original machine has its original constraints.
	mcons1, err = machine1.Constraints()
	c.Assert(err, IsNil)
	c.Assert(mcons1, DeepEquals, econs1)
}
开发者ID:rif,项目名称:golang-stuff,代码行数:27,代码来源:machine_test.go

示例4: TestWithFallbacks

func (s *ConstraintsSuite) TestWithFallbacks(c *C) {
	for i, t := range withFallbacksTests {
		c.Logf("test %d", i)
		initial := constraints.MustParse(t.initial)
		fallbacks := constraints.MustParse(t.fallbacks)
		final := constraints.MustParse(t.final)
		c.Assert(initial.WithFallbacks(fallbacks), DeepEquals, final)
	}
}
开发者ID:rif,项目名称:golang-stuff,代码行数:9,代码来源:constraints_test.go

示例5: TestDeployConstraints

func (s *DeployLocalSuite) TestDeployConstraints(c *C) {
	err := s.State.SetEnvironConstraints(constraints.MustParse("mem=2G"))
	c.Assert(err, IsNil)
	serviceCons := constraints.MustParse("cpu-cores=2")
	service, err := s.Conn.DeployService(juju.DeployServiceParams{
		ServiceName: "bob",
		Charm:       s.charm,
		Constraints: serviceCons,
	})
	c.Assert(err, IsNil)
	s.assertConstraints(c, service, serviceCons)
}
开发者ID:rif,项目名称:golang-stuff,代码行数:12,代码来源:conn_test.go

示例6: TestAssignUnitToNewMachineContainerConstraint

func (s *AssignSuite) TestAssignUnitToNewMachineContainerConstraint(c *C) {
	// Set up service constraints.
	scons := constraints.MustParse("container=lxc")
	err := s.wordpress.SetConstraints(scons)
	c.Assert(err, IsNil)
	s.assertAssignUnitToNewMachineContainerConstraint(c)
}
开发者ID:rif,项目名称:golang-stuff,代码行数:7,代码来源:assign_test.go

示例7: TestHasContainer

func (s *ConstraintsSuite) TestHasContainer(c *C) {
	for i, t := range hasContainerTests {
		c.Logf("test %d", i)
		cons := constraints.MustParse(t.constraints)
		c.Assert(cons.HasContainer(), Equals, t.hasContainer)
	}
}
开发者ID:rif,项目名称:golang-stuff,代码行数:7,代码来源:constraints_test.go

示例8: TestClientServiceDeployPrincipal

func (s *clientSuite) TestClientServiceDeployPrincipal(c *C) {
	// TODO(fwereade): test ToMachineSpec directly on srvClient, when we
	// manage to extract it as a package and can thus do it conveniently.
	store, restore := makeMockCharmStore()
	defer restore()
	curl, bundle := addCharm(c, store, "dummy")
	mem4g := constraints.MustParse("mem=4G")
	err := s.APIState.Client().ServiceDeploy(
		curl.String(), "service", 3, "", mem4g,
	)
	c.Assert(err, IsNil)
	service, err := s.State.Service("service")
	c.Assert(err, IsNil)
	charm, force, err := service.Charm()
	c.Assert(err, IsNil)
	c.Assert(force, Equals, false)
	c.Assert(charm.URL(), DeepEquals, curl)
	c.Assert(charm.Meta(), DeepEquals, bundle.Meta())
	c.Assert(charm.Config(), DeepEquals, bundle.Config())

	cons, err := service.Constraints()
	c.Assert(err, IsNil)
	c.Assert(cons, DeepEquals, mem4g)
	units, err := service.AllUnits()
	c.Assert(err, IsNil)
	for _, unit := range units {
		mid, err := unit.AssignedMachineId()
		c.Assert(err, IsNil)
		machine, err := s.State.Machine(mid)
		c.Assert(err, IsNil)
		cons, err := machine.Constraints()
		c.Assert(err, IsNil)
		c.Assert(cons, DeepEquals, mem4g)
	}
}
开发者ID:hivetech,项目名称:judo.legacy,代码行数:35,代码来源:client_test.go

示例9: TestFindInstanceTools

func (s *ToolsSuite) TestFindInstanceTools(c *C) {
	for i, test := range findInstanceToolsTests {
		c.Logf("\ntest %d: %s", i, test.info)
		s.Reset(c, map[string]interface{}{
			"agent-version": test.agentVersion.String(),
		})
		available := s.uploadPrivate(c, test.available...)
		if len(available) > 0 {
			// These should never be chosen.
			s.uploadPublic(c, vAll...)
		}

		cons := constraints.MustParse(test.constraints)
		actual, err := environs.FindInstanceTools(s.env, test.series, cons)
		if test.err != nil {
			if len(actual) > 0 {
				c.Logf(actual.String())
			}
			c.Check(err, DeepEquals, &errors.NotFoundError{test.err, ""})
			continue
		}
		expect := map[version.Binary]string{}
		for _, expected := range test.expect {
			expect[expected] = available[expected]
		}
		c.Check(actual.URLs(), DeepEquals, expect)
	}
}
开发者ID:johnvilsack,项目名称:golang-stuff,代码行数:28,代码来源:tools_test.go

示例10: TestAssignUsingConstraintsToMachine

func (s *assignCleanSuite) TestAssignUsingConstraintsToMachine(c *C) {
	for i, t := range assignUsingConstraintsTests {
		c.Logf("test %d", i)
		cons := constraints.MustParse(t.unitConstraints)
		err := s.State.SetEnvironConstraints(cons)
		c.Assert(err, IsNil)

		unit, err := s.wordpress.AddUnit()
		c.Assert(err, IsNil)

		m, err := s.State.AddMachine("series", state.JobHostUnits)
		c.Assert(err, IsNil)
		if t.hardwareCharacteristics != "none" {
			hc := instance.MustParseHardware(t.hardwareCharacteristics)
			err = m.SetProvisioned("inst-id", "fake_nonce", &hc)
			c.Assert(err, IsNil)
		}

		um, err := s.assignUnit(unit)
		if t.assignOk {
			c.Assert(err, IsNil)
			c.Assert(um.Id(), Equals, m.Id())
		} else {
			c.Assert(um, IsNil)
			c.Assert(err, ErrorMatches, eligibleMachinesInUse)
			// Destroy the machine so it can't be used for the next test.
			err = m.Destroy()
			c.Assert(err, IsNil)
		}
	}
}
开发者ID:rif,项目名称:golang-stuff,代码行数:31,代码来源:assign_test.go

示例11: TestAssignUnitToNewMachineBecomesDirty

func (s *AssignSuite) TestAssignUnitToNewMachineBecomesDirty(c *C) {
	_, err := s.State.AddMachine("series", state.JobManageEnviron) // bootstrap machine
	c.Assert(err, IsNil)

	// Set up constraints to specify we want to install into a container.
	econs := constraints.MustParse("container=lxc")
	err = s.State.SetEnvironConstraints(econs)
	c.Assert(err, IsNil)

	// Create some units and a clean machine.
	unit, err := s.wordpress.AddUnit()
	c.Assert(err, IsNil)
	anotherUnit, err := s.wordpress.AddUnit()
	c.Assert(err, IsNil)
	machine, err := s.State.AddMachine("series", state.JobHostUnits)
	c.Assert(err, IsNil)

	makeDirty := state.TransactionHook{
		Before: func() { c.Assert(unit.AssignToMachine(machine), IsNil) },
	}
	defer state.SetTransactionHooks(
		c, s.State, makeDirty,
	).Check()

	err = anotherUnit.AssignToNewMachineOrContainer()
	c.Assert(err, IsNil)

	mid, err := unit.AssignedMachineId()
	c.Assert(err, IsNil)
	c.Assert(mid, Equals, "1")

	mid, err = anotherUnit.AssignedMachineId()
	c.Assert(err, IsNil)
	c.Assert(mid, Equals, "2/lxc/0")
}
开发者ID:rif,项目名称:golang-stuff,代码行数:35,代码来源:assign_test.go

示例12: TestAssignUnitToNewMachineDefaultContainerConstraint

func (s *AssignSuite) TestAssignUnitToNewMachineDefaultContainerConstraint(c *C) {
	// Set up env constraints.
	econs := constraints.MustParse("container=lxc")
	err := s.State.SetEnvironConstraints(econs)
	c.Assert(err, IsNil)
	s.assertAssignUnitToNewMachineContainerConstraint(c)
}
开发者ID:rif,项目名称:golang-stuff,代码行数:7,代码来源:assign_test.go

示例13: TestServiceGet

func (s *ConfigSuite) TestServiceGet(c *C) {
	for i, t := range getTests {
		c.Logf("test %d. %s", i, t.about)
		ch := s.AddTestingCharm(c, t.charm)
		svc, err := s.State.AddService(fmt.Sprintf("test%d", i), ch)
		c.Assert(err, IsNil)

		var constraintsv constraints.Value
		if t.constraints != "" {
			constraintsv = constraints.MustParse(t.constraints)
			err = svc.SetConstraints(constraintsv)
			c.Assert(err, IsNil)
		}
		if t.config != nil {
			settings, err := ch.Config().ParseSettingsStrings(t.config)
			c.Assert(err, IsNil)
			err = svc.UpdateConfigSettings(settings)
			c.Assert(err, IsNil)
		}
		expect := t.expect
		expect.Constraints = constraintsv
		expect.Service = svc.Name()
		expect.Charm = ch.Meta().Name
		got, err := statecmd.ServiceGet(s.State, params.ServiceGet{svc.Name()})
		c.Assert(err, IsNil)
		c.Assert(got, DeepEquals, expect)
	}
}
开发者ID:sankark,项目名称:golang-stuff,代码行数:28,代码来源:config_test.go

示例14: TestBootstrapSpecifiedConstraints

func (s *bootstrapSuite) TestBootstrapSpecifiedConstraints(c *gc.C) {
	env := newEnviron("foo", useDefaultKeys)
	cons := constraints.MustParse("cpu-cores=2 mem=4G")
	err := environs.Bootstrap(env, cons)
	c.Assert(err, gc.IsNil)
	c.Assert(env.bootstrapCount, gc.Equals, 1)
	c.Assert(env.constraints, gc.DeepEquals, cons)
}
开发者ID:rif,项目名称:golang-stuff,代码行数:8,代码来源:bootstrap_test.go

示例15: TestAssignUnitNewPolicyWithDefaultContainerConstraint

func (s *AssignSuite) TestAssignUnitNewPolicyWithDefaultContainerConstraint(c *C) {
	_, err := s.State.AddMachine("series", state.JobHostUnits)
	c.Assert(err, IsNil)
	// Set up env constraints.
	econs := constraints.MustParse("container=lxc")
	err = s.State.SetEnvironConstraints(econs)
	c.Assert(err, IsNil)
	s.assertAssignUnitNewPolicyWithContainerConstraint(c)
}
开发者ID:rif,项目名称:golang-stuff,代码行数:9,代码来源:assign_test.go


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