snmp_agent_test.erl

来自「OTP是开放电信平台的简称」· ERL 代码 · 共 2,194 行 · 第 1/5 页

ERL
2,194
字号
    end.test_v1(suite) -> {req, [], {conf, init_v1, v1_cases(), finish_v1}}.%v1_cases() -> [loop_mib];v1_cases() ->    [     simple,      db_notify_client,     v1_processing,      big,      big2,      loop_mib,      api,      subagent,      mnesia,      multiple_reqs,     sa_register,      v1_trap,      sa_error,      next_across_sa,      undo,      reported_bugs,     standard_mibs,      sparse_table,      cnt_64,      opaque,      change_target_addr_config    ].  init_v1(Config) when list(Config) ->    ?line SaNode = ?config(snmp_sa, Config),    ?line create_tables(SaNode),    ?line AgentDir = ?config(agent_dir, Config),    ?line MgrDir = ?config(mgr_dir, Config),    ?line Ip = ?config(ip, Config),    ?line config([v1], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)),    [{vsn, v1} | start_v1_agent(Config)].finish_v1(Config) when list(Config) ->    delete_tables(),    C1 = stop_agent(Config),    delete_files(C1),    lists:keydelete(vsn, 1, C1).test_v2(suite) -> {req, [], {conf, init_v2, v2_cases(), finish_v2}}.v2_cases() ->    [simple_2,      v2_processing,      big_2,      big2_2,      loop_mib_2,     api_2,      subagent_2,      mnesia_2,     multiple_reqs_2,      sa_register_2,      v2_trap,      v2_inform,      sa_error_2,     next_across_sa_2,      undo_2,      reported_bugs_2,      standard_mibs_2,     v2_types,      implied,      sparse_table_2,      cnt_64_2,      opaque_2,      v2_caps    ].init_v2(Config) when list(Config) ->    SaNode = ?config(snmp_sa, Config),    create_tables(SaNode),    AgentDir = ?config(agent_dir, Config),    MgrDir = ?config(mgr_dir, Config),    Ip = ?config(ip, Config),    config([v2], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)),    [{vsn, v2} | start_v2_agent(Config)].finish_v2(Config) when list(Config) ->    delete_tables(),    C1 = stop_agent(Config),    delete_files(C1),    lists:keydelete(vsn, 1, C1).test_v1_v2(suite) ->     {req, [], {conf, init_v1_v2, v1_v2_cases(), finish_v1_v2}}.v1_v2_cases() ->    [simple_bi].init_v1_v2(Config) when list(Config) ->    SaNode = ?config(snmp_sa, Config),    create_tables(SaNode),    AgentDir = ?config(agent_dir, Config),    MgrDir = ?config(mgr_dir, Config),    Ip = ?config(ip, Config),    config([v1,v2], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)),    [{vsn, bilingual} | start_bilingual_agent(Config)].finish_v1_v2(Config) when list(Config) ->    delete_tables(),    C1 = stop_agent(Config),    delete_files(C1),    lists:keydelete(vsn, 1, C1).test_v3(suite) -> {req, [], {conf, init_v3, v3_cases(), finish_v3}}.v3_cases() ->    [     simple_3,      v3_processing,     big_3,      big2_3,      api_3,      subagent_3,      mnesia_3,      loop_mib_3,     multiple_reqs_3,      sa_register_3,      v3_trap,      v3_inform,      sa_error_3,     next_across_sa_3,      undo_3,      reported_bugs_3,      standard_mibs_3,     v3_security,     v2_types_3,      implied_3,      sparse_table_3,      cnt_64_3,      opaque_3,      v2_caps_3    ].init_v3(Config) when list(Config) ->    %% Make sure crypto works, otherwise start_agent will fail    %% and we will be stuck with a bunch of mnesia tables for    %% the rest of this suite...    ?DBG("start_agent -> start crypto app",[]),    case os:type() of	vxworks ->	    no_crypto;	_ ->	    case ?CRYPTO_START() of		ok ->		    case ?CRYPTO_SUPPORT() of			{no, Reason} ->			    ?SKIP({unsupported_encryption, Reason});			yes ->			    ok		    end;		{error, Reason} ->		    ?SKIP({failed_starting_crypto, Reason})	    end    end,    SaNode = ?config(snmp_sa, Config),    create_tables(SaNode),    AgentDir = ?config(agent_dir, Config),    MgrDir = ?config(mgr_dir, Config),    Ip = ?config(ip, Config),    ?line ok = config([v3], MgrDir, AgentDir, 		      tuple_to_list(Ip), tuple_to_list(Ip)),    [{vsn, v3} | start_v3_agent(Config)].finish_v3(Config) when list(Config) ->    delete_tables(),    C1 = stop_agent(Config),    delete_files(C1),    lists:keydelete(vsn, 1, C1).test_multi_threaded(suite) -> {req, [], {conf, init_mt, mt_cases(), finish_mt}}.mt_cases() ->    [multi_threaded, mt_trap].init_mt(Config) when list(Config) ->    SaNode = ?config(snmp_sa, Config),    create_tables(SaNode),    AgentDir = ?config(agent_dir, Config),    MgrDir = ?config(mgr_dir, Config),    Ip = ?config(ip, Config),    ?line ok = config([v2], MgrDir, AgentDir, tuple_to_list(Ip), tuple_to_list(Ip)),    [{vsn, v2} | start_multi_threaded_agent(Config)].finish_mt(Config) when list(Config) ->    delete_tables(),    C1 = stop_agent(Config),    delete_files(C1),    lists:keydelete(vsn, 1, C1).%% This one *must* be run first in each case.init_case(Config) ->    snmp_agent_test_lib: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]).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]).unload_master(Mib) ->    ?DBG("unload_master -> entry with"	"~n   Mib: ~p", [Mib]),    ok = snmpa:unload_mibs(snmp_master_agent, [Mib]).loaded_mibs() ->    ?DBG("loaded_mibs -> entry",[]),    Info = snmpa:info(snmp_master_agent),    {value, {mib_server,  MibInfo}} = lists:keysearch(mib_server, 1, Info),    {value, {loaded_mibs, Mibs}}    = lists:keysearch(loaded_mibs, 1, MibInfo),    [atom_to_list(Mib) || {Mib,_,_} <- Mibs].unload_mibs(Mibs) ->    ?DBG("unload_mibs -> entry with"	"~n   Mibs: ~p", [Mibs]),    ok = snmpa:unload_mibs(snmp_master_agent, Mibs).start_subagent(SaNode, RegTree, Mib) ->    snmp_agent_test_lib:start_subagent(SaNode, RegTree, Mib).stop_subagent(SA) ->    snmp_agent_test_lib:stop_subagent(SA).%%-----------------------------------------------------------------%% This function takes care of the old OTP-SNMPEA-MIB.%% Unfortunately, the testcases were written to use the data in the%% internal tables, and these table are now obsolete and not used%% by the agent.  Therefore, we emulate them by using%% OLD-SNMPEA-MIB, which uses the default impl. of all tables.%%%% These two rows must exist in intCommunityTable%%    {[147,214,36,45], "public", 2, readWrite}.%%    {[147,214,36,45], "standard trap", 2, read}.%% (But with the manager's IP address)%%%%-----------------------------------------------------------------init_old() ->    snmpa_local_db:table_create_row(intCommunityTable,				    get(mip) ++ [6 | "public"],				    {get(mip), "public", 2, 2}),    snmpa_local_db:table_create_row(intCommunityTable,				    get(mip) ++ [13 | "standard trap"],				    {get(mip), "standard trap", 2, 1}),    snmpa_local_db:variable_set(intAgentIpAddress, [127,0,0,1]).    				    simple(suite) -> [];simple(Config) when list(Config) ->    ?P(simple),    init_case(Config),        try_test(simple_standard_test).simple_2(X) -> ?P(simple_2), simple(X).simple_bi(suite) -> [];simple_bi(Config) when list(Config) ->    ?P(simple_bi),    init_case(Config),    put(vsn, v1), % First, try v1 manager    try_test(simple_standard_test),        put(vsn, v2), % Then, try v2 manager    try_test(simple_standard_test).    simple_3(X) ->    ?P(simple_3), simple(X).big(suite) -> [];big(Config) when list(Config) ->    ?P(big),    %% put(sname, {?MODULE, big}),    %% put(verbosity, trace),    {SaNode, _MgrNode, _MibDir} = init_case(Config),    ?P1("Starting subagent..."),    ?line pong = net_adm:ping(SaNode),        ?line {ok, SA} = start_subagent(SaNode, ?klas1, "Klas1"),    ?DBG("big -> SA: ~p", [SA]),    ?line load_master("OLD-SNMPEA-MIB"),    ?line init_old(),    snmpa:dump_mibs(),    snmpa:dump_mibs("dumped_mibs.txt"),    io:format("Local DB: ~n~p~n", [snmpa_local_db:print()]),    try_test(big_test),    ?line stop_subagent(SA),    ?line unload_master("OLD-SNMPEA-MIB").big_2(X) -> ?P(big_2), big(X).big_3(X) -> ?P(big_3), big(X).     big2(suite) -> [];big2(Config) when list(Config) ->    ?P(big2),     %% This is exactly the same tests as 'big', but with the    %% v2 equivalent of the mibs.    {SaNode, _MgrNode, _MibDir} = init_case(Config),    ?P1("Starting subagent..."),    ?line pong = net_adm:ping(SaNode),        ?line {ok, SA} = start_subagent(SaNode, ?klas1, "Klas1-v2"),    ?line load_master("OLD-SNMPEA-MIB-v2"),    ?line init_old(),    try_test(big_test),    ?line stop_subagent(SA),    ?line unload_master("OLD-SNMPEA-MIB-v2").big2_2(X) -> ?P(big2_2), big2(X).big2_3(X) -> ?P(big2_3), big2(X).    multi_threaded(suite) -> [];multi_threaded(Config) when list(Config) ->    ?P(multi_threaded),     init_case(Config),        ?line load_master("Test1"),    try_test(multi_threaded_test),    ?line unload_master("Test1").mt_trap(suite) -> [];mt_trap(Config) when list(Config) ->    ?P(mt_trap),     init_case(Config),    MA = whereis(snmp_master_agent),        ?line load_master("Test1"),    ?line load_master("TestTrapv2"),    try_test(mt_trap_test, [MA]),    ?line unload_master("TestTrapv2"),    ?line unload_master("Test1").v2_types(suite) -> [];v2_types(Config) when list(Config) ->    ?P(v2_types),     init_case(Config),    ?line load_master("Test1"),    try_test(types_v2_test),    ?line unload_master("Test1").v2_types_3(X) -> ?P(v2_types_3), v2_types(X).    implied(suite) -> [];implied(Config) when list(Config) ->    ?P(implied),     init_case(Config),    MA = whereis(snmp_master_agent),    ?line load_master("Test1"),    try_test(implied_test,[MA]),    ?line unload_master("Test1").implied_3(X) -> ?P(implied_3), implied(X).    sparse_table(suite) -> [];sparse_table(Config) when list(Config) ->    ?P(sparse_table),     init_case(Config),    ?line load_master("Test1"),    try_test(sparse_table_test),    ?line unload_master("Test1").sparse_table_2(X) -> ?P(sparse_table_2), sparse_table(X).sparse_table_3(X) -> ?P(sparse_table_3), sparse_table(X).cnt_64(suite) -> [];cnt_64(Config) when list(Config) ->    ?P(cnt_64),     init_case(Config),    MA = whereis(snmp_master_agent),    ?line load_master("Test1"),    try_test(cnt_64_test, [MA]),    ?line unload_master("Test1").cnt_64_2(X) -> ?P(cnt_64_2), cnt_64(X).cnt_64_3(X) -> ?P(cnt_64_3), cnt_64(X).opaque(suite) -> [];opaque(Config) when list(Config) ->    ?P(opaque),     init_case(Config),    ?line load_master("Test1"),    try_test(opaque_test),    ?line unload_master("Test1").opaque_2(X) -> ?P(opaque_2), opaque(X).opaque_3(X) -> ?P(opaque_2), opaque(X).change_target_addr_config(suite) -> [];change_target_addr_config(Config) when list(Config) ->    ?P(change_target_addr_config),     ?LOG("change_target_addr_config -> entry",[]),    init_case(Config),    put(sname,snmp_suite),    put(verbosity,trace),    MA = whereis(snmp_master_agent),    ?LOG("change_target_addr_config -> load TestTrap",[]),    ?line load_master("TestTrap"),    ?LOG("change_target_addr_config -> set trace verbosity for local_db",[]),

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?