diff options
author | Ingela Anderton Andin <[email protected]> | 2014-06-27 15:41:18 +0200 |
---|---|---|
committer | Raimo Niskanen <[email protected]> | 2014-07-25 12:17:50 +0200 |
commit | 1ebfcb6f1f013e62aabc9935c878a55b788967a9 (patch) | |
tree | 83579c5bdb6f83e1601e291d0f209fdee99345f9 /lib/snmp | |
parent | c7d97f4d7a27bd6aca3b6335c90e6a51e28e6719 (diff) | |
download | otp-1ebfcb6f1f013e62aabc9935c878a55b788967a9.tar.gz otp-1ebfcb6f1f013e62aabc9935c878a55b788967a9.tar.bz2 otp-1ebfcb6f1f013e62aabc9935c878a55b788967a9.zip |
snmp: Add inform test
Diffstat (limited to 'lib/snmp')
-rw-r--r-- | lib/snmp/test/Makefile | 1 | ||||
-rw-r--r-- | lib/snmp/test/snmp_to_snmpnet_SUITE.erl | 127 | ||||
-rw-r--r-- | lib/snmp/test/snmp_to_snmpnet_SUITE_data/TestTrapv2.bin | bin | 0 -> 3640 bytes | |||
-rw-r--r-- | lib/snmp/test/snmp_to_snmpnet_SUITE_data/TestTrapv2.mib | 71 |
4 files changed, 148 insertions, 51 deletions
diff --git a/lib/snmp/test/Makefile b/lib/snmp/test/Makefile index d2eca0b250..a9bbe7fe62 100644 --- a/lib/snmp/test/Makefile +++ b/lib/snmp/test/Makefile @@ -239,6 +239,7 @@ release_tests_spec: opt $(INSTALL_DATA) $(RELTEST_FILES) $(COVER_SPEC_FILE) "$(RELSYSDIR)" chmod -R u+w "$(RELSYSDIR)" tar cf - snmp_test_data | (cd "$(RELSYSDIR)"; tar xf -) + tar cf - *_SUITE_data | (cd "$(RELSYSDIR)"; tar xf -) release_docs_spec: diff --git a/lib/snmp/test/snmp_to_snmpnet_SUITE.erl b/lib/snmp/test/snmp_to_snmpnet_SUITE.erl index 4584ad75c2..e8dcffd361 100644 --- a/lib/snmp/test/snmp_to_snmpnet_SUITE.erl +++ b/lib/snmp/test/snmp_to_snmpnet_SUITE.erl @@ -27,7 +27,8 @@ -include_lib("snmp/include/STANDARD-MIB.hrl"). -define(AGENT_ENGIN_ID, "ErlangSnmpAgent"). --define(AGENT_PORT, 4000). +-define(AGENT_PORT, 4000). +-define(MANAGER_PORT, 8989). -define(DEFAULT_MAX_MESSAGE_SIZE, 484). -define(SYS_DESC, "iso.3.6.1.2.1.1.1.0 = STRING: \"Erlang SNMP agent\"\n"). @@ -44,33 +45,21 @@ all() -> ]. groups() -> - [{ipv4, [], ipv4_tests()}, - {ipv6, [], ipv6_tests()}, - {get, [], get_tests()}, - %%{trap, [], trap_tests()}, - {dual_ip, [], dual_ip_tests()}]. - -get_tests() -> - [erlang_agent_netsnmp_get]. -trap_tests() -> - [erlang_agent_netsnmp_trap]. -dual_ip_tests() -> - [erlang_agent_dual_ip_get]. -ipv4_tests() -> - [{group, get}]. -ipv6_tests() -> - [{group, get}, - {group, dual_ip} + [{ipv4, [], [{group, get}, + {group, inform} + ]}, + {ipv6, [], [{group, get}, + {group, inform}, + {group, dual_ip} + ]}, + {get, [], [erlang_agent_netsnmp_get]}, + {inform, [], [erlang_agent_netsnmp_inform]}, + {dual_ip, [], [erlang_agent_dual_ip_get]} ]. init_per_suite(Config) -> - case os:find_executable("snmpget") of - false -> - {skip, "snmpget not found"}; - _ -> - Config - end. - + [{agent_port, ?AGENT_PORT}, {manager_port, ?MANAGER_PORT} | Config]. + end_per_suite(_Config) -> ok. @@ -82,8 +71,8 @@ init_per_group(ipv6, Config) -> {ok, Host} = inet:gethostname(), {ok, IpAddr} = inet:getaddr(Host, inet6), Versions = [v2], - agent_config(Dir, Domain, IpAddr, IpAddr, ?AGENT_PORT, Versions), - [{host, Host}, {port, ?AGENT_PORT}, + agent_config(Dir, Domain, IpAddr, IpAddr, ?config(agent_port, Config), Versions), + [{host, Host}, {snmp_versions, Versions}, {ip_version, ipv6} | Config]; _ -> {skip, "Host does not support IPV6"} @@ -95,11 +84,13 @@ init_per_group(ipv4, Config) -> {ok, Host} = inet:gethostname(), {ok, IpAddr} = inet:getaddr(Host, inet), Versions = [v2], - agent_config(Dir, Domain, IpAddr, IpAddr, ?AGENT_PORT, Versions), - [{host, Host}, {port, ?AGENT_PORT}, {snmp_versions, Versions}, + agent_config(Dir, Domain, IpAddr, {IpAddr, ?config(manager_port, Config)}, + ?config(agent_port, Config), Versions), + [{host, Host}, {snmp_versions, Versions}, {ip_version, ipv4} | Config]; init_per_group(get, Config) -> + %% From Ubuntu package snmp case os:find_executable("snmpget") of false -> {skip, "snmpget not found"}; @@ -107,7 +98,8 @@ init_per_group(get, Config) -> Config end; -init_per_group(trap, Config) -> +init_per_group(inform, Config) -> + %% From Ubuntu package snmptrapfmt case os:find_executable("snmptrapd") of false -> {skip, "snmptrapd not found"}; @@ -121,12 +113,13 @@ end_per_group(_GroupName, Config) -> Config. init_per_testcase(Case, Config) -> + Dog = ct:timetrap(10000), end_per_testcase(Case, Config), application:start(snmp), application:load(snmp), application:set_env(snmp, agent, app_env(Case, Config)), snmp:start_agent(normal), - Config. + [{watchdog, Dog} | Config]. end_per_testcase(_, Config) -> application:stop(snmp), @@ -141,10 +134,10 @@ erlang_agent_netsnmp_get() -> erlang_agent_netsnmp_get(Config) when is_list(Config) -> Host = ?config(host, Config), - Port = ?config(port, Config), + Port = ?config(agent_port, Config), IPVersion = ?config(ip_version, Config), Versions = ?config(snmp_versions, Config), - + Cmd = "snmpget -c public " ++ net_snmp_version(Versions) ++ " " ++ net_snmp_ip_version(IPVersion) ++ Host ++ ":" ++ integer_to_list(Port) ++ @@ -159,26 +152,58 @@ erlang_agent_dual_ip_get(Config) when is_list(Config) -> erlang_agent_netsnmp_get([{ip_version, ipv4}]), erlang_agent_netsnmp_get([{ip_version, ipv6}]). %%-------------------------------------------------------------------- -erlang_agent_netsnmp_trap() -> - %% Host = ?config(host, Config), - %% Port = ?config(port, Config), - %% IPVersion = ?config(ip_version, Config), - %% Versions = ?config(snmp_versions, Config), +erlang_agent_netsnmp_inform(Config) when is_list(Config) -> + Host = ?config(host, Config), + IPVersion = ?config(ip_version, Config), + DataDir = ?config(data_dir, Config), + ok = snmpa:load_mib(snmp_master_agent, filename:join(DataDir, "TestTrapv2")), - Cmd = "", - net_snmp(Cmd, ""). + Cmd = "snmptrapd -L o -M " ++ DataDir ++ + " --disableAuthorization=yes" ++ + " --snmpTrapdAddr=" ++ net_snmp_ip_version(IPVersion) ++ + Host ++ ":" ++ integer_to_list(?config(manager_port, Config)), + NetSnmpPort = net_snmp_trapd(Cmd), + snmpa:send_notification(snmp_master_agent, testTrapv22, + {erlang_agent_test, self()}), + net_snmp_log(NetSnmpPort), + receive + {snmp_targets, erlang_agent_test, Addresses} -> + ct:pal("Notification sent to: ~p~n", [Addresses]) + end, + receive + {snmp_notification, erlang_agent_test, {got_response, Address}} -> + ct:pal("Got respons from: ~p~n", [Address]), + ok; + {snmp_notification, erlang_agent_test, {no_response, _} = + NoResponse} -> + ct:fail(NoResponse) + end. + %%-------------------------------------------------------------------- %% Internal functions ------------------------------------------------ %%-------------------------------------------------------------------- net_snmp(Cmd, Expect) -> - SnmpNetPort = open_port({spawn, Cmd}, [stderr_to_stdout]), + NetSnmpPort = open_port({spawn, Cmd}, [stderr_to_stdout]), receive - {SnmpNetPort, {data, Expect}} -> + {NetSnmpPort, {data, Expect}} -> ok; Msg -> - ct:fail({{expected, {SnmpNetPort, {data, Expect}}}, + ct:fail({{expected, {NetSnmpPort, {data, Expect}}}, {got, Msg}}) + end, + catch erlang:port_close(NetSnmpPort). + +net_snmp_trapd(Cmd) -> + open_port({spawn, Cmd}, [stderr_to_stdout]). + +net_snmp_log(NetSnmpPort) -> + receive + {NetSnmpPort, {data, Data}} -> + ct:pal("Received from netsnmp: ~p~n", [Data]), + net_snmp_log(NetSnmpPort) + after 500 -> + catch erlang:port_close(NetSnmpPort) end. app_env(_Case, Config) -> @@ -212,16 +237,16 @@ oid_str([Int | Rest], Acc) -> agent_config(Dir, Domain, IpA, IpM, Port, Versions) -> EngineID = ?AGENT_ENGIN_ID, MMS = ?DEFAULT_MAX_MESSAGE_SIZE, - snmp_config:write_agent_snmp_conf(Dir, Domain, {IpA, Port}, + ok = snmp_config:write_agent_snmp_conf(Dir, Domain, {IpA, Port}, EngineID, MMS), - snmp_config:write_agent_snmp_context_conf(Dir), - snmp_config:write_agent_snmp_community_conf(Dir), - snmp_config:write_agent_snmp_standard_conf(Dir, "snmp_to_snmpnet_SUITE"), - snmp_config:write_agent_snmp_target_addr_conf(Dir, Domain, + ok = snmp_config:write_agent_snmp_context_conf(Dir), + ok = snmp_config:write_agent_snmp_community_conf(Dir), + ok = snmp_config:write_agent_snmp_standard_conf(Dir, "snmp_to_snmpnet_SUITE"), + ok = snmp_config:write_agent_snmp_target_addr_conf(Dir, Domain, IpM, Versions), - snmp_config:write_agent_snmp_target_params_conf(Dir, Versions), - snmp_config:write_agent_snmp_notify_conf(Dir, inform), - snmp_config:write_agent_snmp_vacm_conf(Dir, Versions, none). + ok = snmp_config:write_agent_snmp_target_params_conf(Dir, Versions), + ok = snmp_config:write_agent_snmp_notify_conf(Dir, inform), + ok = snmp_config:write_agent_snmp_vacm_conf(Dir, Versions, none). net_snmp_version([v3 | _]) -> "-v3"; diff --git a/lib/snmp/test/snmp_to_snmpnet_SUITE_data/TestTrapv2.bin b/lib/snmp/test/snmp_to_snmpnet_SUITE_data/TestTrapv2.bin Binary files differnew file mode 100644 index 0000000000..9d0790498d --- /dev/null +++ b/lib/snmp/test/snmp_to_snmpnet_SUITE_data/TestTrapv2.bin diff --git a/lib/snmp/test/snmp_to_snmpnet_SUITE_data/TestTrapv2.mib b/lib/snmp/test/snmp_to_snmpnet_SUITE_data/TestTrapv2.mib new file mode 100644 index 0000000000..679ddc14b0 --- /dev/null +++ b/lib/snmp/test/snmp_to_snmpnet_SUITE_data/TestTrapv2.mib @@ -0,0 +1,71 @@ +TestTrapv2 DEFINITIONS ::= BEGIN + +IMPORTS + MODULE-IDENTITY, OBJECT-TYPE, NOTIFICATION-TYPE, + TimeTicks, Counter32, snmpModules, mib-2, enterprises, IpAddress, + Integer32 + FROM SNMPv2-SMI + DisplayString, TestAndIncr, TimeStamp, RowStatus, TruthValue, + TEXTUAL-CONVENTION + FROM SNMPv2-TC + MODULE-COMPLIANCE, OBJECT-GROUP, NOTIFICATION-GROUP + FROM SNMPv2-CONF + + system, snmp, ifIndex, ifAdminStatus, ifOperStatus + FROM RFC1213-MIB + snmpTraps + FROM SNMPv2-MIB; + +testTrapv2 MODULE-IDENTITY + LAST-UPDATED "9511090000Z" + ORGANIZATION "IETF SNMPv2 Working Group" + CONTACT-INFO + " Marshall T. Rose + + Postal: Dover Beach Consulting, Inc. + 420 Whisman Court + Mountain View, CA 94043-2186 + US + + Tel: +1 415 968 1052 + + E-mail: [email protected]" + DESCRIPTION + "The MIB module for SNMPv2 entities." + REVISION "9304010000Z" + DESCRIPTION + "The initial revision of this MIB module was published as + RFC 1450." + ::= { system 100 } + + +tst OBJECT IDENTIFIER ::= { system 0 } + +testTrapv21 NOTIFICATION-TYPE + STATUS current + DESCRIPTION + "This trap is exactly the v2 correspondance of testTrap1 in + TestTrap mib." + ::= { snmp 1 } + +testTrapv22 NOTIFICATION-TYPE + STATUS current + DESCRIPTION + "This trap is exactly the v2 correspondance of testTrap2 in + TestTrap mib." + ::= { system 0 1 } + +linkUp NOTIFICATION-TYPE + OBJECTS { ifIndex, ifAdminStatus, ifOperStatus } + STATUS current + DESCRIPTION + "A linkUp trap signifies that the SNMPv2 entity, + acting in an agent role, has detected that the + ifOperStatus object for one of its communication links + has transitioned out of the down state." + ::= { snmpTraps 4 } + + + + +END |