def test_absent_error(self):
        '''
        Test to check absent when removal fails
        '''

        ret = {
            'name': 'localhost',
            'changes': {
                'name': 'localhost'
            },
            'result': False,
            'comment': 'Error removing cluster node'
        }

        mock_status = MagicMock(return_value=0)
        mock_remove = MagicMock(return_value=1)
        with patch.dict(crmshmod.__salt__, {
                'crm.status': mock_status,
                'crm.cluster_remove': mock_remove
        }):
            assert crmshmod.cluster_absent('localhost') == ret
            mock_status.assert_called_once_with()
            mock_remove.assert_called_once_with(host='localhost',
                                                force=True,
                                                quiet=None)
Beispiel #2
0
    def test_absent_absent(self):
        '''
        Test to check absent when cluster is already absent
        '''

        ret = {'name': 'localhost',
               'changes': {},
               'result': True,
               'comment': 'Cluster is already not running'}

        mock_status = MagicMock(return_value=1)
        with patch.dict(crmshmod.__salt__, {'crm.status': mock_status}):
            assert crmshmod.cluster_absent('localhost') == ret
            mock_status.assert_called_once_with()
Beispiel #3
0
    def test_absent_test(self):
        '''
        Test to check absent in test mode
        '''

        ret = {'name': 'localhost',
               'changes': {'name': 'localhost'},
               'result': None,
               'comment': 'Cluster node {} would be removed'.format('localhost')}

        mock_status = MagicMock(return_value=0)
        with patch.dict(crmshmod.__salt__, {'crm.status': mock_status}):
            with patch.dict(crmshmod.__opts__, {'test': True}):
                assert crmshmod.cluster_absent('localhost') == ret
            mock_status.assert_called_once_with()
Beispiel #4
0
    def test_absent_command_error(self):
        '''
        Test to check absent when command execution error is raised
        '''

        ret = {'name': 'localhost',
               'changes': {},
               'result': False,
               'comment': 'cluster command error'}

        mock_status = MagicMock(return_value=0)
        mock_remove = MagicMock(
            side_effect=exceptions.CommandExecutionError('cluster command error'))
        with patch.dict(crmshmod.__salt__, {'crm.status': mock_status,
                                            'crm.cluster_remove': mock_remove}):
            assert crmshmod.cluster_absent('localhost') == ret
            mock_status.assert_called_once_with()
            mock_remove.assert_called_once_with(
                host='localhost', force=True, quiet=None)