def test_installed_error(self): ''' Test to check installed when install fails ''' ret = { 'name': 'prd', 'changes': { 'config_file': 'new' }, 'result': False, 'comment': 'hana command error' } mock_installed = MagicMock(return_value=False) mock_create = MagicMock(return_value='hana_created.conf') mock_update = MagicMock(return_value='hana_updated.conf') mock_install = MagicMock( side_effect=exceptions.CommandExecutionError('hana command error')) mock_remove = MagicMock() with patch.dict( hanamod.__salt__, { 'hana.is_installed': mock_installed, 'hana.create_conf_file': mock_create, 'hana.update_conf_file': mock_update, 'hana.install': mock_install, 'file.remove': mock_remove }): assert hanamod.installed('prd', '00', 'pass', '/software', 'root', 'pass', sapadm_password='******', system_user_password='******') == ret mock_create.assert_called_once_with( software_path='/software', conf_file=hanamod.TMP_CONFIG_FILE, root_user='******', root_password='******') mock_update.assert_called_once_with( conf_file='hana_created.conf', sid='PRD', number='00', password='******', root_user='******', root_password='******', sapadm_password='******', system_user_password='******') mock_install.assert_called_once_with(software_path='/software', conf_file='hana_updated.conf', root_user='******', root_password='******') mock_remove.assert_has_calls([ mock.call(hanamod.TMP_CONFIG_FILE), mock.call('{}.xml'.format(hanamod.TMP_CONFIG_FILE)) ])
def test_installed_invalid_params(self): ''' Test to check installed when install fails ''' ret = { 'name': 'prd', 'changes': {}, 'result': False, 'comment': 'If config_file is not provided ' 'system_user_password and sapadm_password are mandatory' } mock_installed = MagicMock(return_value=False) mock_remove = MagicMock() with patch.dict(hanamod.__salt__, { 'hana.is_installed': mock_installed, 'file.remove': mock_remove }): assert hanamod.installed('prd', '00', 'pass', '/software', 'root', 'pass') == ret mock_remove.assert_has_calls([ mock.call(hanamod.TMP_CONFIG_FILE), mock.call('{}.xml'.format(hanamod.TMP_CONFIG_FILE)) ])
def test_installed_config_file(self): ''' Test to check installed when config file is imported ''' ret = { 'name': 'prd', 'changes': { 'sid': 'prd', 'config_file': 'hana.conf' }, 'result': True, 'comment': 'HANA installed' } mock_installed = MagicMock(return_value=False) mock_cp = MagicMock() mock_update = MagicMock(return_value='hana_updated.conf') mock_install = MagicMock() mock_remove = MagicMock() with patch.dict( hanamod.__salt__, { 'hana.is_installed': mock_installed, 'cp.get_file': mock_cp, 'hana.update_conf_file': mock_update, 'hana.install': mock_install, 'file.remove': mock_remove }): assert hanamod.installed('prd', '00', 'pass', '/software', 'root', 'pass', config_file='hana.conf', extra_parameters=[{ 'hostname': 'hana01' }]) == ret mock_cp.assert_called_once_with(path='hana.conf', dest=hanamod.TMP_CONFIG_FILE) mock_update.assert_called_once_with( conf_file=hanamod.TMP_CONFIG_FILE, extra_parameters={u'hostname': u'hana01'}) mock_install.assert_called_once_with(software_path='/software', conf_file='hana_updated.conf', root_user='******', root_password='******') mock_remove.assert_has_calls([ mock.call(hanamod.TMP_CONFIG_FILE), mock.call('{}.xml'.format(hanamod.TMP_CONFIG_FILE)) ])
def test_installed_installed(self): ''' Test to check installed when hana is already installed ''' ret = { 'name': 'prd', 'changes': {}, 'result': True, 'comment': 'HANA is already installed' } mock_installed = MagicMock(return_value=True) with patch.dict(hanamod.__salt__, {'hana.is_installed': mock_installed}): assert hanamod.installed('prd', '00', 'pass', '/software', 'root', 'pass') == ret
def test_installed_test(self): ''' Test to check installed in test mode ''' ret = { 'name': 'prd', 'changes': { 'sid': 'prd' }, 'result': None, 'comment': '{} would be installed'.format('prd') } mock_installed = MagicMock(return_value=False) with patch.dict(hanamod.__salt__, {'hana.is_installed': mock_installed}): with patch.dict(hanamod.__opts__, {'test': True}): assert hanamod.installed('prd', '00', 'pass', '/software', 'root', 'pass') == ret
def test_installed_config_file(self): ''' Test to check installed when config file is imported and XML password file is created ''' ret = { 'name': 'prd', 'changes': { 'sid': 'prd', 'config_file': 'hana.conf', 'hdb_pwd_file': 'new' }, 'result': True, 'comment': 'HANA installed' } mock_installed = MagicMock(return_value=False) mock_cp = MagicMock() mock_mv = MagicMock() mock_create_xml = MagicMock(return_value='temp.conf') mock_update_xml = MagicMock(return_value=hanamod.TMP_HDB_PWD_FILE) mock_update = MagicMock(return_value='hana_updated.conf') mock_install = MagicMock() mock_remove = MagicMock() with patch.dict( hanamod.__salt__, { 'hana.is_installed': mock_installed, 'cp.get_file': mock_cp, 'file.move': mock_mv, 'hana.create_conf_file': mock_create_xml, 'hana.update_hdb_pwd_file': mock_update_xml, 'hana.update_conf_file': mock_update, 'hana.install': mock_install, 'file.remove': mock_remove }): assert hanamod.installed('prd', '00', 'pass', '/software', 'root', config_file='hana.conf', root_password='******', sapadm_password='******', system_user_password='******', extra_parameters=[{ 'hostname': 'hana01', 'org_manager_password': '******' }]) == ret mock_create_xml.assert_called_once_with( software_path='/software', conf_file=hanamod.TMP_CONFIG_FILE, root_user='******', root_password='******') mock_mv.assert_called_once_with(src='/tmp/hana.conf.xml', dst=hanamod.TMP_HDB_PWD_FILE) mock_update_xml.assert_called_once_with( hdb_pwd_file=hanamod.TMP_HDB_PWD_FILE, root_password='******', password='******', sapadm_password='******', system_user_password='******', org_manager_password='******') mock_cp.assert_called_once_with(path='hana.conf', dest=hanamod.TMP_CONFIG_FILE) mock_update.assert_called_once_with( conf_file=hanamod.TMP_CONFIG_FILE, hostname='hana01') mock_install.assert_called_once_with( software_path='/software', conf_file='hana_updated.conf', root_user='******', root_password='******', hdb_pwd_file=hanamod.TMP_HDB_PWD_FILE) mock_remove.assert_has_calls( [mock.call('{}.xml'.format(hanamod.TMP_CONFIG_FILE))])