aboutsummaryrefslogtreecommitdiff
path: root/rumba/ssh_support.py
diff options
context:
space:
mode:
authorSander Vrijders <sander.vrijders@ugent.be>2017-09-13 11:26:53 +0200
committerSander Vrijders <sander.vrijders@ugent.be>2017-09-13 17:18:56 +0200
commit440ab00aa57dd8c7c0076d93011814b7fb25ec76 (patch)
tree3f65d7b4866c4cc6de68929d254fd04c8adb52e7 /rumba/ssh_support.py
parente7a0deed26ec4015e783742da0796a77c589ce55 (diff)
downloadrumba-440ab00aa57dd8c7c0076d93011814b7fb25ec76.tar.gz
rumba-440ab00aa57dd8c7c0076d93011814b7fb25ec76.zip
build: Add continuous integration
This adds CI to Rumba.
Diffstat (limited to 'rumba/ssh_support.py')
-rw-r--r--rumba/ssh_support.py47
1 files changed, 28 insertions, 19 deletions
diff --git a/rumba/ssh_support.py b/rumba/ssh_support.py
index 9261ce0..dfa290a 100644
--- a/rumba/ssh_support.py
+++ b/rumba/ssh_support.py
@@ -32,6 +32,9 @@ import rumba.log as log
logger = log.get_logger(__name__)
+class SSHException(Exception):
+ pass
+
def get_ssh_client():
ssh_client = paramiko.SSHClient()
ssh_client.load_system_host_keys()
@@ -118,23 +121,29 @@ def execute_commands(testbed, ssh_config, commands, time_out=3):
testbed.username, testbed.password,
look_for_keys=True, timeout=time_out,
sock=proxy)
- o = ""
- for command in commands:
- logger.debug("%s@%s:%s >> %s" % (testbed.username,
- ssh_config.hostname,
- ssh_config.port,
- command))
- envars = '. /etc/profile;'
- command = envars + ' ' + command
- stdin, stdout, stderr = ssh_client.exec_command(command)
- o = _print_stream(stdout)
- _print_stream(stderr)
- ssh_client.close()
- return o
+ except paramiko.ssh_exception.SSHException as e:
+ raise SSHException('Failed to connect to host')
- except Exception as e:
- logger.error(str(e))
- return
+ o = ""
+ for command in commands:
+ logger.debug("%s@%s:%s >> %s" % (testbed.username,
+ ssh_config.hostname,
+ ssh_config.port,
+ command))
+ envars = '. /etc/profile;'
+ command = envars + ' ' + command
+ chan = ssh_client.get_transport().open_session()
+ stdout = chan.makefile()
+ try:
+ chan.exec_command(command)
+ except paramiko.ssh_exception.SSHException as e:
+ raise SSHException('Failed to execute command')
+ if (chan.recv_exit_status() != 0):
+ raise SSHException('A remote command returned an error')
+ o = _print_stream(stdout)
+
+ ssh_client.close()
+ return o
def execute_command(testbed, ssh_config, command, time_out=3):
@@ -195,8 +204,8 @@ def write_text_to_file(testbed, ssh_config, text, file_name):
remote_file.write(text)
remote_file.close()
- except Exception as e:
- logger.error(str(e))
+ except SSHException as e:
+ raise SSHException('Failed to write text to remote file')
def copy_files_to_testbed(testbed, ssh_config, paths, destination):
@@ -239,7 +248,7 @@ def copy_files_to_testbed(testbed, ssh_config, paths, destination):
sftp_client.put(path, dest_file)
except Exception as e:
- logger.error(str(e))
+ raise SSHException('Failed to copy files to testbed')
def copy_file_to_testbed(testbed, ssh_config, path, destination):