2
from mock import MagicMock, patch, call
4
import cinder_utils as utils
6
# Need to do some early patching to get the module loaded.
7
#_restart_map = utils.restart_map
8
_register_configs = utils.register_configs
9
_service_enabled = utils.service_enabled
10
utils.register_configs = MagicMock()
11
utils.service_enabled = MagicMock()
13
import cinder_hooks as hooks
15
# Unpatch it now that its loaded.
16
utils.register_configs = _register_configs
17
utils.service_enabled = _service_enabled
19
from test_utils import (
28
'ensure_block_device',
29
'ensure_ceph_keyring',
34
'prepare_lvm_storage',
37
'set_ceph_env_variables',
40
# charmhelpers.core.hookenv
45
# charmhelpers.core.host
48
# charmhelpers.contrib.openstack.openstack_utils
49
'configure_installation_source',
50
# charmhelpers.contrib.hahelpers.cluster_utils
52
'get_hacluster_config',
56
class TestClusterHooks(CharmTestCase):
58
super(TestClusterHooks, self).setUp(hooks, TO_PATCH)
59
self.config.side_effect = self.test_config.get_all
61
@patch('charmhelpers.core.host.service')
62
@patch('charmhelpers.core.host.file_hash')
63
def test_cluster_hook(self, file_hash, service):
64
'''Ensure API restart before haproxy on cluster changed'''
65
# set first hash lookup on all files
67
# set first hash lookup on all configs in restart_on_change
68
[side_effects.append('foo') for f in RESTART_MAP.keys()]
69
# set second hash lookup on all configs in restart_on_change
70
[side_effects.append('bar') for f in RESTART_MAP.keys()]
71
file_hash.side_effect = side_effects
72
hooks.hooks.execute(['hooks/cluster-relation-changed'])
74
call('restart', 'cinder-api'),
75
call('restart', 'cinder-volume'),
76
call('restart', 'cinder-scheduler'),
77
call('restart', 'haproxy'),
78
call('restart', 'apache2')]
79
self.assertEquals(ex, service.call_args_list)
81
def test_ha_joined_complete_config(self):
82
'''Ensure hacluster subordinate receives all relevant config'''
84
'ha-bindiface': 'eth100',
85
'ha-mcastport': '37373',
86
'vip': '192.168.25.163',
87
'vip_iface': 'eth101',
90
self.get_hacluster_config.return_value = conf
91
hooks.hooks.execute(['hooks/ha-relation-joined'])
93
'corosync_mcastport': '37373',
94
'init_services': {'res_cinder_haproxy': 'haproxy'},
97
'params ip="192.168.25.163" cidr_netmask="19" nic="eth101"',
98
'res_cinder_haproxy': 'op monitor interval="5s"'
100
'corosync_bindiface': 'eth100',
101
'clones': {'cl_cinder_haproxy': 'res_cinder_haproxy'},
103
'res_cinder_vip': 'ocf:heartbeat:IPaddr2',
104
'res_cinder_haproxy': 'lsb:haproxy'
107
self.relation_set.assert_called_with(**ex_args)