Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(3589)

Unified Diff: juju/unit/lifecycle.py

Issue 5845061: juju/control should be aware of subordinates
Patch Set: juju/control should be aware of subordinates Created 13 years ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « juju/state/tests/test_service.py ('k') | juju/unit/tests/test_charm.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: juju/unit/lifecycle.py
=== modified file 'juju/unit/lifecycle.py'
--- juju/unit/lifecycle.py 2012-03-29 22:16:49 +0000
+++ juju/unit/lifecycle.py 2012-04-01 00:48:01 +0000
@@ -13,7 +13,8 @@
from juju.state.hook import (
DepartedRelationHookContext, HookContext, RelationChange)
from juju.state.errors import StopWatcher, UnitRelationStateNotFound
-from juju.state.relation import RelationStateManager, UnitRelationState
+from juju.state.relation import (
+ RelationStateManager, ServiceRelationState, UnitRelationState)
from juju.unit.charm import download_charm
from juju.unit.workflow import RelationWorkflowState
@@ -323,8 +324,8 @@
yield self._unit.clear_relation_resolved()
keys = set(relation_resolved).intersection(self._relations)
- for rel_id in keys:
- workflow = self._relations[rel_id]
+ for internal_rel_id in keys:
+ workflow = self._relations[internal_rel_id]
with (yield workflow.lock()):
state = yield workflow.get_state()
if state != "up":
@@ -413,8 +414,8 @@
lifecycle = UnitRelationLifecycle(
self._client, self._unit.unit_name, unit_relation,
- service_relation.relation_name, self._unit_dir, self._state_dir,
- self._executor)
+ service_relation.relation_ident,
+ self._unit_dir, self._state_dir, self._executor)
workflow = RelationWorkflowState(
self._client, unit_relation, service_relation.relation_name,
@@ -464,8 +465,7 @@
rsm = RelationStateManager(self._client)
relations = yield rsm.get_relations_for_service(self._service)
- relations_by_id = dict(
- (r.internal_relation_id, r) for r in relations)
+ relations_by_id = dict((r.internal_relation_id, r) for r in relations)
with open(self._known_relations_path) as f:
known_relations = yaml.load(f.read())
@@ -484,7 +484,7 @@
relation_info["relation_scope"])
self._relations[relation_id] = workflow
- def _reconstruct_workflow(self, relation_id, relation_name, relation_scope):
+ def _reconstruct_workflow(self, relation_id, relation_ident, relation_scope):
"""Create a RelationWorkflowState which may refer to outdated state.
This means that *if* this service has already departed the relevant
@@ -498,8 +498,9 @@
self._client, self._service.internal_id, self._unit.internal_id,
relation_id, relation_scope)
lifecycle = UnitRelationLifecycle(
- self._client, self._unit.unit_name, unit_relation, relation_name,
+ self._client, self._unit.unit_name, unit_relation, relation_ident,
self._unit_dir, self._state_dir, self._executor)
+ relation_name = relation_ident.split(":")[0]
return RelationWorkflowState(
self._client, unit_relation, relation_name, lifecycle,
self._state_dir)
@@ -530,6 +531,7 @@
def get_environment_from_change(self, env, change):
"""Populate environment with relation change information."""
env["JUJU_RELATION"] = change.relation_name
+ env["JUJU_RELATION_ID"] = change.relation_ident
env["JUJU_REMOTE_UNIT"] = change.unit_name
return env
@@ -555,11 +557,12 @@
discussion of some of the more interesting implementation decisions.
"""
- def __init__(self, client, unit_name, unit_relation, relation_name,
+ def __init__(self, client, unit_name, unit_relation, relation_ident,
unit_dir, state_dir, executor):
self._client = client
self._unit_dir = unit_dir
- self._relation_name = relation_name
+ self._relation_ident = relation_ident
+ self._relation_name = relation_ident.split(":")[0]
self._unit_relation = unit_relation
self._unit_name = unit_name
self._executor = executor
@@ -571,7 +574,7 @@
state_dir, "%s.schedule" % unit_relation.internal_relation_id)
self._scheduler = HookScheduler(
client, self._execute_change_hook, self._unit_relation,
- self._relation_name, unit_name, schedule_path)
+ self._relation_ident, unit_name, schedule_path)
self._watcher = None
@property
@@ -643,11 +646,10 @@
"""
self._log.debug("depart relation lifecycle")
unit_id = self._unit_relation.internal_unit_id
- relation_id = self._unit_relation.internal_relation_id
context = DepartedRelationHookContext(
self._client, self._unit_name, unit_id, self._relation_name,
- relation_id)
- change = RelationChange(self._relation_name, "departed", "")
+ self._unit_relation.internal_relation_id)
+ change = RelationChange(self._relation_ident, "departed", "")
invoker = self._get_invoker(context, change)
hook_name = "%s-relation-broken" % self._relation_name
yield self._execute_hook(invoker, hook_name, change)
« no previous file with comments | « juju/state/tests/test_service.py ('k') | juju/unit/tests/test_charm.py » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b