Merge lp:~freyes/charms/trusty/hacluster/debug-config into lp:~openstack-charmers/charms/trusty/hacluster/next

Proposed by Felipe Reyes
Status: Merged
Merged at revision: 39
Proposed branch: lp:~freyes/charms/trusty/hacluster/debug-config
Merge into: lp:~openstack-charmers/charms/trusty/hacluster/next
Diff against target: 138 lines (+80/-2)
4 files modified
config.yaml (+4/-0)
hooks/hooks.py (+2/-0)
templates/corosync.conf (+2/-2)
unit_tests/test_hacluster_hooks.py (+72/-0)
To merge this branch: bzr merge lp:~freyes/charms/trusty/hacluster/debug-config
Reviewer Review Type Date Requested Status
Billy Olsen Approve
Edward Hope-Morley Approve
Jorge Niedbalski (community) Approve
charmers Pending
Review via email: mp+244728@code.launchpad.net

This proposal supersedes a proposal from 2014-12-15.

Description of the change

Expose a configuration option (debug) to enable corosync debugging.

This is really helpful to get a complete history of corosync decisions to elect the master, fencing, etc.

To post a comment you must log in.
Revision history for this message
Jorge Niedbalski (niedbalski) wrote :

LGTM +1

review: Approve
Revision history for this message
Edward Hope-Morley (hopem) wrote :

lgtm +1

review: Approve
Revision history for this message
Billy Olsen (billy-olsen) wrote :

lgtm +1, thanks Felipe!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'config.yaml'
2--- config.yaml 2014-11-19 15:51:11 +0000
3+++ config.yaml 2014-12-15 13:30:17 +0000
4@@ -90,3 +90,7 @@
5 default: "multicast"
6 description: |
7 Two supported modes are multicast (udp) or unicast (udpu)
8+ debug:
9+ default: False
10+ type: boolean
11+ description: Enable debug logging
12
13=== modified file 'hooks/hooks.py'
14--- hooks/hooks.py 2014-12-08 18:31:37 +0000
15+++ hooks/hooks.py 2014-12-15 13:30:17 +0000
16@@ -127,6 +127,7 @@
17 'ip_version': ip_version,
18 'ha_nodes': get_ha_nodes(),
19 'transport': get_transport(),
20+ 'debug': config('debug'),
21 }
22 if None not in conf.itervalues():
23 return conf
24@@ -144,6 +145,7 @@
25 'ip_version': ip_version,
26 'ha_nodes': get_ha_nodes(),
27 'transport': get_transport(),
28+ 'debug': config('debug'),
29 }
30
31 if config('prefer-ipv6'):
32
33=== modified file 'templates/corosync.conf'
34--- templates/corosync.conf 2014-12-08 18:41:32 +0000
35+++ templates/corosync.conf 2014-12-15 13:30:17 +0000
36@@ -84,9 +84,9 @@
37 to_logfile: no
38 to_syslog: yes
39 syslog_facility: daemon
40- debug: off
41+ debug: {% if debug %}on{% else %}off{% endif %}
42 logger_subsys {
43 subsys: QUORUM
44- debug: off
45+ debug: {% if debug %}on{% else %}off{% endif %}
46 }
47 }
48
49=== modified file 'unit_tests/test_hacluster_hooks.py'
50--- unit_tests/test_hacluster_hooks.py 2014-12-08 20:15:23 +0000
51+++ unit_tests/test_hacluster_hooks.py 2014-12-15 13:30:17 +0000
52@@ -1,10 +1,26 @@
53+from __future__ import print_function
54+
55 import mock
56+import os
57+import re
58+import shutil
59+import tempfile
60 import unittest
61
62 with mock.patch('charmhelpers.core.hookenv.config'):
63 import hooks as hacluster_hooks
64
65
66+def local_log(msg, level='INFO'):
67+ print('[{}] {}'.format(level, msg))
68+
69+
70+def write_file(path, content, *args, **kwargs):
71+ with open(path, 'w') as f:
72+ f.write(content)
73+ f.flush()
74+
75+
76 class SwiftContextTestCase(unittest.TestCase):
77
78 @mock.patch('hooks.config')
79@@ -17,3 +33,59 @@
80
81 mock_config.return_value = 'hafu'
82 self.assertRaises(ValueError, hacluster_hooks.get_transport)
83+
84+
85+@mock.patch('hooks.log', local_log)
86+@mock.patch('hooks.write_file', write_file)
87+class TestCorosyncConf(unittest.TestCase):
88+
89+ def setUp(self):
90+ self.tmpdir = tempfile.mkdtemp()
91+ hacluster_hooks.COROSYNC_CONF = os.path.join(self.tmpdir,
92+ 'corosync.conf')
93+
94+ def tearDown(self):
95+ shutil.rmtree(self.tmpdir)
96+
97+ def test_debug_on(self):
98+ self.check_debug(True)
99+
100+ def test_debug_off(self):
101+ self.check_debug(False)
102+
103+ @mock.patch('hooks.relation_get')
104+ @mock.patch('hooks.related_units')
105+ @mock.patch('hooks.relation_ids')
106+ @mock.patch('hacluster.get_network_address')
107+ @mock.patch('hooks.config')
108+ def check_debug(self, enabled, mock_config, get_network_address,
109+ relation_ids, related_units, relation_get):
110+ cfg = {'debug': enabled,
111+ 'prefer-ipv6': False,
112+ 'corosync_transport': 'udpu',
113+ 'corosync_mcastaddr': 'corosync_mcastaddr'}
114+
115+ def c(k):
116+ return cfg.get(k)
117+
118+ mock_config.side_effect = c
119+ get_network_address.return_value = "127.0.0.1"
120+ relation_ids.return_value = ['foo:1']
121+ related_units.return_value = ['unit-machine-0']
122+ relation_get.return_value = 'iface'
123+
124+ hacluster_hooks.get_ha_nodes = mock.MagicMock()
125+ conf = hacluster_hooks.get_corosync_conf()
126+ self.assertEqual(conf['debug'], enabled)
127+
128+ self.assertTrue(hacluster_hooks.emit_corosync_conf())
129+
130+ with open(hacluster_hooks.COROSYNC_CONF) as fd:
131+ content = fd.read()
132+ if enabled:
133+ pattern = 'debug: on\n'
134+ else:
135+ pattern = 'debug: off\n'
136+
137+ matches = re.findall(pattern, content, re.M)
138+ self.assertEqual(len(matches), 2, str(matches))

Subscribers

People subscribed via source and target branches