Exemplo n.º 1
0
    def test_extract_sar_FileDoesNotExistError(self, mock_sar_file):
        mock_sar_file.side_effect = [True, False]

        with self.assertRaises(saputils.FileDoesNotExistError) as err:
            saputils.extract_sapcar_file(
                sapcar_exe='/sapmedia/sapcar.exe',
                sar_file='/sapmedia/IMDB_SERVER_LINUX.SAR')

        self.assertTrue('The SAR file \'{}\' does not exist'.format(
            '/sapmedia/IMDB_SERVER_LINUX.SAR') in str(err.exception))
Exemplo n.º 2
0
    def test_extract_sapcar_FileDoesNotExistError(self, mock_sapcar_file):
        mock_sapcar_file.return_value = False

        with self.assertRaises(saputils.FileDoesNotExistError) as err:
            saputils.extract_sapcar_file(
                sapcar_exe='/sapmedia/sapcar.exe',
                sar_file='/sapmedia/IMDB_SERVER_LINUX.SAR')

        self.assertTrue('SAPCAR executable \'{}\' does not exist'.format(
            '/sapmedia/sapcar.exe') in str(err.exception))
Exemplo n.º 3
0
    def test_extract_sapcar_error(self, mock_sapcar_file, mock_execute_cmd):
        mock_sapcar_file.side_effect = [True, True]
        proc_mock = mock.Mock()
        proc_mock.returncode = 1
        mock_execute_cmd.return_value = proc_mock

        with self.assertRaises(saputils.SapUtilsError) as err:
            saputils.extract_sapcar_file(
                sapcar_exe='/sapmedia/sapcar.exe',
                sar_file='/sapmedia/IMDB_SERVER_LINUX.SAR')

        cmd = '/sapmedia/sapcar.exe -xvf /sapmedia/IMDB_SERVER_LINUX.SAR'
        mock_execute_cmd.assert_called_once_with(cmd,
                                                 user=None,
                                                 password=None,
                                                 remote_host=None)

        self.assertTrue('Error running SAPCAR command' in str(err.exception))
Exemplo n.º 4
0
    def test_extract_sapcar_file(self, mock_sapcar_file, mock_execute_cmd):
        proc_mock = mock.Mock()
        proc_mock.returncode = 0
        mock_sapcar_file.side_effect = [True, True]
        mock_execute_cmd.return_value = proc_mock

        result = saputils.extract_sapcar_file(
            sapcar_exe='/sapmedia/sapcar.exe',
            sar_file='/sapmedia/IMDB_SERVER_LINUX.SAR',
            output_dir='/sapmedia/HANA',
            options='-v')

        cmd = '/sapmedia/sapcar.exe -xvf /sapmedia/IMDB_SERVER_LINUX.SAR -v -R /sapmedia/HANA'
        mock_execute_cmd.assert_called_once_with(cmd,
                                                 user=None,
                                                 password=None,
                                                 remote_host=None)
        self.assertEqual(proc_mock, result)
Exemplo n.º 5
0
def extract(sapcar_exe, sar_file, output_dir=None, options=None):
    '''
    Extract a SAP sar archive

    sapcar_exe_file
        Path to the SAPCAR executable file. SAPCAR is a SAP tool to extract SAP SAR format archives 
    sar_file
        Path to the sar file to be extracted
    output_dir
        Location where to extract the SAR file
    options:
        Additional parameters to the SAPCAR tool
    '''
    try:
        return saputils.extract_sapcar_file(sapcar_exe=sapcar_exe,
                                            sar_file=sar_file,
                                            output_dir=output_dir,
                                            options=options)
    except saputils.SapUtilsError as err:
        raise exceptions.CommandExecutionError(err)