Skip to content

Commit

Permalink
Merge pull request #31 from QualiSystems/develop
Browse files Browse the repository at this point in the history
Merging for release 1.1
  • Loading branch information
alexazarh committed Jul 2, 2017
2 parents 6f03679 + c578050 commit 98f8a4a
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
[![Dependency Status](https://dependencyci.com/github/QualiSystems/CustomScript-Shell/badge)](https://dependencyci.com/github/QualiSystems/CustomScript-Shell)


# CustomScript-Shell
# CustomScript-Shell
2 changes: 1 addition & 1 deletion drivers/customscript_shell/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
cloudshell-shell-core>=2.2.0,<2.3.0
cloudshell-cm-customscript>=1.0.0,<1.1.0
cloudshell-cm-customscript>=1.1.0,<1.2.0
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import re
import winrm
from logging import Logger

import xml.etree.ElementTree as ET
from winrm.exceptions import WinRMTransportError

from cloudshell.cm.customscript.domain.reservation_output_writer import ReservationOutputWriter
Expand Down Expand Up @@ -179,4 +179,18 @@ def _run_cancelable(self, txt, *args):
self.logger.debug('ReturnedCode:' + str(result.status_code))
self.logger.debug('Stdout:' + result.std_out)
self.logger.debug('Stderr:' + result.std_err)
return result
result.std_err = self._try_decode_error_xml(result.std_err)
self.logger.debug('Stderr(Decoded):' + result.std_err)
return result

def _try_decode_error_xml(self, str):
if str:
try:
str = re.sub(re.escape('#< CLIXML'), '', str, 1)
root = ET.fromstring(str)
str = ''.join([e.text for e in root.findall('*/[@S="Error"]')])
str = re.sub('_x([0-9a-fA-F]{4})_', lambda match: unichr(int(match.group(1), 16)), str)
self.logger.error('Sucedded to decode stderr : ' + str)
except Exception as e:
self.logger.error('Failed to decode stderr. Error: %s' % e.message)
return str
16 changes: 16 additions & 0 deletions package/tests/test_windows_script_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,22 @@ def test_run_script_fail(self):
output_writer.write.assert_any_call('some output')
output_writer.write.assert_any_call('some error')

def test_run_script_fail_with_xml_error(self):
executor = WindowsScriptExecutor(self.logger, self.host, self.cancel_sampler)
output_writer = Mock()
err_xml = '''#< CLIXML
<Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04">
<S S="Error">some error1_x000D__x000A_</S>
<S S="Error">some error2</S>
<S S="warn">some warning</S>
</Objs>'''
self.session.protocol.get_command_output = Mock(return_value=('some output', err_xml, 1))
with self.assertRaises(Exception, ) as e:
executor.run_script('tmp123', ScriptFile('script1', 'some script code'), {}, output_writer)
self.assertEqual(ErrorMsg.RUN_SCRIPT % 'some error1\r\nsome error2', e.exception.message)
output_writer.write.assert_any_call('some output')
output_writer.write.assert_any_call('some error1\r\nsome error2')

# Delete temp folder

def test_delete_temp_folder_success(self):
Expand Down
2 changes: 1 addition & 1 deletion package/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.0.0
1.1.0.0
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.0
1.1.0

0 comments on commit 98f8a4a

Please sign in to comment.