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
a565bdd5
Commit
a565bdd5
authored
10 years ago
by
cody burkard
Browse files
Options
Downloads
Patches
Plain Diff
fix popen to work with shell
parent
cf5bbd59
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
examples/sshd.py
+1
-2
1 addition, 2 deletions
examples/sshd.py
mininet/util.py
+15
-10
15 additions, 10 deletions
mininet/util.py
with
16 additions
and
12 deletions
examples/sshd.py
+
1
−
2
View file @
a565bdd5
...
...
@@ -60,10 +60,9 @@ def sshd( network, cmd='/usr/sbin/sshd', opts='-D',
connectToRootNS
(
network
,
switch
,
ip
,
routes
)
for
host
in
network
.
hosts
:
host
.
cmd
(
cmd
+
'
'
+
opts
+
'
&
'
)
client
=
network
.
switches
[
0
]
# wait until each host's sshd has started up
for
server
in
network
.
hosts
:
waitListening
(
client
,
server
,
22
,
timeout
=
5
)
waitListening
(
server
=
server
,
port
=
22
,
timeout
=
5
)
print
print
"
*** Hosts are running sshd at the following addresses:
"
...
...
This diff is collapsed.
Click to expand it.
mininet/util.py
+
15
−
10
View file @
a565bdd5
...
...
@@ -10,6 +10,7 @@
from
fcntl
import
fcntl
,
F_GETFL
,
F_SETFL
from
os
import
O_NONBLOCK
import
os
from
functools
import
partial
# Command execution support
...
...
@@ -61,12 +62,6 @@ def errRun( *cmd, **kwargs ):
stderr: STDOUT to merge stderr with stdout
shell: run command using shell
echo: monitor output to console
"""
# Allow passing in a list or a string
if
len
(
cmd
)
==
1
:
cmd
=
cmd
[
0
]
if
isinstance
(
cmd
,
str
):
cmd
=
cmd
.
split
(
'
'
)
cmd
=
[
str
(
arg
)
for
arg
in
cmd
]
# By default we separate stderr, don't run in a shell, and don't echo
stderr
=
kwargs
.
get
(
'
stderr
'
,
PIPE
)
shell
=
kwargs
.
get
(
'
shell
'
,
False
)
...
...
@@ -74,6 +69,14 @@ def errRun( *cmd, **kwargs ):
if
echo
:
# cmd goes to stderr, output goes to stdout
info
(
cmd
,
'
\n
'
)
if
len
(
cmd
)
==
1
:
cmd
=
cmd
[
0
]
# Allow passing in a list or a string
if
isinstance
(
cmd
,
str
)
and
not
shell
:
cmd
=
cmd
.
split
(
'
'
)
cmd
=
[
str
(
arg
)
for
arg
in
cmd
]
elif
isinstance
(
cmd
,
list
)
and
shell
:
cmd
=
"
"
.
join
(
arg
for
arg
in
cmd
)
popen
=
Popen
(
cmd
,
stdout
=
PIPE
,
stderr
=
stderr
,
shell
=
shell
)
# We use poll() because select() doesn't work with large fd numbers,
# and thus communicate() doesn't work either
...
...
@@ -539,18 +542,20 @@ def ensureRoot():
exit
(
1
)
return
def
waitListening
(
client
,
server
,
port
,
timeout
=
None
):
def
waitListening
(
client
=
None
,
server
=
'
127.0.0.1
'
,
port
=
80
,
timeout
=
None
):
"
Wait until server is listening on port
"
if
not
client
.
cmd
(
'
which telnet
'
):
run
=
(
client
.
cmd
if
client
else
partial
(
quietRun
,
shell
=
True
)
)
if
not
run
(
'
which telnet
'
):
raise
Exception
(
'
Could not find telnet
'
)
cmd
=
(
'
sh -c
"
echo A | telnet -e A %s %s
"'
%
(
server
.
IP
(),
port
)
)
time
=
0
while
'
Connected
'
not
in
client
.
cmd
(
cmd
):
while
'
Connected
'
not
in
run
(
cmd
):
if
timeout
:
if
time
>=
timeout
:
error
(
'
could not connect to %s on port %d
\n
'
%
(
client
,
port
)
)
%
(
server
,
port
)
)
break
output
(
'
waiting for
'
,
server
,
'
to listen on port
'
,
port
,
'
\n
'
)
...
...
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