Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mininet
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Olaf Bergmann
mininet
Commits
7c5d2771
Commit
7c5d2771
authored
10 years ago
by
cody burkard
Browse files
Options
Downloads
Patches
Plain Diff
wait for sshd to start in example
parent
2ceb5791
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
examples/baresshd.py
+8
-2
8 additions, 2 deletions
examples/baresshd.py
examples/test/test_baresshd.py
+14
-12
14 additions, 12 deletions
examples/test/test_baresshd.py
mininet/util.py
+5
-3
5 additions, 3 deletions
mininet/util.py
with
27 additions
and
17 deletions
examples/baresshd.py
+
8
−
2
View file @
7c5d2771
...
...
@@ -4,9 +4,10 @@
import
sys
from
mininet.node
import
Host
from
mininet.util
import
ensureRoot
from
mininet.util
import
ensureRoot
,
waitListening
ensureRoot
()
timeout
=
5
print
"
*** Creating nodes
"
h1
=
Host
(
'
h1
'
)
...
...
@@ -33,5 +34,10 @@
if
len
(
sys
.
argv
)
>
1
:
cmd
+=
'
'
+
'
'
.
join
(
sys
.
argv
[
1
:
]
)
h1
.
cmd
(
cmd
)
listening
=
waitListening
(
server
=
h1
,
port
=
22
,
timeout
=
timeout
)
print
"
*** You may now ssh into
"
,
h1
.
name
,
"
at
"
,
h1
.
IP
()
if
listening
:
print
"
*** You may now ssh into
"
,
h1
.
name
,
"
at
"
,
h1
.
IP
()
else
:
print
(
"
*** Warning: after %s seconds, %s is not listening on port 22
"
%
(
timeout
,
h1
.
name
)
)
This diff is collapsed.
Click to expand it.
examples/test/test_baresshd.py
+
14
−
12
View file @
7c5d2771
...
...
@@ -6,21 +6,18 @@
import
unittest
import
pexpect
from
time
import
sleep
from
mininet.clean
import
cleanup
,
sh
class
testBareSSHD
(
unittest
.
TestCase
):
opts
=
[
'
\(yes/no\)\?
'
,
'
Welcome to h1
'
,
'
refused
'
,
pexpect
.
EOF
,
pexpect
.
TIMEOUT
]
opts
=
[
'
Welcome to h1
'
,
pexpect
.
EOF
,
pexpect
.
TIMEOUT
]
def
connected
(
self
):
"
Log into ssh server, check banner, then exit
"
p
=
pexpect
.
spawn
(
'
ssh 10.0.0.1 -i /tmp/ssh/test_rsa exit
'
)
p
=
pexpect
.
spawn
(
'
ssh 10.0.0.1
-o StrictHostKeyChecking=no
-i /tmp/ssh/test_rsa exit
'
)
while
True
:
index
=
p
.
expect
(
self
.
opts
)
if
index
==
0
:
p
.
sendline
(
'
yes
'
)
elif
index
==
1
:
return
True
else
:
return
False
...
...
@@ -37,18 +34,23 @@ def setUp( self ):
cmd
=
(
'
python -m mininet.examples.baresshd
'
'
-o AuthorizedKeysFile=/tmp/ssh/authorized_keys
'
'
-o StrictModes=no
'
)
sh
(
cmd
)
p
=
pexpect
.
spawn
(
cmd
)
runOpts
=
[
'
You may now ssh into h1 at 10.0.0.1
'
,
'
after 5 seconds, h1 is not listening on port 22
'
,
pexpect
.
EOF
,
pexpect
.
TIMEOUT
]
while
True
:
index
=
p
.
expect
(
runOpts
)
if
index
==
0
:
break
else
:
self
.
tearDown
()
self
.
fail
(
'
sshd failed to start in host h1
'
)
def
testSSH
(
self
):
"
Simple test to verify that we can ssh into h1
"
result
=
False
# try to connect up to 3 times; sshd can take a while to start
for
_
in
range
(
3
):
result
=
self
.
connected
()
if
result
:
break
else
:
sleep
(
1
)
result
=
self
.
connected
()
self
.
assertTrue
(
result
)
def
tearDown
(
self
):
...
...
This diff is collapsed.
Click to expand it.
mininet/util.py
+
5
−
3
View file @
7c5d2771
...
...
@@ -543,7 +543,8 @@ def ensureRoot():
return
def
waitListening
(
client
=
None
,
server
=
'
127.0.0.1
'
,
port
=
80
,
timeout
=
None
):
"
Wait until server is listening on port
"
"""
Wait until server is listening on port.
returns True if server is listening
"""
run
=
(
client
.
cmd
if
client
else
partial
(
quietRun
,
shell
=
True
)
)
if
not
run
(
'
which telnet
'
):
...
...
@@ -554,12 +555,13 @@ def waitListening( client=None, server='127.0.0.1', port=80, timeout=None ):
time
=
0
while
'
Connected
'
not
in
run
(
cmd
):
if
timeout
:
print
time
if
time
>=
timeout
:
error
(
'
could not connect to %s on port %d
\n
'
%
(
server
,
port
)
)
b
re
ak
re
turn
False
output
(
'
waiting for
'
,
server
,
'
to listen on port
'
,
port
,
'
\n
'
)
sleep
(
.
5
)
time
+=
.
5
return
True
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment