• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang constraints.MustParse函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: TestAssignUnitToNewMachineSetsConstraints

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

	// Unit will take combined service/environ constraints on creation.
	unit, err := s.wordpress.AddUnit()
	c.Assert(err, gc.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, gc.IsNil)
	econs = constraints.MustParse("cpu-cores=4")
	err = s.State.SetEnvironConstraints(econs)
	c.Assert(err, gc.IsNil)

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


示例2: TestDeployForceMachineIdWithContainer

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

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


示例3: TestWithout

func (s *ConstraintsSuite) TestWithout(c *gc.C) {
	for i, t := range withoutTests {
		c.Logf("test %d", i)
		initial := constraints.MustParse(t.initial)
		final, err := constraints.Without(initial, t.without...)
		c.Assert(err, gc.IsNil)
		c.Check(final, gc.DeepEquals, constraints.MustParse(t.final))
	}
}
开发者ID:jameinel,项目名称:core,代码行数:9,代码来源:constraints_test.go


示例4: TestConstraintsMerge

func (t *localServerSuite) TestConstraintsMerge(c *gc.C) {
	env := t.Prepare(c)
	validator, err := env.ConstraintsValidator()
	c.Assert(err, gc.IsNil)
	consA := constraints.MustParse("arch=amd64 mem=1G cpu-power=10 cpu-cores=2 tags=bar")
	consB := constraints.MustParse("arch=i386 instance-type=m1.small")
	cons, err := validator.Merge(consA, consB)
	c.Assert(err, gc.IsNil)
	c.Assert(cons, gc.DeepEquals, constraints.MustParse("arch=i386 instance-type=m1.small tags=bar"))
}
开发者ID:jameinel,项目名称:core,代码行数:10,代码来源:local_test.go


示例5: TestMergeError

func (s *validationSuite) TestMergeError(c *gc.C) {
	validator := constraints.NewValidator()
	validator.RegisterConflicts([]string{"instance-type"}, []string{"mem"})
	consFallback := constraints.MustParse("instance-type=foo mem=4G")
	cons := constraints.MustParse("cpu-cores=2")
	_, err := validator.Merge(consFallback, cons)
	c.Assert(err, gc.ErrorMatches, `ambiguous constraints: "mem" overlaps with "instance-type"`)
	_, err = validator.Merge(cons, consFallback)
	c.Assert(err, gc.ErrorMatches, `ambiguous constraints: "mem" overlaps with "instance-type"`)
}
开发者ID:jameinel,项目名称:core,代码行数:10,代码来源:validation_test.go


示例6: TestConstraintsValidatorVocab

func (t *localServerSuite) TestConstraintsValidatorVocab(c *gc.C) {
	env := t.Prepare(c)
	validator, err := env.ConstraintsValidator()
	c.Assert(err, gc.IsNil)
	cons := constraints.MustParse("arch=ppc64")
	_, err = validator.Validate(cons)
	c.Assert(err, gc.ErrorMatches, "invalid constraint value: arch=ppc64\nvalid values are:.*")
	cons = constraints.MustParse("instance-type=foo")
	_, err = validator.Validate(cons)
	c.Assert(err, gc.ErrorMatches, "invalid constraint value: instance-type=foo\nvalid values are:.*")
}
开发者ID:jameinel,项目名称:core,代码行数:11,代码来源:local_test.go


示例7: TestMachineConstraints

func (s *constraintsValidationSuite) TestMachineConstraints(c *gc.C) {
	for i, t := range setConstraintsTests {
		c.Logf("test %d", i)
		err := s.State.SetEnvironConstraints(constraints.MustParse(t.consFallback))
		c.Check(err, gc.IsNil)
		m, err := s.addOneMachine(c, constraints.MustParse(t.cons))
		c.Check(err, gc.IsNil)
		cons, err := m.Constraints()
		c.Check(err, gc.IsNil)
		c.Check(cons, gc.DeepEquals, constraints.MustParse(t.expected))
	}
}
开发者ID:jameinel,项目名称:core,代码行数:12,代码来源:constraintsvalidation_test.go


示例8: TestDeployConstraints

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


示例9: TestMerge

func (s *validationSuite) TestMerge(c *gc.C) {
	for i, t := range mergeTests {
		c.Logf("test %d: %s", i, t.desc)
		validator := constraints.NewValidator()
		validator.RegisterConflicts(t.reds, t.blues)
		consFallback := constraints.MustParse(t.consFallback)
		cons := constraints.MustParse(t.cons)
		merged, err := validator.Merge(consFallback, cons)
		c.Assert(err, gc.IsNil)
		expected := constraints.MustParse(t.expected)
		c.Check(merged, gc.DeepEquals, expected)
	}
}
开发者ID:jameinel,项目名称:core,代码行数:13,代码来源:validation_test.go


示例10: TestAssignUsingConstraintsToMachine

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

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

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

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


示例11: TestHasContainer

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


示例12: TestAssignUnitToNewMachineBecomesDirty

func (s *AssignSuite) TestAssignUnitToNewMachineBecomesDirty(c *gc.C) {
	_, err := s.State.AddMachine("quantal", state.JobManageEnviron) // bootstrap machine
	c.Assert(err, gc.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, gc.IsNil)

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

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

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

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

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


示例13: TestAssignUnitToNewMachineBecomesHost

func (s *AssignSuite) TestAssignUnitToNewMachineBecomesHost(c *gc.C) {
	_, err := s.State.AddMachine("quantal", state.JobManageEnviron) // bootstrap machine
	c.Assert(err, gc.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, gc.IsNil)

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

	addContainer := state.TransactionHook{
		Before: func() {
			_, err := s.State.AddMachineInsideMachine(state.MachineTemplate{
				Series: "quantal",
				Jobs:   []state.MachineJob{state.JobHostUnits},
			}, machine.Id(), instance.LXC)
			c.Assert(err, gc.IsNil)
		},
	}
	defer state.SetTransactionHooks(
		c, s.State, addContainer,
	).Check()

	err = unit.AssignToNewMachineOrContainer()
	c.Assert(err, gc.IsNil)

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


示例14: TestAssignUnitToNewMachineDefaultContainerConstraint

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


示例15: TestConstraints

func (s *withoutStateServerSuite) TestConstraints(c *gc.C) {
	// Add a machine with some constraints.
	template := state.MachineTemplate{
		Series:      "quantal",
		Jobs:        []state.MachineJob{state.JobHostUnits},
		Constraints: constraints.MustParse("cpu-cores=123", "mem=8G"),
	}
	consMachine, err := s.State.AddOneMachine(template)
	c.Assert(err, gc.IsNil)

	machine0Constraints, err := s.machines[0].Constraints()
	c.Assert(err, gc.IsNil)

	args := params.Entities{Entities: []params.Entity{
		{Tag: s.machines[0].Tag()},
		{Tag: consMachine.Tag()},
		{Tag: "machine-42"},
		{Tag: "unit-foo-0"},
		{Tag: "service-bar"},
	}}
	result, err := s.provisioner.Constraints(args)
	c.Assert(err, gc.IsNil)
	c.Assert(result, gc.DeepEquals, params.ConstraintsResults{
		Results: []params.ConstraintsResult{
			{Constraints: machine0Constraints},
			{Constraints: template.Constraints},
			{Error: apiservertesting.NotFoundError("machine 42")},
			{Error: apiservertesting.ErrUnauthorized},
			{Error: apiservertesting.ErrUnauthorized},
		},
	})
}
开发者ID:jameinel,项目名称:core,代码行数:32,代码来源:provisioner_test.go


示例16: TestServiceGet

func (s *getSuite) TestServiceGet(c *gc.C) {
	for i, t := range getTests {
		c.Logf("test %d. %s", i, t.about)
		ch := s.AddTestingCharm(c, t.charm)
		svc := s.AddTestingService(c, fmt.Sprintf("test%d", i), ch)

		var constraintsv constraints.Value
		if t.constraints != "" {
			constraintsv = constraints.MustParse(t.constraints)
			err := svc.SetConstraints(constraintsv)
			c.Assert(err, gc.IsNil)
		}
		if t.config != nil {
			err := svc.UpdateConfigSettings(t.config)
			c.Assert(err, gc.IsNil)
		}
		expect := t.expect
		expect.Constraints = constraintsv
		expect.Service = svc.Name()
		expect.Charm = ch.Meta().Name
		apiclient := s.APIState.Client()
		got, err := apiclient.ServiceGet(svc.Name())
		c.Assert(err, gc.IsNil)
		c.Assert(*got, gc.DeepEquals, expect)
	}
}
开发者ID:jameinel,项目名称:core,代码行数:26,代码来源:get_test.go


示例17: TestAssignUnitToNewMachineContainerConstraint

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


示例18: TestFindInstanceSpec

func (s *instanceTypeSuite) TestFindInstanceSpec(c *gc.C) {
	env := s.setupEnvWithDummyMetadata(c)
	for i, t := range findInstanceSpecTests {
		c.Logf("test %d", i)

		cons := constraints.MustParse(t.cons)
		constraints := &instances.InstanceConstraint{
			Region:      "West US",
			Series:      t.series,
			Arches:      []string{"amd64"},
			Constraints: cons,
		}

		// Find a matching instance type and image.
		spec, err := findInstanceSpec(env, constraints)
		c.Assert(err, gc.IsNil)

		// We got the instance type we described in our constraints, and
		// the image returned by (the fake) simplestreams.
		if cons.HasInstanceType() {
			c.Check(spec.InstanceType.Name, gc.Equals, *cons.InstanceType)
		} else {
			c.Check(spec.InstanceType.Name, gc.Equals, t.itype)
		}
		c.Check(spec.Image.Id, gc.Equals, "image-id")
	}
}
开发者ID:jameinel,项目名称:core,代码行数:27,代码来源:instancetype_test.go


示例19: TestPrecheckInstanceValidInstanceType

func (s *instanceTypeSuite) TestPrecheckInstanceValidInstanceType(c *gc.C) {
	env := s.setupEnvWithDummyMetadata(c)
	cons := constraints.MustParse("instance-type=Large")
	placement := ""
	err := env.PrecheckInstance("precise", cons, placement)
	c.Assert(err, gc.IsNil)
}
开发者ID:jameinel,项目名称:core,代码行数:7,代码来源:instancetype_test.go


示例20: TestPrecheckInstanceInvalidInstanceType

func (s *localServerSuite) TestPrecheckInstanceInvalidInstanceType(c *gc.C) {
	env := s.Open(c)
	cons := constraints.MustParse("instance-type=m1.large")
	placement := ""
	err := env.PrecheckInstance("precise", cons, placement)
	c.Assert(err, gc.ErrorMatches, `invalid Openstack flavour "m1.large" specified`)
}
开发者ID:jameinel,项目名称:core,代码行数:7,代码来源:local_test.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang environs.New函数代码示例发布时间:2022-05-28
下一篇:
Golang cmd.Context类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap