mirror of
https://github.com/Telecominfraproject/wlan-cloud-loadsim.git
synced 2026-01-27 10:22:43 +00:00
Adding the ability ro run a script
This commit is contained in:
@@ -32,11 +32,27 @@ mkdir docker_logs_node1
|
||||
|
||||
HOSTNAMES="--add-host mgr.owls.net:172.21.10.2 --add-host node1.owls.net:172.21.10.3 --add-host $TIP_CONTROLLER_NAME:$TIP_CONTROLLER_IP"
|
||||
|
||||
#
|
||||
# A simulation file is used to describe how a simulation should run. Here is the content...
|
||||
#
|
||||
# simulation:
|
||||
# name: sim1
|
||||
# ca:
|
||||
# name: tip1
|
||||
# cert: tipcert.pem (this file should be in the $PWD/ssl dir)
|
||||
# key: tipkey.pem (this file should be in the $PWD/ssl dir)
|
||||
# password: mypassword
|
||||
# server: (should be the same name as TIP_CONTROLLER_NAME
|
||||
# port: 6643
|
||||
# devices: 10
|
||||
#
|
||||
|
||||
docker run -d -p 9091:9090 --init \
|
||||
--network=owls_net \
|
||||
--volume="$PWD/ssl:/etc/ssl/certs" \
|
||||
--volume="$PWD/docker_logs_manager:/app_data/logs" \
|
||||
-e ERL_NODE_NAME="mgr@mgr.owls.net" -e ERL_OPTIONS="-noshell -noinput" -e ERL_NODE_TYPE="manager" -e TIP_AUTH="2" \
|
||||
--volume="$PWD/scripts:/scripts" \
|
||||
-e ERL_NODE_NAME="mgr@mgr.owls.net" -e ERL_OPTIONS="-noshell -noinput" -e ERL_NODE_TYPE="manager" -e TIP_AUTH="2" -e SIM_SCRIPT="sim1.yaml" \
|
||||
--ip="172.21.10.2" $HOSTNAMES \
|
||||
--name="manager" $DOCKER_NAME
|
||||
|
||||
|
||||
@@ -6,7 +6,12 @@ case $ERL_NODE_TYPE in
|
||||
manager)
|
||||
cp priv/templates/simmanager.args.template.docker config/vm.args
|
||||
cp priv/templates/simmanager.config.template.docker config/sys.config
|
||||
erl -config config/sys.config -args_file config/vm.args -name $ERL_NODE_NAME $ERL_OPTIONS -pa deps/*/ebin -pa ebin -tipauth $TIP_AUTH
|
||||
if [ -z "$SIM_SCRIPT" ]
|
||||
then
|
||||
erl -config config/sys.config -args_file config/vm.args -name $ERL_NODE_NAME $ERL_OPTIONS -pa deps/*/ebin -pa ebin -tipauth $TIP_AUTH
|
||||
else
|
||||
erl -config config/sys.config -args_file config/vm.args -name $ERL_NODE_NAME $ERL_OPTIONS -pa deps/*/ebin -pa ebin -tipauth $TIP_AUTH -sim $SIM_SCRIPT
|
||||
fi
|
||||
;;
|
||||
node)
|
||||
cp priv/templates/simnode.args.template.docker config/vm.args
|
||||
|
||||
@@ -2,9 +2,9 @@ simulation:
|
||||
name: sim1
|
||||
ca:
|
||||
name: tip1
|
||||
# (this file should be in the $PWD/ssl dir)
|
||||
# (this file should be in the $PWD/ssl dir for docker. In docker, this name should be /etc/ssl/<mame>.)
|
||||
cert: tipcert.pem
|
||||
# (this file should be in the $PWD/ssl dir)
|
||||
# (this file should be in the $PWD/ssl dir for docker. In docker, this name should be /etc/ssl/<mame>.)
|
||||
key: tipkey.pem
|
||||
password: mypassword
|
||||
# should be the same name as TIP_CONTROLLER_NAME
|
||||
|
||||
@@ -23,6 +23,12 @@ stop(_State) ->
|
||||
|
||||
start() ->
|
||||
ok = app_settings(),
|
||||
case init:get_argument(sim) of
|
||||
{ok,[[Script]]} ->
|
||||
timer:apply_after(30*1000,user_default,run_script,[Script]);
|
||||
_ ->
|
||||
ok
|
||||
end,
|
||||
application:ensure_all_started(owls).
|
||||
|
||||
load_cli()->
|
||||
|
||||
@@ -433,7 +433,7 @@ wait_for_nodes(Seconds)->
|
||||
end.
|
||||
|
||||
wait_job_id(Id)->
|
||||
wait_job_id(Id,120).
|
||||
wait_job_id(Id,600).
|
||||
|
||||
wait_job_id(_,0)->
|
||||
throw("operation did not complete...~n");
|
||||
@@ -531,3 +531,35 @@ run(SimName,Delay)->
|
||||
io:format("~nAne error occured while trying to start the simulation. ~p~n",[Error])
|
||||
end.
|
||||
|
||||
run_script(ScriptName) ->
|
||||
try
|
||||
[ Script ] = yamerl_constr:file(ScriptName),
|
||||
%% verify that we have everything
|
||||
{"simulation", SimInfo} = proplists:lookup("simulation",Script),
|
||||
{"name", SimName} = proplists:lookup("name",SimInfo),
|
||||
{"server", SimServer} = proplists:lookup("server",SimInfo),
|
||||
{"port", SimPort} = proplists:lookup("port", SimInfo),
|
||||
{"devices", NumDevices} = proplists:lookup("devices",SimInfo),
|
||||
{"ca",CAInfo} = proplists:lookup("ca",SimInfo),
|
||||
{"name",CAName} = proplists:lookup("name",CAInfo),
|
||||
{"cert",CACert} = proplists:lookup("cert",CAInfo),
|
||||
{"key",CAKey} = proplists:lookup("key",CAInfo),
|
||||
{"password",CAPassword} = proplists:lookup("password",CAInfo),
|
||||
io:format("SIM: ~p: ~p/~p/~p CA: ~p: ~p/~p/~p",[SimName,SimServer,SimPort,NumDevices,CAName,CACert,CAKey,CAPassword]),
|
||||
inventory:import_raw_ca(CAName,CAPassword,CAKey,CACert),
|
||||
Nodes = wait_for_nodes(),
|
||||
Simulation = #simulation{ name = utils:safe_binary(SimName),
|
||||
ca = utils:safe_binary(CAName),
|
||||
num_devices = NumDevices,
|
||||
opensync_server_port = 6643,
|
||||
opensync_server_name = utils:safe_binary(SimServer),
|
||||
nodes = Nodes },
|
||||
_ = simengine:create(Simulation),
|
||||
{ok,ID} = simengine:prepare(SimName,#{},utils:noop_mfa()),
|
||||
wait_job_id(ID),
|
||||
run(SimName,120),
|
||||
?L_IA("Simulation ~p is now running.",[SimName])
|
||||
catch
|
||||
_:_ ->
|
||||
?L_IA("Cannot run script: ~p. Please look at the template simulation.yaml",[ScriptName])
|
||||
end.
|
||||
|
||||
Reference in New Issue
Block a user