def test_stop_corosync_services(mocker, mock_ssh_call, mock_ssh_call_output, mock_subprocess, node): get_one_controller = mocker.patch('octane.util.env.get_one_controller') get_one_controller.return_value = node get_crm_services = mocker.patch.object(maintenance, 'get_crm_services') get_crm_services.return_value = ['s1', 's2'] mock_ssh_call.side_effect = \ [subprocess.CalledProcessError(1, 'cmd'), None, None] mocker.patch('time.sleep') wait_for_services = \ mocker.patch.object(maintenance, 'wait_for_corosync_services_sync') maintenance.stop_corosync_services('env') assert not mock_subprocess.called mock_ssh_call_output.assert_called_once_with( ['cibadmin', '--query', '--scope', 'resources'], node=node) assert wait_for_services.call_args_list == \ [mock.call('env', ['s1', 's2'], 'stop')] assert mock_ssh_call.call_args_list == [ mock.call(['crm', 'resource', 'stop', 's1'], node=node), mock.call(['crm', 'resource', 'stop', 's1'], node=node), mock.call(['crm', 'resource', 'stop', 's2'], node=node), ]
def _read_in_subprocess(*args, **kwargs): stdin = kwargs['stdin'] stdin.call_args.append((args, kwargs)) assert 0 == stdin.seek_point if stdin.raise_exception_on_revert and '-R' in args[0]: raise subprocess.CalledProcessError(1, 'cmd') stdin.read() return mock.DEFAULT
def test_stop_corosync_services(mocker, mock_ssh_call, mock_ssh_call_output, mock_subprocess, node): get_one_controller = mocker.patch('octane.util.env.get_one_controller') get_one_controller.return_value = node parse_crm_status = mocker.patch.object(maintenance, 'parse_crm_status') parse_crm_status.return_value = ['s1', 's2'] mock_ssh_call.side_effect = \ [subprocess.CalledProcessError(1, 'cmd'), None, None] mocker.patch('time.sleep') maintenance.stop_corosync_services('env') assert not mock_subprocess.called mock_ssh_call_output.assert_called_once_with(['crm', 'status'], node=node) assert mock_ssh_call.call_args_list == [ mock.call(['crm', 'resource', 'stop', 's1'], node=node), mock.call(['crm', 'resource', 'stop', 's1'], node=node), mock.call(['crm', 'resource', 'stop', 's2'], node=node), ]
def test_apply_host_error(mock_subprocess): exc = subprocess.CalledProcessError(1, 'TEST_PROCESS') mock_subprocess.side_effect = exc with pytest.raises(type(exc)): puppet_util.apply_host()