Merge ~hloeung/content-cache-charm:nginx-config into content-cache-charm:master

Proposed by Haw Loeung
Status: Merged
Approved by: John Losito
Approved revision: 1ce5dbff8939343f15fbb6de24cc2b4835a4efdb
Merged at revision: 85c6c683af73c31c16c75dfcabe41acc07e538b3
Proposed branch: ~hloeung/content-cache-charm:nginx-config
Merge into: content-cache-charm:master
Diff against target: 50 lines (+20/-1)
2 files modified
reactive/content_cache.py (+13/-1)
tests/unit/test_content_cache.py (+7/-0)
Reviewer Review Type Date Requested Status
John Losito (community) Approve
Canonical IS Reviewers Pending
Review via email: mp+380329@code.launchpad.net

Commit message

Fixed where initial install hook fails because Nginx listens to TCP/80 by default

To post a comment you must log in.
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Unable to determine commit message from repository - please click "Set commit message" and enter the commit message manually.

Revision history for this message
John Losito (jlosito) :
review: Approve
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Change successfully merged at revision 85c6c683af73c31c16c75dfcabe41acc07e538b3

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/reactive/content_cache.py b/reactive/content_cache.py
2index b778711..558275f 100644
3--- a/reactive/content_cache.py
4+++ b/reactive/content_cache.py
5@@ -83,7 +83,9 @@ def service_start_or_reload():
6 time.sleep(rnd)
7
8 for name in services:
9- if reactive.is_flag_set('content_cache.{}.restart-required'.format(name)):
10+ if reactive.is_flag_set('content_cache.{}.configured'.format(name)) and reactive.is_flag_set(
11+ 'content_cache.{}.restart-required'.format(name)
12+ ):
13 status.maintenance('Reloading {}...'.format(name))
14 host.service_reload(name)
15 reactive.clear_flag('content_cache.{}.restart-required'.format(name))
16@@ -115,6 +117,16 @@ def configure_nginx_metrics(ngx_conf, enable_prometheus_metrics):
17 return changed
18
19
20+@reactive.when_not('content_cache.nginx.installed')
21+def stop_nginx():
22+ # Just by installing the Nginx package, it has a default site configured
23+ # and listens on TCP/80. This causes HAProxy to fail until such time as
24+ # Nginx is configured and reloaded. We'll just stop it here.
25+ host.service_stop('nginx')
26+ reactive.set_flag('content_cache.nginx.installed')
27+
28+
29+@reactive.when('content_cache.nginx.installed')
30 @reactive.when_not('content_cache.nginx.configured')
31 def configure_nginx(conf_path=None):
32 status.maintenance('setting up Nginx as caching layer')
33diff --git a/tests/unit/test_content_cache.py b/tests/unit/test_content_cache.py
34index 623b091..9e1de72 100644
35--- a/tests/unit/test_content_cache.py
36+++ b/tests/unit/test_content_cache.py
37@@ -141,6 +141,13 @@ class TestCharm(unittest.TestCase):
38 service_start.assert_called_with('nginx')
39 service_reload.assert_not_called()
40
41+ @mock.patch('charms.reactive.set_flag')
42+ @mock.patch('charmhelpers.core.host.service_stop')
43+ def test_stop_nginx(self, service_stop, set_flag):
44+ content_cache.stop_nginx()
45+ service_stop.assert_called_with('nginx')
46+ set_flag.assert_called_once_with('content_cache.nginx.installed')
47+
48 @mock.patch('charms.reactive.clear_flag')
49 @mock.patch('reactive.content_cache.update_logrotate')
50 def test_configure_nginx_no_sites(self, logrotation, clear_flag):

Subscribers

People subscribed via source and target branches