Merge lp:~verterok/charms/trusty/haproxy/restart-rsyslog-after-install into lp:charms/trusty/haproxy

Proposed by Guillermo Gonzalez
Status: Merged
Merged at revision: 99
Proposed branch: lp:~verterok/charms/trusty/haproxy/restart-rsyslog-after-install
Merge into: lp:charms/trusty/haproxy
Diff against target: 196 lines (+54/-17)
8 files modified
Makefile (+3/-3)
config.yaml (+1/-1)
hooks/hooks.py (+7/-1)
hooks/tests/test_config_changed_hooks.py (+31/-5)
hooks/tests/test_install.py (+5/-5)
hooks/tests/test_reverseproxy_hooks.py (+2/-1)
hooks/tests/test_website_hooks.py (+1/-1)
tests/10_deploy_test.py (+4/-0)
To merge this branch: bzr merge lp:~verterok/charms/trusty/haproxy/restart-rsyslog-after-install
Reviewer Review Type Date Requested Status
Kevin W Monroe Approve
Andrew McLeod (community) Approve
Review Queue (community) automated testing Approve
Cory Johns (community) Needs Fixing
Review via email: mp+268981@code.launchpad.net

Commit message

Update default global_log and add a restart of rsyslog at the end of install_hook to make logging work by default.

Description of the change

Due to bug: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=790871, after installing the haproxy package we end up without getting any logs to rsyslog.
This branch restarts rsyslog service at the end of install_hook.
Also, for logging to work out of the box, I had to change the default global_log config to use /dev/log instead of 127.0.0.1

To post a comment you must log in.
Revision history for this message
Andrew McLeod (admcleod) wrote :

Hi Guillermo,

I manually deployed as per the amulet test and: haproxy restart worked, socketfile defined in /etc/rsyslog.d/haproxy.conf exists, /var/log/haproxy.log exists,

However, I ran into problems with running bundletester against this update:

Checking for Python syntax...
/tmp/bundletester-DsZsMg/haproxy/hooks/tests/test_reverseproxy_hooks.py:17:80: E501 line too long (101 > 79 characters)
make: *** [lint] Error 1

I fixed this manually and then ran into this:

http://pastebin.ubuntu.com/12207030/

I managed to get past these issues once (randomly), and although 49-haproxy.conf exists and the restart occurs according to debug logs, there is no socketfile and no /var/log/haproxy.log.

http://pastebin.ubuntu.com/12207109/ (clock differences in container and local machine)

Looks like its probably just a test problem which needs to be resolved

review: Needs Fixing
Revision history for this message
Guillermo Gonzalez (verterok) wrote :

Hi,
Thanks for the prompt review.
Will work on fixing those issues, marking this as work in progress.

Cheers,

Revision history for this message
Guillermo Gonzalez (verterok) wrote :

Fixed some lint issues and install test to patch hooks.lsb_release (to make it work on != trusty).
Also had to change the Makefile to just install dependencies from the archive, as the pypi ones were not working.

Installed bundletester and everything seems to work, didn't changed anything related to this MP :/

The logs of bundleteser run: http://paste.ubuntu.com/12245509/

And the log file is there, also the socket: http://paste.ubuntu.com/12245510/

Let me know if I missed something.

Cheers,

Revision history for this message
Kevin W Monroe (kwmonroe) wrote :

Hey Guillermo, thanks for the work to make haproxy better! I tried to review your changes, but could not get the tests to pass. I tried 'make tests', '.venv/bin/bundletester -l DEBUG', and 'bundletester -l DEBUG' (to use my system bundletester vs the .venv version). In all three cases, I get the following when make hits the 'test' target:

http://paste.ubuntu.com/12263768/

Does this look familiar to you? I'm curious how you were able to get a successful run when mine is failing so miserably. I'm reviewing as 'Needs Fixing' for now, but hope there's a simple environment difference that I just don't have.

review: Needs Fixing
Revision history for this message
Guillermo Gonzalez (verterok) wrote :

Hi Kevin,

> Hey Guillermo, thanks for the work to make haproxy better! I tried to review
> your changes, but could not get the tests to pass. I tried 'make tests',
> '.venv/bin/bundletester -l DEBUG', and 'bundletester -l DEBUG' (to use my
> system bundletester vs the .venv version). In all three cases, I get the
> following when make hits the 'test' target:
>
> http://paste.ubuntu.com/12263768/
>
> Does this look familiar to you? I'm curious how you were able to get a
> successful run when mine is failing so miserably. I'm reviewing as 'Needs
> Fixing' for now, but hope there's a simple environment difference that I just
> don't have.

I'm running make test in vivid (host) and trusty (lxc), the trusty lxc is a vanialla (just created for this)

The bundletester run is done using the version from pypi (via the virtualenv), in the vivid host using the local provider.

Hope this helps, if not please let me know in what environment you'r running make test and I'll try to replicate.

One thing that might help, rm .venv; and then make test.

Cheers

104. By Guillermo Gonzalez

- fix tests to work latest mock version
- add python-yaml dep

Revision history for this message
Guillermo Gonzalez (verterok) wrote :

Just pushed some fixes to the tests to work with both mock versions trusty/vivid and pypi

105. By Guillermo Gonzalez

Rework rsyslog restart when installing/updating haproxy, required when changing the source config and the package is down|upgraded.

Revision history for this message
Cory Johns (johnsca) wrote :

Guillermo,

There was an outstanding lint error, and when running the 10_deploy_test.py the haproxy unit went into an error state on config-changed, even though the test passed.

The error was due to your change using the wrong indentation level and changing the logic of the surrounding if / else block. The test didn't pick it up because it was missing calls to d.sentry.wait().

I've submitted an MP with all of these issues fixed, and once that is merged, I'd give this change my +1: https://code.launchpad.net/~johnsca/charms/trusty/haproxy/verterok-restart-rsyslog-after-install/+merge/273867

review: Needs Fixing
106. By Cory Johns

Fixed config-changed hook failure, test not catching aforementioned error, and minor lint issue.

107. By Guillermo Gonzalez

move rsyslog restart condition outside of the check if/else block

108. By Guillermo Gonzalez

fix test to avoid restarting host rsyslog

Revision history for this message
Guillermo Gonzalez (verterok) wrote :

Pushed a fix for the upgrade-charm case, moved the restart block outside the last if/else.
Also fixed a test that was trying to restart the host rsyslog

P.S: tested on vivid using: make buid; source .venv/bin/activate; bundletester

Revision history for this message
Review Queue (review-queue) wrote :

This item has failed automated testing! Results available here http://juju-ci.vapour.ws:8080/job/charm-bundle-test-lxc/1408/

review: Needs Fixing (automated testing)
Revision history for this message
Review Queue (review-queue) wrote :

The results (PASS) are in and available here: http://juju-ci.vapour.ws:8080/job/charm-bundle-test-hp/1119/

review: Approve (automated testing)
Revision history for this message
Review Queue (review-queue) wrote :

The results (PASS) are in and available here: http://juju-ci.vapour.ws:8080/job/charm-bundle-test-aws/1419/

review: Approve (automated testing)
Revision history for this message
Andrew McLeod (admcleod) wrote :

Hi Guillermo,

I've manually bundletested this, everything passed first time - I was then able to generate live http traffic and watch it being logged into an rsyslog handled file, so the restart of rsyslog was successful.

Approve

review: Approve
Revision history for this message
Kevin W Monroe (kwmonroe) wrote :

Hi Guillermo,

In juju-1.25, the first unit number for a service may not always be 0. If you deploy haproxy for the first time, you'll get haproxy/0. If you then destroy haproxy and re-deploy it, you'll get haproxy/1. Because of this, I tweaked your 10_deploy_test.py like this:

-haproxy_unit = d.sentry.unit['haproxy/0']
+haproxy_unit = d.sentry['haproxy'][0]

-apache_unit = d.sentry.unit['apache2/0']
+apache_unit = d.sentry['apache2'][0]

-apache_unit2 = d.sentry.unit['apache2/1']
+apache_unit2 = d.sentry['apache2'][1]

The [0] bracket notation ensures you always get the 1st unit; similarly, [1] gives you the 2nd unit, no matter what the actual unit number may be.

I also added python-flake8 to your list of apt packages to make sure lint would be successful on systems without flake8.

Since these were such trivial changes, I made them while merging into the promulgated haproxy charm. The charm store should have an updated haproxy shortly that contains your changes + these tweaks.

Everything LGTM, so a big thanks to you for this proposal and for your patience during the review process!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Makefile'
2--- Makefile 2015-05-15 16:54:14 +0000
3+++ Makefile 2015-11-04 14:12:30 +0000
4@@ -14,13 +14,13 @@
5 @charm proof
6
7 .venv:
8- sudo apt-get install -y python-apt python-virtualenv python-jinja2
9+ sudo apt-get install -y python-apt python-virtualenv python-jinja2 python-mock python-yaml python-testtools python-nose python-yaml
10 virtualenv .venv --system-site-packages
11- .venv/bin/pip install -I nose testtools mock pyyaml
12+ .venv/bin/pip install bundletester
13
14 test: .venv
15 @echo Starting tests...
16- @CHARM_DIR=$(CHARM_DIR) $(TEST_PREFIX) .venv/bin/nosetests -s $(TEST_DIR)
17+ @CHARM_DIR=$(CHARM_DIR) $(TEST_PREFIX) nosetests -s $(TEST_DIR)
18
19 lint:
20 @echo Checking for Python syntax...
21
22=== modified file 'config.yaml'
23--- config.yaml 2015-08-17 12:58:35 +0000
24+++ config.yaml 2015-11-04 14:12:30 +0000
25@@ -1,6 +1,6 @@
26 options:
27 global_log:
28- default: "127.0.0.1 local0, 127.0.0.1 local1 notice"
29+ default: "/dev/log local0, /dev/log local1 notice"
30 type: string
31 description: Global log line ( multiples ... comma separated list )
32 global_maxconn:
33
34=== modified file 'hooks/hooks.py'
35--- hooks/hooks.py 2015-10-16 09:39:42 +0000
36+++ hooks/hooks.py 2015-11-04 14:12:30 +0000
37@@ -14,7 +14,7 @@
38 from itertools import izip, tee
39 from operator import itemgetter
40
41-from charmhelpers.core.host import pwgen, lsb_release
42+from charmhelpers.core.host import pwgen, lsb_release, service_restart
43 from charmhelpers.core.hookenv import (
44 log,
45 config as config_get,
46@@ -963,6 +963,12 @@
47 # to be broken.
48 log("HAProxy configuration check failed, exiting.")
49 sys.exit(1)
50+ if config_data.changed("global_log") or config_data.changed("source"):
51+ # restart rsyslog to pickup haproxy rsyslog config
52+ # This could be removed once the following bug is fixed in the haproxy
53+ # package:
54+ # https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=790871
55+ service_restart("rsyslog")
56
57
58 def start_hook():
59
60=== modified file 'hooks/tests/test_config_changed_hooks.py'
61--- hooks/tests/test_config_changed_hooks.py 2015-04-14 14:21:45 +0000
62+++ hooks/tests/test_config_changed_hooks.py 2015-11-04 14:12:30 +0000
63@@ -3,7 +3,7 @@
64 import os
65
66 from testtools import TestCase
67-from mock import patch
68+from mock import patch, call
69
70 import hooks
71 from utils_for_tests import patch_open
72@@ -92,10 +92,36 @@
73 config_data = self.config_get()
74 config_data.changed.return_value = True
75 _notify_reverseproxy = self.patch_hook("_notify_reverseproxy")
76-
77- hooks.config_changed()
78- config_data.changed.assert_called_once_with("ssl_cert")
79- _notify_reverseproxy.assert_called_once()
80+ service_restart = self.patch_hook('service_restart')
81+
82+ hooks.config_changed()
83+ self.assertIn(call('ssl_cert'), config_data.changed.mock_calls)
84+ _notify_reverseproxy.assert_called_once_with()
85+ service_restart.assert_called_once_with('rsyslog')
86+
87+ def test_config_changed_restart_rsyslog(self):
88+ """
89+ If the gloabl_log or source config value changes, rsyslog is
90+ restarted
91+ """
92+ config_data = self.config_get()
93+ called = []
94+
95+ def changed(a):
96+ if a in called or a == 'ssl_cert':
97+ return False
98+ called.append(a)
99+ return True
100+
101+ config_data.changed.side_effect = changed
102+ service_restart = self.patch_hook('service_restart')
103+
104+ hooks.config_changed()
105+ self.assertIn(call('global_log'), config_data.changed.mock_calls)
106+ service_restart.assert_called_once_with('rsyslog')
107+ hooks.config_changed()
108+ self.assertIn(call('source'), config_data.changed.mock_calls)
109+ service_restart.assert_called_with('rsyslog')
110
111
112 class HelpersTest(TestCase):
113
114=== modified file 'hooks/tests/test_install.py'
115--- hooks/tests/test_install.py 2015-02-09 12:53:57 +0000
116+++ hooks/tests/test_install.py 2015-11-04 14:12:30 +0000
117@@ -53,7 +53,7 @@
118
119 def test_add_source(self):
120 hooks.install_hook()
121- self.config_get.assert_called_once()
122+ self.config_get.assert_called_once_with()
123 self.add_source.assert_called_once_with(
124 self.config_get.return_value.get("source"),
125 self.config_get.return_value.get("key"))
126@@ -65,12 +65,12 @@
127 def test_add_source_with_backports(self):
128 self.config_get.return_value = {
129 'source': 'backports', 'package_status': 'install'}
130- with patch("charmhelpers.core.host.lsb_release") as lsb_release:
131+ with patch("hooks.lsb_release") as lsb_release:
132 lsb_release.return_value = {'DISTRIB_CODENAME': 'trusty'}
133 with patch("hooks.add_backports_preferences") as add_apt_prefs:
134- add_apt_prefs.assert_called_once()
135 hooks.install_hook()
136- self.config_get.assert_called_once()
137+ add_apt_prefs.assert_called_once_with('trusty')
138+ self.config_get.assert_called_once_with()
139 source = ("deb http://archive.ubuntu.com/ubuntu trusty-backports "
140 "main restricted universe multiverse")
141 self.add_source.assert_called_once_with(
142@@ -79,7 +79,7 @@
143
144 def test_ensures_package_status(self):
145 hooks.install_hook()
146- self.config_get.assert_called_once()
147+ self.config_get.assert_called_once_with()
148 self.ensure_package_status.assert_called_once_with(
149 hooks.service_affecting_packages,
150 self.config_get.return_value["package_status"])
151
152=== modified file 'hooks/tests/test_reverseproxy_hooks.py'
153--- hooks/tests/test_reverseproxy_hooks.py 2015-08-17 12:58:35 +0000
154+++ hooks/tests/test_reverseproxy_hooks.py 2015-11-04 14:12:30 +0000
155@@ -14,7 +14,8 @@
156 super(ReverseProxyRelationTest, self).setUp()
157
158 self.config_get = self.patch_hook("config_get")
159- self.config_get.return_value = {"monitoring_port": "10000", "peering_mode": "active-passive"}
160+ self.config_get.return_value = {"monitoring_port": "10000",
161+ "peering_mode": "active-passive"}
162 self.relations_of_type = self.patch_hook("relations_of_type")
163 self.get_config_services = self.patch_hook("get_config_services")
164 self.log = self.patch_hook("log")
165
166=== modified file 'hooks/tests/test_website_hooks.py'
167--- hooks/tests/test_website_hooks.py 2013-11-04 13:09:04 +0000
168+++ hooks/tests/test_website_hooks.py 2015-11-04 14:12:30 +0000
169@@ -146,4 +146,4 @@
170 relation_id="website:1", port="4242", hostname="bar.local",
171 all_services=""),
172 ])
173- self.log.assert_not_called()
174+ self.log.assert_has_calls([call("No services configured, exiting.")])
175
176=== modified file 'tests/10_deploy_test.py'
177--- tests/10_deploy_test.py 2015-03-18 20:28:29 +0000
178+++ tests/10_deploy_test.py 2015-11-04 14:12:30 +0000
179@@ -105,6 +105,8 @@
180 'crts': ['DEFAULT'],
181 'servers': [['apache', apache_private, 80, 'maxconn 50']]}])
182 })
183+time.sleep(10)
184+d.sentry.wait(seconds)
185
186 # We need a retry loop here, since there's no way to tell when the new
187 # configuration is in place.
188@@ -151,6 +153,8 @@
189 ['apache2', apache_private2, 80, 'maxconn 50']]}
190 ]}])
191 })
192+time.sleep(10)
193+d.sentry.wait(seconds)
194
195 # Let's exercise our URL-based routing by trying to fetch a URL that will
196 # only work for the second apache unit (which is configured as server

Subscribers

People subscribed via source and target branches

to all changes: