Merge lp:~danilo/charms/trusty/percona-cluster/autodetect-vip-cidr into lp:~openstack-charmers-archive/charms/trusty/percona-cluster/next

Proposed by Данило Шеган
Status: Merged
Merged at revision: 77
Proposed branch: lp:~danilo/charms/trusty/percona-cluster/autodetect-vip-cidr
Merge into: lp:~openstack-charmers-archive/charms/trusty/percona-cluster/next
Diff against target: 117 lines (+67/-4)
2 files modified
hooks/percona_hooks.py (+4/-3)
unit_tests/test_percona_hooks.py (+63/-1)
To merge this branch: bzr merge lp:~danilo/charms/trusty/percona-cluster/autodetect-vip-cidr
Reviewer Review Type Date Requested Status
OpenStack Charmers Pending
Review via email: mp+272813@code.launchpad.net

Description of the change

Make percona-cluster auto-detect vip_cidr and vip_iface like other charms

percona-cluster is currently behaving differently from other OpenStack charms: it does not attempt to auto-detect a VIP CIDR at all.

This branch (which is mostly by Andreas) changes that to behave like all other charms: autodetect first, if it fails, use the passed-in config value.

I've added a few unit tests for all the cases.

To post a comment you must log in.
Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_lint_check #11026 percona-cluster-next for danilo mp272813
    LINT OK: passed

Build: http://10.245.162.77:8080/job/charm_lint_check/11026/

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_unit_test #10236 percona-cluster-next for danilo mp272813
    UNIT OK: passed

Build: http://10.245.162.77:8080/job/charm_unit_test/10236/

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_amulet_test #6879 percona-cluster-next for danilo mp272813
    AMULET OK: passed

Build: http://10.245.162.77:8080/job/charm_amulet_test/6879/

Revision history for this message
Ryan Beisner (1chb1n) wrote :

FYI, full amulet output: http://paste.ubuntu.com/12619610/

Be aware, that the percona-cluster amulet tests are on my list to refactor and extend. Until then, these existing tests do exercise some basic functionality, on Trusty only.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'hooks/percona_hooks.py'
2--- hooks/percona_hooks.py 2015-09-22 13:54:27 +0000
3+++ hooks/percona_hooks.py 2015-09-29 15:46:38 +0000
4@@ -75,6 +75,7 @@
5 from charmhelpers.payload.execd import execd_preinstall
6 from charmhelpers.contrib.network.ip import (
7 get_address_in_network,
8+ get_iface_for_address,
9 get_netmask_for_address,
10 get_ipv6_addr,
11 is_address_in_network,
12@@ -535,8 +536,8 @@
13 @hooks.hook('ha-relation-joined')
14 def ha_relation_joined():
15 vip = config('vip')
16- vip_iface = config('vip_iface')
17- vip_cidr = config('vip_cidr')
18+ vip_iface = get_iface_for_address(vip) or config('vip_iface')
19+ vip_cidr = get_netmask_for_address(vip) or config('vip_cidr')
20 corosync_bindiface = config('ha-bindiface')
21 corosync_mcastport = config('ha-mcastport')
22
23@@ -547,7 +548,7 @@
24 if config('prefer-ipv6'):
25 res_mysql_vip = 'ocf:heartbeat:IPv6addr'
26 vip_params = 'params ipv6addr="%s" cidr_netmask="%s" nic="%s"' % \
27- (vip, get_netmask_for_address(vip), vip_iface)
28+ (vip, vip_cidr, vip_iface)
29 else:
30 res_mysql_vip = 'ocf:heartbeat:IPaddr2'
31 vip_params = 'params ip="%s" cidr_netmask="%s" nic="%s"' % \
32
33=== modified file 'unit_tests/test_percona_hooks.py'
34--- unit_tests/test_percona_hooks.py 2015-09-15 23:55:31 +0000
35+++ unit_tests/test_percona_hooks.py 2015-09-29 15:46:38 +0000
36@@ -9,7 +9,9 @@
37 'get_db_helper',
38 'relation_ids',
39 'relation_set',
40- 'update_nrpe_config']
41+ 'update_nrpe_config',
42+ 'get_iface_for_address',
43+ 'get_netmask_for_address']
44
45
46 class TestHaRelation(CharmTestCase):
47@@ -35,6 +37,8 @@
48 attrs = {'get_mysql_password.return_value': password}
49 helper.configure_mock(**attrs)
50 self.get_db_helper.return_value = helper
51+ self.get_netmask_for_address.return_value = None
52+ self.get_iface_for_address.return_value = None
53 self.test_config.set('vip', '10.0.3.3')
54 self.test_config.set('sst-password', password)
55
56@@ -65,3 +69,61 @@
57 corosync_mcastport=f('ha-mcastport'), resources=resources,
58 resource_params=resource_params, groups=groups,
59 clones=clones, colocations=colocations, locations=locations)
60+
61+ def test_resource_params_vip_cidr_iface_autodetection(self):
62+ """
63+ Auto-detected values for vip_cidr and vip_iface are used to configure
64+ VIPs, even when explicit config options are provided.
65+ """
66+ self.relation_ids.return_value = ['ha:1']
67+ helper = mock.Mock()
68+ self.get_db_helper.return_value = helper
69+ self.get_netmask_for_address.return_value = '20'
70+ self.get_iface_for_address.return_value = 'eth1'
71+ self.test_config.set('vip', '10.0.3.3')
72+ self.test_config.set('vip_cidr', '16')
73+ self.test_config.set('vip_iface', 'eth0')
74+
75+ def f(k):
76+ return self.test_config.get(k)
77+
78+ self.config.side_effect = f
79+ hooks.ha_relation_joined()
80+
81+ resource_params = {'res_mysql_vip': ('params ip="10.0.3.3" '
82+ 'cidr_netmask="20" '
83+ 'nic="eth1"'),
84+ 'res_mysql_monitor':
85+ hooks.RES_MONITOR_PARAMS % {'sstpass': 'None'}}
86+
87+ call_args, call_kwargs = self.relation_set.call_args
88+ self.assertEqual(resource_params, call_kwargs['resource_params'])
89+
90+ def test_resource_params_no_vip_cidr_iface_autodetection(self):
91+ """
92+ When autodetecting vip_cidr and vip_iface fails, values from
93+ vip_cidr and vip_iface config options are used instead.
94+ """
95+ self.relation_ids.return_value = ['ha:1']
96+ helper = mock.Mock()
97+ self.get_db_helper.return_value = helper
98+ self.get_netmask_for_address.return_value = None
99+ self.get_iface_for_address.return_value = None
100+ self.test_config.set('vip', '10.0.3.3')
101+ self.test_config.set('vip_cidr', '16')
102+ self.test_config.set('vip_iface', 'eth1')
103+
104+ def f(k):
105+ return self.test_config.get(k)
106+
107+ self.config.side_effect = f
108+ hooks.ha_relation_joined()
109+
110+ resource_params = {'res_mysql_vip': ('params ip="10.0.3.3" '
111+ 'cidr_netmask="16" '
112+ 'nic="eth1"'),
113+ 'res_mysql_monitor':
114+ hooks.RES_MONITOR_PARAMS % {'sstpass': 'None'}}
115+
116+ call_args, call_kwargs = self.relation_set.call_args
117+ self.assertEqual(resource_params, call_kwargs['resource_params'])

Subscribers

People subscribed via source and target branches