def test_installed_command_error(self, mock_get): ''' Test to check installed when it raises an error ''' ret = { 'name': 'prd', 'changes': {}, 'result': False, 'comment': 'error' } mock_installed = MagicMock(return_value=False) mock_get.return_value = 'ascs' mock_attach = MagicMock( side_effect=exceptions.CommandExecutionError('error')) with patch.dict( netweavermod.__salt__, { 'netweaver.is_installed': mock_installed, 'netweaver.attach_virtual_host': mock_attach }): assert netweavermod.installed('prd', '00', 'pass', '/software', 'root', 'pass', 'config_file', 'vhost', 'eth1', 'productID') == ret mock_installed.assert_called_once_with(sid='prd', inst='00', password='******', sap_instance='ascs') mock_get.assert_called_once_with('productID') mock_attach.assert_called_once_with(virtual_host='vhost', virtual_host_interface='eth1')
def test_installed_test(self, mock_get): ''' Test to check installed in test mode ''' ret = { 'name': 'prd', 'changes': { 'sid': 'prd' }, 'result': None, 'comment': '{}:ascs would be installed'.format('prd') } mock_installed = MagicMock(return_value=False) mock_get.return_value = 'ascs' with patch.dict(netweavermod.__salt__, {'netweaver.is_installed': mock_installed}): with patch.dict(netweavermod.__opts__, {'test': True}): assert netweavermod.installed('prd', '00', 'pass', '/software', 'root', 'pass', 'config_file', 'vhost', 'eth1', 'productID') == ret mock_installed.assert_called_once_with(sid='prd', inst='00', password='******', sap_instance='ascs') mock_get.assert_called_once_with('productID')
def test_installed_not_installed(self, mock_get): ''' Test to check installed when the installation fails ''' ret = { 'name': 'prd', 'changes': {}, 'result': False, 'comment': 'Netweaver was not installed' } mock_installed = MagicMock(side_effect=[False, False]) mock_get.return_value = '' 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_installed': mock_installed, 'netweaver.attach_virtual_host': mock_attach, 'netweaver.setup_cwd': mock_setup_cwd, 'netweaver.install': mock_install }): assert netweavermod.installed('prd', '00', 'pass', '/software', 'root', 'pass', 'config_file', 'vhost', 'eth1', 'productID') == ret mock_installed.assert_has_calls([ mock.call(sid='prd', inst='00', password='******', sap_instance=''), mock.call(sid='prd', inst='00', password='******', sap_instance=''), ]) mock_get.assert_called_once_with('productID') mock_attach.assert_called_once_with(virtual_host='vhost', virtual_host_interface='eth1', virtual_host_mask=24) 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')
def test_installed_installed(self, mock_get): ''' Test to check installed when netweaver is already installed ''' ret = { 'name': 'prd', 'changes': {}, 'result': True, 'comment': 'Netweaver ascs is already installed' } mock_installed = MagicMock(return_value=True) mock_get.return_value = 'ascs' with patch.dict(netweavermod.__salt__, {'netweaver.is_installed': mock_installed}): assert netweavermod.installed('prd', '00', 'pass', '/software', 'root', 'pass', 'config_file', 'vhost', 'eth1', 'productID') == ret mock_installed.assert_called_once_with(sid='prd', inst='00', password='******', sap_instance='ascs') mock_get.assert_called_once_with('productID')
def test_installed_ers_correct(self, mock_get): ''' Test to check installed when ers is installed correctly ''' ret = { 'name': 'prd', 'changes': { 'sid': 'prd' }, 'result': True, 'comment': 'Netweaver ers installed' } mock_installed = MagicMock(side_effect=[False, True]) mock_get.return_value = 'ers' mock_attach = MagicMock(return_value='192.168.15.1') mock_setup_cwd = MagicMock(return_value='/tmp_nw') mock_install = MagicMock() mock_chown = MagicMock() with patch.dict( netweavermod.__salt__, { 'netweaver.is_installed': mock_installed, 'netweaver.attach_virtual_host': mock_attach, 'netweaver.setup_cwd': mock_setup_cwd, 'netweaver.install_ers': mock_install, 'file.chown': mock_chown }): assert netweavermod.installed('prd', '00', 'pass', '/software', 'root', 'pass', 'config_file', 'vhost', 'eth1', 'productID', ascs_password='******') == ret mock_installed.assert_has_calls([ mock.call(sid='prd', inst='00', password='******', sap_instance='ers'), mock.call(sid='prd', inst='00', password='******', sap_instance='ers'), ]) assert mock_chown.call_count == 0 mock_get.assert_called_once_with('productID') 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', ascs_password='******', timeout=0, interval=5)