Hello community, here is the log from the commit of package python-shaptools for openSUSE:Factory checked in at 2020-05-15 23:52:34 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/python-shaptools (Old) and /work/SRC/openSUSE:Factory/.python-shaptools.new.2738 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "python-shaptools" Fri May 15 23:52:34 2020 rev:11 rq:805830 version:0.3.8 Changes: -------- --- /work/SRC/openSUSE:Factory/python-shaptools/python-shaptools.changes 2020-01-10 17:51:53.122137435 +0100 +++ /work/SRC/openSUSE:Factory/.python-shaptools.new.2738/python-shaptools.changes 2020-05-15 23:52:40.909586368 +0200 @@ -1,0 +2,19 @@ +Fri Mar 27 18:15:37 UTC 2020 - Simranpal Singh <simranpal.si...@suse.com> + +- Create version 0.3.8 +- Add functionality to extract SAP sar files using SAPCAR tool + +------------------------------------------------------------------- +Tue Mar 24 11:29:14 UTC 2020 - Xabier Arbulu <xarb...@suse.com> + +- Create version 0.3.7 +- Improve hana installation software detection to allow more use + cases + +------------------------------------------------------------------- +Thu Mar 19 15:31:22 UTC 2020 - Xabier Arbulu <xarb...@suse.com> + +- Create version 0.3.6 +- Change the get_platform method to include the system OS type + +------------------------------------------------------------------- Old: ---- shaptools-0.3.5.tar.gz New: ---- shaptools-0.3.8.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ python-shaptools.spec ++++++ --- /var/tmp/diff_new_pack.S8KUm7/_old 2020-05-15 23:52:41.817588119 +0200 +++ /var/tmp/diff_new_pack.S8KUm7/_new 2020-05-15 23:52:41.821588126 +0200 @@ -22,7 +22,7 @@ %{?!python_module:%define python_module() python-%{**} python3-%{**}} Name: python-shaptools -Version: 0.3.5 +Version: 0.3.8 Release: 0 Summary: Python tools to interact with SAP HANA utilities License: Apache-2.0 ++++++ shaptools-0.3.5.tar.gz -> shaptools-0.3.8.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/shaptools-0.3.5/python-shaptools.changes new/shaptools-0.3.8/python-shaptools.changes --- old/shaptools-0.3.5/python-shaptools.changes 2020-01-08 18:00:27.219596228 +0100 +++ new/shaptools-0.3.8/python-shaptools.changes 2020-03-30 16:38:50.408194346 +0200 @@ -1,4 +1,23 @@ ------------------------------------------------------------------- +Fri Mar 27 18:15:37 UTC 2020 - Simranpal Singh <simranpal.si...@suse.com> + +- Create version 0.3.8 +- Add functionality to extract SAP sar files using SAPCAR tool + +------------------------------------------------------------------- +Tue Mar 24 11:29:14 UTC 2020 - Xabier Arbulu <xarb...@suse.com> + +- Create version 0.3.7 +- Improve hana installation software detection to allow more use + cases + +------------------------------------------------------------------- +Thu Mar 19 15:31:22 UTC 2020 - Xabier Arbulu <xarb...@suse.com> + +- Create version 0.3.6 +- Change the get_platform method to include the system OS type + +------------------------------------------------------------------- Thu Jan 2 21:59:30 UTC 2020 - Simranpal Singh <simranpal.si...@suse.com> - Create package version 0.3.5 @@ -9,7 +28,7 @@ Thu Dec 5 10:48:53 UTC 2019 - Xabier Arbulu <xarb...@suse.com> - Create package version 0.3.4 -- Fix ascs restart conditions in ers installation +- Fix ascs restart conditions in ers installation ------------------------------------------------------------------- Thu Nov 7 00:36:08 UTC 2019 - Simranpal Singh <simranpal.si...@suse.com> @@ -21,7 +40,7 @@ Tue Oct 22 02:41:35 UTC 2019 - Xabier Arbulu <xarb...@suse.com> - Create package version 0.3.2 -- Add isconnected and reconnect methods +- Add isconnected and reconnect methods ------------------------------------------------------------------- Wed Aug 7 12:50:36 UTC 2019 - Xabier Arbulu Insausti <xarb...@suse.com> @@ -29,7 +48,7 @@ - Add the required code to install SAP Netweaver instances * Wrap sapcontrol command usage * Install and uninstall SAP instances - * Check current installation status + * Check current installation status ------------------------------------------------------------------- Tue Jul 23 11:04:25 UTC 2019 - Xabier Arbulu Insausti <xarb...@suse.com> diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/shaptools-0.3.5/python-shaptools.spec new/shaptools-0.3.8/python-shaptools.spec --- old/shaptools-0.3.5/python-shaptools.spec 2020-01-08 18:00:27.219596228 +0100 +++ new/shaptools-0.3.8/python-shaptools.spec 2020-03-30 16:38:50.408194346 +0200 @@ -22,7 +22,7 @@ %{?!python_module:%define python_module() python-%{**} python3-%{**}} Name: python-shaptools -Version: 0.3.5 +Version: 0.3.8 Release: 0 Summary: Python tools to interact with SAP HANA utilities License: Apache-2.0 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/shaptools-0.3.5/shaptools/hana.py new/shaptools-0.3.8/shaptools/hana.py --- old/shaptools-0.3.5/shaptools/hana.py 2020-01-08 18:00:27.219596228 +0100 +++ new/shaptools-0.3.8/shaptools/hana.py 2020-03-30 16:38:50.408194346 +0200 @@ -35,11 +35,16 @@ Error during HANA command execution """ -class FileDoesNotExistError(Exception): +class FileDoesNotExistError(HanaError): """ Error when the specified files does not exist """ +class HanaSoftwareNotFoundError(HanaError): + """ + HANA installation software not found + """ + # System replication states # Random value used SR_STATES = { @@ -73,10 +78,12 @@ """ PATH = '/usr/sap/{sid}/HDB{inst}/' - INSTALL_EXEC = '{software_path}/DATA_UNITS/HDB_LCM_LINUX_{platform}/hdblcm' + INSTALL_EXEC = 'hdblcm' + HANA_PLATFORM = '^HDB:HANA:.*:{platform}:.*' SUPPORTED_PLATFORMS = [ 'x86_64', 'ppc64le' ] + SUPPORTED_SYSTEMS = ['Linux'] # SID is usualy written uppercased, but the OS user is always created lower case. HANAUSER = '{sid}adm'.lower() SYNCMODES = ['sync', 'syncmem', 'async'] @@ -106,7 +113,57 @@ logger.info('current platform is %s', current_platform) if current_platform not in cls.SUPPORTED_PLATFORMS: raise ValueError('not supported platform: {}'.format(current_platform)) - return current_platform.upper() + + current_system = platform.system() + logger.info('current system is %s', current_system) + if current_system not in cls.SUPPORTED_SYSTEMS: + raise ValueError('not supported system: {}'.format(current_system)) + + return '{}_{}'.format(current_system.upper(), current_platform.upper()) + + @classmethod + def find_hana_hdblcm(cls, software_path): + """ + Find a HANA installation executable in a folder (and subfolders) + + Args: + software_path (str): Path of a folder where the HANA installation software is + available + """ + logger = logging.getLogger('__name__') + # hdbclm in the provider folder + hdblcm_path = os.path.join(software_path, cls.INSTALL_EXEC) + if os.path.exists(hdblcm_path): + logger.info('HANA installer found: %s', hdblcm_path) + return hdblcm_path + + # HANA platform folder + label_file = os.path.join(software_path, 'LABEL.ASC') + if os.path.exists(label_file): + with open(label_file) as file_ptr: + hana_platform = cls.get_platform() + hana_pattern = cls.HANA_PLATFORM.format(platform=hana_platform) + if re.match(hana_pattern, file_ptr.read()): + hdblcm_path = os.path.join( + software_path, 'DATA_UNITS', + 'HDB_LCM_{}'.format(hana_platform), cls.INSTALL_EXEC) + hdbserver_path = os.path.join( + software_path, 'DATA_UNITS', + 'HDB_SERVER_{}'.format(hana_platform), cls.INSTALL_EXEC) + if os.path.exists(hdblcm_path): + logger.info('HANA installer found: %s', hdblcm_path) + return hdblcm_path + elif os.path.exists(hdbserver_path): + logger.info('HANA installer found: %s', hdbserver_path) + return hdbserver_path + + # HANA server SAR patch + hana_server_path = os.path.join(software_path, 'SAP_HANA_DATABASE', cls.INSTALL_EXEC) + if os.path.exists(hana_server_path): + logger.info('HANA installer found: %s', hana_server_path) + return hana_server_path + + raise HanaSoftwareNotFoundError('HANA installer not found in {}'.format(software_path)) def _run_hana_command(self, cmd, exception=True): """ @@ -202,8 +259,7 @@ remote_host (str, opt): Remote host where the command will be executed """ - platform_folder = cls.get_platform() - executable = cls.INSTALL_EXEC.format(software_path=software_path, platform=platform_folder) + executable = cls.find_hana_hdblcm(software_path) cmd = '{executable} --action=install '\ '--dump_configfile_template={conf_file}'.format( executable=executable, conf_file=conf_file) @@ -231,12 +287,12 @@ # TODO: do some integrity check stuff if not os.path.isfile(conf_file): - raise FileDoesNotExistError('The configuration file \'{}\' does not exist'.format(conf_file)) + raise FileDoesNotExistError( + 'The configuration file \'{}\' does not exist'.format(conf_file)) if hdb_pwd_file is not None and not os.path.isfile(hdb_pwd_file): - raise FileDoesNotExistError('The XML password file \'{}\' does not exist'.format(hdb_pwd_file)) - - platform_folder = cls.get_platform() - executable = cls.INSTALL_EXEC.format(software_path=software_path, platform=platform_folder) + raise FileDoesNotExistError( + 'The XML password file \'{}\' does not exist'.format(hdb_pwd_file)) + executable = cls.find_hana_hdblcm(software_path) if hdb_pwd_file: cmd = 'cat {hdb_pwd_file} | {executable} -b '\ '--read_password_from_stdin=xml --configfile={conf_file}'.format( diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/shaptools-0.3.5/shaptools/saputils.py new/shaptools-0.3.8/shaptools/saputils.py --- old/shaptools-0.3.5/shaptools/saputils.py 1970-01-01 01:00:00.000000000 +0100 +++ new/shaptools-0.3.8/shaptools/saputils.py 2020-03-30 16:38:50.408194346 +0200 @@ -0,0 +1,65 @@ +""" +Module to utilize SAP Technology components + +:author: sisingh +:organization: SUSE LLC +:contact: sisi...@suse.com + +:since: 2020-03-12 +""" +#TODO: Add support for other SAPCAR functionalties apart from extraction + +import os + +from shaptools import shell + + +class SapUtilsError(Exception): + """ + Error during SapUtils command execution + """ + + +class FileDoesNotExistError(SapUtilsError): + """ + Error when the specified files does not exist + """ + + +def extract_sapcar_file(sapcar_exe, sar_file, **kwargs): + """ + Execute SAPCAR command to decompress a SAP CAR or SAR archive files. + If user and password are provided it will be executed with this user. + + Args: + sapcar_exe(str): Path to the SAPCAR executable + sar_file (str): Path to the sar file to be extracted + options (str, opt): Additional options to SAPCAR command + output_dir (str, opt): Directory where archive will be extracted. It creates the dir + if the path doesn't exist. If it's not set the current dir is used + user (str, opt): User to execute the SAPCAR command + password (str, opt): User password + remote_host (str, opt): Remote host where the command will be executed + """ + if not os.path.isfile(sapcar_exe): + raise FileDoesNotExistError('SAPCAR executable \'{}\' does not exist'.format(sapcar_exe)) + if not os.path.isfile(sar_file): + raise FileDoesNotExistError('The SAR file \'{}\' does not exist'.format(sar_file)) + + options = kwargs.get('options', None) + output_dir = kwargs.get('output_dir', None) + user = kwargs.get('user', None) + password = kwargs.get('password', None) + remote_host = kwargs.get('remote_host', None) + + output_dir_str = ' -R {}'.format(output_dir) if output_dir else '' + options_str = ' {}'.format(options) if options else '' + + cmd = '{sapcar_exe} -xvf {sar_file}{options_str}{output_dir_str}'.format( + sapcar_exe=sapcar_exe, sar_file=sar_file, + options_str=options_str, output_dir_str=output_dir_str) + + result = shell.execute_cmd(cmd, user=user, password=password, remote_host=remote_host) + if result.returncode: + raise SapUtilsError('Error running SAPCAR command') + return result diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/shaptools-0.3.5/tests/hana_test.py new/shaptools-0.3.8/tests/hana_test.py --- old/shaptools-0.3.5/tests/hana_test.py 2020-01-08 18:00:27.223598228 +0100 +++ new/shaptools-0.3.8/tests/hana_test.py 2020-03-30 16:38:50.408194346 +0200 @@ -78,27 +78,123 @@ 'provided sid, inst and password parameters must be str type' in str(err.exception)) + @mock.patch('platform.system') @mock.patch('platform.machine') - def test_get_platform(self, mock_machine): + def test_get_platform(self, mock_machine, mock_system): mock_machine.return_value = 'x86_64' + mock_system.return_value = 'Linux' machine = hana.HanaInstance.get_platform() - self.assertEqual(machine, 'X86_64') + self.assertEqual(machine, 'LINUX_X86_64') mock_machine.assert_called_once_with() mock_machine.reset_mock() mock_machine.return_value = 'ppc64le' + mock_system.return_value = 'Linux' machine = hana.HanaInstance.get_platform() - self.assertEqual(machine, 'PPC64LE') + self.assertEqual(machine, 'LINUX_PPC64LE') mock_machine.assert_called_once_with() @mock.patch('platform.machine') - def test_get_platform_error(self, mock_machine): + def test_get_platform_machine_error(self, mock_machine): mock_machine.return_value = 'ppc64' with self.assertRaises(ValueError) as err: hana.HanaInstance.get_platform() self.assertTrue('not supported platform: {}'.format('ppc64') in str(err.exception)) mock_machine.assert_called_once_with() + @mock.patch('platform.system') + @mock.patch('platform.machine') + def test_get_platform_system_error(self, mock_machine, mock_system): + mock_machine.return_value = 'x86_64' + mock_system.return_value = 'Mac' + with self.assertRaises(ValueError) as err: + hana.HanaInstance.get_platform() + self.assertTrue('not supported system: {}'.format('Mac') in str(err.exception)) + mock_machine.assert_called_once_with() + + @mock.patch('logging.Logger.info') + @mock.patch('os.path.exists') + def test_find_hana_hdblcm(self, mock_exists, mock_info): + mock_exists.return_value = True + hdblcm = hana.HanaInstance.find_hana_hdblcm('software_path') + assert hdblcm == 'software_path/hdblcm' + mock_exists.assert_called_once_with('software_path/hdblcm') + mock_info.assert_called_once_with('HANA installer found: %s', 'software_path/hdblcm') + + @mock.patch('logging.Logger.info') + @mock.patch('shaptools.hana.HanaInstance.get_platform') + @mock.patch('os.path.exists') + def test_find_hana_hdblcm_units_lcm(self, mock_exists, mock_get_platform, mock_info): + mock_exists.side_effect = [False, True, True] + mock_get_platform.return_value = 'LINUX_X86_64' + + file_content = 'HDB:HANA:2.0:LINUX_X86_64:SAP HANA PLATFORM EDITION 2.0::BD51053787\n' + with mock.patch('shaptools.hana.open', mock.mock_open(read_data=file_content)) as mock_file: + hdblcm = hana.HanaInstance.find_hana_hdblcm('software_path') + + assert hdblcm == 'software_path/DATA_UNITS/HDB_LCM_LINUX_X86_64/hdblcm' + mock_get_platform.assert_called_once_with() + mock_exists.assert_has_calls([ + mock.call('software_path/hdblcm'), + mock.call('software_path/LABEL.ASC'), + mock.call('software_path/DATA_UNITS/HDB_LCM_LINUX_X86_64/hdblcm') + ]) + mock_info.assert_called_once_with( + 'HANA installer found: %s', 'software_path/DATA_UNITS/HDB_LCM_LINUX_X86_64/hdblcm') + + @mock.patch('logging.Logger.info') + @mock.patch('shaptools.hana.HanaInstance.get_platform') + @mock.patch('os.path.exists') + def test_find_hana_hdblcm_units_server(self, mock_exists, mock_get_platform, mock_info): + mock_exists.side_effect = [False, True, False, True] + mock_get_platform.return_value = 'LINUX_X86_64' + + file_content = 'HDB:HANA:2.0:LINUX_X86_64:SAP HANA PLATFORM EDITION 2.0::BD51053787\n' + with mock.patch('shaptools.hana.open', mock.mock_open(read_data=file_content)) as mock_file: + hdblcm = hana.HanaInstance.find_hana_hdblcm('software_path') + + assert hdblcm == 'software_path/DATA_UNITS/HDB_SERVER_LINUX_X86_64/hdblcm' + mock_get_platform.assert_called_once_with() + mock_exists.assert_has_calls([ + mock.call('software_path/hdblcm'), + mock.call('software_path/LABEL.ASC'), + mock.call('software_path/DATA_UNITS/HDB_LCM_LINUX_X86_64/hdblcm'), + mock.call('software_path/DATA_UNITS/HDB_SERVER_LINUX_X86_64/hdblcm') + ]) + mock_info.assert_called_once_with( + 'HANA installer found: %s', 'software_path/DATA_UNITS/HDB_SERVER_LINUX_X86_64/hdblcm') + + @mock.patch('logging.Logger.info') + @mock.patch('os.path.exists') + def test_find_hana_hdblcm_extracted(self, mock_exists, mock_info): + mock_exists.side_effect = [False, False, True] + + hdblcm = hana.HanaInstance.find_hana_hdblcm('software_path') + + assert hdblcm == 'software_path/SAP_HANA_DATABASE/hdblcm' + mock_exists.assert_has_calls([ + mock.call('software_path/hdblcm'), + mock.call('software_path/LABEL.ASC'), + mock.call('software_path/SAP_HANA_DATABASE/hdblcm') + ]) + mock_info.assert_called_once_with( + 'HANA installer found: %s', 'software_path/SAP_HANA_DATABASE/hdblcm') + + @mock.patch('os.path.exists') + def test_find_hana_hdblcm_error(self, mock_exists): + mock_exists.side_effect = [False, False, False] + + with self.assertRaises(hana.HanaError) as err: + hana.HanaInstance.find_hana_hdblcm('software_path') + + mock_exists.assert_has_calls([ + mock.call('software_path/hdblcm'), + mock.call('software_path/LABEL.ASC'), + mock.call('software_path/SAP_HANA_DATABASE/hdblcm') + ]) + self.assertTrue( + 'HANA installer not found in software_path' in str(err.exception)) + @mock.patch('shaptools.shell.execute_cmd') def test_run_hana_command(self, mock_execute): proc_mock = mock.Mock() @@ -183,109 +279,109 @@ pwd = os.path.dirname(os.path.abspath(__file__)) shutil.copyfile(pwd+'/support/original.conf.xml', '/tmp/test.conf.xml') hdb_pwd_file = hana.HanaInstance.update_hdb_pwd_file( - '/tmp/test.conf.xml', master_password='Master1234', + '/tmp/test.conf.xml', master_password='Master1234', sapadm_password='Adm1234', system_user_password='Qwerty1234') self.assertTrue(filecmp.cmp(pwd+'/support/modified.conf.xml', hdb_pwd_file)) - @mock.patch('shaptools.hana.HanaInstance.get_platform') + @mock.patch('shaptools.hana.HanaInstance.find_hana_hdblcm') @mock.patch('shaptools.shell.execute_cmd') - def test_create_conf_file(self, mock_execute, mock_get_platform): + def test_create_conf_file(self, mock_execute, mock_find_hana): proc_mock = mock.Mock() proc_mock.returncode = 0 mock_execute.return_value = proc_mock - mock_get_platform.return_value = 'my_arch' + mock_find_hana.return_value = 'my_path/hdblcm' conf_file = hana.HanaInstance.create_conf_file( 'software_path', 'conf_file.conf', 'root', 'pass') mock_execute.assert_called_once_with( - 'software_path/DATA_UNITS/HDB_LCM_LINUX_my_arch/hdblcm ' + 'my_path/hdblcm ' '--action=install --dump_configfile_template={conf_file}'.format( conf_file='conf_file.conf'), 'root', 'pass', None) - mock_get_platform.assert_called_once_with() + mock_find_hana.assert_called_once_with('software_path') self.assertEqual('conf_file.conf', conf_file) - @mock.patch('shaptools.hana.HanaInstance.get_platform') + @mock.patch('shaptools.hana.HanaInstance.find_hana_hdblcm') @mock.patch('shaptools.shell.execute_cmd') - def test_create_conf_file_error(self, mock_execute, mock_get_platform): + def test_create_conf_file_error(self, mock_execute, mock_find_hana): proc_mock = mock.Mock() proc_mock.returncode = 1 mock_execute.return_value = proc_mock - mock_get_platform.return_value = 'my_arch' + mock_find_hana.return_value = 'my_path/hdblcm' with self.assertRaises(hana.HanaError) as err: hana.HanaInstance.create_conf_file( 'software_path', 'conf_file.conf', 'root', 'pass') mock_execute.assert_called_once_with( - 'software_path/DATA_UNITS/HDB_LCM_LINUX_my_arch/hdblcm ' + 'my_path/hdblcm ' '--action=install --dump_configfile_template={conf_file}'.format( conf_file='conf_file.conf'), 'root', 'pass', None) - mock_get_platform.assert_called_once_with() + mock_find_hana.assert_called_once_with('software_path') self.assertTrue( 'SAP HANA configuration file creation failed' in str(err.exception)) - @mock.patch('shaptools.hana.HanaInstance.get_platform') + @mock.patch('shaptools.hana.HanaInstance.find_hana_hdblcm') @mock.patch('shaptools.shell.execute_cmd') @mock.patch('os.path.isfile') - def test_install(self, mock_conf_file, mock_execute, mock_get_platform): + def test_install(self, mock_conf_file, mock_execute, mock_find_hana): proc_mock = mock.Mock() proc_mock.returncode = 0 mock_conf_file.side_effect = [True, True] mock_execute.return_value = proc_mock - mock_get_platform.return_value = 'my_arch' + mock_find_hana.return_value = 'my_path/hdblcm' hana.HanaInstance.install( 'software_path', 'conf_file.conf', 'root', 'pass') mock_execute.assert_called_once_with( - 'software_path/DATA_UNITS/HDB_LCM_LINUX_my_arch/hdblcm ' + 'my_path/hdblcm ' '-b --configfile={conf_file}'.format( conf_file='conf_file.conf'), 'root', 'pass', None) - mock_get_platform.assert_called_once_with() + mock_find_hana.assert_called_once_with('software_path') - @mock.patch('shaptools.hana.HanaInstance.get_platform') + @mock.patch('shaptools.hana.HanaInstance.find_hana_hdblcm') @mock.patch('shaptools.shell.execute_cmd') @mock.patch('os.path.isfile') - def test_install_xml(self, mock_conf_file, mock_execute, mock_get_platform): + def test_install_xml(self, mock_conf_file, mock_execute, mock_find_hana): proc_mock = mock.Mock() proc_mock.returncode = 0 mock_conf_file.side_effect = [True, True] mock_execute.return_value = proc_mock - mock_get_platform.return_value = 'my_arch' + mock_find_hana.return_value = 'my_path/hdblcm' hana.HanaInstance.install( - 'software_path', 'conf_file.conf', 'root', 'pass', + 'software_path', 'conf_file.conf', 'root', 'pass', hdb_pwd_file='hdb_passwords.xml') mock_execute.assert_called_once_with( - 'cat {hdb_pwd_file} | software_path/DATA_UNITS/HDB_LCM_LINUX_my_arch/hdblcm '\ + 'cat {hdb_pwd_file} | my_path/hdblcm '\ '-b --read_password_from_stdin=xml --configfile={conf_file}'.format( - hdb_pwd_file='hdb_passwords.xml', + hdb_pwd_file='hdb_passwords.xml', conf_file='conf_file.conf'), 'root', 'pass', None) - mock_get_platform.assert_called_once_with() + mock_find_hana.assert_called_once_with('software_path') - @mock.patch('shaptools.hana.HanaInstance.get_platform') + @mock.patch('shaptools.hana.HanaInstance.find_hana_hdblcm') @mock.patch('shaptools.shell.execute_cmd') @mock.patch('os.path.isfile') - def test_install_error(self, mock_conf_file, mock_execute, mock_get_platform): + def test_install_error(self, mock_conf_file, mock_execute, mock_find_hana): proc_mock = mock.Mock() proc_mock.returncode = 1 mock_conf_file.side_effect = [True, True] mock_execute.return_value = proc_mock - mock_get_platform.return_value = 'my_arch' + mock_find_hana.return_value = 'my_path/hdblcm' with self.assertRaises(hana.HanaError) as err: hana.HanaInstance.install( 'software_path', 'conf_file.conf', 'root', 'pass') mock_execute.assert_called_once_with( - 'software_path/DATA_UNITS/HDB_LCM_LINUX_my_arch/hdblcm ' + 'my_path/hdblcm ' '-b --configfile={conf_file}'.format( conf_file='conf_file.conf'), 'root', 'pass', None) - mock_get_platform.assert_called_once_with() + mock_find_hana.assert_called_once_with('software_path') self.assertTrue( 'SAP HANA installation failed' in str(err.exception)) @@ -293,7 +389,7 @@ @mock.patch('os.path.isfile') def test_install_FileDoesNotExistError(self, mock_conf_file): mock_conf_file.return_value = False - + with self.assertRaises(hana.FileDoesNotExistError) as err: hana.HanaInstance.install( 'software_path', 'conf_file.conf', 'root', 'pass') diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/shaptools-0.3.5/tests/saputils_test.py new/shaptools-0.3.8/tests/saputils_test.py --- old/shaptools-0.3.5/tests/saputils_test.py 1970-01-01 01:00:00.000000000 +0100 +++ new/shaptools-0.3.8/tests/saputils_test.py 2020-03-30 16:38:50.408194346 +0200 @@ -0,0 +1,111 @@ +""" +Unitary tests for saputils.py. + +:author: sisingh +:organization: SUSE LLC +:contact: sisi...@suse.com + +:since: 2020-03-26 +""" + +# pylint:disable=C0103,C0111,W0212,W0611 + +import os +import sys +sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) + +import logging +import unittest + +try: + from unittest import mock +except ImportError: + import mock + + +from shaptools import saputils + +class TestSapUtils(unittest.TestCase): + """ + Unitary tests for shaptools/saputis.py. + """ + + @classmethod + def setUpClass(cls): + """ + Global setUp. + """ + + logging.basicConfig(level=logging.INFO) + + def setUp(self): + """ + Test setUp. + """ + + def tearDown(self): + """ + Test tearDown. + """ + + @classmethod + def tearDownClass(cls): + """ + Global tearDown. + """ + + @mock.patch('shaptools.shell.execute_cmd') + @mock.patch('os.path.isfile') + 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) + + @mock.patch('shaptools.shell.execute_cmd') + @mock.patch('os.path.isfile') + 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)) + + @mock.patch('os.path.isfile') + 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)) + + @mock.patch('os.path.isfile') + 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)) \ No newline at end of file