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
=== modified file '.bzrignore'
--- .bzrignore 2014-10-12 08:12:10 +0000
+++ .bzrignore 2015-03-06 15:20:06 +0000
@@ -1,1 +1,2 @@
1bin1bin
2.coverage
23
=== modified file 'hooks/hooks.py'
--- hooks/hooks.py 2014-12-17 17:17:29 +0000
+++ hooks/hooks.py 2015-03-06 15:20:06 +0000
@@ -350,6 +350,7 @@
350 orders = parse_data(relid, unit, 'orders')350 orders = parse_data(relid, unit, 'orders')
351 colocations = parse_data(relid, unit, 'colocations')351 colocations = parse_data(relid, unit, 'colocations')
352 clones = parse_data(relid, unit, 'clones')352 clones = parse_data(relid, unit, 'clones')
353 locations = parse_data(relid, unit, 'locations')
353 init_services = parse_data(relid, unit, 'init_services')354 init_services = parse_data(relid, unit, 'init_services')
354 else:355 else:
355 log('Related to {} ha services'.format(len(relids)))356 log('Related to {} ha services'.format(len(relids)))
@@ -374,7 +375,7 @@
374 # from the oldest peer unit.375 # from the oldest peer unit.
375 if oldest_peer(peer_units()):376 if oldest_peer(peer_units()):
376 log('Deleting Resources')377 log('Deleting Resources')
377 log(str(delete_resources))378 log(delete_resources)
378 for res_name in delete_resources:379 for res_name in delete_resources:
379 if pcmk.crm_opt_exists(res_name):380 if pcmk.crm_opt_exists(res_name):
380 log('Stopping and deleting resource %s' % res_name)381 log('Stopping and deleting resource %s' % res_name)
@@ -383,7 +384,7 @@
383 pcmk.commit('crm -w -F configure delete %s' % res_name)384 pcmk.commit('crm -w -F configure delete %s' % res_name)
384385
385 log('Configuring Resources')386 log('Configuring Resources')
386 log(str(resources))387 log(resources)
387 for res_name, res_type in resources.iteritems():388 for res_name, res_type in resources.iteritems():
388 # disable the service we are going to put in HA389 # disable the service we are going to put in HA
389 if res_type.split(':')[0] == "lsb":390 if res_type.split(':')[0] == "lsb":
@@ -415,7 +416,7 @@
415 pcmk.commit(cmd)416 pcmk.commit(cmd)
416417
417 log('Configuring Groups')418 log('Configuring Groups')
418 log(str(groups))419 log(groups)
419 for grp_name, grp_params in groups.iteritems():420 for grp_name, grp_params in groups.iteritems():
420 if not pcmk.crm_opt_exists(grp_name):421 if not pcmk.crm_opt_exists(grp_name):
421 cmd = 'crm -w -F configure group %s %s' % (grp_name,422 cmd = 'crm -w -F configure group %s %s' % (grp_name,
@@ -424,7 +425,7 @@
424 log('%s' % cmd)425 log('%s' % cmd)
425426
426 log('Configuring Master/Slave (ms)')427 log('Configuring Master/Slave (ms)')
427 log(str(ms))428 log(ms)
428 for ms_name, ms_params in ms.iteritems():429 for ms_name, ms_params in ms.iteritems():
429 if not pcmk.crm_opt_exists(ms_name):430 if not pcmk.crm_opt_exists(ms_name):
430 cmd = 'crm -w -F configure ms %s %s' % (ms_name, ms_params)431 cmd = 'crm -w -F configure ms %s %s' % (ms_name, ms_params)
@@ -432,7 +433,7 @@
432 log('%s' % cmd)433 log('%s' % cmd)
433434
434 log('Configuring Orders')435 log('Configuring Orders')
435 log(str(orders))436 log(orders)
436 for ord_name, ord_params in orders.iteritems():437 for ord_name, ord_params in orders.iteritems():
437 if not pcmk.crm_opt_exists(ord_name):438 if not pcmk.crm_opt_exists(ord_name):
438 cmd = 'crm -w -F configure order %s %s' % (ord_name,439 cmd = 'crm -w -F configure order %s %s' % (ord_name,
@@ -441,7 +442,7 @@
441 log('%s' % cmd)442 log('%s' % cmd)
442443
443 log('Configuring Colocations')444 log('Configuring Colocations')
444 log(str(colocations))445 log(colocations)
445 for col_name, col_params in colocations.iteritems():446 for col_name, col_params in colocations.iteritems():
446 if not pcmk.crm_opt_exists(col_name):447 if not pcmk.crm_opt_exists(col_name):
447 cmd = 'crm -w -F configure colocation %s %s' % (col_name,448 cmd = 'crm -w -F configure colocation %s %s' % (col_name,
@@ -450,7 +451,7 @@
450 log('%s' % cmd)451 log('%s' % cmd)
451452
452 log('Configuring Clones')453 log('Configuring Clones')
453 log(str(clones))454 log(clones)
454 for cln_name, cln_params in clones.iteritems():455 for cln_name, cln_params in clones.iteritems():
455 if not pcmk.crm_opt_exists(cln_name):456 if not pcmk.crm_opt_exists(cln_name):
456 cmd = 'crm -w -F configure clone %s %s' % (cln_name,457 cmd = 'crm -w -F configure clone %s %s' % (cln_name,
@@ -458,6 +459,15 @@
458 pcmk.commit(cmd)459 pcmk.commit(cmd)
459 log('%s' % cmd)460 log('%s' % cmd)
460461
462 log('Configuring Locations')
463 log(locations)
464 for loc_name, loc_params in locations.iteritems():
465 if not pcmk.crm_opt_exists(loc_name):
466 cmd = 'crm -w -F configure location %s %s' % (loc_name,
467 loc_params)
468 pcmk.commit(cmd)
469 log('%s' % cmd)
470
461 for res_name, res_type in resources.iteritems():471 for res_name, res_type in resources.iteritems():
462 if len(init_services) != 0 and res_name in init_services:472 if len(init_services) != 0 and res_name in init_services:
463 # Checks that the resources are running and started.473 # Checks that the resources are running and started.
464474
=== added file 'setup.cfg'
--- setup.cfg 1970-01-01 00:00:00 +0000
+++ setup.cfg 2015-03-06 15:20:06 +0000
@@ -0,0 +1,6 @@
1[nosetests]
2verbosity=2
3with-coverage=1
4cover-erase=1
5cover-package=hooks
6
07
=== modified file 'unit_tests/test_hacluster_hooks.py'
--- unit_tests/test_hacluster_hooks.py 2014-12-15 12:55:12 +0000
+++ unit_tests/test_hacluster_hooks.py 2015-03-06 15:20:06 +0000
@@ -89,3 +89,87 @@
8989
90 matches = re.findall(pattern, content, re.M)90 matches = re.findall(pattern, content, re.M)
91 self.assertEqual(len(matches), 2, str(matches))91 self.assertEqual(len(matches), 2, str(matches))
92
93 @mock.patch('pcmk.wait_for_pcmk')
94 @mock.patch('hooks.peer_units')
95 @mock.patch('pcmk.crm_opt_exists')
96 @mock.patch('hooks.oldest_peer')
97 @mock.patch('hooks.configure_corosync')
98 @mock.patch('hooks.configure_cluster_global')
99 @mock.patch('hooks.configure_monitor_host')
100 @mock.patch('hooks.configure_stonith')
101 @mock.patch('hooks.related_units')
102 @mock.patch('hooks.get_cluster_nodes')
103 @mock.patch('hooks.relation_set')
104 @mock.patch('hooks.relation_ids')
105 @mock.patch('hooks.get_corosync_conf')
106 @mock.patch('pcmk.commit')
107 @mock.patch('hooks.config')
108 @mock.patch('hooks.parse_data')
109 def test_configure_principle_cluster_resources(self, parse_data, config,
110 commit,
111 get_corosync_conf,
112 relation_ids, relation_set,
113 get_cluster_nodes,
114 related_units,
115 configure_stonith,
116 configure_monitor_host,
117 configure_cluster_global,
118 configure_corosync,
119 oldest_peer, crm_opt_exists,
120 peer_units, wait_for_pcmk):
121 crm_opt_exists.return_value = False
122 oldest_peer.return_value = True
123 related_units.return_value = ['ha/0', 'ha/1', 'ha/2']
124 get_cluster_nodes.return_value = ['10.0.3.2', '10.0.3.3', '10.0.3.4']
125 relation_ids.return_value = ['hanode:1']
126 get_corosync_conf.return_value = True
127 cfg = {'debug': False,
128 'prefer-ipv6': False,
129 'corosync_transport': 'udpu',
130 'corosync_mcastaddr': 'corosync_mcastaddr',
131 'cluster_count': 3}
132
133 def c(k):
134 return cfg.get(k)
135
136 config.side_effect = c
137
138 rel_get_data = {'locations': {'loc_foo': 'bar rule inf: meh eq 1'},
139 'clones': {'cl_foo': 'res_foo meta interleave=true'},
140 'groups': {'grp_foo': 'res_foo'},
141 'colocations': {'co_foo': 'inf: grp_foo cl_foo'},
142 'resources': {'res_foo': 'ocf:heartbeat:IPaddr2',
143 'res_bar': 'ocf:heartbear:IPv6addr'},
144 'resource_params': {'res_foo': 'params bar'},
145 'ms': {'ms_foo': 'res_foo meta notify=true'},
146 'orders': {'foo_after': 'inf: res_foo ms_foo'}}
147
148 def fake_parse_data(relid, unit, key):
149 return rel_get_data.get(key, {})
150
151 parse_data.side_effect = fake_parse_data
152
153 hacluster_hooks.configure_principle_cluster_resources()
154 relation_set.assert_any_call(relation_id='hanode:1', ready=True)
155 configure_stonith.assert_called_with()
156 configure_monitor_host.assert_called_with()
157 configure_cluster_global.assert_called_with()
158 configure_corosync.assert_called_with()
159
160 for kw, key in [('location', 'locations'),
161 ('clone', 'clones'),
162 ('group', 'groups'),
163 ('colocation', 'colocations'),
164 ('primitive', 'resources'),
165 ('ms', 'ms'),
166 ('order', 'orders')]:
167 for name, params in rel_get_data[key].items():
168 if name in rel_get_data['resource_params']:
169 res_params = rel_get_data['resource_params'][name]
170 commit.assert_any_call(
171 'crm -w -F configure %s %s %s %s' % (kw, name, params,
172 res_params))
173 else:
174 commit.assert_any_call(
175 'crm -w -F configure %s %s %s' % (kw, name, params))

Subscribers

People subscribed via source and target branches