Commit 5c45163d authored by Raphael Defosseux's avatar Raphael Defosseux

CI: adding retry strategy when connecting to remote server

Signed-off-by: default avatarRaphael Defosseux <raphael.defosseux@eurecom.fr>
parent 67c089cd
......@@ -90,6 +90,9 @@ class SSHConnection():
self.htmlUEConnected = 0
def open(self, ipaddress, username, password):
count = 0
connect_status = False
while count < 4:
self.ssh = pexpect.spawn('ssh', [username + '@' + ipaddress], timeout = 5)
self.sshresponse = self.ssh.expect(['Are you sure you want to continue connecting (yes/no)?', 'password:', 'Last login', pexpect.EOF, pexpect.TIMEOUT])
if self.sshresponse == 0:
......@@ -98,30 +101,36 @@ class SSHConnection():
self.ssh.sendline(password)
self.sshresponse = self.ssh.expect(['\$', 'Permission denied', 'password:', pexpect.EOF, pexpect.TIMEOUT])
if self.sshresponse == 0:
pass
count = 10
connect_status = True
else:
logging.debug('self.sshresponse = ' + str(self.sshresponse))
sys.exit('SSH Connection Failed')
elif self.sshresponse == 1:
self.ssh.sendline(password)
self.sshresponse = self.ssh.expect(['\$', 'Permission denied', 'password:', pexpect.EOF, pexpect.TIMEOUT])
if self.sshresponse == 0:
pass
count = 10
connect_status = True
else:
logging.debug('self.sshresponse = ' + str(self.sshresponse))
sys.exit('SSH Connection Failed')
elif self.sshresponse == 2:
# Checking if we are really on the remote client defined by its IP address
self.command('stdbuf -o0 ifconfig | egrep --color=never "inet addr:"', '\$', 5)
result = re.search(str(ipaddress), str(self.ssh.before))
if result is None:
sys.exit('SSH Connection Failed: TIMEOUT !!!')
pass
self.close()
else:
count = 10
connect_status = True
else:
# debug output
logging.debug(str(self.ssh.before))
logging.debug('self.sshresponse = ' + str(self.sshresponse))
sys.exit('SSH Connection Failed!!!')
count += 1
if connect_status:
pass
else:
sys.exit('SSH Connection Failed')
def command(self, commandline, expectedline, timeout):
logging.debug(commandline)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment