本文整理汇总了Golang中launchpad/net/juju-core/state/api/params.ErrCode函数的典型用法代码示例。如果您正苦于以下问题:Golang ErrCode函数的具体用法?Golang ErrCode怎么用?Golang ErrCode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ErrCode函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestUnitRemove
func (s *deployerSuite) TestUnitRemove(c *gc.C) {
unit, err := s.st.Unit(s.principal.Tag())
c.Assert(err, gc.IsNil)
// It fails because the entity is still alive.
// And EnsureDead will fail because there is a subordinate.
err = unit.Remove()
c.Assert(err, gc.ErrorMatches, `cannot remove entity "unit-mysql-0": still alive`)
c.Assert(params.ErrCode(err), gc.Equals, "")
// With the subordinate it also fails due to it being alive.
unit, err = s.st.Unit(s.subordinate.Tag())
c.Assert(err, gc.IsNil)
err = unit.Remove()
c.Assert(err, gc.ErrorMatches, `cannot remove entity "unit-logging-0": still alive`)
c.Assert(params.ErrCode(err), gc.Equals, "")
// Make it dead first and try again.
err = s.subordinate.EnsureDead()
c.Assert(err, gc.IsNil)
err = unit.Remove()
c.Assert(err, gc.IsNil)
// Verify it's gone.
err = unit.Refresh()
s.assertUnauthorized(c, err)
unit, err = s.st.Unit(s.subordinate.Tag())
s.assertUnauthorized(c, err)
c.Assert(unit, gc.IsNil)
}
示例2: TestEnsureDead
func (s *uniterSuite) TestEnsureDead(c *gc.C) {
c.Assert(s.unit.Life(), gc.Equals, state.Alive)
unit, err := s.uniter.Unit("unit-wordpress-0")
c.Assert(err, gc.IsNil)
err = unit.EnsureDead()
c.Assert(err, gc.IsNil)
err = s.unit.Refresh()
c.Assert(err, gc.IsNil)
c.Assert(s.unit.Life(), gc.Equals, state.Dead)
err = unit.EnsureDead()
c.Assert(err, gc.IsNil)
err = s.unit.Refresh()
c.Assert(err, gc.IsNil)
c.Assert(s.unit.Life(), gc.Equals, state.Dead)
err = s.unit.Remove()
c.Assert(err, gc.IsNil)
err = s.unit.Refresh()
c.Assert(err, jc.Satisfies, errors.IsNotFoundError)
err = unit.EnsureDead()
c.Assert(err, gc.ErrorMatches, `unit "wordpress/0" not found`)
c.Assert(params.ErrCode(err), gc.Equals, params.CodeNotFound)
}
示例3: opClientDestroyRelation
func opClientDestroyRelation(c *C, st *api.State, mst *state.State) (func(), error) {
err := st.Client().DestroyRelation("nosuch1", "nosuch2")
if params.ErrCode(err) == params.CodeNotFound {
err = nil
}
return func() {}, err
}
示例4: opClientServiceSetCharm
func opClientServiceSetCharm(c *C, st *api.State, mst *state.State) (func(), error) {
err := st.Client().ServiceSetCharm("nosuch", "local:series/wordpress", false)
if params.ErrCode(err) == params.CodeNotFound {
err = nil
}
return func() {}, err
}
示例5: TestSetToolsWrongMachine
func (s *upgraderSuite) TestSetToolsWrongMachine(c *C) {
err := s.st.SetTools("42", &tools.Tools{
Version: version.Current,
})
c.Assert(err, ErrorMatches, "permission denied")
c.Assert(params.ErrCode(err), Equals, params.CodeUnauthorized)
}
示例6: opClientAddServiceUnits
func opClientAddServiceUnits(c *C, st *api.State, mst *state.State) (func(), error) {
_, err := st.Client().AddServiceUnits("nosuch", 1)
if params.ErrCode(err) == params.CodeNotFound {
err = nil
}
return func() {}, err
}
示例7: opClientServiceDestroy
func opClientServiceDestroy(c *C, st *api.State, mst *state.State) (func(), error) {
err := st.Client().ServiceDestroy("non-existent")
if params.ErrCode(err) == params.CodeNotFound {
err = nil
}
return func() {}, err
}
示例8: OpenAPI
// OpenAPI tries to open the state using the given Conf. If it
// returns a non-empty newPassword, the password used to connect
// to the state should be changed accordingly - the caller should write the
// configuration with StateInfo.Password set to newPassword, then
// set the entity's password accordingly.
func (c *Conf) OpenAPI(dialOpts api.DialOpts) (st *api.State, newPassword string, err error) {
info := *c.APIInfo
info.Nonce = c.MachineNonce
if info.Password != "" {
st, err := api.Open(&info, dialOpts)
if err == nil {
return st, "", nil
}
if params.ErrCode(err) != params.CodeUnauthorized {
return nil, "", err
}
// Access isn't authorized even though we have a password
// This can happen if we crash after saving the
// password but before changing it, so we'll try again
// with the old password.
}
info.Password = c.OldPassword
st, err = api.Open(&info, dialOpts)
if err != nil {
return nil, "", err
}
// We've succeeded in connecting with the old password, so
// we can now change it to something more private.
password, err := utils.RandomPassword()
if err != nil {
st.Close()
return nil, "", err
}
return st, password, nil
}
示例9: TestEnsureDead
func (s *machinerSuite) TestEnsureDead(c *C) {
c.Assert(s.machine.Life(), Equals, state.Alive)
machine, err := s.st.Machiner().Machine("machine-0")
c.Assert(err, IsNil)
err = machine.EnsureDead()
c.Assert(err, IsNil)
err = s.machine.Refresh()
c.Assert(err, IsNil)
c.Assert(s.machine.Life(), Equals, state.Dead)
err = machine.EnsureDead()
c.Assert(err, IsNil)
err = s.machine.Refresh()
c.Assert(err, IsNil)
c.Assert(s.machine.Life(), Equals, state.Dead)
err = s.machine.Remove()
c.Assert(err, IsNil)
err = s.machine.Refresh()
c.Assert(err, checkers.Satisfies, errors.IsNotFoundError)
err = machine.EnsureDead()
c.Assert(err, ErrorMatches, "machine 0 not found")
c.Assert(params.ErrCode(err), Equals, params.CodeNotFound)
}
示例10: isFatal
func isFatal(err error) bool {
isTerminate := err == worker.ErrTerminateAgent
notProvisioned := params.ErrCode(err) == params.CodeNotProvisioned
if isTerminate || notProvisioned || isUpgraded(err) {
return true
}
_, ok := err.(*fatalError)
return ok
}
示例11: TestMachineAndMachineTag
func (s *machinerSuite) TestMachineAndMachineTag(c *gc.C) {
machine, err := s.machiner.Machine("machine-42")
c.Assert(err, gc.ErrorMatches, "permission denied")
c.Assert(params.ErrCode(err), gc.Equals, params.CodeUnauthorized)
c.Assert(machine, gc.IsNil)
machine, err = s.machiner.Machine("machine-0")
c.Assert(err, gc.IsNil)
c.Assert(machine.Tag(), gc.Equals, "machine-0")
}
示例12: TestMachineAndMachineId
func (s *machinerSuite) TestMachineAndMachineId(c *C) {
machine, err := s.st.Machiner().Machine("machine-42")
c.Assert(err, ErrorMatches, "permission denied")
c.Assert(params.ErrCode(err), Equals, params.CodeUnauthorized)
c.Assert(machine, IsNil)
machine, err = s.st.Machiner().Machine("machine-0")
c.Assert(err, IsNil)
c.Assert(machine.Tag(), Equals, "machine-0")
}
示例13: TestUnitAndUnitTag
func (s *uniterSuite) TestUnitAndUnitTag(c *gc.C) {
unit, err := s.uniter.Unit("unit-foo-42")
c.Assert(err, gc.ErrorMatches, "permission denied")
c.Assert(params.ErrCode(err), gc.Equals, params.CodeUnauthorized)
c.Assert(unit, gc.IsNil)
unit, err = s.uniter.Unit("unit-wordpress-0")
c.Assert(err, gc.IsNil)
c.Assert(unit.Tag(), gc.Equals, "unit-wordpress-0")
}
示例14: TestMachine
func (s *suite) TestMachine(c *C) {
m, err := s.st.MachineAgent().Machine("42")
c.Assert(err, ErrorMatches, "permission denied")
c.Assert(params.ErrCode(err), Equals, params.CodeUnauthorized)
c.Assert(m, IsNil)
m, err = s.st.MachineAgent().Machine(s.machine.Tag())
c.Assert(err, IsNil)
c.Assert(m.Tag(), Equals, s.machine.Tag())
c.Assert(m.Life(), Equals, params.Alive)
c.Assert(m.Jobs(), DeepEquals, []params.MachineJob{params.JobHostUnits})
err = s.machine.EnsureDead()
c.Assert(err, IsNil)
err = s.machine.Remove()
c.Assert(err, IsNil)
m, err = s.st.MachineAgent().Machine(s.machine.Tag())
c.Assert(err, ErrorMatches, fmt.Sprintf("machine %s not found", s.machine.Id()))
c.Assert(params.ErrCode(err), Equals, params.CodeNotFound)
c.Assert(m, IsNil)
}
示例15: TestUnitEntity
func (s *unitSuite) TestUnitEntity(c *gc.C) {
m, err := s.st.Agent().Entity("wordpress/1")
c.Assert(err, gc.ErrorMatches, "permission denied")
c.Assert(params.ErrCode(err), gc.Equals, params.CodeUnauthorized)
c.Assert(m, gc.IsNil)
m, err = s.st.Agent().Entity(s.unit.Tag())
c.Assert(err, gc.IsNil)
c.Assert(m.Tag(), gc.Equals, s.unit.Tag())
c.Assert(m.Life(), gc.Equals, params.Alive)
c.Assert(m.Jobs(), gc.HasLen, 0)
err = s.unit.EnsureDead()
c.Assert(err, gc.IsNil)
err = s.unit.Remove()
c.Assert(err, gc.IsNil)
m, err = s.st.Agent().Entity(s.unit.Tag())
c.Assert(err, gc.ErrorMatches, fmt.Sprintf("unit %q not found", s.unit.Name()))
c.Assert(params.ErrCode(err), gc.Equals, params.CodeNotFound)
c.Assert(m, gc.IsNil)
}