aboutsummaryrefslogtreecommitdiffstats
path: root/lib/snmp/test
diff options
context:
space:
mode:
Diffstat (limited to 'lib/snmp/test')
-rw-r--r--lib/snmp/test/snmp_agent_mibs_test.erl22
-rw-r--r--lib/snmp/test/snmp_agent_test.erl146
-rw-r--r--lib/snmp/test/snmp_agent_test_lib.erl74
-rw-r--r--lib/snmp/test/snmp_manager_config_test.erl43
4 files changed, 205 insertions, 80 deletions
diff --git a/lib/snmp/test/snmp_agent_mibs_test.erl b/lib/snmp/test/snmp_agent_mibs_test.erl
index 248fe7d83e..f7dae64e3f 100644
--- a/lib/snmp/test/snmp_agent_mibs_test.erl
+++ b/lib/snmp/test/snmp_agent_mibs_test.erl
@@ -238,6 +238,8 @@ start_and_stop(Config) when is_list(Config) ->
load_unload(suite) -> [];
load_unload(Config) when is_list(Config) ->
+ ?DBG("load_unload -> start", []),
+
Prio = normal,
Verbosity = log,
MibDir = ?config(data_dir, Config),
@@ -253,8 +255,10 @@ load_unload(Config) when is_list(Config) ->
?line ok = load_mibs(MibsPid, MibDir, ["Test2"]),
?line ok = verify_loaded_mibs(MibsPid, MibDir, ["Test2"]),
- ?DBG("load_unload -> load one already loaded mib", []),
- ?line {error, _} = load_mibs(MibsPid, MibDir, ["Test2"]),
+ ?DBG("load_unload -> try load one *already loaded* mib", []),
+ EMib = join(MibDir, "Test2"),
+ ?line {error, {'load aborted at', EMib, already_loaded}} =
+ load_mibs(MibsPid, MibDir, ["Test2"]),
?DBG("load_unload -> load 2 not already loaded mibs", []),
?line ok = load_mibs(MibsPid, MibDir, ["TestTrap", "TestTrapv2"]),
@@ -266,7 +270,8 @@ load_unload(Config) when is_list(Config) ->
?line ok = verify_loaded_mibs(MibsPid, MibDir, ["TestTrap", "TestTrapv2"]),
?DBG("load_unload -> try unload two loaded mibs and one not loaded", []),
- ?line {error, _} = unload_mibs(MibsPid, ["TestTrap","Test2","TestTrapv2"]),
+ ?line {error, {'unload aborted at', "Test2", not_loaded}} =
+ unload_mibs(MibsPid, ["TestTrap","Test2","TestTrapv2"]),
?line ok = verify_loaded_mibs(MibsPid, MibDir, ["TestTrapv2"]),
?DBG("load_unload -> unload the remaining loaded mib", []),
@@ -279,6 +284,7 @@ load_unload(Config) when is_list(Config) ->
?DBG("load_unload -> stop symbolic store", []),
?line sym_stop(),
+ ?DBG("load_unload -> done", []),
ok.
@@ -691,10 +697,16 @@ mibs_info(Pid) ->
load_mibs(Pid, Dir, Mibs0) ->
Mibs = [join(Dir, Mib) || Mib <- Mibs0],
- snmpa_mib:load_mibs(Pid, Mibs).
+ Res = snmpa_mib:load_mibs(Pid, Mibs),
+ %% ?DBG("load_mibs -> "
+ %% "~n Res: ~p", [Res]),
+ Res.
unload_mibs(Pid, Mibs) ->
- snmpa_mib:unload_mibs(Pid, Mibs).
+ Res = snmpa_mib:unload_mibs(Pid, Mibs),
+ %% ?DBG("unload_mibs -> "
+ %% "~n Res: ~p", [Res]),
+ Res.
verify_loaded_mibs(Pid, Dir, ExpectedMibs0) ->
ExpectedMibs = [join(Dir, Mib) || Mib <- ExpectedMibs0],
diff --git a/lib/snmp/test/snmp_agent_test.erl b/lib/snmp/test/snmp_agent_test.erl
index 6fe97ccd25..b7d34eb198 100644
--- a/lib/snmp/test/snmp_agent_test.erl
+++ b/lib/snmp/test/snmp_agent_test.erl
@@ -34,6 +34,7 @@
%% all_tcs - misc
app_info/1,
info_test/1,
+ create_local_db_dir/1,
%% all_tcs - test_v1
simple/1,
@@ -554,7 +555,7 @@ init_per_suite(Config0) when is_list(Config0) ->
%% Mib-dirs
MibDir = snmp_test_lib:lookup(data_dir, Config2),
- StdMibDir = filename:join([code:priv_dir(snmp), "mibs"]),
+ StdMibDir = join([code:priv_dir(snmp), "mibs"]),
Config3 = [{mib_dir, MibDir}, {std_mib_dir, StdMibDir} | Config2],
@@ -748,21 +749,21 @@ init_per_testcase2(Case, Config) ->
CaseTopDir = snmp_test_lib:init_testcase_top_dir(Case, Config),
%% Create agent top-dir(s)
- AgentTopDir = filename:join([CaseTopDir, agent]),
+ AgentTopDir = join([CaseTopDir, agent]),
ok = file:make_dir(AgentTopDir),
- AgentConfDir = filename:join([AgentTopDir, config]),
+ AgentConfDir = join([AgentTopDir, config]),
ok = file:make_dir(AgentConfDir),
- AgentDbDir = filename:join([AgentTopDir, db]),
+ AgentDbDir = join([AgentTopDir, db]),
ok = file:make_dir(AgentDbDir),
- AgentLogDir = filename:join([AgentTopDir, log]),
+ AgentLogDir = join([AgentTopDir, log]),
ok = file:make_dir(AgentLogDir),
%% Create sub-agent top-dir(s)
- SubAgentTopDir = filename:join([CaseTopDir, sub_agent]),
+ SubAgentTopDir = join([CaseTopDir, sub_agent]),
ok = file:make_dir(SubAgentTopDir),
%% Create manager top-dir(s)
- ManagerTopDir = filename:join([CaseTopDir, manager]),
+ ManagerTopDir = join([CaseTopDir, manager]),
ok = file:make_dir(ManagerTopDir),
[{case_top_dir, CaseTopDir},
@@ -1506,7 +1507,8 @@ finish_misc(Config) ->
misc_cases() ->
[
app_info,
- info_test
+ info_test,
+ create_local_db_dir
].
app_info(suite) -> [];
@@ -1539,7 +1541,75 @@ app_dir(App) ->
"undefined"
end.
+create_local_db_dir(Config) when is_list(Config) ->
+ ?P(create_local_db_dir),
+ DataDir = snmp_test_lib:lookup(data_dir, Config),
+ T = erlang:now(),
+ [As,Bs,Cs] = [integer_to_list(I) || I <- tuple_to_list(T)],
+ DbDir = filename:join([DataDir, As, Bs, Cs]),
+ ok = del_dir(DbDir, 3),
+ Name = list_to_atom(atom_to_list(create_local_db_dir)
+ ++"-"++As++"-"++Bs++"-"++Cs),
+ Pa = filename:dirname(code:which(?MODULE)),
+ {ok,Node} = ?t:start_node(Name, slave, [{args, "-pa "++Pa}]),
+
+ %% first start with a nonexisting DbDir
+ Fun1 = fun() ->
+ false = filelib:is_dir(DbDir),
+ process_flag(trap_exit,true),
+ {error, {error, {failed_open_dets, {file_error, _, _}}}} =
+ snmpa_local_db:start_link(normal, DbDir, [{verbosity,trace}]),
+ false = filelib:is_dir(DbDir),
+ {ok, not_found}
+ end,
+ {ok, not_found} = nodecall(Node, Fun1),
+ %% now start with a nonexisting DbDir but pass the
+ %% create_local_db_dir option as well
+ Fun2 = fun() ->
+ false = filelib:is_dir(DbDir),
+ process_flag(trap_exit,true),
+ {ok, _Pid} =
+ snmpa_local_db:start_link(normal, DbDir,
+ create_db_and_dir, [{verbosity,trace}]),
+ snmpa_local_db:stop(),
+ true = filelib:is_dir(DbDir),
+ {ok, found}
+ end,
+ {ok, found} = nodecall(Node, Fun2),
+ %% cleanup
+ ?t:stop_node(Node),
+ ok = del_dir(DbDir, 3),
+ ok.
+nodecall(Node, Fun) ->
+ Parent = self(),
+ Ref = make_ref(),
+ spawn_link(Node,
+ fun() ->
+ Res = Fun(),
+ unlink(Parent),
+ Parent ! {Ref, Res}
+ end),
+ receive
+ {Ref, Res} ->
+ Res
+ end.
+
+del_dir(_Dir, 0) ->
+ ok;
+del_dir(Dir, Depth) ->
+ case filelib:is_dir(Dir) of
+ true ->
+ {ok, Files} = file:list_dir(Dir),
+ lists:map(fun(F) ->
+ Nm = filename:join(Dir,F),
+ ok = file:delete(Nm)
+ end, Files),
+ ok = file:del_dir(Dir),
+ del_dir(filename:dirname(Dir), Depth-1);
+ false ->
+ ok
+ end.
%v1_cases() -> [loop_mib];
v1_cases() ->
@@ -1738,19 +1808,19 @@ init_case(Config) ->
load_master(Mib) ->
?DBG("load_master -> entry with"
"~n Mib: ~p", [Mib]),
- snmpa:unload_mibs(snmp_master_agent, [Mib]), % Unload for safety
- ok = snmpa:load_mibs(snmp_master_agent, [get(mib_dir) ++ Mib]).
+ snmpa:unload_mib(snmp_master_agent, Mib), % Unload for safety
+ ok = snmpa:load_mib(snmp_master_agent, join(get(mib_dir), Mib)).
load_master_std(Mib) ->
?DBG("load_master_std -> entry with"
"~n Mib: ~p", [Mib]),
- snmpa:unload_mibs(snmp_master_agent, [Mib]), % Unload for safety
- ok = snmpa:load_mibs(snmp_master_agent, [get(std_mib_dir) ++ Mib]).
+ snmpa:unload_mib(snmp_master_agent, Mib), % Unload for safety
+ ok = snmpa:load_mib(snmp_master_agent, join(get(std_mib_dir), Mib)).
unload_master(Mib) ->
?DBG("unload_master -> entry with"
"~n Mib: ~p", [Mib]),
- ok = snmpa:unload_mibs(snmp_master_agent, [Mib]).
+ ok = snmpa:unload_mib(snmp_master_agent, Mib).
loaded_mibs() ->
?DBG("loaded_mibs -> entry",[]),
@@ -2155,11 +2225,11 @@ subagent(Config) when is_list(Config) ->
try_test(unreg_test),
?P1("Loading previous subagent mib in master and testing..."),
- ?line ok = snmpa:load_mibs(MA, [MibDir ++ "Klas1"]),
+ ?line ok = snmpa:load_mib(MA, join(MibDir, "Klas1")),
try_test(load_test),
?P1("Unloading previous subagent mib in master and testing..."),
- ?line ok = snmpa:unload_mibs(MA, [MibDir ++ "Klas1"]),
+ ?line ok = snmpa:unload_mib(MA, join(MibDir, "Klas1")),
try_test(unreg_test),
?P1("Testing register subagent..."),
rpc:call(SaNode, snmp, register_subagent,
@@ -2355,11 +2425,11 @@ sa_register(Config) when is_list(Config) ->
?P1("Unloading Klas1..."),
?DBG("sa_register -> unload mibs", []),
- snmpa:unload_mibs(SA, [MibDir ++ "Klas1"]),
+ snmpa:unload_mib(SA, join(MibDir, "Klas1")),
?P1("Loading SA-MIB..."),
?DBG("sa_register -> unload mibs", []),
- snmpa:load_mibs(SA, [MibDir ++ "SA-MIB"]),
+ snmpa:load_mib(SA, join(MibDir, "SA-MIB")),
?P1("register subagent..."),
?DBG("sa_register -> register subagent", []),
@@ -2578,7 +2648,7 @@ next_across_sa(Config) when is_list(Config) ->
?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"),
?P1("Loading another subagent mib (Klas1)..."),
- ?line ok = snmpa:load_mibs(SA, [MibDir ++ "Klas1"]),
+ ?line ok = snmpa:load_mib(SA, MibDir ++ "Klas1"),
?P1("register subagent..."),
rpc:call(SaNode, snmp, register_subagent, [MA, ?klas1, SA]),
@@ -2590,7 +2660,7 @@ next_across_sa(Config) when is_list(Config) ->
try_test(next_across_sa_test),
?P1("Unloading mib (Klas1)"),
- snmpa:unload_mibs(SA, [MibDir ++ "Klas1"]),
+ snmpa:unload_mib(SA, join(MibDir, "Klas1")),
rpc:call(SaNode, snmp, unregister_subagent, [MA, ?klas1]),
try_test(unreg_test),
@@ -2631,25 +2701,25 @@ undo(Config) when is_list(Config) ->
?line {ok, SA} = start_subagent(SaNode, ?sa, "SA-MIB"),
?P1("Load Klas3 & Klas4..."),
- ?line ok = snmpa:load_mibs(MA, [MibDir ++ "Klas3"]),
- ?line ok = snmpa:load_mibs(MA, [MibDir ++ "Klas4"]),
+ ?line ok = snmpa:load_mib(MA, join(MibDir, "Klas3")),
+ ?line ok = snmpa:load_mib(MA, join(MibDir, "Klas4")),
?P1("Testing undo phase at master agent..."),
try_test(undo_test),
try_test(api_test2),
?P1("Unload Klas3..."),
- ?line ok = snmpa:unload_mibs(MA, [MibDir ++ "Klas3"]),
+ ?line ok = snmpa:unload_mib(MA, join(MibDir, "Klas3")),
?P1("Testing bad return values from instrum. funcs..."),
try_test(bad_return),
?P1("Unload Klas4..."),
- ?line ok = snmpa:unload_mibs(MA, [MibDir ++ "Klas4"]),
+ ?line ok = snmpa:unload_mib(MA, join(MibDir, "Klas4")),
?P1("Testing undo phase at subagent..."),
- ?line ok = snmpa:load_mibs(SA, [MibDir ++ "Klas3"]),
- ?line ok = snmpa:load_mibs(SA, [MibDir ++ "Klas4"]),
+ ?line ok = snmpa:load_mib(SA, join(MibDir, "Klas3")),
+ ?line ok = snmpa:load_mib(SA, join(MibDir, "Klas4")),
?line ok = snmpa:register_subagent(MA, ?klas3, SA),
?line ok = snmpa:register_subagent(MA, ?klas4, SA),
try_test(undo_test),
@@ -6247,8 +6317,8 @@ otp_4394_config(AgentConfDir, MgrDir, Ip0) ->
"OTP-4394 test"),
?line case update_usm(Vsn, AgentConfDir) of
true ->
- ?line copy_file(filename:join(AgentConfDir, "usm.conf"),
- filename:join(MgrDir, "usm.conf")),
+ ?line copy_file(join(AgentConfDir, "usm.conf"),
+ join(MgrDir, "usm.conf")),
?line update_usm_mgr(Vsn, MgrDir);
false ->
?line ok
@@ -6407,11 +6477,11 @@ otp8395({init, Config}) when is_list(Config) ->
%%
AgentDbDir = ?config(agent_db_dir, Config),
- AgentMnesiaDir = filename:join([AgentDbDir, "mnesia"]),
+ AgentMnesiaDir = join([AgentDbDir, "mnesia"]),
mnesia_init(AgentNode, AgentMnesiaDir),
%% SubAgentDir = ?config(sub_agent_dir, Config),
- %% SubAgentMnesiaDir = filename:join([SubAgentDir, "mnesia"]),
+ %% SubAgentMnesiaDir = join([SubAgentDir, "mnesia"]),
%% mnesia_init(SubAgentNode, SubAgentMnesiaDir),
%% ok = mnesia_create_schema(AgentNode, [AgentNode, SubAgentNode]),
@@ -6541,7 +6611,7 @@ otp8395(Config) when is_list(Config) ->
?SLEEP(1000),
AgentNode = ?config(agent_node, Config),
AgentLogDir = ?config(agent_log_dir, Config),
- OutFile = filename:join([AgentLogDir, "otp8395.txt"]),
+ OutFile = join([AgentLogDir, "otp8395.txt"]),
{ok, LogInfo} = rpc:call(AgentNode, snmpa, log_info, []),
?DBG("otp8395 -> LogInfo: ~p", [LogInfo]),
@@ -6579,7 +6649,7 @@ otp9884({init, Config}) when is_list(Config) ->
%%
AgentDbDir = ?config(agent_db_dir, Config),
- AgentMnesiaDir = filename:join([AgentDbDir, "mnesia"]),
+ AgentMnesiaDir = join([AgentDbDir, "mnesia"]),
mnesia_init(AgentNode, AgentMnesiaDir),
mnesia_create_schema(AgentNode, [AgentNode]),
@@ -6609,8 +6679,8 @@ otp9884({init, Config}) when is_list(Config) ->
ManagerConfDir = ?config(manager_top_dir, Config),
AgentConfDir = ?config(agent_conf_dir, Config),
AgentTopDir = ?config(agent_top_dir, Config),
- AgentBkpDir1 = filename:join([AgentTopDir, backup1]),
- AgentBkpDir2 = filename:join([AgentTopDir, backup2]),
+ AgentBkpDir1 = join([AgentTopDir, backup1]),
+ AgentBkpDir2 = join([AgentTopDir, backup2]),
ok = file:make_dir(AgentBkpDir1),
ok = file:make_dir(AgentBkpDir2),
AgentBkpDirs = [AgentBkpDir1, AgentBkpDir2],
@@ -7105,7 +7175,7 @@ display_log(Config) ->
{value, {_, Node}} ->
LogDir = Dir,
Mibs = [],
- OutFile = filename:join(LogDir, "snmpa_log.txt"),
+ OutFile = join(LogDir, "snmpa_log.txt"),
p("~n"
"========================="
" < Audit Trail Log > "
@@ -7252,6 +7322,14 @@ lists_key1search(Key, List) when is_atom(Key) ->
%% regs() ->
%% lists:sort(registered()).
+%% ------
+
+join(Parts) ->
+ filename:join(Parts).
+
+join(Dir, File) ->
+ filename:join(Dir, File).
+
%% ------
diff --git a/lib/snmp/test/snmp_agent_test_lib.erl b/lib/snmp/test/snmp_agent_test_lib.erl
index 7e4b713e56..122289c28e 100644
--- a/lib/snmp/test/snmp_agent_test_lib.erl
+++ b/lib/snmp/test/snmp_agent_test_lib.erl
@@ -139,31 +139,31 @@ init_all(Config) when is_list(Config) ->
SuiteTopDir = ?config(snmp_suite_top_dir, Config),
?DBG("init_all -> SuiteTopDir ~p", [SuiteTopDir]),
- AgentDir = filename:join(SuiteTopDir, "agent/"),
+ AgentDir = join(SuiteTopDir, "agent/"),
?line ok = file:make_dir(AgentDir),
?DBG("init_all -> AgentDir ~p", [AgentDir]),
- AgentDbDir = filename:join(AgentDir, "db/"),
+ AgentDbDir = join(AgentDir, "db/"),
?line ok = file:make_dir(AgentDbDir),
?DBG("init_all -> AgentDbDir ~p", [AgentDbDir]),
- AgentLogDir = filename:join(AgentDir, "log/"),
+ AgentLogDir = join(AgentDir, "log/"),
?line ok = file:make_dir(AgentLogDir),
?DBG("init_all -> AgentLogDir ~p", [AgentLogDir]),
- AgentConfDir = filename:join(AgentDir, "conf/"),
+ AgentConfDir = join(AgentDir, "conf/"),
?line ok = file:make_dir(AgentConfDir),
?DBG("init_all -> AgentConfDir ~p", [AgentConfDir]),
- MgrDir = filename:join(SuiteTopDir, "mgr/"),
+ MgrDir = join(SuiteTopDir, "mgr/"),
?line ok = file:make_dir(MgrDir),
?DBG("init_all -> MgrDir ~p", [MgrDir]),
- SaDir = filename:join(SuiteTopDir, "sa/"),
+ SaDir = join(SuiteTopDir, "sa/"),
?line ok = file:make_dir(SaDir),
?DBG("init_all -> SaDir ~p", [SaDir]),
- SaDbDir = filename:join(SaDir, "db/"),
+ SaDbDir = join(SaDir, "db/"),
?line ok = file:make_dir(SaDbDir),
?DBG("init_all -> SaDbDir ~p", [SaDbDir]),
@@ -183,11 +183,11 @@ init_all(Config) when is_list(Config) ->
?DBG("init_all -> application mnesia: set_env dir",[]),
?line application_controller:set_env(mnesia, dir,
- filename:join(AgentDbDir, "Mnesia1")),
+ join(AgentDbDir, "Mnesia1")),
?DBG("init_all -> application mnesia: set_env dir on node ~p",[SaNode]),
?line rpc:call(SaNode, application_controller, set_env,
- [mnesia, dir, filename:join(SaDir, "Mnesia2")]),
+ [mnesia, dir, join(SaDir, "Mnesia2")]),
?DBG("init_all -> create mnesia schema",[]),
?line ok = mnesia:create_schema([SaNode, node()]),
@@ -253,7 +253,7 @@ init_case(Config) when is_list(Config) ->
MibDir = ?config(mib_dir, Config),
put(mib_dir, MibDir),
- StdM = filename:join(code:priv_dir(snmp), "mibs") ++ "/",
+ StdM = join(code:priv_dir(snmp), "mibs") ++ "/",
put(std_mib_dir, StdM),
MgrDir = ?config(mgr_dir, Config),
@@ -341,7 +341,7 @@ run(Mod, Func, Args, Opts) ->
Crypto = ?CRYPTO_START(),
?DBG("run -> Crypto: ~p", [Crypto]),
catch snmp_test_mgr:stop(), % If we had a running mgr from a failed case
- StdM = filename:join(code:priv_dir(snmp), "mibs") ++ "/",
+ StdM = join(code:priv_dir(snmp), "mibs") ++ "/",
Vsn = get(vsn),
?DBG("run -> config:"
"~n M: ~p"
@@ -763,7 +763,7 @@ start_subagent(SaNode, RegTree, Mib) ->
MA = whereis(snmp_master_agent),
?DBG("start_subagent -> MA: ~p", [MA]),
MibDir = get(mib_dir),
- Mib1 = join(MibDir,Mib),
+ Mib1 = join(MibDir, Mib),
Mod = snmpa_supervisor,
Func = start_sub_agent,
Args = [MA, RegTree, [Mib1]],
@@ -800,28 +800,25 @@ mibs(StdMibDir,MibDir) ->
join(MibDir, "Test2.bin"),
join(MibDir, "TestTrapv2.bin")].
-join(D,F) ->
- filename:join(D,F).
-
%% --- various mib load/unload functions ---
load_master(Mib) ->
?DBG("load_master -> entry with"
"~n Mib: ~p", [Mib]),
- snmpa:unload_mibs(snmp_master_agent, [Mib]), % Unload for safety
- ok = snmpa:load_mibs(snmp_master_agent, [get(mib_dir) ++ Mib]).
+ snmpa:unload_mib(snmp_master_agent, Mib), % Unload for safety
+ ok = snmpa:load_mib(snmp_master_agent, join(get(mib_dir), Mib)).
load_master_std(Mib) ->
?DBG("load_master_std -> entry with"
"~n Mib: ~p", [Mib]),
- snmpa:unload_mibs(snmp_master_agent, [Mib]), % Unload for safety
- ok = snmpa:load_mibs(snmp_master_agent, [get(std_mib_dir) ++ Mib]).
+ snmpa:unload_mib(snmp_master_agent, Mib), % Unload for safety
+ ok = snmpa:load_mibs(snmp_master_agent, join(get(std_mib_dir), Mib)).
unload_master(Mib) ->
?DBG("unload_master -> entry with"
"~n Mib: ~p", [Mib]),
- ok = snmpa:unload_mibs(snmp_master_agent, [Mib]).
+ ok = snmpa:unload_mib(snmp_master_agent, Mib).
loaded_mibs() ->
?DBG("loaded_mibs -> entry",[]),
@@ -1383,8 +1380,8 @@ config(Vsns, MgrDir, AgentConfDir, MIp, AIp) ->
"test"),
?line case update_usm(Vsns, AgentConfDir) of
true ->
- ?line copy_file(filename:join(AgentConfDir, "usm.conf"),
- filename:join(MgrDir, "usm.conf")),
+ ?line copy_file(join(AgentConfDir, "usm.conf"),
+ join(MgrDir, "usm.conf")),
?line update_usm_mgr(Vsns, MgrDir);
false ->
?line ok
@@ -1403,9 +1400,9 @@ delete_files(Config) ->
delete_files(_AgentFiles, []) ->
ok;
delete_files(AgentDir, [DirName|DirNames]) ->
- Dir = filename:join(AgentDir, DirName),
+ Dir = join(AgentDir, DirName),
{ok, Files} = file:list_dir(Dir),
- lists:foreach(fun(FName) -> file:delete(filename:join(Dir, FName)) end,
+ lists:foreach(fun(FName) -> file:delete(join(Dir, FName)) end,
Files),
delete_files(AgentDir, DirNames).
@@ -1481,8 +1478,8 @@ update_usm_mgr(Vsns, Dir) ->
end.
rewrite_usm_mgr(Dir, ShaKey, DesKey) ->
- ?line ok = file:rename(filename:join(Dir,"usm.conf"),
- filename:join(Dir,"usm.old")),
+ ?line ok = file:rename(join(Dir,"usm.conf"),
+ join(Dir,"usm.old")),
Conf = [{"agentEngine", "newUser", "newUser", zeroDotZero,
usmHMACSHAAuthProtocol, "", "",
usmDESPrivProtocol, "", "", "", ShaKey, DesKey},
@@ -1492,8 +1489,8 @@ rewrite_usm_mgr(Dir, ShaKey, DesKey) ->
ok = snmp_config:write_agent_usm_config(Dir, "", Conf).
reset_usm_mgr(Dir) ->
- ?line ok = file:rename(filename:join(Dir,"usm.old"),
- filename:join(Dir,"usm.conf")).
+ ?line ok = file:rename(join(Dir,"usm.old"),
+ join(Dir,"usm.conf")).
update_community([v3], _Dir) ->
@@ -1526,7 +1523,7 @@ write_target_addr_conf(Dir, ManagerIp, UDP, Vsns) ->
rewrite_target_addr_conf(Dir, NewPort) ->
?DBG("rewrite_target_addr_conf -> entry with"
"~n NewPort: ~p", [NewPort]),
- TAFile = filename:join(Dir, "target_addr.conf"),
+ TAFile = join(Dir, "target_addr.conf"),
case file:read_file_info(TAFile) of
{ok, _} ->
ok;
@@ -1546,8 +1543,8 @@ rewrite_target_addr_conf(Dir, NewPort) ->
?DBG("rewrite_target_addr_conf -> NewAddrs: ~p",[NewAddrs]),
- ?line ok = file:rename(filename:join(Dir,"target_addr.conf"),
- filename:join(Dir,"target_addr.old")),
+ ?line ok = file:rename(join(Dir,"target_addr.conf"),
+ join(Dir,"target_addr.old")),
?line ok = snmp_config:write_agent_target_addr_config(Dir, "", NewAddrs).
@@ -1565,8 +1562,8 @@ rewrite_target_addr_conf2(_NewPort,O) ->
O.
reset_target_addr_conf(Dir) ->
- ?line ok = file:rename(filename:join(Dir, "target_addr.old"),
- filename:join(Dir, "target_addr.conf")).
+ ?line ok = file:rename(join(Dir, "target_addr.old"),
+ join(Dir, "target_addr.conf")).
write_target_params_conf(Dir, Vsns) ->
F = fun(v1) -> {"target_v1", v1, v1, "all-rights", noAuthNoPriv};
@@ -1578,14 +1575,14 @@ write_target_params_conf(Dir, Vsns) ->
rewrite_target_params_conf(Dir, SecName, SecLevel)
when is_list(SecName) andalso is_atom(SecLevel) ->
- ?line ok = file:rename(filename:join(Dir,"target_params.conf"),
- filename:join(Dir,"target_params.old")),
+ ?line ok = file:rename(join(Dir,"target_params.conf"),
+ join(Dir,"target_params.old")),
Conf = [{"target_v3", v3, usm, SecName, SecLevel}],
snmp_config:write_agent_target_params_config(Dir, "", Conf).
reset_target_params_conf(Dir) ->
- ?line ok = file:rename(filename:join(Dir,"target_params.old"),
- filename:join(Dir,"target_params.conf")).
+ ?line ok = file:rename(join(Dir,"target_params.old"),
+ join(Dir,"target_params.conf")).
write_notify_conf(Dir) ->
Conf = [{"standard trap", "std_trap", trap},
@@ -1648,6 +1645,9 @@ rpc(Node, F, A) ->
rpc:call(Node, snmpa, F, A).
+join(Dir, File) ->
+ filename:join(Dir, File).
+
%% await_pdu(To) ->
%% await_response(To, pdu).
%%
diff --git a/lib/snmp/test/snmp_manager_config_test.erl b/lib/snmp/test/snmp_manager_config_test.erl
index 3192fe1b40..7b9924b83c 100644
--- a/lib/snmp/test/snmp_manager_config_test.erl
+++ b/lib/snmp/test/snmp_manager_config_test.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 2004-2012. All Rights Reserved.
+%% Copyright Ericsson AB 2004-2013. All Rights Reserved.
%%
%% The contents of this file are subject to the Erlang Public License,
%% Version 1.1, (the "License"); you may not use this file except in
@@ -57,6 +57,7 @@
start_with_invalid_users_conf_file1/1,
start_with_invalid_agents_conf_file1/1,
start_with_invalid_usm_conf_file1/1,
+ start_with_create_db_and_dir_opt/1,
@@ -139,8 +140,13 @@ init_per_testcase(Case, Config) when is_list(Config) ->
file:make_dir(MgrTopDir = filename:join(CaseTopDir, "manager/")),
?line ok =
file:make_dir(MgrConfDir = filename:join(MgrTopDir, "conf/")),
- ?line ok =
- file:make_dir(MgrDbDir = filename:join(MgrTopDir, "db/")),
+ MgrDbDir = filename:join(MgrTopDir, "db/"),
+ case Case of
+ start_with_create_db_and_dir_opt ->
+ ok;
+ _ ->
+ ?line ok = file:make_dir(MgrDbDir)
+ end,
?line ok =
file:make_dir(MgrLogDir = filename:join(MgrTopDir, "log/")),
[{case_top_dir, CaseTopDir},
@@ -174,6 +180,7 @@ groups() ->
start_without_mandatory_opts2,
start_with_all_valid_opts, start_with_unknown_opts,
start_with_incorrect_opts,
+ start_with_create_db_and_dir_opt,
start_with_invalid_manager_conf_file1,
start_with_invalid_users_conf_file1,
start_with_invalid_agents_conf_file1,
@@ -332,7 +339,8 @@ start_with_all_valid_opts(Conf) when is_list(Conf) ->
{no_reuse, false}]}],
ServerOpts = [{timeout, 10000}, {verbosity, trace}],
NoteStoreOpts = [{timeout, 20000}, {verbosity, trace}],
- ConfigOpts = [{dir, ConfDir}, {verbosity, trace}, {db_dir, DbDir}],
+ ConfigOpts = [{dir, ConfDir}, {verbosity, trace},
+ {db_dir, DbDir}, {db_init_error, create}],
Mibs = [join(StdMibDir, "SNMP-NOTIFICATION-MIB"),
join(StdMibDir, "SNMP-USER-BASED-SM-MIB")],
Prio = normal,
@@ -1674,7 +1682,34 @@ start_with_invalid_usm_conf_file1(Conf) when is_list(Conf) ->
%% ---
%%
+start_with_create_db_and_dir_opt(suite) -> [];
+start_with_create_db_and_dir_opt(doc) ->
+ "Start the snmp manager config process with the\n"
+ "create_db_and_dir option.";
+start_with_create_db_and_dir_opt(Conf) when is_list(Conf) ->
+ put(tname, swcdado),
+ p("start"),
+ process_flag(trap_exit, true),
+ ConfDir = ?config(manager_conf_dir, Conf),
+ DbDir = ?config(manager_db_dir, Conf),
+ true = not filelib:is_dir(DbDir) and not filelib:is_file(DbDir),
+ write_manager_conf(ConfDir),
+
+ p("verify nonexistent db_dir"),
+ ConfigOpts01 = [{verbosity,trace}, {dir, ConfDir}, {db_dir, DbDir}],
+ {error, Reason01} = config_start([{config, ConfigOpts01}]),
+ p("nonexistent db_dir res: ~p", [Reason01]),
+ {invalid_conf_db_dir, _, not_found} = Reason01,
+ p("verify nonexistent db_dir gets created"),
+ ConfigOpts02 = [{db_init_error, create_db_and_dir} | ConfigOpts01],
+ {ok, _Pid} = config_start([{config, ConfigOpts02}]),
+ true = filelib:is_dir(DbDir),
+ p("verified: nonexistent db_dir was correctly created"),
+ ok = config_stop(),
+
+ p("done"),
+ ok.
%%
%% ---