From 689f862f24f949361603a808250ae3f7ec9f40f6 Mon Sep 17 00:00:00 2001 From: Shwetha-H-Panduranga Date: Mon, 12 Dec 2011 11:29:47 +0530 Subject: Changes to logger class, Using the logger class in the framework, adding new global values, Changes made to argument parser, testruninfo --- libs/connect/ssh.py | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) (limited to 'libs/connect') diff --git a/libs/connect/ssh.py b/libs/connect/ssh.py index a9952bb..a419c31 100755 --- a/libs/connect/ssh.py +++ b/libs/connect/ssh.py @@ -3,16 +3,15 @@ remote server using SSH Protocol. """ import paramiko -import pdb import time +from atfglobals import GlobalObj class SshConnection(): - def __init__(self): - self._connection = None + def __init__(self): self._connection = paramiko.SSHClient() - def connect(self, host, user=None, password=None): + def connect(self, host, user, password): """ Objective: SSH to Server "host" as User "user" @@ -26,30 +25,24 @@ class SshConnection(): Success: 0 Failure: 1 """ + logger = GlobalObj.getLoggerObj() self._connection.set_missing_host_key_policy(paramiko.AutoAddPolicy()) - if user == None: - user = "root" - - if password == None: - password = "syst3m" - try: self._connection.connect(host, username=user, password=password) except paramiko.BadHostKeyException as result: - print( - "BadHostKeyException: Unable to Connect to Server: '" + host + - "' as User: '" + user + "'") + logger.error("BadHostKeyException: Unable to Connect to Server: '" + host + + "' as User: '" + user + "'") return 1 except paramiko.AuthenticationException: - print("AuthenticationException: Unable to Authenticate " - + user + "@" + host) + logger.error("AuthenticationException: Unable to Authenticate " + + user + "@" + host) return 1 except paramiko.SSHException: - print("SSHException: Unknown server " + host) + logger.error("SSHException: Unknown server " + host) return 1 return 0 @@ -74,6 +67,7 @@ class SshConnection(): Success: 0 Failure: 1 """ + logger = GlobalObj.getLoggerObj() output = {} output["exitstatus"] = None output["stdoutdata"] = None @@ -93,8 +87,8 @@ class SshConnection(): if commandInput: stdin.write(commandInput) else: - print "This command requirs Command Input \ - after executing comamnd for command completion" + logger.error("This command requirs Command Input \ + after executing comamnd for command completion") stdin.write("\n") return output @@ -107,7 +101,7 @@ class SshConnection(): output["stderrdata"] = stderr.readlines() except paramiko.SSHException: - print("Unable to Execute Command: " + command) + logger.error("Unable to Execute Command: " + command) return output -- cgit