コード例 #1
0
ファイル: uniter.go プロジェクト: bac/juju
func (u *UniterAPIV3) checkRemoteUnit(relUnit *state.RelationUnit, remoteUnitTag string) (string, error) {
	// Make sure the unit is indeed remote.
	if remoteUnitTag == u.auth.GetAuthTag().String() {
		return "", common.ErrPerm
	}
	// Check remoteUnit is indeed related. Note that we don't want to actually get
	// the *Unit, because it might have been removed; but its relation settings will
	// persist until the relation itself has been removed (and must remain accessible
	// because the local unit's view of reality may be time-shifted).
	tag, err := names.ParseUnitTag(remoteUnitTag)
	if err != nil {
		return "", common.ErrPerm
	}
	remoteUnitName := tag.Id()
	remoteServiceName, err := names.UnitApplication(remoteUnitName)
	if err != nil {
		return "", common.ErrPerm
	}
	rel := relUnit.Relation()
	_, err = rel.RelatedEndpoints(remoteServiceName)
	if err != nil {
		return "", common.ErrPerm
	}
	return remoteUnitName, nil
}
コード例 #2
0
func changeSettings(c *gc.C, ru *state.RelationUnit) {
	node, err := ru.Settings()
	c.Assert(err, jc.ErrorIsNil)
	value, _ := node.Get("value")
	v, _ := value.(int)
	node.Set("value", v+1)
	_, err = node.Write()
	c.Assert(err, jc.ErrorIsNil)
}
コード例 #3
0
ファイル: util_test.go プロジェクト: jiasir/juju
func setSettings(c *gc.C, ru *state.RelationUnit, settings map[string]interface{}) {
	node, err := ru.Settings()
	c.Assert(err, gc.IsNil)
	for _, k := range node.Keys() {
		node.Delete(k)
	}
	node.Update(settings)
	_, err = node.Write()
	c.Assert(err, gc.IsNil)
}
コード例 #4
0
ファイル: uniter.go プロジェクト: bac/juju
func (u *UniterAPIV3) watchOneRelationUnit(relUnit *state.RelationUnit) (params.RelationUnitsWatchResult, error) {
	watch := relUnit.Watch()
	// Consume the initial event and forward it to the result.
	if changes, ok := <-watch.Changes(); ok {
		return params.RelationUnitsWatchResult{
			RelationUnitsWatcherId: u.resources.Register(watch),
			Changes:                changes,
		}, nil
	}
	return params.RelationUnitsWatchResult{}, watcher.EnsureErr(watch)
}
コード例 #5
0
ファイル: uniter_test.go プロジェクト: imoapps/juju
func (s *uniterSuite) assertInScope(c *gc.C, relUnit *state.RelationUnit, inScope bool) {
	ok, err := relUnit.InScope()
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(ok, gc.Equals, inScope)
}
コード例 #6
0
func assertNotJoined(c *gc.C, ru *state.RelationUnit) {
	ok, err := ru.Joined()
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(ok, jc.IsFalse)
}
コード例 #7
0
func assertJoined(c *gc.C, ru *state.RelationUnit) {
	assertInScope(c, ru)
	ok, err := ru.Joined()
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(ok, jc.IsTrue)
}
コード例 #8
0
func assertInScope(c *gc.C, ru *state.RelationUnit) {
	ok, err := ru.InScope()
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(ok, jc.IsTrue)
}
コード例 #9
0
ファイル: relationunit_test.go プロジェクト: jiasir/juju
func assertNotInScope(c *gc.C, ru *state.RelationUnit) {
	assertNotJoined(c, ru)
	ok, err := ru.InScope()
	c.Assert(err, gc.IsNil)
	c.Assert(ok, jc.IsFalse)
}