Merge lp:~jimbaker/pyjuju/new-hook-semantics-2-joined-hook into lp:pyjuju

Proposed by Jim Baker
Status: Merged
Approved by: Gustavo Niemeyer
Approved revision: 182
Merged at revision: 190
Proposed branch: lp:~jimbaker/pyjuju/new-hook-semantics-2-joined-hook
Merge into: lp:pyjuju
Prerequisite: lp:~jimbaker/pyjuju/new-hook-semantics-1-departed-hook
Diff against target: 230 lines (+55/-17)
3 files modified
ensemble/unit/lifecycle.py (+4/-0)
ensemble/unit/tests/test_lifecycle.py (+43/-17)
ensemble/unit/tests/test_workflow.py (+8/-0)
To merge this branch: bzr merge lp:~jimbaker/pyjuju/new-hook-semantics-2-joined-hook
Reviewer Review Type Date Requested Status
Gustavo Niemeyer Approve
Review via email: mp+55384@code.launchpad.net

Description of the change

Adds a <name>-relation-joined hook, while keeping the existing
<name>-relation-changed hook. A similar small change to what was done
for the departed event was made for the joined event in this branch:

          elif change.change_type == "joined":
              hook_names = [
                  "%s-relation-joined" % self._relation_name,
                  "%s-relation-changed" % self._relation_name]

To post a comment you must log in.
Revision history for this message
Gustavo Niemeyer (niemeyer) wrote :

This looks good. +1, but please take care of the pre-requisite branch
before this is merged.

[1]

+ ("#!/bin/bash\n" "echo joined >> %s\n" % (file_path)))

Please remove the parenthesis around file_path here too.

[2]

+ "app-relation-joined", "app-relation-changed",

Please make sure the lists are all evenly organized.

[3]

You'll have to do some changes here due to the pre-requisite branch.

review: Approve
Revision history for this message
Jim Baker (jimbaker) wrote :

On Wed, Apr 6, 2011 at 10:57 AM, Gustavo Niemeyer <email address hidden>wrote:

> Review: Approve
> This looks good. +1, but please take care of the pre-requisite branch
> before this is merged.
>
> [1]
>
> + ("#!/bin/bash\n" "echo joined >> %s\n" % (file_path)))
>
> Please remove the parenthesis around file_path here too.
>
>
Removed in all cases

> [2]
>
> + "app-relation-joined", "app-relation-changed",
>
> Please make sure the lists are all evenly organized.
>
>
Reorganized and commented as with the previous branch

>
> [3]
>
> You'll have to do some changes here due to the pre-requisite branch.
>

Those changes were made

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ensemble/unit/lifecycle.py'
2--- ensemble/unit/lifecycle.py 2011-03-29 17:13:27 +0000
3+++ ensemble/unit/lifecycle.py 2011-03-29 17:13:27 +0000
4@@ -283,6 +283,10 @@
5 hook_names = [
6 "%s-relation-changed" % self._relation_name,
7 "%s-relation-departed" % self._relation_name]
8+ elif change.change_type == "joined":
9+ hook_names = [
10+ "%s-relation-joined" % self._relation_name,
11+ "%s-relation-changed" % self._relation_name]
12 else:
13 hook_names = ["%s-relation-changed" % self._relation_name]
14 else:
15
16=== modified file 'ensemble/unit/tests/test_lifecycle.py'
17--- ensemble/unit/tests/test_lifecycle.py 2011-03-29 17:13:27 +0000
18+++ ensemble/unit/tests/test_lifecycle.py 2011-03-29 17:13:27 +0000
19@@ -224,8 +224,11 @@
20 self.write_hook("start", ("#!/bin/bash\n" "echo hello"))
21 self.write_hook("stop", ("#!/bin/bash\n" "echo goodbye"))
22 self.write_hook(
23+ "%s-relation-joined" % relation_name,
24+ ("#!/bin/bash\n" "echo joined >> %s\n" % (file_path)))
25+ self.write_hook(
26 "%s-relation-changed" % relation_name,
27- ("#!/bin/bash\n" "echo $ENSEMBLE_CHANGE >> %s\n" % (file_path)))
28+ ("#!/bin/bash\n" "echo changed >> %s\n" % (file_path)))
29 self.write_hook(
30 "%s-relation-departed" % relation_name,
31 ("#!/bin/bash\n" "echo departed >> %s\n" % (file_path)))
32@@ -251,13 +254,14 @@
33
34 self.assertTrue(os.path.exists(file_path))
35 self.assertEqual([x.strip() for x in open(file_path).readlines()],
36- ["joined"])
37+ ["joined", "changed"])
38
39 # Queue up our wait condition, of 3 hooks firing
40 hooks_complete = self.wait_on_hook(
41- sequence=["app-relation-changed",
42- "app-relation-changed",
43- "app-relation-changed", "app-relation-departed"])
44+ sequence=[
45+ "app-relation-joined", "app-relation-changed",
46+ "app-relation-changed",
47+ "app-relation-changed", "app-relation-departed"])
48
49 # add another.
50 wordpress2_states = yield self.add_opposite_service_unit(
51@@ -280,7 +284,7 @@
52 yield hooks_complete
53 self.assertEqual(
54 set([x.strip() for x in open(file_path).readlines()]),
55- set(["joined", "joined", "modified", "departed"]))
56+ set(["joined", "changed", "joined", "changed", "changed", "departed"]))
57
58 @inlineCallbacks
59 def test_removed_relation_depart(self):
60@@ -299,7 +303,7 @@
61
62 self.assertTrue(os.path.exists(file_path))
63 self.assertEqual([x.strip() for x in open(file_path).readlines()],
64- ["joined"])
65+ ["joined", "changed"])
66
67 self.assertTrue(self.lifecycle.get_relation_workflow(
68 self.states["relation"].internal_id))
69@@ -320,7 +324,7 @@
70
71 # Verify no notice was recieved for the modify before we where stopped.
72 self.assertEqual([x.strip() for x in open(file_path).readlines()],
73- ["joined"])
74+ ["joined", "changed"])
75
76 # Verify the unit relation lifecycle has been disposed of.
77 self.assertRaises(KeyError,
78@@ -372,7 +376,7 @@
79 # Verify no hooks are executed.
80 yield self.sleep(0.1)
81 self.assertEqual([x.strip() for x in open(file_path)],
82- ["joined", "joined"])
83+ ["joined", "changed", "joined", "changed"])
84
85 # XXX - With scheduler local state recovery, we should get the modify.
86
87@@ -381,11 +385,12 @@
88 sequence=[
89 "start",
90 "app-relation-changed", "app-relation-departed",
91- "app-relation-changed"])
92+ "app-relation-joined", "app-relation-changed"])
93 yield self.lifecycle.start()
94 yield hooks_executed
95 self.assertEqual([x.strip() for x in open(file_path)],
96- ["joined", "joined", "departed", "departed", "joined"])
97+ ["joined", "changed", "joined", "changed",
98+ "changed", "departed", "joined", "changed"])
99
100 @inlineCallbacks
101 def test_lock_start_stop_watch(self):
102@@ -471,6 +476,7 @@
103
104 hook_template = (
105 "#!/bin/bash\n"
106+ "echo %(change_type)s >> %(file_path)s\n"
107 "echo ENSEMBLE_RELATION=$ENSEMBLE_RELATION >> %(file_path)s\n"
108 "echo ENSEMBLE_CHANGE=$ENSEMBLE_CHANGE >> %(file_path)s\n"
109 "echo ENSEMBLE_REMOTE_UNIT=$ENSEMBLE_REMOTE_UNIT >> %(file_path)s")
110@@ -513,16 +519,26 @@
111 yield self.add_opposite_service_unit(self.states)
112
113 file_path = self.makeFile()
114+ self.write_hook("%s-relation-joined" % self.relation_name,
115+ self.hook_template % dict(change_type="joined",
116+ file_path=file_path))
117 self.write_hook("%s-relation-changed" % self.relation_name,
118- self.hook_template % {"file_path": file_path})
119+ self.hook_template % dict(change_type="changed",
120+ file_path=file_path))
121
122 yield self.lifecycle.start()
123- yield self.wait_on_hook("app-relation-changed")
124+ yield self.wait_on_hook(
125+ sequence=["app-relation-joined", "app-relation-changed"])
126 self.assertTrue(os.path.exists(file_path))
127
128 contents = open(file_path).read()
129 self.assertEqual(contents,
130- ("ENSEMBLE_RELATION=app\n"
131+ ("joined\n"
132+ "ENSEMBLE_RELATION=app\n"
133+ "ENSEMBLE_CHANGE=joined\n"
134+ "ENSEMBLE_REMOTE_UNIT=wordpress/0\n"
135+ "changed\n"
136+ "ENSEMBLE_RELATION=app\n"
137 "ENSEMBLE_CHANGE=joined\n"
138 "ENSEMBLE_REMOTE_UNIT=wordpress/0\n"))
139
140@@ -531,8 +547,12 @@
141 """If the unit relation lifecycle is stopped, hooks will no longer
142 be executed."""
143 file_path = self.makeFile()
144+ self.write_hook("%s-relation-joined" % self.relation_name,
145+ self.hook_template % dict(change_type="joined",
146+ file_path=file_path))
147 self.write_hook("%s-relation-changed" % self.relation_name,
148- self.hook_template % {"file_path": file_path})
149+ self.hook_template % dict(change_type="changed",
150+ file_path=file_path))
151
152 # starting is async
153 yield self.lifecycle.start()
154@@ -560,6 +580,7 @@
155 @inlineCallbacks
156 def test_hook_error_handler(self):
157 # use an error handler that completes async.
158+ self.write_hook("app-relation-joined", "#!/bin/bash\nexit 0\n")
159 self.write_hook("app-relation-changed", "#!/bin/bash\nexit 1\n")
160
161 results = []
162@@ -589,6 +610,7 @@
163 output = (
164 "start relation lifecycle",
165 "app: executing change hook",
166+ "app: executing change hook",
167 "app: change hook error: %s '%s/%s': exit code 1." % (
168 "Error processing",
169 self.unit_directory, hook_relative_path),
170@@ -601,14 +623,18 @@
171 """If a relation is departed, the depart hook is executed.
172 """
173 file_path = self.makeFile()
174+ self.write_hook("%s-relation-joined" % self.relation_name,
175+ "#!/bin/bash\n echo joined")
176 self.write_hook("%s-relation-changed" % self.relation_name,
177 "#!/bin/bash\n echo hello")
178 self.write_hook("%s-relation-broken" % self.relation_name,
179- self.hook_template % {"file_path": file_path})
180+ self.hook_template % dict(change_type="broken",
181+ file_path=file_path))
182
183 yield self.lifecycle.start()
184 wordpress_states = yield self.add_opposite_service_unit(self.states)
185- yield self.wait_on_hook("app-relation-changed")
186+ yield self.wait_on_hook(
187+ sequence=["app-relation-joined", "app-relation-changed"])
188 yield self.lifecycle.stop()
189 yield self.relation_manager.remove_relation_state(
190 wordpress_states["relation"])
191
192=== modified file 'ensemble/unit/tests/test_workflow.py'
193--- ensemble/unit/tests/test_workflow.py 2010-12-23 18:40:40 +0000
194+++ ensemble/unit/tests/test_workflow.py 2011-03-29 17:13:27 +0000
195@@ -210,6 +210,8 @@
196 def test_up_down_cycle(self):
197 """The workflow can be transition from up to down, and back.
198 """
199+ self.write_hook("%s-relation-joined" % self.relation_name,
200+ "#!/bin/bash\nexit 0\n")
201 self.write_hook("%s-relation-changed" % self.relation_name,
202 "#!/bin/bash\nexit 0\n")
203
204@@ -253,6 +255,8 @@
205 in the workflow transitioning to the down state.
206 """
207 self.capture_logging("unit.relation.lifecycle", logging.DEBUG)
208+ self.write_hook("%s-relation-joined" % self.relation_name,
209+ "#!/bin/bash\nexit 0\n")
210 self.write_hook("%s-relation-changed" % self.relation_name,
211 "#!/bin/bash\nexit 1\n")
212
213@@ -287,6 +291,8 @@
214 broken hook is executed, and the unit stops responding to relation
215 changes.
216 """
217+ self.write_hook("%s-relation-joined" % self.relation_name,
218+ "#!/bin/bash\necho hello\n")
219 self.write_hook("%s-relation-changed" % self.relation_name,
220 "#!/bin/bash\necho hello\n")
221 self.write_hook("%s-relation-broken" % self.relation_name,
222@@ -326,6 +332,8 @@
223 """A depart hook error, still results in a transition to the
224 departed state with a state variable noting the error."""
225
226+ self.write_hook("%s-relation-joined" % self.relation_name,
227+ "#!/bin/bash\necho hello\n")
228 self.write_hook("%s-relation-changed" % self.relation_name,
229 "#!/bin/bash\necho hello\n")
230 self.write_hook("%s-relation-broken" % self.relation_name,

Subscribers

People subscribed via source and target branches

to status/vote changes: