From 0c7cec874f341ac4d3a76ffb6074206dbdb49314 Mon Sep 17 00:00:00 2001 From: Eike Waldt Date: Wed, 13 May 2020 17:32:15 +0200 Subject: [PATCH] add tests for parameters sbd watchdog and msgwait timeouts --- tests/unit/modules/test_crmshmod.py | 96 ++++++++++++++--------------- tests/unit/states/test_crmshmod.py | 12 ++++ 2 files changed, 59 insertions(+), 49 deletions(-) diff --git a/tests/unit/modules/test_crmshmod.py b/tests/unit/modules/test_crmshmod.py index 40d2489e..b1c5e418 100644 --- a/tests/unit/modules/test_crmshmod.py +++ b/tests/unit/modules/test_crmshmod.py @@ -352,7 +352,7 @@ def test_crm_init_complete(self): with patch.dict(crmshmod.__salt__, {'cmd.retcode': mock_cmd_run}): result = crmshmod._crm_init( - 'hacluster', 'dog', 'eth1', True, '192.168.1.50', True, ['dev1', 'dev2'], True, True) + 'hacluster', 'dog', 'eth1', True, '192.168.1.50', True, ['dev1', 'dev2'], '10', '20', True, True) assert result mock_cmd_run.assert_called_once_with( '{} cluster init -y -n {} -w {} -i {} -u -A {} ' @@ -386,7 +386,7 @@ def test_ha_cluster_init_complete(self, mock_corosync, mock_watchdog): 'network.get_hostname': mock_get_hostname, 'network.interface_ip': mock_interface_ip}): result = crmshmod._ha_cluster_init( - 'dog', 'eth1', True, '192.168.1.50', True, ['dev1', 'dev2'], True) + 'dog', 'eth1', True, '192.168.1.50', True, ['dev1', 'dev2'], None, None, True) assert result == 0 mock_watchdog.assert_called_once_with('dog') mock_corosync.assert_called_once_with('1.0.1.0', 'node') @@ -395,104 +395,101 @@ def test_ha_cluster_init_complete(self, mock_corosync, mock_watchdog): '{} -y -i {} -A {} -S -s {} -s {} -q'.format( crmshmod.HA_INIT_COMMAND, 'eth1', '192.168.1.50', 'dev1', 'dev2')) - def test_manage_multiple_sbd(self): + def test_manage_sbd(self): - sbd, devs = crmshmod._manage_multiple_sbd(None, None) + sbd, devs, sbd_timeout_watchdog, sbd_timeout_msgwait = crmshmod._manage_sbd(None, None, None, None) assert sbd is None assert devs is None + assert sbd_timeout_watchdog is None + assert sbd_timeout_msgwait is None - sbd, devs = crmshmod._manage_multiple_sbd(True, 'disk') + sbd, devs, sbd_timeout_watchdog, sbd_timeout_msgwait = crmshmod._manage_sbd(True, 'disk', None, None) assert sbd is True assert devs == ['disk'] + assert sbd_timeout_watchdog is None + assert sbd_timeout_msgwait is None - def test_manage_multiple_sbd_workaround(self): + def test_manage_sbd_workaround(self): - mock_cmd_run = MagicMock(side_effect=[0, 0]) - mock_file_replace = MagicMock(return_code=0) + mock_cmd_run = MagicMock(side_effect=[0, 0, 0, 0]) with patch.dict(crmshmod.__salt__, { - 'cmd.retcode': mock_cmd_run, - 'file.replace': mock_file_replace}): - sbd, devs = crmshmod._manage_multiple_sbd(True, ['disk1', 'disk2']) + 'cmd.retcode': mock_cmd_run}): + sbd, devs, sbd_timeout_watchdog, sbd_timeout_msgwait = crmshmod._manage_sbd(True, ['disk1', 'disk2'], '10', '20') mock_cmd_run.assert_has_calls([ - mock.call('sbd -d disk1 -d disk2 create'), - mock.call('{} cluster init sbd -s {}'.format(crmshmod.CRM_COMMAND, 'disk1')) + mock.call('sbd -d disk1 -d disk2 create -1 10 -4 20') ]) - mock_file_replace.assert_called_once_with( - path='/etc/sysconfig/sbd', - pattern='^SBD_DEVICE=.*', - repl='SBD_DEVICE={}'.format(';'.join(['disk1', 'disk2'])), - append_if_not_found=True - ) - assert sbd is None - assert devs is None + assert sbd is True + assert devs == ['disk1', 'disk2'] + assert sbd_timeout_watchdog == '10' + assert sbd_timeout_msgwait == '20' - def test_manage_multiple_sbd_workaround_errors(self): + def test_manage_sbd_workaround_errors(self): - mock_cmd_run = MagicMock(side_effect=[1, 0]) + mock_cmd_run = MagicMock(side_effect=[1, 0, 0, 0]) with patch.dict(crmshmod.__salt__, { 'cmd.retcode': mock_cmd_run}): with pytest.raises(exceptions.SaltInvocationError) as err: - crmshmod._manage_multiple_sbd(True, ['disk1', 'disk2']) + crmshmod._manage_sbd(True, ['disk1', 'disk2'], '10', '20') assert 'sbd disks could not be formatted properly' in str(err.value) - mock_cmd_run.assert_called_once_with('sbd -d disk1 -d disk2 create') - - mock_cmd_run = MagicMock(side_effect=[0, 1]) - - with patch.dict(crmshmod.__salt__, { - 'cmd.retcode': mock_cmd_run}): - with pytest.raises(exceptions.SaltInvocationError) as err: - crmshmod._manage_multiple_sbd(True, ['disk1', 'disk2']) + mock_cmd_run.assert_called_once_with('sbd -d disk1 -d disk2 create -1 10 -4 20') - assert 'crm cluster init sbd failed' in str(err.value) - mock_cmd_run.assert_has_calls([ - mock.call('sbd -d disk1 -d disk2 create'), - mock.call('{} cluster init sbd -s {}'.format(crmshmod.CRM_COMMAND, 'disk1')) - ]) + # mock_cmd_run = MagicMock(side_effect=[0, 1]) - @mock.patch('salt.modules.crmshmod._manage_multiple_sbd') + @mock.patch('logging.Logger.warning') + @mock.patch('salt.modules.crmshmod._manage_sbd') @mock.patch('salt.modules.crmshmod._crm_init') - def test_cluster_init_crm(self, crm_init, manage_sbd): + def test_cluster_init_crm(self, crm_init, manage_sbd, logger): ''' Test cluster_init with crm option ''' - manage_sbd.return_value = ('sbd', 'devs') + manage_sbd.return_value = ('sbd', 'devs', '10', '20') with patch.dict(crmshmod.__salt__, {'crm.use_crm': True}): crm_init.return_value = 0 value = crmshmod.cluster_init('hacluster', 'dog', 'eth1') assert value == 0 crm_init.assert_called_once_with( - 'hacluster', 'dog', 'eth1', None, None, 'sbd', 'devs', False, None) + 'hacluster', 'dog', 'eth1', None, None, None, None, None, None, False, None) + crm_init.reset_mock() + + with patch.dict(crmshmod.__salt__, {'crm.use_crm': True}): + crm_init.return_value = 0 + value = crmshmod.cluster_init('hacluster', 'dog', 'eth1', sbd=True, sbd_dev=['disk1', 'disk2']) + assert value == 0 + crm_init.assert_called_once_with( + 'hacluster', 'dog', 'eth1', None, None, True, ['disk1', 'disk2'], None, None, False, None) crm_init.reset_mock() with patch.dict(crmshmod.__salt__, {'crm.use_crm': True}): crm_init.return_value = 0 - value = crmshmod.cluster_init('hacluster', 'dog', 'eth1', sbd_dev=['disk1', 'disk2']) + value = crmshmod.cluster_init('hacluster', 'dog', 'eth1', sbd=True, sbd_dev='disk1') assert value == 0 crm_init.assert_called_once_with( - 'hacluster', 'dog', 'eth1', None, None, 'sbd', 'devs', False, None) + 'hacluster', 'dog', 'eth1', None, None, True, 'disk1', None, None, False, None) crm_init.reset_mock() with patch.dict(crmshmod.__salt__, {'crm.use_crm': True}): crm_init.return_value = 0 - value = crmshmod.cluster_init('hacluster', 'dog', 'eth1', sbd_dev='disk1') + value = crmshmod.cluster_init('hacluster', 'dog', 'eth1', sbd=True, sbd_dev=['disk1', 'disk2', 'disk3'], sbd_timeout_watchdog='10', sbd_timeout_msgwait='20') assert value == 0 crm_init.assert_called_once_with( - 'hacluster', 'dog', 'eth1', None, None, 'sbd', 'devs', False, None) + 'hacluster', 'dog', 'eth1', None, None, True, ['disk1', 'disk2', 'disk3'], '10', '20', False, None) + @mock.patch('logging.Logger.warning') - @mock.patch('salt.modules.crmshmod._manage_multiple_sbd') + @mock.patch('salt.modules.crmshmod._manage_sbd') @mock.patch('salt.modules.crmshmod._ha_cluster_init') - def test_cluster_init_ha(self, ha_cluster_init, manage_sbd, logger): + def test_cluster_init_ha(self, ha_cluster_init, _manage_sbd, logger): ''' Test cluster_init with ha_cluster_init option ''' - manage_sbd.return_value = ('sbd', 'devs') + + _manage_sbd.return_value = ('sbd', 'devs', '10', '20') with patch.dict(crmshmod.__salt__, {'crm.use_crm': False}): ha_cluster_init.return_value = 0 @@ -504,7 +501,8 @@ def test_cluster_init_ha(self, ha_cluster_init, manage_sbd, logger): mock.call('--no_overwrite_sshkey option not available') ]) ha_cluster_init.assert_called_once_with( - 'dog', 'eth1', None, None, 'sbd', 'devs', None) + 'dog', 'eth1', None, None, None, None, None, None, None) + def test_crm_join_basic(self): ''' diff --git a/tests/unit/states/test_crmshmod.py b/tests/unit/states/test_crmshmod.py index 126924f5..efcff8d5 100644 --- a/tests/unit/states/test_crmshmod.py +++ b/tests/unit/states/test_crmshmod.py @@ -179,6 +179,8 @@ def test_initialized(self): admin_ip='192.168.1.50', sbd=True, sbd_dev='/dev/sbd', + sbd_timeout_watchdog=10, + sbd_timeout_msgwait=20, no_overwrite_sshkey=True, quiet=False) == ret mock_status.assert_called_once_with() @@ -190,6 +192,8 @@ def test_initialized(self): admin_ip='192.168.1.50', sbd=True, sbd_dev='/dev/sbd', + sbd_timeout_watchdog=10, + sbd_timeout_msgwait=20, no_overwrite_sshkey=True, quiet=False) @@ -215,6 +219,8 @@ def test_initialized_error(self): admin_ip='192.168.1.50', sbd=True, sbd_dev='/dev/sbd', + sbd_timeout_watchdog=10, + sbd_timeout_msgwait=20, no_overwrite_sshkey=True, quiet=False) == ret mock_status.assert_called_once_with() @@ -226,6 +232,8 @@ def test_initialized_error(self): admin_ip='192.168.1.50', sbd=True, sbd_dev='/dev/sbd', + sbd_timeout_watchdog=10, + sbd_timeout_msgwait=20, no_overwrite_sshkey=True, quiet=False) @@ -252,6 +260,8 @@ def test_initialized_command_error(self): admin_ip='192.168.1.50', sbd=True, sbd_dev='/dev/sbd', + sbd_timeout_watchdog=10, + sbd_timeout_msgwait=20, no_overwrite_sshkey=False, quiet=False) == ret mock_status.assert_called_once_with() @@ -263,6 +273,8 @@ def test_initialized_command_error(self): admin_ip='192.168.1.50', sbd=True, sbd_dev='/dev/sbd', + sbd_timeout_watchdog=10, + sbd_timeout_msgwait=20, no_overwrite_sshkey=False, quiet=False)