def test_db_installed_command_error(self):
        '''
        Test to check db_installed when it raises an error
        '''

        ret = {
            'name': '192.168.10.15:30015',
            'changes': {},
            'result': False,
            'comment': 'error'
        }

        mock_db_installed = MagicMock(return_value=False)
        mock_attach = MagicMock(
            side_effect=exceptions.CommandExecutionError('error'))
        with patch.dict(
                netweavermod.__salt__, {
                    'netweaver.is_db_installed': mock_db_installed,
                    'netweaver.attach_virtual_host': mock_attach
                }):
            assert netweavermod.db_installed('192.168.10.15', 30015,
                                             'SAPABAP1', 'schema_pass',
                                             '/software', 'root', 'pass',
                                             'config_file', 'vhost', 'eth1',
                                             'productID') == ret
            mock_db_installed.assert_called_once_with(
                host='192.168.10.15',
                port=30015,
                schema_name='SAPABAP1',
                schema_password='******')
            mock_attach.assert_called_once_with(virtual_host='vhost',
                                                virtual_host_interface='eth1')
    def test_db_installed_test(self):
        '''
        Test to check db_installed in test mode
        '''

        ret = {
            'name': '192.168.10.15:30015',
            'changes': {
                'host': '192.168.10.15:30015'
            },
            'result': None,
            'comment': 'Netweaver DB instance would be installed'
        }

        mock_db_installed = MagicMock(return_value=False)
        with patch.dict(netweavermod.__salt__,
                        {'netweaver.is_db_installed': mock_db_installed}):
            with patch.dict(netweavermod.__opts__, {'test': True}):
                assert netweavermod.db_installed('192.168.10.15', 30015,
                                                 'SAPABAP1', 'schema_pass',
                                                 '/software', 'root', 'pass',
                                                 'config_file', 'vhost',
                                                 'eth1', 'productID') == ret
            mock_db_installed.assert_called_once_with(
                host='192.168.10.15',
                port=30015,
                schema_name='SAPABAP1',
                schema_password='******')
    def test_db_installed_correct(self):
        '''
        Test to check installed when it is installed correctly
        '''

        ret = {
            'name': '192.168.10.15:30015',
            'changes': {
                'host': '192.168.10.15:30015'
            },
            'result': True,
            'comment': 'Netweaver DB instance installed'
        }

        mock_db_installed = MagicMock(side_effect=[False, True])
        mock_attach = MagicMock(return_value='192.168.15.1')
        mock_setup_cwd = MagicMock(return_value='/tmp_nw')
        mock_install = MagicMock()
        with patch.dict(
                netweavermod.__salt__, {
                    'netweaver.is_db_installed': mock_db_installed,
                    'netweaver.attach_virtual_host': mock_attach,
                    'netweaver.setup_cwd': mock_setup_cwd,
                    'netweaver.install': mock_install
                }):
            assert netweavermod.db_installed('192.168.10.15', 30015,
                                             'SAPABAP1', 'schema_pass',
                                             '/software', 'root', 'pass',
                                             'config_file', 'vhost', 'eth1',
                                             'productID') == ret
            mock_db_installed.assert_has_calls([
                mock.call(host='192.168.10.15',
                          port=30015,
                          schema_name='SAPABAP1',
                          schema_password='******'),
                mock.call(host='192.168.10.15',
                          port=30015,
                          schema_name='SAPABAP1',
                          schema_password='******'),
            ])

            mock_attach.assert_called_once_with(virtual_host='vhost',
                                                virtual_host_interface='eth1')
            mock_setup_cwd.assert_called_once_with(software_path='/software',
                                                   cwd='/tmp/swpm_unattended',
                                                   additional_dvds=None)
            mock_install.assert_called_once_with(software_path='/software',
                                                 virtual_host='vhost',
                                                 product_id='productID',
                                                 conf_file='config_file',
                                                 root_user='******',
                                                 root_password='******',
                                                 cwd='/tmp_nw')