本文整理汇总了Golang中github.com/juju/names.NewUnitTag函数的典型用法代码示例。如果您正苦于以下问题:Golang NewUnitTag函数的具体用法?Golang NewUnitTag怎么用?Golang NewUnitTag使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewUnitTag函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestUnitStorageAttachments
func (s *storageSuite) TestUnitStorageAttachments(c *gc.C) {
storageAttachmentIds := []params.StorageAttachmentId{{
StorageTag: "storage-whatever-0",
UnitTag: "unit-mysql-0",
}}
var called bool
apiCaller := testing.APICallerFunc(func(objType string, version int, id, request string, arg, result interface{}) error {
c.Check(objType, gc.Equals, "Uniter")
c.Check(version, gc.Equals, 2)
c.Check(id, gc.Equals, "")
c.Check(request, gc.Equals, "UnitStorageAttachments")
c.Check(arg, gc.DeepEquals, params.Entities{
Entities: []params.Entity{{Tag: "unit-mysql-0"}},
})
c.Assert(result, gc.FitsTypeOf, ¶ms.StorageAttachmentIdsResults{})
*(result.(*params.StorageAttachmentIdsResults)) = params.StorageAttachmentIdsResults{
Results: []params.StorageAttachmentIdsResult{{
Result: params.StorageAttachmentIds{storageAttachmentIds},
}},
}
called = true
return nil
})
st := uniter.NewState(apiCaller, names.NewUnitTag("mysql/0"))
attachmentIds, err := st.UnitStorageAttachments(names.NewUnitTag("mysql/0"))
c.Check(err, jc.ErrorIsNil)
c.Check(called, jc.IsTrue)
c.Assert(attachmentIds, gc.DeepEquals, storageAttachmentIds)
}
开发者ID:imoapps,项目名称:juju,代码行数:31,代码来源:storage_test.go
示例2: TestRemoveStorageAttachment
func (s *storageSuite) TestRemoveStorageAttachment(c *gc.C) {
apiCaller := testing.APICallerFunc(func(objType string, version int, id, request string, arg, result interface{}) error {
c.Check(objType, gc.Equals, "Uniter")
c.Check(version, gc.Equals, 2)
c.Check(id, gc.Equals, "")
c.Check(request, gc.Equals, "RemoveStorageAttachments")
c.Check(arg, gc.DeepEquals, params.StorageAttachmentIds{
Ids: []params.StorageAttachmentId{{
StorageTag: "storage-data-0",
UnitTag: "unit-mysql-0",
}},
})
c.Assert(result, gc.FitsTypeOf, ¶ms.ErrorResults{})
*(result.(*params.ErrorResults)) = params.ErrorResults{
Results: []params.ErrorResult{{
Error: ¶ms.Error{Message: "yoink"},
}},
}
return nil
})
st := uniter.NewState(apiCaller, names.NewUnitTag("mysql/0"))
err := st.RemoveStorageAttachment(names.NewStorageTag("data/0"), names.NewUnitTag("mysql/0"))
c.Check(err, gc.ErrorMatches, "yoink")
}
开发者ID:imoapps,项目名称:juju,代码行数:25,代码来源:storage_test.go
示例3: TestWatchStorageAttachments
func (s *storageSuite) TestWatchStorageAttachments(c *gc.C) {
var called bool
apiCaller := testing.APICallerFunc(func(objType string, version int, id, request string, arg, result interface{}) error {
c.Check(objType, gc.Equals, "Uniter")
c.Check(version, gc.Equals, 2)
c.Check(id, gc.Equals, "")
c.Check(request, gc.Equals, "WatchStorageAttachments")
c.Check(arg, gc.DeepEquals, params.StorageAttachmentIds{
Ids: []params.StorageAttachmentId{{
StorageTag: "storage-data-0",
UnitTag: "unit-mysql-0",
}},
})
c.Assert(result, gc.FitsTypeOf, ¶ms.NotifyWatchResults{})
*(result.(*params.NotifyWatchResults)) = params.NotifyWatchResults{
Results: []params.NotifyWatchResult{{
Error: ¶ms.Error{Message: "FAIL"},
}},
}
called = true
return nil
})
st := uniter.NewState(apiCaller, names.NewUnitTag("mysql/0"))
_, err := st.WatchStorageAttachment(names.NewStorageTag("data/0"), names.NewUnitTag("mysql/0"))
c.Check(err, gc.ErrorMatches, "FAIL")
c.Check(called, jc.IsTrue)
}
开发者ID:imoapps,项目名称:juju,代码行数:28,代码来源:storage_test.go
示例4: TestAPIErrors
func (s *storageSuite) TestAPIErrors(c *gc.C) {
apiCaller := testing.APICallerFunc(func(objType string, version int, id, request string, arg, result interface{}) error {
return errors.New("bad")
})
st := uniter.NewState(apiCaller, names.NewUnitTag("mysql/0"))
_, err := st.UnitStorageAttachments(names.NewUnitTag("mysql/0"))
c.Check(err, gc.ErrorMatches, "bad")
}
开发者ID:imoapps,项目名称:juju,代码行数:8,代码来源:storage_test.go
示例5: TestRemoveStorageAttachments
func (s *storageSuite) TestRemoveStorageAttachments(c *gc.C) {
setMock := func(st *mockStorageState, f func(s names.StorageTag, u names.UnitTag) error) {
st.remove = f
}
unitTag0 := names.NewUnitTag("mysql/0")
unitTag1 := names.NewUnitTag("mysql/1")
storageTag0 := names.NewStorageTag("data/0")
storageTag1 := names.NewStorageTag("data/1")
resources := common.NewResources()
getCanAccess := func() (common.AuthFunc, error) {
return func(tag names.Tag) bool {
return tag == unitTag0
}, nil
}
state := &mockStorageState{}
setMock(state, func(s names.StorageTag, u names.UnitTag) error {
c.Assert(u, gc.DeepEquals, unitTag0)
if s == storageTag1 {
return errors.New("badness")
}
return nil
})
storage, err := uniter.NewStorageAPI(state, resources, getCanAccess)
c.Assert(err, jc.ErrorIsNil)
errors, err := storage.RemoveStorageAttachments(params.StorageAttachmentIds{
Ids: []params.StorageAttachmentId{{
StorageTag: storageTag0.String(),
UnitTag: unitTag0.String(),
}, {
StorageTag: storageTag1.String(),
UnitTag: unitTag0.String(),
}, {
StorageTag: storageTag0.String(),
UnitTag: unitTag1.String(),
}, {
StorageTag: unitTag0.String(), // oops
UnitTag: unitTag0.String(),
}, {
StorageTag: storageTag0.String(),
UnitTag: storageTag0.String(), // oops
}},
})
c.Assert(err, jc.ErrorIsNil)
c.Assert(errors, jc.DeepEquals, params.ErrorResults{
Results: []params.ErrorResult{
{nil},
{¶ms.Error{Message: "badness"}},
{¶ms.Error{Code: params.CodeUnauthorized, Message: "permission denied"}},
{¶ms.Error{Message: `"unit-mysql-0" is not a valid storage tag`}},
{¶ms.Error{Message: `"storage-data-0" is not a valid unit tag`}},
},
})
}
开发者ID:imoapps,项目名称:juju,代码行数:57,代码来源:storage_test.go
示例6: TestUnit
func (s *unitSuite) TestUnit(c *gc.C) {
apiUnitFoo, err := s.firewaller.Unit(names.NewUnitTag("foo/42"))
c.Assert(err, gc.ErrorMatches, `unit "foo/42" not found`)
c.Assert(err, jc.Satisfies, params.IsCodeNotFound)
c.Assert(apiUnitFoo, gc.IsNil)
apiUnit0, err := s.firewaller.Unit(s.units[0].Tag().(names.UnitTag))
c.Assert(err, jc.ErrorIsNil)
c.Assert(apiUnit0, gc.NotNil)
c.Assert(apiUnit0.Name(), gc.Equals, s.units[0].Name())
c.Assert(apiUnit0.Tag(), gc.Equals, names.NewUnitTag(s.units[0].Name()))
}
开发者ID:imoapps,项目名称:juju,代码行数:12,代码来源:unit_test.go
示例7: TestStorageAttachmentResultCountMismatch
func (s *storageSuite) TestStorageAttachmentResultCountMismatch(c *gc.C) {
apiCaller := testing.APICallerFunc(func(objType string, version int, id, request string, arg, result interface{}) error {
*(result.(*params.StorageAttachmentIdsResults)) = params.StorageAttachmentIdsResults{
[]params.StorageAttachmentIdsResult{{}, {}},
}
return nil
})
st := uniter.NewState(apiCaller, names.NewUnitTag("mysql/0"))
c.Assert(func() {
st.UnitStorageAttachments(names.NewUnitTag("mysql/0"))
}, gc.PanicMatches, "expected 1 result, got 2")
}
开发者ID:imoapps,项目名称:juju,代码行数:12,代码来源:storage_test.go
示例8: TestNamespace
func (s *RsyslogSuite) TestNamespace(c *gc.C) {
st := s.st
// set the rsyslog cert
err := s.APIState.Client().EnvironmentSet(map[string]interface{}{"rsyslog-ca-cert": coretesting.CACert})
c.Assert(err, jc.ErrorIsNil)
// namespace only takes effect in filenames
// for machine-0; all others assume isolation.
s.testNamespace(c, st, names.NewMachineTag("0"), "", "25-juju.conf", *rsyslog.LogDir)
s.testNamespace(c, st, names.NewMachineTag("0"), "mynamespace", "25-juju-mynamespace.conf", *rsyslog.LogDir+"-mynamespace")
s.testNamespace(c, st, names.NewMachineTag("1"), "", "25-juju.conf", *rsyslog.LogDir)
s.testNamespace(c, st, names.NewMachineTag("1"), "mynamespace", "25-juju.conf", *rsyslog.LogDir)
s.testNamespace(c, st, names.NewUnitTag("myservice/0"), "", "26-juju-unit-myservice-0.conf", *rsyslog.LogDir)
s.testNamespace(c, st, names.NewUnitTag("myservice/0"), "mynamespace", "26-juju-unit-myservice-0.conf", *rsyslog.LogDir)
}
开发者ID:Pankov404,项目名称:juju,代码行数:15,代码来源:rsyslog_test.go
示例9: TestHandle
func (testsuite) TestHandle(c *gc.C) {
f := &fakeAPI{}
ua := unitAssignerHandler{api: f}
ids := []string{"foo/0", "bar/0"}
err := ua.Handle(nil, ids)
c.Assert(err, jc.ErrorIsNil)
c.Assert(f.assignTags, gc.DeepEquals, []names.UnitTag{
names.NewUnitTag("foo/0"),
names.NewUnitTag("bar/0"),
})
f.err = errors.New("boo")
err = ua.Handle(nil, ids)
c.Assert(err, gc.Equals, f.err)
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:15,代码来源:unitassigner_test.go
示例10: TestWorkerPathsWindows
func (s *PathsSuite) TestWorkerPathsWindows(c *gc.C) {
s.PatchValue(&os.HostOS, func() os.OSType { return os.Windows })
dataDir := c.MkDir()
unitTag := names.NewUnitTag("some-service/323")
worker := "some-worker"
paths := uniter.NewWorkerPaths(dataDir, unitTag, worker)
relData := relPathFunc(dataDir)
relAgent := relPathFunc(relData("agents", "unit-some-service-323"))
c.Assert(paths, jc.DeepEquals, uniter.Paths{
ToolsDir: relData("tools/unit-some-service-323"),
Runtime: uniter.RuntimePaths{
JujuRunSocket: `\\.\pipe\unit-some-service-323-some-worker-run`,
JujucServerSocket: `\\.\pipe\unit-some-service-323-some-worker-agent`,
},
State: uniter.StatePaths{
BaseDir: relAgent(),
CharmDir: relAgent("charm"),
OperationsFile: relAgent("state", "uniter"),
RelationsDir: relAgent("state", "relations"),
BundlesDir: relAgent("state", "bundles"),
DeployerDir: relAgent("state", "deployer"),
StorageDir: relAgent("state", "storage"),
MetricsSpoolDir: relAgent("state", "spool", "metrics"),
},
})
}
开发者ID:imoapps,项目名称:juju,代码行数:28,代码来源:paths_test.go
示例11: ReadSettings
// ReadSettings returns a map holding the settings of the unit with the
// supplied name within this relation. An error will be returned if the
// relation no longer exists, or if the unit's service is not part of the
// relation, or the settings are invalid; but mere non-existence of the
// unit is not grounds for an error, because the unit settings are
// guaranteed to persist for the lifetime of the relation, regardless
// of the lifetime of the unit.
func (ru *RelationUnit) ReadSettings(uname string) (params.RelationSettings, error) {
if !names.IsValidUnit(uname) {
return nil, errors.Errorf("%q is not a valid unit", uname)
}
tag := names.NewUnitTag(uname)
var results params.RelationSettingsResults
args := params.RelationUnitPairs{
RelationUnitPairs: []params.RelationUnitPair{{
Relation: ru.relation.tag.String(),
LocalUnit: ru.unit.tag.String(),
RemoteUnit: tag.String(),
}},
}
err := ru.st.facade.FacadeCall("ReadRemoteSettings", args, &results)
if err != nil {
return nil, err
}
if len(results.Results) != 1 {
return nil, fmt.Errorf("expected 1 result, got %d", len(results.Results))
}
result := results.Results[0]
if result.Error != nil {
return nil, result.Error
}
return result.Settings, nil
}
开发者ID:zhouqt,项目名称:juju,代码行数:33,代码来源:relationunit.go
示例12: TestAddMetricBatches
func (s *metricsAdderSuite) TestAddMetricBatches(c *gc.C) {
var called bool
var callParams params.MetricBatchParams
metricsadder.PatchFacadeCall(s, s.adder, func(request string, args, response interface{}) error {
p, ok := args.(params.MetricBatchParams)
c.Assert(ok, jc.IsTrue)
callParams = p
called = true
c.Assert(request, gc.Equals, "AddMetricBatches")
result := response.(*params.ErrorResults)
result.Results = make([]params.ErrorResult, 1)
return nil
})
batches := []params.MetricBatchParam{{
Tag: names.NewUnitTag("test-unit/0").String(),
Batch: params.MetricBatch{
UUID: utils.MustNewUUID().String(),
CharmURL: "test-charm-url",
Created: time.Now(),
Metrics: []params.Metric{{Key: "pings", Value: "5", Time: time.Now().UTC()}},
},
}}
_, err := s.adder.AddMetricBatches(batches)
c.Assert(err, jc.ErrorIsNil)
c.Assert(called, jc.IsTrue)
c.Assert(callParams.Batches, gc.DeepEquals, batches)
}
开发者ID:exekias,项目名称:juju,代码行数:29,代码来源:client_test.go
示例13: Subordinates
// Subordinates implements Unit.
func (u *unit) Subordinates() []names.UnitTag {
var subordinates []names.UnitTag
for _, s := range u.Subordinates_ {
subordinates = append(subordinates, names.NewUnitTag(s))
}
return subordinates
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:8,代码来源:unit.go
示例14: TestClaimLeadershipDeniedError
func (s *leadershipSuite) TestClaimLeadershipDeniedError(c *gc.C) {
var ldrMgr stubLeadershipManager
ldrMgr.ClaimLeadershipFn = func(sid, uid string, duration time.Duration) error {
c.Check(sid, gc.Equals, StubServiceNm)
c.Check(uid, gc.Equals, StubUnitNm)
expectDuration := time.Duration(5.001 * float64(time.Second))
checkDurationEquals(c, duration, expectDuration)
return errors.Annotatef(leadership.ErrClaimDenied, "obfuscated")
}
ldrSvc := &leadershipService{LeadershipManager: &ldrMgr, authorizer: &stubAuthorizer{}}
results, err := ldrSvc.ClaimLeadership(params.ClaimLeadershipBulkParams{
Params: []params.ClaimLeadershipParams{
{
ServiceTag: names.NewServiceTag(StubServiceNm).String(),
UnitTag: names.NewUnitTag(StubUnitNm).String(),
DurationSeconds: 5.001,
},
},
})
c.Check(err, jc.ErrorIsNil)
c.Assert(results.Results, gc.HasLen, 1)
c.Check(results.Results[0].Error, jc.Satisfies, params.IsCodeLeadershipClaimDenied)
}
开发者ID:Pankov404,项目名称:juju,代码行数:25,代码来源:leadership_test.go
示例15: TestWatchUnitStorageAttachments
func (s *storageSuite) TestWatchUnitStorageAttachments(c *gc.C) {
resources := common.NewResources()
getCanAccess := func() (common.AuthFunc, error) {
return func(names.Tag) bool {
return true
}, nil
}
unitTag := names.NewUnitTag("mysql/0")
watcher := &mockStringsWatcher{
changes: make(chan []string, 1),
}
watcher.changes <- []string{"storage/0", "storage/1"}
state := &mockStorageState{
watchStorageAttachments: func(u names.UnitTag) state.StringsWatcher {
c.Assert(u, gc.DeepEquals, unitTag)
return watcher
},
}
storage, err := uniter.NewStorageAPI(state, resources, getCanAccess)
c.Assert(err, jc.ErrorIsNil)
watches, err := storage.WatchUnitStorageAttachments(params.Entities{
Entities: []params.Entity{{unitTag.String()}},
})
c.Assert(err, jc.ErrorIsNil)
c.Assert(watches, gc.DeepEquals, params.StringsWatchResults{
Results: []params.StringsWatchResult{{
StringsWatcherId: "1",
Changes: []string{"storage/0", "storage/1"},
}},
})
c.Assert(resources.Get("1"), gc.Equals, watcher)
}
开发者ID:imoapps,项目名称:juju,代码行数:33,代码来源:storage_test.go
示例16: GetPrincipal
// GetPrincipal returns the result of calling PrincipalName() and
// converting it to a tag, on each given unit.
func (u *UniterAPI) GetPrincipal(args params.Entities) (params.StringBoolResults, error) {
result := params.StringBoolResults{
Results: make([]params.StringBoolResult, len(args.Entities)),
}
canAccess, err := u.accessUnit()
if err != nil {
return params.StringBoolResults{}, err
}
for i, entity := range args.Entities {
tag, err := names.ParseUnitTag(entity.Tag)
if err != nil {
result.Results[i].Error = common.ServerError(common.ErrPerm)
continue
}
err = common.ErrPerm
if canAccess(tag) {
var unit *state.Unit
unit, err = u.getUnit(tag)
if err == nil {
principal, ok := unit.PrincipalName()
if principal != "" {
result.Results[i].Result = names.NewUnitTag(principal).String()
}
result.Results[i].Ok = ok
}
}
result.Results[i].Error = common.ServerError(err)
}
return result, nil
}
开发者ID:zhouqt,项目名称:juju,代码行数:32,代码来源:uniter.go
示例17: TestWatchRetryStrategyResultError
func (s *retryStrategySuite) TestWatchRetryStrategyResultError(c *gc.C) {
tag := names.NewUnitTag("wp/1")
var called bool
apiCaller := testing.APICallerFunc(func(objType string, version int, id, request string, arg, response interface{}) error {
called = true
c.Check(objType, gc.Equals, "RetryStrategy")
c.Check(version, gc.Equals, 0)
c.Check(id, gc.Equals, "")
c.Check(request, gc.Equals, "WatchRetryStrategy")
c.Check(arg, gc.DeepEquals, params.Entities{
Entities: []params.Entity{{Tag: tag.String()}},
})
c.Assert(response, gc.FitsTypeOf, ¶ms.NotifyWatchResults{})
result := response.(*params.NotifyWatchResults)
result.Results = []params.NotifyWatchResult{{
Error: ¶ms.Error{
Message: "rigged",
Code: params.CodeNotAssigned,
},
}}
return nil
})
client := retrystrategy.NewClient(apiCaller)
c.Assert(client, gc.NotNil)
w, err := client.WatchRetryStrategy(tag)
c.Assert(called, jc.IsTrue)
c.Assert(err, gc.ErrorMatches, "rigged")
c.Assert(w, gc.IsNil)
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:32,代码来源:retrystrategy_test.go
示例18: TestClaimLeadershipTranslation
func (s *leadershipSuite) TestClaimLeadershipTranslation(c *gc.C) {
var ldrMgr stubLeadershipManager
ldrMgr.ClaimLeadershipFn = func(sid, uid string, duration time.Duration) error {
c.Check(sid, gc.Equals, StubServiceNm)
c.Check(uid, gc.Equals, StubUnitNm)
expectDuration := time.Duration(299.9 * float64(time.Second))
checkDurationEquals(c, duration, expectDuration)
return nil
}
ldrSvc := &leadershipService{LeadershipManager: &ldrMgr, authorizer: &stubAuthorizer{}}
results, err := ldrSvc.ClaimLeadership(params.ClaimLeadershipBulkParams{
Params: []params.ClaimLeadershipParams{
{
ServiceTag: names.NewServiceTag(StubServiceNm).String(),
UnitTag: names.NewUnitTag(StubUnitNm).String(),
DurationSeconds: 299.9,
},
},
})
c.Check(err, jc.ErrorIsNil)
c.Assert(results.Results, gc.HasLen, 1)
c.Check(results.Results[0].Error, gc.IsNil)
}
开发者ID:Pankov404,项目名称:juju,代码行数:25,代码来源:leadership_test.go
示例19: TestRetryStrategyMoreResults
func (s *retryStrategySuite) TestRetryStrategyMoreResults(c *gc.C) {
tag := names.NewUnitTag("wp/1")
var called bool
apiCaller := testing.APICallerFunc(func(objType string, version int, id, request string, arg, response interface{}) error {
called = true
c.Check(objType, gc.Equals, "RetryStrategy")
c.Check(version, gc.Equals, 0)
c.Check(id, gc.Equals, "")
c.Check(request, gc.Equals, "RetryStrategy")
c.Check(arg, gc.DeepEquals, params.Entities{
Entities: []params.Entity{{Tag: tag.String()}},
})
c.Assert(response, gc.FitsTypeOf, ¶ms.RetryStrategyResults{})
result := response.(*params.RetryStrategyResults)
result.Results = make([]params.RetryStrategyResult, 2)
return nil
})
client := retrystrategy.NewClient(apiCaller)
c.Assert(client, gc.NotNil)
retryStrategy, err := client.RetryStrategy(tag)
c.Assert(called, jc.IsTrue)
c.Assert(err, gc.ErrorMatches, "expected 1 result, got 2")
c.Assert(retryStrategy, jc.DeepEquals, params.RetryStrategy{})
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:27,代码来源:retrystrategy_test.go
示例20: checkCanUpgrade
func (st *State) checkCanUpgrade(currentVersion, newVersion string) error {
matchCurrent := "^" + regexp.QuoteMeta(currentVersion) + "-"
matchNew := "^" + regexp.QuoteMeta(newVersion) + "-"
// Get all machines and units with a different or empty version.
sel := bson.D{{"$or", []bson.D{
{{"tools", bson.D{{"$exists", false}}}},
{{"$and", []bson.D{
{{"tools.version", bson.D{{"$not", bson.RegEx{matchCurrent, ""}}}}},
{{"tools.version", bson.D{{"$not", bson.RegEx{matchNew, ""}}}}},
}}},
}}}
var agentTags []string
for _, collection := range []*mgo.Collection{st.machines, st.units} {
var doc struct {
Id string `bson:"_id"`
}
iter := collection.Find(sel).Select(bson.D{{"_id", 1}}).Iter()
for iter.Next(&doc) {
switch collection.Name {
case "machines":
agentTags = append(agentTags, names.NewMachineTag(doc.Id).String())
case "units":
agentTags = append(agentTags, names.NewUnitTag(doc.Id).String())
}
}
if err := iter.Close(); err != nil {
return err
}
}
if len(agentTags) > 0 {
return newVersionInconsistentError(version.MustParse(currentVersion), agentTags)
}
return nil
}
开发者ID:klyachin,项目名称:juju,代码行数:34,代码来源:state.go
注:本文中的github.com/juju/names.NewUnitTag函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论