Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
oai
openairinterface5G
Commits
5c45163d
Commit
5c45163d
authored
Sep 28, 2018
by
Raphael Defosseux
Browse files
CI: adding retry strategy when connecting to remote server
Signed-off-by:
Raphael Defosseux
<
raphael.defosseux@eurecom.fr
>
parent
67c089cd
Changes
1
Hide whitespace changes
Inline
Side-by-side
ci-scripts/main.py
View file @
5c45163d
...
...
@@ -90,38 +90,47 @@ class SSHConnection():
self
.
htmlUEConnected
=
0
def
open
(
self
,
ipaddress
,
username
,
password
):
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
:
self
.
ssh
.
sendline
(
'yes'
)
self
.
ssh
.
expect
(
'password:'
)
self
.
ssh
.
sendline
(
password
)
self
.
sshresponse
=
self
.
ssh
.
expect
([
'\$'
,
'Permission denied'
,
'password:'
,
pexpect
.
EOF
,
pexpect
.
TIMEOUT
])
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
:
pass
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
self
.
ssh
.
sendline
(
'yes'
)
self
.
ssh
.
expect
(
'password:'
)
self
.
ssh
.
sendline
(
password
)
self
.
sshresponse
=
self
.
ssh
.
expect
([
'\$'
,
'Permission denied'
,
'password:'
,
pexpect
.
EOF
,
pexpect
.
TIMEOUT
])
if
self
.
sshresponse
==
0
:
count
=
10
connect_status
=
True
else
:
logging
.
debug
(
'self.sshresponse = '
+
str
(
self
.
sshresponse
))
elif
self
.
sshresponse
==
1
:
self
.
ssh
.
sendline
(
password
)
self
.
sshresponse
=
self
.
ssh
.
expect
([
'\$'
,
'Permission denied'
,
'password:'
,
pexpect
.
EOF
,
pexpect
.
TIMEOUT
])
if
self
.
sshresponse
==
0
:
count
=
10
connect_status
=
True
else
:
logging
.
debug
(
'self.sshresponse = '
+
str
(
self
.
sshresponse
))
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
:
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'
)
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 !!!'
)
count
+=
1
if
connect_status
:
pass
else
:
# debug output
logging
.
debug
(
str
(
self
.
ssh
.
before
))
logging
.
debug
(
'self.sshresponse = '
+
str
(
self
.
sshresponse
))
sys
.
exit
(
'SSH Connection Failed!!!'
)
sys
.
exit
(
'SSH Connection Failed'
)
def
command
(
self
,
commandline
,
expectedline
,
timeout
):
logging
.
debug
(
commandline
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment