137
init_suite(Config) ->
138
?DBG("init_suite -> entry with"
139
"~n Config: ~p", [Config]),
141
%% Suite root dir for test suite
142
PrivDir = ?config(priv_dir, Config),
144
%% Create top-directory for this sub-suite
145
SuiteTopDir = filename:join([PrivDir, ?MODULE]),
146
case file:make_dir(SuiteTopDir) of
150
%% This can happen since this is not really a
151
%% suite-init function.
154
?FAIL({failed_creating_suite_top_dir, SuiteTopDir, Reason})
159
%% Fix config (data-dir is not correct):
162
Config1 = fix_data_dir(Config),
166
MibDir = ?config(data_dir, Config1),
167
StdMibDir = filename:join([code:priv_dir(snmp), "mibs"]),
169
Config2 = [{suite_top_dir, SuiteTopDir},
171
{std_mib_dir, StdMibDir} | Config1],
173
?DBG("init_suite -> done when"
174
"~n Config2: ~p", [Config2]),
177
%% end_per_suite(Config) ->
181
fix_data_dir(Config) ->
182
DataDir0 = ?config(data_dir, Config),
183
DataDir1 = filename:split(filename:absname(DataDir0)),
184
[_|DataDir2] = lists:reverse(DataDir1),
185
DataDir = filename:join(lists:reverse(DataDir2) ++ [?snmp_test_data]),
186
Config1 = lists:keydelete(data_dir, 1, Config),
187
[{data_dir, DataDir} | Config1].
190
init_per_testcase2(Case, Config) ->
191
SuiteToDir = ?config(suite_top_dir, Config),
193
%% Create top-directory for this test-case
194
CaseTopDir = filename:join([SuiteToDir, Case]),
195
ok = file:make_dir(CaseTopDir),
197
%% Create agent top-dir(s)
198
AgentTopDir = filename:join([CaseTopDir, agent]),
199
ok = file:make_dir(AgentTopDir),
200
AgentConfDir = filename:join([AgentTopDir, config]),
201
ok = file:make_dir(AgentConfDir),
202
AgentDbDir = filename:join([AgentTopDir, db]),
203
ok = file:make_dir(AgentDbDir),
204
AgentLogDir = filename:join([AgentTopDir, log]),
205
ok = file:make_dir(AgentLogDir),
207
%% Create sub-agent top-dir(s)
208
SubAgentTopDir = filename:join([CaseTopDir, sub_agent]),
209
ok = file:make_dir(SubAgentTopDir),
211
%% Create manager top-dir(s)
212
ManagerTopDir = filename:join([CaseTopDir, manager]),
213
ok = file:make_dir(ManagerTopDir),
215
[{case_top_dir, CaseTopDir},
216
{agent_top_dir, AgentTopDir},
217
{agent_conf_dir, AgentConfDir},
218
{agent_db_dir, AgentDbDir},
219
{agent_log_dir, AgentLogDir},
220
{sub_agent_top_dir, SubAgentTopDir},
221
{manager_top_dir, ManagerTopDir} | Config].
223
fin_per_testcase2(_Case, Config) ->
131
228
case ?OSTYPE() of
5693
5797
%%-----------------------------------------------------------------
5799
%% These cases are started in the new way
5800
%%-----------------------------------------------------------------
5802
otp8395({init, Config}) when is_list(Config) ->
5803
?DBG("otp8395(init) -> entry with"
5804
"~n Config: ~p", [Config]),
5810
{ok, AgentNode} = start_node(agent),
5811
%% {ok, SubAgentNode} = start_node(sub_agent),
5812
{ok, ManagerNode} = start_node(manager),
5818
AgentDbDir = ?config(agent_db_dir, Config),
5819
AgentMnesiaDir = filename:join([AgentDbDir, "mnesia"]),
5820
mnesia_init(AgentNode, AgentMnesiaDir),
5822
%% SubAgentDir = ?config(sub_agent_dir, Config),
5823
%% SubAgentMnesiaDir = filename:join([SubAgentDir, "mnesia"]),
5824
%% mnesia_init(SubAgentNode, SubAgentMnesiaDir),
5826
%% ok = mnesia_create_schema(AgentNode, [AgentNode, SubAgentNode]),
5827
%% ok = mnesia:create_schema([AgentNode, SubAgentNode]),
5828
mnesia_create_schema(AgentNode, [AgentNode]),
5830
mnesia_start(AgentNode),
5831
%% mnesia_start(SubAgentNode),
5837
AgentHost = ?HOSTNAME(AgentNode),
5838
%% SubAgentHost = ?HPSTNAME(SubAgentNode),
5839
ManagerHost = ?HOSTNAME(ManagerNode),
5841
Host = snmp_test_lib:hostname(),
5843
{ok, AgentIP0} = snmp_misc:ip(AgentHost),
5844
AgentIP = tuple_to_list(AgentIP0),
5845
%% {ok, SubAgentIP0} = snmp_misc:ip(SubAgentHost),
5846
%% SubAgentIP = tuple_to_list(SubAgentIP0),
5847
{ok, ManagerIP0} = snmp_misc:ip(ManagerHost),
5848
ManagerIP = tuple_to_list(ManagerIP0),
5852
%% Write agent config
5856
AgentConfDir = ?config(agent_conf_dir, Config),
5857
ManagerConfDir = ?config(manager_top_dir, Config),
5858
snmp_agent_test_lib:config(Vsns,
5859
ManagerConfDir, AgentConfDir,
5860
ManagerIP, AgentIP),
5867
Config2 = start_agent([{host, Host},
5869
{agent_node, AgentNode},
5870
{agent_host, AgentHost},
5871
{agent_ip, AgentIP},
5872
%% {sub_agent_node, SubAgentNode},
5873
%% {sub_agent_host, SubAgentHost},
5874
%% {sub_agent_ip, SubAgentIP},
5875
{manager_node, ManagerNode},
5876
{manager_host, ManagerHost},
5877
{manager_ip, ManagerIP}|Config]),
5883
Dog = ?WD_START(?MINS(1)),
5885
[{watchdog, Dog} | Config2];
5887
otp8395({fin, Config}) when is_list(Config) ->
5888
?DBG("otp8395(fin) -> entry with"
5889
"~n Config: ~p", [Config]),
5891
AgentNode = ?config(agent_node, Config),
5892
ManagerNode = ?config(manager_node, Config),
5895
%% Stop agent (this is the nice way to do it,
5896
%% so logs and files can be closed in the proper way).
5899
AgentSup = ?config(agent_sup, Config),
5900
?DBG("otp8395(fin) -> stop (stand-alone) agent: ~p", [AgentSup]),
5901
stop_stdalone_agent(AgentSup),
5906
?DBG("otp8395(fin) -> stop mnesia", []),
5907
mnesia_stop(AgentNode),
5911
%% Stop the agent node
5914
?DBG("otp8395(fin) -> stop agent node", []),
5915
stop_node(AgentNode),
5918
%% SubAgentNode = ?config(sub_agent_node, Config),
5919
%% stop_node(SubAgentNode),
5923
%% Stop the manager node
5926
?DBG("otp8395(fin) -> stop manager node", []),
5927
stop_node(ManagerNode),
5929
Dog = ?config(watchdog, Config),
5931
lists:keydelete(watchdog, 1, Config);
5934
"OTP-8395 - ATL with sequence numbering. ";
5936
otp8395(Config) when is_list(Config) ->
5937
?DBG("otp8395 -> entry with"
5938
"~n Config: ~p", [Config]),
5942
%% This is just to dirty trick for the ***old*** test-code
5943
put(mgr_node, ?config(manager_node, Config)),
5944
put(mgr_dir, ?config(manager_top_dir, Config)),
5945
put(mib_dir, ?config(mib_dir, Config)),
5947
put(master_host, ?config(agent_host, Config)),
5948
try_test(simple_standard_test),
5951
AgentNode = ?config(agent_node, Config),
5952
AgentLogDir = ?config(agent_log_dir, Config),
5953
OutFile = filename:join([AgentLogDir, "otp8395.txt"]),
5954
{ok, LogInfo} = rpc:call(AgentNode, snmpa, log_info, []),
5955
?DBG("otp8395 -> LogInfo: ~p", [LogInfo]),
5957
%% SyncRes = rpc:call(AgentNode, snmp, log_sync, [?audit_trail_log_name]),
5958
%% ?DBG("otp8395 -> SyncRes: ~p", [SyncRes]),
5960
ok = agent_log_validation(AgentNode),
5962
rpc:call(AgentNode, snmpa, log_to_txt, [AgentLogDir, [], OutFile]),
5963
?DBG("otp8395 -> LTTRes: ~p", [LTTRes]),
5966
?DBG("otp8395 -> done", []),
5970
agent_log_validation(Node) ->
5971
rpc:call(Node, ?MODULE, agent_log_validation, []).
5973
agent_log_validation() ->
5974
put(sname, otp8308),
5975
put(verbosity, trace),
5976
snmp_log:validate(?audit_trail_log_name, true).
5978
mnesia_init(Node, Dir) ->
5979
rpc:call(Node, ?MODULE, mnesia_init, [Dir]).
5982
ok = application:load(mnesia),
5983
application_controller:set_env(mnesia, dir, Dir).
5985
mnesia_create_schema(Node, Nodes) ->
5986
rpc:call(Node, mnesia, create_schema, [Nodes]).
5988
mnesia_start(Node) ->
5989
rpc:call(Node, application, start, [mnesia]).
5992
application:start(mnesia).
5994
mnesia_stop(Node) ->
5995
rpc:call(Node, application, stop, [mnesia]).
5998
application:start(mnesia).
6001
start_agent(Config) ->
6002
start_agent(Config, []).
6004
start_agent(Config, Opts) ->
6007
ConfDir = ?config(agent_conf_dir, Config),
6008
DbDir = ?config(agent_db_dir, Config),
6009
LogDir = ?config(agent_log_dir, Config),
6013
AgentConfig = process_agent_options(ConfDir, DbDir, LogDir, Vsns, Opts),
6016
AgentNode = ?config(agent_node, Config),
6017
%% ManagerNode = ?config(manager_node, Config),
6019
process_flag(trap_exit,true),
6021
AgentTopSup = start_stdalone_agent(AgentNode, AgentConfig),
6023
[{agent_sup, AgentTopSup} | Config].
6026
process_agent_options(ConfDir, DbDir, LogDir, Vsns, Opts) ->
6028
[{agent_type, master},
6029
{agent_verbosity, trace},
6034
{local_db, [{repair, true},
6037
{error_report_module, snmpa_error_logger},
6038
{config, [{dir, ConfDir},
6040
{verbosity, trace}]},
6041
{multi_threaded, true},
6042
{mib_server, [{mibentry_override, false},
6043
{trapentry_override, false},
6044
{verbosity, info}]},
6045
{target_cache, [{verbosity,info}]},
6046
{symbolic_store, [{verbosity,log}]},
6047
{note_store, [{timeout,30000}, {verbosity,log}]},
6048
{net_if, [{module, snmpa_net_if},
6050
{options, [{bind_to, false},
6052
{req_limit, infinity}]}]},
6053
{audit_trail_log, [{type, read_write},
6059
process_options(Defaults, Opts).
6061
process_options(Defaults, _Opts) ->
6062
%% process_options(Defaults, Opts, []).
6065
%% process_options([], _Opts, Acc) ->
6066
%% lists:reverse(Acc);
6067
%% process_options([{Key, DefaultValue}|Defaults], Opts, Acc) ->
6068
%% case lists:keysearch(Key, 1, Opts) of
6069
%% {value, {Key, Value}} when is_list->
6072
snmp_app_env_init(Node, Entity, Conf) ->
6073
rpc:call(Node, snmp_app_env_init, [Entity, Conf]).
6075
snmp_app_env_init(Entity, Conf) ->
6076
application:unload(snmp),
6077
application:load(snmp),
6078
application:set_env(snmp, Entity, Conf).
6080
start_stdalone_agent(Node, Config) ->
6081
rpc:call(Node, ?MODULE, start_stdalone_agent, [Config]).
6083
start_stdalone_agent(Config) ->
6084
case snmpa_supervisor:start_link(normal, Config) of
6085
{ok, AgentTopSup} ->
6086
unlink(AgentTopSup),
6088
{error, {already_started, AgentTopSup}} ->
6092
stop_stdalone_agent(Pid) when (node(Pid) =/= node()) ->
6093
MRef = erlang:monitor(process, Pid),
6094
rpc:call(node(Pid), ?MODULE, stop_stdalone_agent, [Pid]),
6096
{'DOWN', MRef, process, Pid, Info} ->
6097
?DBG("received expected DOWN message "
6098
"regarding snmp agent supervisor: "
6099
"~n Info: ~p", [Info]),
6102
?DBG("no DOWN message "
6103
"regarding snmp agent supervisor within time", []),
6106
stop_stdalone_agent(Pid) ->
6107
?DBG("attempting to terminate agent top-supervisor: ~p", [Pid]),
6111
nkill(Pid, Reason) ->
6112
nkill(Pid, Reason, 10).
6114
nkill(Pid, Reason, N) when N > 0 ->
6115
case (catch erlang:process_info(Pid)) of
6116
Info when is_list(Info) ->
6117
?DBG("Info for process to kill: "
6118
"~n Info: ~p", [Info]),
6121
nkill(Pid, Reason, N-1);
6123
?DBG("No process info => already dead?", []),
6128
%%-----------------------------------------------------------------
5694
6129
%% Slogan: info test
5695
6130
%%-----------------------------------------------------------------