Merge lp:~canonical-ci-engineering/charms/precise/gunicorn/fix-config-changed-departed into lp:~charmers/charms/precise/gunicorn/trunk

Proposed by Andy Doan
Status: Rejected
Rejected by: Matt Bruzek
Proposed branch: lp:~canonical-ci-engineering/charms/precise/gunicorn/fix-config-changed-departed
Merge into: lp:~charmers/charms/precise/gunicorn/trunk
Diff against target: 65 lines (+13/-8)
2 files modified
hooks/hooks.py (+6/-4)
hooks/tests/test_hooks.py (+7/-4)
To merge this branch: bzr merge lp:~canonical-ci-engineering/charms/precise/gunicorn/fix-config-changed-departed
Reviewer Review Type Date Requested Status
Matt Bruzek (community) Needs Fixing
Evan (community) Approve
Review via email: mp+213338@code.launchpad.net

Description of the change

fix config-changed and wsgi_file_relation_broken hooks

These were depending on "remote unit" for the service name that's
only available in those contexts. This saves the service name so
that config-changed and wsgi_file_relation_broken can properly deal
with the upstart file.

To post a comment you must log in.
Revision history for this message
Evan (ev) wrote :

Can we have a comment in the code for why __unit__ is needed? I want to make sure that when we try to merge back to gunicorn trunk, they understand the rationale behind all the changes without having to endlessly dig through bzr logs.

Otherwise, +1.

review: Approve
Revision history for this message
Simon Davy (bloodearnest) wrote :

Heya, I have a branch pending that fixes this issue, but differently. It also provides support for an upgrade path for those using the older env_extra relation paramter format.

https://code.launchpad.net/~bloodearnest/charms/precise/gunicorn/upgrade-path/+merge/213236

My solution was like yours to just use the gunicorn unit name rather than the remote unit name (which was the original authors design). I did not bother saving it, as it is always available to all gunicorn hooks, but maybe I missed some detail?

Be good to coordinate these landing.

Revision history for this message
Evan (ev) wrote :

Wow, well spotted Simon. Andy, any objections to picking up Simon's change?

Revision history for this message
Andy Doan (doanac) wrote :

> Wow, well spotted Simon. Andy, any objections to picking up Simon's change?

No, I'll take either. My change is slightly different. It still uses the remote-unit for the service name, so the upstart file/service name will continue to have the same name as the current version of the charm. This change uses the local-unit so things will be like "myservice-gunicorn" rather than the prior "myservice-django".

Revision history for this message
Simon Davy (bloodearnest) wrote :

Ah, so it does.

I'm not too bothered on the upstart name either way, tbh. Given that a user shouldn't really need to manually restart gunicorn often, I don't think it matters that much. Slight preference for just using local_unit to reduce the complexity of the charm slightly, but it's not a big deal.

Revision history for this message
Andy Doan (doanac) wrote :

On 04/02/2014 10:54 AM, Simon Davy wrote:
> Ah, so it does.
>
> I'm not too bothered on the upstart name either way, tbh. Given that a user shouldn't really need to manually restart gunicorn often, I don't think it matters that much. Slight preference for just using local_unit to reduce the complexity of the charm slightly, but it's not a big deal.

+1 for me then. I just really want to get a fix upstreamed so my team
doesn't have to carry this patch along.

Revision history for this message
Matt Bruzek (mbruzek) wrote :
review: Needs Fixing
Revision history for this message
Matt Bruzek (mbruzek) wrote :

Hello Andy,

Thanks for your submission this problem was addressed by Simon Davy (bloodearnest) in a different merge propsoal that was merged today. I rejected this merge proposal because you indicated that the fix that bloodearnest came up with would work for your team. Please contact me or reopen the merge proposal if you have anything else to add.

Thanks again,

  - Matt Bruzek

Unmerged revisions

30. By Andy Doan

fix config-changed and wsgi_file_relation_broken hooks

These were depending on "remote unit" for the service name that's
only available in those contexts. This saves the service name so
that config-changed and wsgi_file_relation_broken can properly deal
with the upstart file.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'hooks/hooks.py'
2--- hooks/hooks.py 2014-02-27 14:54:18 +0000
3+++ hooks/hooks.py 2014-03-28 21:08:05 +0000
4@@ -29,8 +29,8 @@
5 return s
6
7
8-def sanitized_service_name():
9- return sanitize(hookenv.remote_unit().split('/')[0])
10+def sanitized_service_name(unit):
11+ return sanitize(unit.split('/')[0])
12
13
14 def upstart_conf_path(name):
15@@ -76,8 +76,10 @@
16
17 relation_data = relations[0]
18
19- service_name = sanitized_service_name()
20+ service_name = sanitized_service_name(relation_data['__unit__'])
21 wsgi_config['unit_name'] = service_name
22+ if os.path.basename(sys.argv[0]) == 'wsgi-file-relation-joined':
23+ hookenv.relation_set(None, {'service_name': service_name})
24
25 project_conf = upstart_conf_path(service_name)
26
27@@ -117,7 +119,7 @@
28
29 @hooks.hook("wsgi_file_relation_broken")
30 def wsgi_file_relation_broken():
31- service_name = sanitized_service_name()
32+ service_name = hookenv.relation_get('service_name', hookenv.local_unit())
33 host.service_stop(service_name)
34 try:
35 os.remove(upstart_conf_path(service_name))
36
37=== modified file 'hooks/tests/test_hooks.py'
38--- hooks/tests/test_hooks.py 2014-02-27 14:54:18 +0000
39+++ hooks/tests/test_hooks.py 2014-03-28 21:08:05 +0000
40@@ -47,7 +47,10 @@
41 # environment context to juju hooks
42
43 self.config = DEFAULTS.copy()
44- self.relation_data = {'working_dir': self.WORKING_DIR}
45+ self.relation_data = {
46+ 'working_dir': self.WORKING_DIR,
47+ '__unit__': 'foo/0'
48+ }
49
50 # intercept all charmsupport usage
51 self.hookenv = self.apply_patch('hooks.hookenv')
52@@ -147,10 +150,10 @@
53 def test_configure_worker_class_gevent(self):
54 self.do_worker_class('gevent')
55
56-
57-
58 @patch('hooks.os.remove')
59- def test_wsgi_file_relation_broken(self, remove):
60+ @patch('hooks.hookenv.relation_get')
61+ def test_wsgi_file_relation_broken(self, relation_get, remove):
62+ relation_get.return_value = self.SERVICE_NAME
63 hooks.wsgi_file_relation_broken()
64 self.host.service_stop.assert_called_once_with(self.SERVICE_NAME)
65 remove.assert_called_once_with(

Subscribers

People subscribed via source and target branches