def test_initialized_command_error(self): ''' Test to check initialized when command execution error is raised ''' ret = {'name': 'hacluster', 'changes': {}, 'result': False, 'comment': 'cluster command error'} mock_status = MagicMock(return_value=1) mock_init = MagicMock( side_effect=exceptions.CommandExecutionError('cluster command error')) with patch.dict(crmshmod.__salt__, {'crm.status': mock_status, 'crm.cluster_init': mock_init}): assert crmshmod.cluster_initialized( name='hacluster', watchdog='/dev/watchdog', interface='eth0', unicast=False, admin_ip='192.168.1.50', sbd=True, sbd_dev='/dev/sbd', quiet=False) == ret mock_status.assert_called_once_with() mock_init.assert_called_once_with( name='hacluster', watchdog='/dev/watchdog', interface='eth0', unicast=False, admin_ip='192.168.1.50', sbd=True, sbd_dev='/dev/sbd', quiet=False)
def test_initialized_error(self): ''' Test to check initialized when initialization fails ''' ret = {'name': 'hacluster', 'changes': {'name': 'hacluster'}, 'result': False, 'comment': 'Error initialazing cluster'} mock_status = MagicMock(return_value=1) mock_init = MagicMock(return_value=1) with patch.dict(crmshmod.__salt__, {'crm.status': mock_status, 'crm.cluster_init': mock_init}): assert crmshmod.cluster_initialized( name='hacluster', watchdog='/dev/watchdog', interface='eth0', unicast=False, admin_ip='192.168.1.50', sbd=True, sbd_dev='/dev/sbd', quiet=False) == ret mock_status.assert_called_once_with() mock_init.assert_called_once_with( name='hacluster', watchdog='/dev/watchdog', interface='eth0', unicast=False, admin_ip='192.168.1.50', sbd=True, sbd_dev='/dev/sbd', quiet=False)
def test_initialized_initialized(self): ''' Test to check initialized when cluster is already initialized ''' ret = {'name': 'hacluster', 'changes': {}, 'result': True, 'comment': 'Cluster is already initialized'} mock_status = MagicMock(return_value=0) with patch.dict(crmshmod.__salt__, {'crm.status': mock_status}): assert crmshmod.cluster_initialized('hacluster') == ret mock_status.assert_called_once_with()
def test_initialized_test(self): ''' Test to check initialized in test mode ''' ret = {'name': 'hacluster', 'changes': {'name': 'hacluster'}, 'result': None, 'comment': '{} would be initialized'.format('hacluster')} mock_status = MagicMock(return_value=1) with patch.dict(crmshmod.__salt__, {'crm.status': mock_status}): with patch.dict(crmshmod.__opts__, {'test': True}): assert crmshmod.cluster_initialized('hacluster') == ret mock_status.assert_called_once_with()
def test_initialized(self): ''' Test to check initialized when cluster is not created yet ''' ret = { 'name': 'hacluster', 'changes': { 'name': 'hacluster' }, 'result': True, 'comment': 'Cluster initialized' } mock_status = MagicMock(return_value=1) mock_init = MagicMock(return_value=0) with patch.dict(crmshmod.__salt__, { 'crm.status': mock_status, 'crm.cluster_init': mock_init }): assert crmshmod.cluster_initialized(name='hacluster', watchdog='/dev/watchdog', interface='eth0', unicast=False, admin_ip='192.168.1.50', sbd=True, sbd_dev='/dev/sbd', no_overwrite_sshkey=True, quiet=False) == ret mock_status.assert_called_once_with() mock_init.assert_called_once_with(name='hacluster', watchdog='/dev/watchdog', interface='eth0', unicast=False, admin_ip='192.168.1.50', sbd=True, sbd_dev='/dev/sbd', no_overwrite_sshkey=True, quiet=False)