Add unit test for configure_principle_cluster_resources()

This is the handler for ha-relation-joined, ha-relation-changed,
hanode-relation-joined and hanode-relation-changed
This commit is contained in:
Felipe Reyes 2015-03-06 11:58:15 -03:00
parent c485049b4e
commit 50a2b137b6
3 changed files with 91 additions and 0 deletions

View File

@ -1 +1,2 @@
bin
.coverage

6
setup.cfg Normal file
View File

@ -0,0 +1,6 @@
[nosetests]
verbosity=2
with-coverage=1
cover-erase=1
cover-package=hooks

View File

@ -89,3 +89,87 @@ class TestCorosyncConf(unittest.TestCase):
matches = re.findall(pattern, content, re.M)
self.assertEqual(len(matches), 2, str(matches))
@mock.patch('pcmk.wait_for_pcmk')
@mock.patch('hooks.peer_units')
@mock.patch('pcmk.crm_opt_exists')
@mock.patch('hooks.oldest_peer')
@mock.patch('hooks.configure_corosync')
@mock.patch('hooks.configure_cluster_global')
@mock.patch('hooks.configure_monitor_host')
@mock.patch('hooks.configure_stonith')
@mock.patch('hooks.related_units')
@mock.patch('hooks.get_cluster_nodes')
@mock.patch('hooks.relation_set')
@mock.patch('hooks.relation_ids')
@mock.patch('hooks.get_corosync_conf')
@mock.patch('pcmk.commit')
@mock.patch('hooks.config')
@mock.patch('hooks.parse_data')
def test_configure_principle_cluster_resources(self, parse_data, config,
commit,
get_corosync_conf,
relation_ids, relation_set,
get_cluster_nodes,
related_units,
configure_stonith,
configure_monitor_host,
configure_cluster_global,
configure_corosync,
oldest_peer, crm_opt_exists,
peer_units, wait_for_pcmk):
crm_opt_exists.return_value = False
oldest_peer.return_value = True
related_units.return_value = ['ha/0', 'ha/1', 'ha/2']
get_cluster_nodes.return_value = ['10.0.3.2', '10.0.3.3', '10.0.3.4']
relation_ids.return_value = ['hanode:1']
get_corosync_conf.return_value = True
cfg = {'debug': False,
'prefer-ipv6': False,
'corosync_transport': 'udpu',
'corosync_mcastaddr': 'corosync_mcastaddr',
'cluster_count': 3}
def c(k):
return cfg.get(k)
config.side_effect = c
rel_get_data = {'locations': {'loc_foo': 'bar rule inf: meh eq 1'},
'clones': {'cl_foo': 'res_foo meta interleave=true'},
'groups': {'grp_foo': 'res_foo'},
'colocations': {'co_foo': 'inf: grp_foo cl_foo'},
'resources': {'res_foo': 'ocf:heartbeat:IPaddr2',
'res_bar': 'ocf:heartbear:IPv6addr'},
'resource_params': {'res_foo': 'params bar'},
'ms': {'ms_foo': 'res_foo meta notify=true'},
'orders': {'foo_after': 'inf: res_foo ms_foo'}}
def fake_parse_data(relid, unit, key):
return rel_get_data.get(key, {})
parse_data.side_effect = fake_parse_data
hacluster_hooks.configure_principle_cluster_resources()
relation_set.assert_any_call(relation_id='hanode:1', ready=True)
configure_stonith.assert_called_with()
configure_monitor_host.assert_called_with()
configure_cluster_global.assert_called_with()
configure_corosync.assert_called_with()
for kw, key in [('location', 'locations'),
('clone', 'clones'),
('group', 'groups'),
('colocation', 'colocations'),
('primitive', 'resources'),
('ms', 'ms'),
('order', 'orders')]:
for name, params in rel_get_data[key].items():
if name in rel_get_data['resource_params']:
res_params = rel_get_data['resource_params'][name]
commit.assert_any_call(
'crm -w -F configure %s %s %s %s' % (kw, name, params,
res_params))
else:
commit.assert_any_call(
'crm -w -F configure %s %s %s' % (kw, name, params))