Skip to content

Commit

Permalink
Merge pull request #35 from QualiSystems/develop
Browse files Browse the repository at this point in the history
Merging dev to master for release 1.2.0
  • Loading branch information
alexazarh committed Aug 8, 2017
2 parents 98f8a4a + cb9f4e1 commit 6db7039
Show file tree
Hide file tree
Showing 14 changed files with 36 additions and 25 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ python:
- "2.7"

install:
- pip install -r package/external_requirements.txt --extra-index-url https://pypi.python.org/simple
- pip install -r package/test_requirements.txt --extra-index-url https://pypi.python.org/simple
- pip install -r external_requirements.txt --extra-index-url https://pypi.python.org/simple
- pip install -r test_requirements.txt --extra-index-url https://pypi.python.org/simple
- pip install "cloudshell-shell-core>=2.2.0,<2.3.0" --extra-index-url https://testpypi.python.org/simple
- pip install "cloudshell-automation-api>=8.0.0.0,<8.1.0.0" --extra-index-url https://testpypi.python.org/simple
Expand Down
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.1.0,<1.2.0
cloudshell-cm-customscript>=1.2.0,<1.3.0
2 changes: 1 addition & 1 deletion drivers/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.0
1.2.0
File renamed without changes.
4 changes: 2 additions & 2 deletions package/cloudshell/cm/customscript/customscript_shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ def execute_script(self, command_context, script_conf_json, cancellation_context

self._warn_for_unexpected_file_type(script_conf.host_conf, service, script_file, output_writer)

logger.info('Connectiong ...')
logger.info('Connecting ...')
self._connect(service, cancel_sampler, script_conf.timeout_minutes)
logger.info('Done.')

service.execute(script_file, script_conf.host_conf.parameters, output_writer)
service.execute(script_file, script_conf.host_conf.parameters, output_writer, script_conf.print_output)

def _download_script(self, script_repo, logger, cancel_sampler):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,11 @@ def get_expected_file_extensions(self):
# if file_ext and file_ext != '.sh' and file_ext != '.bash':
# output_writer.write_warning('Trying to run "%s" file via ssh on host %s' % (file_ext, self.target_host.ip))

def execute(self, script_file, env_vars, output_writer):
def execute(self, script_file, env_vars, output_writer, print_output=True):
"""
:type script_file: ScriptFile
:type output_writer: ReservationOutputWriter
:type print_output: bool
"""
self.logger.info('Creating temp folder on target machine ...')
tmp_folder = self.create_temp_folder()
Expand All @@ -81,7 +82,7 @@ def execute(self, script_file, env_vars, output_writer):
self.logger.info('Done.')

self.logger.info('Running "%s" on target machine ...' % script_file.name)
self.run_script(tmp_folder, script_file, env_vars, output_writer)
self.run_script(tmp_folder, script_file, env_vars, output_writer, print_output)
self.logger.info('Done.')

finally:
Expand Down Expand Up @@ -115,12 +116,13 @@ def copy_script(self, tmp_folder, script_file):
if scp:
scp.close()

def run_script(self, tmp_folder, script_file, env_vars, output_writer):
def run_script(self, tmp_folder, script_file, env_vars, output_writer, print_output=True):
"""
:type tmp_folder: str
:type script_file: ScriptFile
:type env_vars: dict
:type output_writer: ReservationOutputWriter
:type print_output: bool
"""
code = ''
for key, value in (env_vars or {}).iteritems():
Expand All @@ -129,8 +131,9 @@ def run_script(self, tmp_folder, script_file, env_vars, output_writer):
code += 'export %s=%s;' % (self.PasswordEnvVarName, self._escape(self.target_host.password))
code += 'sh '+tmp_folder+'/'+script_file.name
result = self._run_cancelable(code)
output_writer.write(result.std_out)
output_writer.write(result.std_err)
if print_output:
output_writer.write(result.std_out)
output_writer.write(result.std_err)
if not result.success:
raise Exception(ErrorMsg.RUN_SCRIPT % result.std_err)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@


class ScriptConfiguration(object):
def __init__(self, script_repo = None, host_conf = None, timeout_minutes = None):
def __init__(self, script_repo = None, host_conf = None, timeout_minutes = None, print_output = True):
"""
:type script_repo: ScriptRepository
:type host_conf: HostConfiguration
:type timeout_minutes: float
:type print_output: bool
"""
self.timeout_minutes = timeout_minutes or 0.0
self.script_repo = script_repo or ScriptRepository()
self.host_conf = host_conf or HostConfiguration()
self.print_output = print_output


class ScriptRepository(object):
Expand Down Expand Up @@ -51,6 +53,7 @@ def json_to_object(self, json_str):

script_conf = ScriptConfiguration()
script_conf.timeout_minutes = json_obj.get('timeoutMinutes', 0.0)
script_conf.print_output = bool_parse(json_obj.get('printOutput'))

repo = json_obj['repositoryDetails']
script_conf.script_repo.url = repo.get('url')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def get_expected_file_extensions(self):
pass

@abstractmethod
def execute(self, script_file, env_vars, output_writer):
def execute(self, script_file, env_vars, output_writer, print_output):
"""
:type script_file: ScriptFile
:type output_writer: ReservationOutputWriter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,11 @@ def get_expected_file_extensions(self):
# return file_ext != '.ps1':
# output_writer.write_warning('Trying to run "%s" file via ssh on host %s' % (file_ext, self.target_host.ip))

def execute(self, script_file, env_vars, output_writer):
def execute(self, script_file, env_vars, output_writer, print_output=True):
"""
:type script_file: ScriptFile
:type output_writer: ReservationOutputWriter
:type print_output: bool
"""
self.logger.info('Creating temp folder on target machine ...')
tmp_folder = self.create_temp_folder()
Expand All @@ -75,7 +76,7 @@ def execute(self, script_file, env_vars, output_writer):
self.logger.info('Done.')

self.logger.info('Running "%s" on target machine ...' % script_file.name)
self.run_script(tmp_folder, script_file, env_vars, output_writer)
self.run_script(tmp_folder, script_file, env_vars, output_writer, print_output)
self.logger.info('Done.')

finally:
Expand Down Expand Up @@ -118,12 +119,13 @@ def copy_script(self, tmp_folder, script_file):
if result.status_code != 0:
raise Exception(ErrorMsg.COPY_SCRIPT % result.std_err)

def run_script(self, tmp_folder, script_file, env_vars, output_writer):
def run_script(self, tmp_folder, script_file, env_vars, output_writer, print_output=True):
"""
:type tmp_folder: str
:type script_file: ScriptFile
:type env_vars: dict
:type output_writer: ReservationOutputWriter
:type print_output: bool
"""
code = ''
for key, value in (env_vars or {}).iteritems():
Expand All @@ -133,8 +135,9 @@ def run_script(self, tmp_folder, script_file, env_vars, output_writer):
Invoke-Expression "& '$path'"
"""
result = self._run_cancelable(code, tmp_folder, script_file.name)
output_writer.write(result.std_out)
output_writer.write(result.std_err)
if print_output:
output_writer.write(result.std_out)
output_writer.write(result.std_err)
if result.status_code != 0:
raise Exception(ErrorMsg.RUN_SCRIPT % result.std_err)

Expand Down
5 changes: 4 additions & 1 deletion package/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
cloudshell-automation-api>=8.0.0.0,<8.1.0.0
cloudshell-shell-core>=2.2.0,<2.3.0
cloudshell-shell-core>=2.2.0,<2.3.0
pywinrm>=0.2.2
paramiko>=2.1.1
scpclient>=0.7
3 changes: 0 additions & 3 deletions package/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
with open('requirements.txt') as f_required:
required = f_required.read().splitlines()

with open('external_requirements.txt') as f_required:
required.extend(f_required.read().splitlines())

with open('test_requirements.txt') as f_tests:
required_for_tests = f_tests.read().splitlines()

Expand Down
2 changes: 1 addition & 1 deletion package/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.0.0
1.2.0
5 changes: 4 additions & 1 deletion test_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
coverage
teamcity-messages
nose-exclude
coveralls
coveralls
nose
mock
unittest2
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.0
1.2.0

0 comments on commit 6db7039

Please sign in to comment.