Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

if filename is "-", read config from stdin (TSUN-193)

  • Loading branch information...
commit f7f7d08d17a0f70fa0a783699444898da6c6bf4b 1 parent 0dfefc2
Nicolas Niclausse nniclausse authored
50 src/tsung_controller/ts_config.erl
View
@@ -57,24 +57,26 @@
%%% @doc: read and parse the xml config file
%%% @end
%%%----------------------------------------------------------------------
+read(Filename=standard_io, LogDir) ->
+ ?LOG("Reading config file from stdin~n", ?NOTICE),
+ XML = read_stdio(),
+ handle_read(catch xmerl_scan:string(XML,
+ [{fetch_path,["/usr/share/tsung/","./"]},
+ {validation,true}]),Filename,LogDir);
read(Filename, LogDir) ->
- case catch xmerl_scan:file(Filename,
- [{fetch_path,["/usr/share/tsung/","./"]},
- {validation,true}]) of
- {ok, Root = #xmlElement{}} -> % xmerl-0.15
- ?LOGF("Reading config file: ~s~n", [Filename], ?NOTICE),
- Table = ets:new(sessiontable, [ordered_set, protected]),
- {ok, parse(Root, #config{session_tab = Table})};
- {Root = #xmlElement{}, _Tail} -> % xmerl-0.19 and up
- ?LOGF("Reading config file: ~s~n", [Filename], ?NOTICE),
- Table = ets:new(sessiontable, [ordered_set, protected]),
- backup_config(LogDir, Filename, Root),
- {ok, parse(Root, #config{session_tab = Table, proto_opts=#proto_opts{}})};
- {error,Reason} ->
- {error, Reason};
- {'EXIT',Reason} ->
- {error, Reason}
- end.
+ ?LOGF("Reading config file: ~s~n", [Filename], ?NOTICE),
+ handle_read(catch xmerl_scan:file(Filename,
+ [{fetch_path,["/usr/share/tsung/","./"]},
+ {validation,true}]),Filename,LogDir).
+
+handle_read( {Root = #xmlElement{}, _Tail}, Filename, LogDir) ->
+ Table = ets:new(sessiontable, [ordered_set, protected]),
+ backup_config(LogDir, Filename, Root),
+ {ok, parse(Root, #config{session_tab = Table, proto_opts=#proto_opts{}})};
+handle_read({error,Reason},_,_) ->
+ {error, Reason};
+handle_read({'EXIT',Reason},_,_) ->
+ {error, Reason}.
%%%----------------------------------------------------------------------
%%% Function: parse/2
@@ -948,6 +950,8 @@ shortnames(Hostname)->
%% Use parsed config file to expand all ENTITY
%% @end
%%----------------------------------------------------------------------
+backup_config(Dir,standard_io, Config) ->
+ backup_config(Dir, "tsung_stdin.xml", Config);
backup_config(Dir, Name, Config) ->
BaseName = filename:basename(Name),
{ok,IOF}=file:open(filename:join(Dir,BaseName),[write]),
@@ -959,3 +963,15 @@ backup_config(Dir, Name, Config) ->
ok
end,
file:close(IOF).
+
+%% @spec read_stdio()-> string()
+%% @doc Read config from standard input
+%% @end
+read_stdio()->
+ read_stdio(io:get_line(""),[]).
+
+read_stdio(eof, Data)->
+ lists:flatten(Data);
+read_stdio(Data,Acc) ->
+ read_stdio(io:get_line(""),[Acc,Data]).
+
28 src/tsung_controller/tsung_controller.erl
View
@@ -60,17 +60,23 @@ start(_Type, _StartArgs) ->
end.
start_phase(load_config, _StartType, _PhaseArgs) ->
- Conf = ?config(config_file),
- Timeout = case file:read_file_info(Conf) of
- {ok, #file_info{size=Size}} when Size > 10000000 -> % > 10MB
- erlang:display(["Can take up to 5mn to read config ",Size]),
- 300000; % 10mn
- {ok, #file_info{size=Size}} when Size > 1000000 -> % > 1MB
- erlang:display(["Can take up to 3mn to read config ",Size]),
- 180000; % 5mn
- {ok, #file_info{size=Size}} ->
- 120000 % 2mn
- end,
+ {Conf,Timeout} =
+ case ?config(config_file) of
+ "-" ->
+ {standard_io, 120000}; %2mn timeout
+ File ->
+ T = case file:read_file_info(File) of
+ {ok, #file_info{size=Size}} when Size > 10000000 -> % > 10MB
+ erlang:display(["Can take up to 5mn to read config ",Size]),
+ 300000; % 10mn
+ {ok, #file_info{size=Size}} when Size > 1000000 -> % > 1MB
+ erlang:display(["Can take up to 3mn to read config ",Size]),
+ 180000; % 5mn
+ {ok, #file_info{size=_}} ->
+ 120000 % 2mn
+ end,
+ {File, T}
+ end,
case ts_config_server:read_config(Conf,Timeout) of
{error,Reason}->
erlang:display(["Config Error, aborting ! ", Reason]),
2  tsung.sh.in
View
@@ -90,7 +90,7 @@ version() {
}
checkconfig() {
- if [ ! -e $CONF_OPT_FILE ]
+ if [ ! -e $CONF_OPT_FILE ] && [ $CONF_OPT_FILE != "-" ]
then
echo "Config file $CONF_OPT_FILE doesn't exist, aborting !"
exit 1
Please sign in to comment.
Something went wrong with that request. Please try again.