Ejemplo n.º 1
0
    def test_configured_error(self):
        '''
        Test to check configured when configuration fails
        '''

        ret = {
            'name':
            'update',
            'changes': {},
            'result':
            False,
            'comment':
            'Error configuring the cluster with method {} and file {}'.format(
                'update', 'file.config')
        }

        mock_status = MagicMock(return_value=0)
        mock_configured = MagicMock(return_value=1)
        with patch.dict(crmshmod.__salt__, {
                'crm.status': mock_status,
                'crm.configure_load': mock_configured
        }):
            assert crmshmod.cluster_configured(name='update',
                                               url='file.config',
                                               is_xml=False,
                                               force=True) == ret
            mock_status.assert_called_once_with()
            mock_configured.assert_called_once_with(method='update',
                                                    url='file.config',
                                                    is_xml=False,
                                                    force=True)
Ejemplo n.º 2
0
    def test_configured_command_error(self):
        '''
        Test to check configured when command execution error is raised
        '''

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

        mock_status = MagicMock(return_value=0)
        mock_configured = MagicMock(
            side_effect=exceptions.CommandExecutionError(
                'cluster command error'))
        with patch.dict(crmshmod.__salt__, {
                'crm.status': mock_status,
                'crm.configure_load': mock_configured
        }):
            assert crmshmod.cluster_configured(name='update',
                                               url='file.config',
                                               is_xml=False) == ret
            mock_status.assert_called_once_with()
            mock_configured.assert_called_once_with(method='update',
                                                    url='file.config',
                                                    is_xml=False,
                                                    force=False)
Ejemplo n.º 3
0
    def test_configured(self):
        '''
        Test to check configured when configuration is applied properly
        '''

        ret = {
            'name': 'update',
            'changes': {
                'method': 'update',
                'url': 'file.config'
            },
            'result': True,
            'comment': 'Cluster properly configured'
        }

        mock_status = MagicMock(return_value=0)
        mock_configured = MagicMock(return_value=0)
        with patch.dict(crmshmod.__salt__, {
                'crm.status': mock_status,
                'crm.configure_load': mock_configured
        }):
            assert crmshmod.cluster_configured(name='update',
                                               url='file.config',
                                               is_xml=False) == ret
            mock_status.assert_called_once_with()
            mock_configured.assert_called_once_with(method='update',
                                                    url='file.config',
                                                    is_xml=False,
                                                    force=False)
Ejemplo n.º 4
0
    def test_configured_test(self):
        '''
        Test to check configured in test mode
        '''

        ret = {'name': 'update',
               'changes': {'method': 'update', 'url': 'file.config'},
               'result': None,
               'comment': 'Cluster would be configured with method {} and file {}'.format(
                   'update', 'file.config')}

        with patch.dict(crmshmod.__opts__, {'test': True}):
            assert crmshmod.cluster_configured('update', 'file.config') == ret
Ejemplo n.º 5
0
    def test_configured_not_cluster(self):
        '''
        Test to check configured when the cluster is not initialized
        '''

        ret = {'name': 'update',
               'changes': {},
               'result': False,
               'comment': 'Cluster is not created yet. Run cluster_initialized before'}

        mock_status = MagicMock(return_value=1)
        with patch.dict(crmshmod.__salt__, {'crm.status': mock_status}):
            assert crmshmod.cluster_configured('update', 'file.config') == ret
            mock_status.assert_called_once_with()