Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ycai
simbricks
Commits
8c910d9c
Commit
8c910d9c
authored
Jul 02, 2021
by
Antoine Kaufmann
Browse files
experiments: add executor abstraction for commands
Preparation for remote execution
parent
21610420
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
24 deletions
+39
-24
experiments/simbricks/exectools.py
experiments/simbricks/exectools.py
+26
-14
experiments/simbricks/experiments.py
experiments/simbricks/experiments.py
+13
-10
No files found.
experiments/simbricks/exectools.py
View file @
8c910d9c
...
@@ -195,17 +195,29 @@ class SimpleComponent(Component):
...
@@ -195,17 +195,29 @@ class SimpleComponent(Component):
raise
Exception
(
'Command Failed: '
+
str
(
self
.
cmd_parts
))
raise
Exception
(
'Command Failed: '
+
str
(
self
.
cmd_parts
))
# runs the list of commands as strings sequentially
class
Executor
(
object
):
async
def
run_cmdlist
(
label
,
cmds
,
verbose
=
True
):
def
create_component
(
self
,
label
,
parts
,
**
kwargs
):
i
=
0
raise
NotImplementedError
(
"Please Implement this method"
)
for
cmd
in
cmds
:
cmdC
=
SimpleComponent
(
label
+
'.'
+
str
(
i
),
shlex
.
split
(
cmd
),
async
def
await_file
(
self
,
path
,
delay
=
0.05
,
verbose
=
False
):
verbose
=
verbose
)
raise
NotImplementedError
(
"Please Implement this method"
)
await
cmdC
.
start
()
await
cmdC
.
wait
()
# runs the list of commands as strings sequentially
async
def
await_file
(
path
,
delay
=
0.05
,
verbose
=
False
):
async
def
run_cmdlist
(
self
,
label
,
cmds
,
verbose
=
True
,
host
=
None
):
if
verbose
:
i
=
0
print
(
'await_file(%s)'
%
path
)
for
cmd
in
cmds
:
while
not
os
.
path
.
exists
(
path
):
cmdC
=
self
.
create_component
(
label
+
'.'
+
str
(
i
),
shlex
.
split
(
cmd
),
await
asyncio
.
sleep
(
delay
)
verbose
=
verbose
)
await
cmdC
.
start
()
await
cmdC
.
wait
()
class
LocalExecutor
(
Executor
):
def
create_component
(
self
,
label
,
parts
,
**
kwargs
):
return
SimpleComponent
(
label
,
parts
,
**
kwargs
)
async
def
await_file
(
self
,
path
,
delay
=
0.05
,
verbose
=
False
):
if
verbose
:
print
(
'await_file(%s)'
%
path
)
while
not
os
.
path
.
exists
(
path
):
await
asyncio
.
sleep
(
delay
)
\ No newline at end of file
experiments/simbricks/experiments.py
View file @
8c910d9c
...
@@ -59,7 +59,7 @@ class Experiment(object):
...
@@ -59,7 +59,7 @@ class Experiment(object):
raise
Exception
(
'Duplicate net name'
)
raise
Exception
(
'Duplicate net name'
)
self
.
networks
.
append
(
sim
)
self
.
networks
.
append
(
sim
)
async
def
prepare
(
self
,
env
,
verbose
=
False
):
async
def
prepare
(
self
,
env
,
verbose
=
False
,
exec
=
exectools
.
LocalExecutor
()
):
# generate config tars
# generate config tars
for
host
in
self
.
hosts
:
for
host
in
self
.
hosts
:
path
=
env
.
cfgtar_path
(
host
)
path
=
env
.
cfgtar_path
(
host
)
...
@@ -71,11 +71,11 @@ class Experiment(object):
...
@@ -71,11 +71,11 @@ class Experiment(object):
sims
=
[]
sims
=
[]
for
sim
in
self
.
hosts
+
self
.
nics
+
self
.
networks
:
for
sim
in
self
.
hosts
+
self
.
nics
+
self
.
networks
:
prep_cmds
=
[
pc
for
pc
in
sim
.
prep_cmds
(
env
)]
prep_cmds
=
[
pc
for
pc
in
sim
.
prep_cmds
(
env
)]
sims
.
append
(
exec
tools
.
run_cmdlist
(
'prepare_'
+
self
.
name
,
prep_cmds
,
sims
.
append
(
exec
.
run_cmdlist
(
'prepare_'
+
self
.
name
,
prep_cmds
,
verbose
=
verbose
))
verbose
=
verbose
))
await
asyncio
.
wait
(
sims
)
await
asyncio
.
wait
(
sims
)
async
def
run
(
self
,
env
,
verbose
=
False
):
async
def
run
(
self
,
env
,
verbose
=
False
,
exec
=
exectools
.
LocalExecutor
()
):
running
=
[]
running
=
[]
sockets
=
[]
sockets
=
[]
out
=
ExpOutput
(
self
)
out
=
ExpOutput
(
self
)
...
@@ -87,8 +87,9 @@ class Experiment(object):
...
@@ -87,8 +87,9 @@ class Experiment(object):
for
nic
in
self
.
nics
:
for
nic
in
self
.
nics
:
if
verbose
:
if
verbose
:
print
(
'start NIC:'
,
nic
.
run_cmd
(
env
))
print
(
'start NIC:'
,
nic
.
run_cmd
(
env
))
sc
=
exectools
.
SimpleComponent
(
nic
.
full_name
(),
sc
=
exec
.
create_component
(
nic
.
full_name
(),
shlex
.
split
(
nic
.
run_cmd
(
env
)),
verbose
=
verbose
,
canfail
=
True
)
shlex
.
split
(
nic
.
run_cmd
(
env
)),
verbose
=
verbose
,
canfail
=
True
)
await
sc
.
start
()
await
sc
.
start
()
running
.
append
((
nic
,
sc
))
running
.
append
((
nic
,
sc
))
...
@@ -100,7 +101,7 @@ class Experiment(object):
...
@@ -100,7 +101,7 @@ class Experiment(object):
print
(
'%s: waiting for sockets'
%
self
.
name
)
print
(
'%s: waiting for sockets'
%
self
.
name
)
for
s
in
sockets
:
for
s
in
sockets
:
await
exec
tools
.
await_file
(
s
,
verbose
=
verbose
)
await
exec
.
await_file
(
s
,
verbose
=
verbose
)
await
asyncio
.
sleep
(
0.5
)
await
asyncio
.
sleep
(
0.5
)
...
@@ -109,8 +110,9 @@ class Experiment(object):
...
@@ -109,8 +110,9 @@ class Experiment(object):
if
verbose
:
if
verbose
:
print
(
'start Net:'
,
net
.
run_cmd
(
env
))
print
(
'start Net:'
,
net
.
run_cmd
(
env
))
sc
=
exectools
.
SimpleComponent
(
net
.
full_name
(),
sc
=
exec
.
create_component
(
net
.
full_name
(),
shlex
.
split
(
net
.
run_cmd
(
env
)),
verbose
=
verbose
,
canfail
=
True
)
shlex
.
split
(
net
.
run_cmd
(
env
)),
verbose
=
verbose
,
canfail
=
True
)
await
sc
.
start
()
await
sc
.
start
()
running
.
append
((
net
,
sc
))
running
.
append
((
net
,
sc
))
...
@@ -120,8 +122,9 @@ class Experiment(object):
...
@@ -120,8 +122,9 @@ class Experiment(object):
if
verbose
:
if
verbose
:
print
(
'start Host:'
,
host
.
run_cmd
(
env
))
print
(
'start Host:'
,
host
.
run_cmd
(
env
))
sc
=
exectools
.
SimpleComponent
(
host
.
full_name
(),
sc
=
exec
.
create_component
(
host
.
full_name
(),
shlex
.
split
(
host
.
run_cmd
(
env
)),
verbose
=
verbose
,
canfail
=
True
)
shlex
.
split
(
host
.
run_cmd
(
env
)),
verbose
=
verbose
,
canfail
=
True
)
await
sc
.
start
()
await
sc
.
start
()
running
.
append
((
host
,
sc
))
running
.
append
((
host
,
sc
))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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