Merge lp:~freyes/charms/trusty/hacluster/add-location into lp:~openstack-charmers/charms/trusty/hacluster/next

Proposed by Felipe Reyes
Status: Merged
Merged at revision: 42
Proposed branch: lp:~freyes/charms/trusty/hacluster/add-location
Merge into: lp:~openstack-charmers/charms/trusty/hacluster/next
Diff against target: 200 lines (+108/-7)
4 files modified
.bzrignore (+1/-0)
hooks/hooks.py (+17/-7)
setup.cfg (+6/-0)
unit_tests/test_hacluster_hooks.py (+84/-0)
To merge this branch: bzr merge lp:~freyes/charms/trusty/hacluster/add-location
Reviewer Review Type Date Requested Status
Jorge Niedbalski Pending
Review via email: mp+252127@code.launchpad.net

This proposal supersedes a proposal from 2015-03-06.

Description of the change

Dear OpenStack Charmers,

Add 'location' parameter to define location rules[0]. Fixes bug #1428850, and it's to fix bug #1426508

Having this consumers can define rules like "grp_percona_cluster rule inf: writable eq 1" which mean "the percona cluster vip has to be always running on a node that has the 'writable' property set to 1", in this example mysql_monitor agent will take care of check the state of percona and change the properties to reflect their actual state.

Best,

[0] http://clusterlabs.org/doc/en-US/Pacemaker/1.1-crmsh/html/Clusters_from_Scratch/_specifying_a_preferred_location.html

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

Felipe,

Thanks for this patch. Mind to add a test for covering your change?

review: Needs Fixing
Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote : Posted in a previous version of this proposal

charm_lint_check #2488 hacluster-next for freyes mp252022
    LINT OK: passed

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

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote : Posted in a previous version of this proposal

charm_unit_test #2278 hacluster-next for freyes mp252022
    UNIT OK: passed

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

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote : Posted in a previous version of this proposal

charm_amulet_test #2360 hacluster-next for freyes mp252022
    AMULET FAIL: amulet-test missing

AMULET Results (max last 2 lines):
INFO:root:Search string not found in makefile target commands.
ERROR:root:No make target was executed.

Full amulet test output: http://paste.ubuntu.com/10543782/
Build: http://10.245.162.77:8080/job/charm_amulet_test/2360/

Revision history for this message
Felipe Reyes (freyes) wrote : Posted in a previous version of this proposal

@niedbalski, added a unit test as suggested :) thanks to it the coverage went from 23% to 51%, so thanks for encourage me to add it.

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

charm_lint_check #2492 hacluster-next for freyes mp252127
    LINT OK: passed

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

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

charm_amulet_test #2364 hacluster-next for freyes mp252127
    AMULET FAIL: amulet-test missing

AMULET Results (max last 2 lines):
INFO:root:Search string not found in makefile target commands.
ERROR:root:No make target was executed.

Full amulet test output: http://paste.ubuntu.com/10553671/
Build: http://10.245.162.77:8080/job/charm_amulet_test/2364/

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

charm_unit_test #2282 hacluster-next for freyes mp252127
    UNIT OK: passed

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '.bzrignore'
2--- .bzrignore 2014-10-12 08:12:10 +0000
3+++ .bzrignore 2015-03-06 15:20:06 +0000
4@@ -1,1 +1,2 @@
5 bin
6+.coverage
7
8=== modified file 'hooks/hooks.py'
9--- hooks/hooks.py 2014-12-17 17:17:29 +0000
10+++ hooks/hooks.py 2015-03-06 15:20:06 +0000
11@@ -350,6 +350,7 @@
12 orders = parse_data(relid, unit, 'orders')
13 colocations = parse_data(relid, unit, 'colocations')
14 clones = parse_data(relid, unit, 'clones')
15+ locations = parse_data(relid, unit, 'locations')
16 init_services = parse_data(relid, unit, 'init_services')
17 else:
18 log('Related to {} ha services'.format(len(relids)))
19@@ -374,7 +375,7 @@
20 # from the oldest peer unit.
21 if oldest_peer(peer_units()):
22 log('Deleting Resources')
23- log(str(delete_resources))
24+ log(delete_resources)
25 for res_name in delete_resources:
26 if pcmk.crm_opt_exists(res_name):
27 log('Stopping and deleting resource %s' % res_name)
28@@ -383,7 +384,7 @@
29 pcmk.commit('crm -w -F configure delete %s' % res_name)
30
31 log('Configuring Resources')
32- log(str(resources))
33+ log(resources)
34 for res_name, res_type in resources.iteritems():
35 # disable the service we are going to put in HA
36 if res_type.split(':')[0] == "lsb":
37@@ -415,7 +416,7 @@
38 pcmk.commit(cmd)
39
40 log('Configuring Groups')
41- log(str(groups))
42+ log(groups)
43 for grp_name, grp_params in groups.iteritems():
44 if not pcmk.crm_opt_exists(grp_name):
45 cmd = 'crm -w -F configure group %s %s' % (grp_name,
46@@ -424,7 +425,7 @@
47 log('%s' % cmd)
48
49 log('Configuring Master/Slave (ms)')
50- log(str(ms))
51+ log(ms)
52 for ms_name, ms_params in ms.iteritems():
53 if not pcmk.crm_opt_exists(ms_name):
54 cmd = 'crm -w -F configure ms %s %s' % (ms_name, ms_params)
55@@ -432,7 +433,7 @@
56 log('%s' % cmd)
57
58 log('Configuring Orders')
59- log(str(orders))
60+ log(orders)
61 for ord_name, ord_params in orders.iteritems():
62 if not pcmk.crm_opt_exists(ord_name):
63 cmd = 'crm -w -F configure order %s %s' % (ord_name,
64@@ -441,7 +442,7 @@
65 log('%s' % cmd)
66
67 log('Configuring Colocations')
68- log(str(colocations))
69+ log(colocations)
70 for col_name, col_params in colocations.iteritems():
71 if not pcmk.crm_opt_exists(col_name):
72 cmd = 'crm -w -F configure colocation %s %s' % (col_name,
73@@ -450,7 +451,7 @@
74 log('%s' % cmd)
75
76 log('Configuring Clones')
77- log(str(clones))
78+ log(clones)
79 for cln_name, cln_params in clones.iteritems():
80 if not pcmk.crm_opt_exists(cln_name):
81 cmd = 'crm -w -F configure clone %s %s' % (cln_name,
82@@ -458,6 +459,15 @@
83 pcmk.commit(cmd)
84 log('%s' % cmd)
85
86+ log('Configuring Locations')
87+ log(locations)
88+ for loc_name, loc_params in locations.iteritems():
89+ if not pcmk.crm_opt_exists(loc_name):
90+ cmd = 'crm -w -F configure location %s %s' % (loc_name,
91+ loc_params)
92+ pcmk.commit(cmd)
93+ log('%s' % cmd)
94+
95 for res_name, res_type in resources.iteritems():
96 if len(init_services) != 0 and res_name in init_services:
97 # Checks that the resources are running and started.
98
99=== added file 'setup.cfg'
100--- setup.cfg 1970-01-01 00:00:00 +0000
101+++ setup.cfg 2015-03-06 15:20:06 +0000
102@@ -0,0 +1,6 @@
103+[nosetests]
104+verbosity=2
105+with-coverage=1
106+cover-erase=1
107+cover-package=hooks
108+
109
110=== modified file 'unit_tests/test_hacluster_hooks.py'
111--- unit_tests/test_hacluster_hooks.py 2014-12-15 12:55:12 +0000
112+++ unit_tests/test_hacluster_hooks.py 2015-03-06 15:20:06 +0000
113@@ -89,3 +89,87 @@
114
115 matches = re.findall(pattern, content, re.M)
116 self.assertEqual(len(matches), 2, str(matches))
117+
118+ @mock.patch('pcmk.wait_for_pcmk')
119+ @mock.patch('hooks.peer_units')
120+ @mock.patch('pcmk.crm_opt_exists')
121+ @mock.patch('hooks.oldest_peer')
122+ @mock.patch('hooks.configure_corosync')
123+ @mock.patch('hooks.configure_cluster_global')
124+ @mock.patch('hooks.configure_monitor_host')
125+ @mock.patch('hooks.configure_stonith')
126+ @mock.patch('hooks.related_units')
127+ @mock.patch('hooks.get_cluster_nodes')
128+ @mock.patch('hooks.relation_set')
129+ @mock.patch('hooks.relation_ids')
130+ @mock.patch('hooks.get_corosync_conf')
131+ @mock.patch('pcmk.commit')
132+ @mock.patch('hooks.config')
133+ @mock.patch('hooks.parse_data')
134+ def test_configure_principle_cluster_resources(self, parse_data, config,
135+ commit,
136+ get_corosync_conf,
137+ relation_ids, relation_set,
138+ get_cluster_nodes,
139+ related_units,
140+ configure_stonith,
141+ configure_monitor_host,
142+ configure_cluster_global,
143+ configure_corosync,
144+ oldest_peer, crm_opt_exists,
145+ peer_units, wait_for_pcmk):
146+ crm_opt_exists.return_value = False
147+ oldest_peer.return_value = True
148+ related_units.return_value = ['ha/0', 'ha/1', 'ha/2']
149+ get_cluster_nodes.return_value = ['10.0.3.2', '10.0.3.3', '10.0.3.4']
150+ relation_ids.return_value = ['hanode:1']
151+ get_corosync_conf.return_value = True
152+ cfg = {'debug': False,
153+ 'prefer-ipv6': False,
154+ 'corosync_transport': 'udpu',
155+ 'corosync_mcastaddr': 'corosync_mcastaddr',
156+ 'cluster_count': 3}
157+
158+ def c(k):
159+ return cfg.get(k)
160+
161+ config.side_effect = c
162+
163+ rel_get_data = {'locations': {'loc_foo': 'bar rule inf: meh eq 1'},
164+ 'clones': {'cl_foo': 'res_foo meta interleave=true'},
165+ 'groups': {'grp_foo': 'res_foo'},
166+ 'colocations': {'co_foo': 'inf: grp_foo cl_foo'},
167+ 'resources': {'res_foo': 'ocf:heartbeat:IPaddr2',
168+ 'res_bar': 'ocf:heartbear:IPv6addr'},
169+ 'resource_params': {'res_foo': 'params bar'},
170+ 'ms': {'ms_foo': 'res_foo meta notify=true'},
171+ 'orders': {'foo_after': 'inf: res_foo ms_foo'}}
172+
173+ def fake_parse_data(relid, unit, key):
174+ return rel_get_data.get(key, {})
175+
176+ parse_data.side_effect = fake_parse_data
177+
178+ hacluster_hooks.configure_principle_cluster_resources()
179+ relation_set.assert_any_call(relation_id='hanode:1', ready=True)
180+ configure_stonith.assert_called_with()
181+ configure_monitor_host.assert_called_with()
182+ configure_cluster_global.assert_called_with()
183+ configure_corosync.assert_called_with()
184+
185+ for kw, key in [('location', 'locations'),
186+ ('clone', 'clones'),
187+ ('group', 'groups'),
188+ ('colocation', 'colocations'),
189+ ('primitive', 'resources'),
190+ ('ms', 'ms'),
191+ ('order', 'orders')]:
192+ for name, params in rel_get_data[key].items():
193+ if name in rel_get_data['resource_params']:
194+ res_params = rel_get_data['resource_params'][name]
195+ commit.assert_any_call(
196+ 'crm -w -F configure %s %s %s %s' % (kw, name, params,
197+ res_params))
198+ else:
199+ commit.assert_any_call(
200+ 'crm -w -F configure %s %s %s' % (kw, name, params))

Subscribers

People subscribed via source and target branches