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
=== modified file 'hooks/hooks.py'
--- hooks/hooks.py 2014-02-27 14:54:18 +0000
+++ hooks/hooks.py 2014-03-28 21:08:05 +0000
@@ -29,8 +29,8 @@
29 return s29 return s
3030
3131
32def sanitized_service_name():32def sanitized_service_name(unit):
33 return sanitize(hookenv.remote_unit().split('/')[0])33 return sanitize(unit.split('/')[0])
3434
3535
36def upstart_conf_path(name):36def upstart_conf_path(name):
@@ -76,8 +76,10 @@
7676
77 relation_data = relations[0]77 relation_data = relations[0]
7878
79 service_name = sanitized_service_name()79 service_name = sanitized_service_name(relation_data['__unit__'])
80 wsgi_config['unit_name'] = service_name80 wsgi_config['unit_name'] = service_name
81 if os.path.basename(sys.argv[0]) == 'wsgi-file-relation-joined':
82 hookenv.relation_set(None, {'service_name': service_name})
8183
82 project_conf = upstart_conf_path(service_name)84 project_conf = upstart_conf_path(service_name)
8385
@@ -117,7 +119,7 @@
117119
118@hooks.hook("wsgi_file_relation_broken")120@hooks.hook("wsgi_file_relation_broken")
119def wsgi_file_relation_broken():121def wsgi_file_relation_broken():
120 service_name = sanitized_service_name()122 service_name = hookenv.relation_get('service_name', hookenv.local_unit())
121 host.service_stop(service_name)123 host.service_stop(service_name)
122 try:124 try:
123 os.remove(upstart_conf_path(service_name))125 os.remove(upstart_conf_path(service_name))
124126
=== modified file 'hooks/tests/test_hooks.py'
--- hooks/tests/test_hooks.py 2014-02-27 14:54:18 +0000
+++ hooks/tests/test_hooks.py 2014-03-28 21:08:05 +0000
@@ -47,7 +47,10 @@
47 # environment context to juju hooks47 # environment context to juju hooks
4848
49 self.config = DEFAULTS.copy()49 self.config = DEFAULTS.copy()
50 self.relation_data = {'working_dir': self.WORKING_DIR}50 self.relation_data = {
51 'working_dir': self.WORKING_DIR,
52 '__unit__': 'foo/0'
53 }
5154
52 # intercept all charmsupport usage55 # intercept all charmsupport usage
53 self.hookenv = self.apply_patch('hooks.hookenv')56 self.hookenv = self.apply_patch('hooks.hookenv')
@@ -147,10 +150,10 @@
147 def test_configure_worker_class_gevent(self):150 def test_configure_worker_class_gevent(self):
148 self.do_worker_class('gevent')151 self.do_worker_class('gevent')
149152
150
151
152 @patch('hooks.os.remove')153 @patch('hooks.os.remove')
153 def test_wsgi_file_relation_broken(self, remove):154 @patch('hooks.hookenv.relation_get')
155 def test_wsgi_file_relation_broken(self, relation_get, remove):
156 relation_get.return_value = self.SERVICE_NAME
154 hooks.wsgi_file_relation_broken()157 hooks.wsgi_file_relation_broken()
155 self.host.service_stop.assert_called_once_with(self.SERVICE_NAME)158 self.host.service_stop.assert_called_once_with(self.SERVICE_NAME)
156 remove.assert_called_once_with(159 remove.assert_called_once_with(

Subscribers

People subscribed via source and target branches