SSHConnection class: don't exit, raise Exception to have main loop handle
This commit is contained in:
@@ -100,7 +100,7 @@ class SSHConnection():
|
|||||||
if connect_status:
|
if connect_status:
|
||||||
self.command('unset HISTFILE', prompt, 5, silent=True)
|
self.command('unset HISTFILE', prompt, 5, silent=True)
|
||||||
else:
|
else:
|
||||||
sys.exit('SSH Connection Failed')
|
raise ConnectionError('SSH Connection Failed')
|
||||||
self.ipaddress = ipaddress
|
self.ipaddress = ipaddress
|
||||||
self.username = username
|
self.username = username
|
||||||
|
|
||||||
@@ -136,20 +136,20 @@ class SSHConnection():
|
|||||||
logging.error('\u001B[1;37;41m Unexpected EOF \u001B[0m')
|
logging.error('\u001B[1;37;41m Unexpected EOF \u001B[0m')
|
||||||
logging.error('Expected Line : ' + expectedline)
|
logging.error('Expected Line : ' + expectedline)
|
||||||
logging.error(str(self.ssh.before))
|
logging.error(str(self.ssh.before))
|
||||||
sys.exit(self.sshresponse)
|
raise ConnectionError(self.sshresponse)
|
||||||
elif self.sshresponse == 2:
|
elif self.sshresponse == 2:
|
||||||
logging.error('\u001B[1;37;41m Unexpected TIMEOUT \u001B[0m')
|
logging.error('\u001B[1;37;41m Unexpected TIMEOUT \u001B[0m')
|
||||||
logging.error('Expected Line : ' + expectedline)
|
logging.error('Expected Line : ' + expectedline)
|
||||||
result = re.search('ping |iperf |picocom', str(commandline))
|
result = re.search('ping |iperf |picocom', str(commandline))
|
||||||
if result is None:
|
if result is None:
|
||||||
logging.warning(str(self.ssh.before))
|
logging.warning(str(self.ssh.before))
|
||||||
sys.exit(self.sshresponse)
|
raise ConnectionError(self.sshresponse)
|
||||||
else:
|
else:
|
||||||
return -1
|
return -1
|
||||||
else:
|
else:
|
||||||
logging.error('\u001B[1;37;41m Unexpected Others \u001B[0m')
|
logging.error('\u001B[1;37;41m Unexpected Others \u001B[0m')
|
||||||
logging.error('Expected Line : ' + expectedline)
|
logging.error('Expected Line : ' + expectedline)
|
||||||
sys.exit(self.sshresponse)
|
raise ConnectionError(self.sshresponse)
|
||||||
|
|
||||||
def command2(self, commandline, timeout, silent=False):
|
def command2(self, commandline, timeout, silent=False):
|
||||||
if not silent:
|
if not silent:
|
||||||
@@ -275,7 +275,7 @@ class SSHConnection():
|
|||||||
if copy_status:
|
if copy_status:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
sys.exit('SCP failed')
|
raise ConnectionError('SCP failed')
|
||||||
|
|
||||||
def getBefore(self):
|
def getBefore(self):
|
||||||
return self.ssh.before.decode('utf-8')
|
return self.ssh.before.decode('utf-8')
|
||||||
|
|||||||
Reference in New Issue
Block a user