From c7d97f4d7a27bd6aca3b6335c90e6a51e28e6719 Mon Sep 17 00:00:00 2001 From: Ingela Anderton Andin Date: Wed, 25 Jun 2014 08:55:53 +0200 Subject: snmp: Add new test suite --- lib/snmp/test/snmp_to_snmpnet_SUITE.erl | 235 ++++++++++++++++++++++++++++++++ 1 file changed, 235 insertions(+) create mode 100644 lib/snmp/test/snmp_to_snmpnet_SUITE.erl (limited to 'lib/snmp/test/snmp_to_snmpnet_SUITE.erl') diff --git a/lib/snmp/test/snmp_to_snmpnet_SUITE.erl b/lib/snmp/test/snmp_to_snmpnet_SUITE.erl new file mode 100644 index 0000000000..4584ad75c2 --- /dev/null +++ b/lib/snmp/test/snmp_to_snmpnet_SUITE.erl @@ -0,0 +1,235 @@ +%% +%% %CopyrightBegin% +%% +%% Copyright Ericsson AB 2014-2014. 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 +%% compliance with the License. You should have received a copy of the +%% Erlang Public License along with this software. If not, it can be +%% retrieved online at http://www.erlang.org/. +%% +%% Software distributed under the License is distributed on an "AS IS" +%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See +%% the License for the specific language governing rights and limitations +%% under the License. +%% +%% %CopyrightEnd% +%% +%% + +-module(snmp_to_snmpnet_SUITE). + +%% Note: This directive should only be used in test suites. +-compile(export_all). + +-include_lib("common_test/include/ct.hrl"). +-include_lib("snmp/include/STANDARD-MIB.hrl"). + +-define(AGENT_ENGIN_ID, "ErlangSnmpAgent"). +-define(AGENT_PORT, 4000). +-define(DEFAULT_MAX_MESSAGE_SIZE, 484). +-define(SYS_DESC, "iso.3.6.1.2.1.1.1.0 = STRING: \"Erlang SNMP agent\"\n"). + +%%-------------------------------------------------------------------- +%% Common Test interface functions ----------------------------------- +%%-------------------------------------------------------------------- + +suite() -> [{ct_hooks,[ts_install_cth]}]. + +all() -> + [ + {group, ipv4}, + {group, ipv6} + ]. + +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} + ]. + +init_per_suite(Config) -> + case os:find_executable("snmpget") of + false -> + {skip, "snmpget not found"}; + _ -> + Config + end. + +end_per_suite(_Config) -> + ok. + +init_per_group(ipv6, Config) -> + case ct:require(ipv6_hosts) of + ok -> + Dir = ?config(priv_dir, Config), + Domain = transportDomainUdpIpv6, + {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}, + {snmp_versions, Versions}, {ip_version, ipv6} | Config]; + _ -> + {skip, "Host does not support IPV6"} + end; + +init_per_group(ipv4, Config) -> + Dir = ?config(priv_dir, Config), + Domain = transportDomainUdpIpv4, + {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}, + {ip_version, ipv4} | Config]; + +init_per_group(get, Config) -> + case os:find_executable("snmpget") of + false -> + {skip, "snmpget not found"}; + _ -> + Config + end; + +init_per_group(trap, Config) -> + case os:find_executable("snmptrapd") of + false -> + {skip, "snmptrapd not found"}; + _ -> + Config + end; +init_per_group(_, Config) -> + Config. + +end_per_group(_GroupName, Config) -> + Config. + +init_per_testcase(Case, Config) -> + 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. + +end_per_testcase(_, Config) -> + application:stop(snmp), + Config. + +%%-------------------------------------------------------------------- +%% Test Cases -------------------------------------------------------- +%%-------------------------------------------------------------------- +erlang_agent_netsnmp_get() -> + [{doc,"Test that we can access erlang snmp agent " + "from snmpnet manager"}]. + +erlang_agent_netsnmp_get(Config) when is_list(Config) -> + Host = ?config(host, Config), + Port = ?config(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) ++ + " " ++ oid_str(?sysDescr_instance), + net_snmp(Cmd, ?SYS_DESC). + +%%-------------------------------------------------------------------- +erlang_agent_dual_ip_get() -> + [{doc,"Test that we can access erlang snmp agent from both " + "snmpnet ipv4 and snmpnet ipv6 manager at the same time"}]. +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), + + Cmd = "", + net_snmp(Cmd, ""). + +%%-------------------------------------------------------------------- +%% Internal functions ------------------------------------------------ +%%-------------------------------------------------------------------- +net_snmp(Cmd, Expect) -> + SnmpNetPort = open_port({spawn, Cmd}, [stderr_to_stdout]), + receive + {SnmpNetPort, {data, Expect}} -> + ok; + Msg -> + ct:fail({{expected, {SnmpNetPort, {data, Expect}}}, + {got, Msg}}) + end. + +app_env(_Case, Config) -> + Dir = ?config(priv_dir, Config), + Vsns = ?config(snmp_versions, Config), + [{versions, Vsns}, + {agent_type, master}, + {agent_verbosity, trace}, + {db_dir, Dir}, + {audit_trail_log, [{type, read_write}, + {dir, Dir}, + {size, {10240, 10}}]}, + {config, [{dir, Dir}, + {force_load, false}, + {verbosity, trace}]}, + {local_db, [{repair, true}, + {verbosity, silence}]}, + {mib_server, [{verbosity, silence}]}, + {symbolic_store, [{verbosity, silence}]}, + {note_store, [{verbosity, silence}]}, + {net_if, [{verbosity, trace}]}]. + +oid_str([Int | Rest]) -> + oid_str(Rest, integer_to_list(Int)). + +oid_str([], Acc) -> + Acc; +oid_str([Int | Rest], Acc) -> + oid_str(Rest, Acc ++ "." ++ integer_to_list(Int)). + +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}, + 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, + 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). + +net_snmp_version([v3 | _]) -> + "-v3"; +net_snmp_version([v2 | _]) -> + "-v2c"; +net_snmp_version([v1 | _]) -> + "-v1". +net_snmp_ip_version(ipv4) -> + "udp:"; +net_snmp_ip_version(ipv6) -> + "udp6:". -- cgit v1.2.3 From 1ebfcb6f1f013e62aabc9935c878a55b788967a9 Mon Sep 17 00:00:00 2001 From: Ingela Anderton Andin Date: Fri, 27 Jun 2014 15:41:18 +0200 Subject: snmp: Add inform test --- lib/snmp/test/snmp_to_snmpnet_SUITE.erl | 127 +++++++++++++++++++------------- 1 file changed, 76 insertions(+), 51 deletions(-) (limited to 'lib/snmp/test/snmp_to_snmpnet_SUITE.erl') 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"; -- cgit v1.2.3 From d38674e8dd8224da8a66d77ca4f5a8073e01f794 Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Tue, 1 Jul 2014 10:17:50 +0200 Subject: Add dual_ip tests in snmp_to_snmpnet_SUITE --- lib/snmp/test/snmp_to_snmpnet_SUITE.erl | 70 ++++++++++++++++++++++++--------- 1 file changed, 52 insertions(+), 18 deletions(-) (limited to 'lib/snmp/test/snmp_to_snmpnet_SUITE.erl') diff --git a/lib/snmp/test/snmp_to_snmpnet_SUITE.erl b/lib/snmp/test/snmp_to_snmpnet_SUITE.erl index e8dcffd361..3271b98ec3 100644 --- a/lib/snmp/test/snmp_to_snmpnet_SUITE.erl +++ b/lib/snmp/test/snmp_to_snmpnet_SUITE.erl @@ -68,12 +68,16 @@ init_per_group(ipv6, Config) -> ok -> Dir = ?config(priv_dir, Config), Domain = transportDomainUdpIpv6, + AgentPort = ?config(agent_port, Config), + ManagerPort = ?config(manager_port, Config), {ok, Host} = inet:gethostname(), {ok, IpAddr} = inet:getaddr(Host, inet6), + Transports = [{Domain, {IpAddr, AgentPort}}], + TrapAddr = {IpAddr, ManagerPort}, Versions = [v2], - agent_config(Dir, Domain, IpAddr, IpAddr, ?config(agent_port, Config), Versions), - [{host, Host}, - {snmp_versions, Versions}, {ip_version, ipv6} | Config]; + agent_config(Dir, Transports, Domain, TrapAddr, Versions), + [{host, Host}, {snmp_versions, Versions}, {ip_version, ipv6} + | Config]; _ -> {skip, "Host does not support IPV6"} end; @@ -81,13 +85,36 @@ init_per_group(ipv6, Config) -> init_per_group(ipv4, Config) -> Dir = ?config(priv_dir, Config), Domain = transportDomainUdpIpv4, + AgentPort = ?config(agent_port, Config), + ManagerPort = ?config(manager_port, Config), {ok, Host} = inet:gethostname(), {ok, IpAddr} = inet:getaddr(Host, inet), + Transports = [{Domain, {IpAddr, AgentPort}}], + TrapAddr = {IpAddr, ManagerPort}, Versions = [v2], - agent_config(Dir, Domain, IpAddr, {IpAddr, ?config(manager_port, Config)}, - ?config(agent_port, Config), Versions), - [{host, Host}, {snmp_versions, Versions}, - {ip_version, ipv4} | Config]; + agent_config(Dir, Transports, Domain, TrapAddr, Versions), + [{host, Host}, {snmp_versions, Versions}, {ip_version, ipv4} + | Config]; + +init_per_group(dual_ip, Config) -> + case ct:require(ipv6_hosts) of + ok -> + Dir = ?config(priv_dir, Config), + {ok, Host} = inet:gethostname(), + {ok, IPv4Addr} = inet:getaddr(Host, inet), + {ok, IPv6Addr} = inet:getaddr(Host, inet6), + Domain = snmpUDPDomain, + Transports = + [{Domain, {IPv4Addr, ?AGENT_PORT}}, + {transportDomainUdpIpv6, {IPv6Addr, ?AGENT_PORT}}], + TrapAddr = {IPv4Addr, 0}, + Versions = [v2], + agent_config(Dir, Transports, Domain, TrapAddr, Versions), + [{host, Host}, {port, ?AGENT_PORT}, {snmp_versions, Versions} + | Config]; + _ -> + {skip, "Host does not support IPV6"} + end; init_per_group(get, Config) -> %% From Ubuntu package snmp @@ -149,14 +176,16 @@ erlang_agent_dual_ip_get() -> [{doc,"Test that we can access erlang snmp agent from both " "snmpnet ipv4 and snmpnet ipv6 manager at the same time"}]. 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_get([{ip_version, ipv4} | Config]), + erlang_agent_netsnmp_get([{ip_version, ipv6} | 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")), + ok = + snmpa:load_mib( + snmp_master_agent, filename:join(DataDir, "TestTrapv2")), Cmd = "snmptrapd -L o -M " ++ DataDir ++ " --disableAuthorization=yes" ++ @@ -173,7 +202,7 @@ erlang_agent_netsnmp_inform(Config) when is_list(Config) -> end, receive {snmp_notification, erlang_agent_test, {got_response, Address}} -> - ct:pal("Got respons from: ~p~n", [Address]), + ct:pal("Got response from: ~p~n", [Address]), ok; {snmp_notification, erlang_agent_test, {no_response, _} = NoResponse} -> @@ -185,6 +214,7 @@ erlang_agent_netsnmp_inform(Config) when is_list(Config) -> %%-------------------------------------------------------------------- net_snmp(Cmd, Expect) -> NetSnmpPort = open_port({spawn, Cmd}, [stderr_to_stdout]), + ct:pal("net_snmp started: ~s~n", [Cmd]), receive {NetSnmpPort, {data, Expect}} -> ok; @@ -195,7 +225,9 @@ net_snmp(Cmd, Expect) -> catch erlang:port_close(NetSnmpPort). net_snmp_trapd(Cmd) -> - open_port({spawn, Cmd}, [stderr_to_stdout]). + NetSnmpTrapdPort = open_port({spawn, Cmd}, [stderr_to_stdout]), + ct:pal("net_snmp_trapd started: ~s~n", [Cmd]), + NetSnmpTrapdPort. net_snmp_log(NetSnmpPort) -> receive @@ -234,16 +266,18 @@ oid_str([], Acc) -> oid_str([Int | Rest], Acc) -> oid_str(Rest, Acc ++ "." ++ integer_to_list(Int)). -agent_config(Dir, Domain, IpA, IpM, Port, Versions) -> +agent_config(Dir, Transports, TargetDomain, TargetAddr, Versions) -> EngineID = ?AGENT_ENGIN_ID, MMS = ?DEFAULT_MAX_MESSAGE_SIZE, - ok = snmp_config:write_agent_snmp_conf(Dir, Domain, {IpA, Port}, - EngineID, MMS), + ok = snmp_config:write_agent_snmp_conf(Dir, Transports, EngineID, MMS), 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), + ok = + snmp_config:write_agent_snmp_standard_conf( + Dir, "snmp_to_snmpnet_SUITE"), + ok = + snmp_config:write_agent_snmp_target_addr_conf( + Dir, TargetDomain, TargetAddr, Versions), 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). -- cgit v1.2.3 From 7e775edac0a5fa736046940d6b1776e238978804 Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Thu, 3 Jul 2014 18:07:30 +0200 Subject: Improve dual stack test suite --- lib/snmp/test/snmp_to_snmpnet_SUITE.erl | 261 ++++++++++++++++++++++---------- 1 file changed, 182 insertions(+), 79 deletions(-) (limited to 'lib/snmp/test/snmp_to_snmpnet_SUITE.erl') diff --git a/lib/snmp/test/snmp_to_snmpnet_SUITE.erl b/lib/snmp/test/snmp_to_snmpnet_SUITE.erl index 3271b98ec3..fa92beb6b1 100644 --- a/lib/snmp/test/snmp_to_snmpnet_SUITE.erl +++ b/lib/snmp/test/snmp_to_snmpnet_SUITE.erl @@ -30,7 +30,7 @@ -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"). +-define(SYS_DESC, <<"iso.3.6.1.2.1.1.1.0 = STRING: \"Erlang SNMP agent\"">>). %%-------------------------------------------------------------------- %% Common Test interface functions ----------------------------------- @@ -97,23 +97,30 @@ init_per_group(ipv4, Config) -> | Config]; init_per_group(dual_ip, Config) -> - case ct:require(ipv6_hosts) of - ok -> - Dir = ?config(priv_dir, Config), - {ok, Host} = inet:gethostname(), - {ok, IPv4Addr} = inet:getaddr(Host, inet), - {ok, IPv6Addr} = inet:getaddr(Host, inet6), - Domain = snmpUDPDomain, - Transports = - [{Domain, {IPv4Addr, ?AGENT_PORT}}, - {transportDomainUdpIpv6, {IPv6Addr, ?AGENT_PORT}}], - TrapAddr = {IPv4Addr, 0}, - Versions = [v2], - agent_config(Dir, Transports, Domain, TrapAddr, Versions), - [{host, Host}, {port, ?AGENT_PORT}, {snmp_versions, Versions} - | Config]; - _ -> - {skip, "Host does not support IPV6"} + case os:find_executable("snmpget") of + false -> + {skip, "snmpget not found"}; + Path -> + case ct:require(ipv6_hosts) of + ok -> + Dir = ?config(priv_dir, Config), + {ok, Host} = inet:gethostname(), + {ok, IPv4Addr} = inet:getaddr(Host, inet), + {ok, IPv6Addr} = inet:getaddr(Host, inet6), + Domain = snmpUDPDomain, + Transports = + [{Domain, {IPv4Addr, ?AGENT_PORT}}, + {transportDomainUdpIpv6, {IPv6Addr, ?AGENT_PORT}}], + TrapAddr = {IPv4Addr, 0}, + Versions = [v2], + agent_config( + Dir, Transports, Domain, TrapAddr, Versions), + [{host, Host}, {port, ?AGENT_PORT}, + {snmp_versions, Versions}, + {snmpget, Path} | Config]; + _ -> + {skip, "Host does not support IPV6"} + end end; init_per_group(get, Config) -> @@ -121,8 +128,8 @@ init_per_group(get, Config) -> case os:find_executable("snmpget") of false -> {skip, "snmpget not found"}; - _ -> - Config + Path -> + [{snmpget, Path} | Config] end; init_per_group(inform, Config) -> @@ -130,8 +137,8 @@ init_per_group(inform, Config) -> case os:find_executable("snmptrapd") of false -> {skip, "snmptrapd not found"}; - _ -> - Config + Path -> + [{snmptrapd, Path} | Config] end; init_per_group(_, Config) -> Config. @@ -139,19 +146,32 @@ init_per_group(_, Config) -> end_per_group(_GroupName, Config) -> Config. -init_per_testcase(Case, 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), + application:stop(snmp), + application:unload(snmp), [{watchdog, Dog} | Config]. end_per_testcase(_, Config) -> - application:stop(snmp), + case application:stop(snmp) of + ok -> + ok; + E1 -> + ct:pal("application:stop(snmp) -> ~p", [E1]) + end, + case application:unload(snmp) of + ok -> + ok; + E2 -> + ct:pal("application:unload(snmp) -> ~p", [E2]) + end, Config. +start_agent(Config) -> + ok = application:load(snmp), + ok = application:set_env(snmp, agent, app_env(Config)), + ok = application:start(snmp). + %%-------------------------------------------------------------------- %% Test Cases -------------------------------------------------------- %%-------------------------------------------------------------------- @@ -160,42 +180,46 @@ erlang_agent_netsnmp_get() -> "from snmpnet manager"}]. erlang_agent_netsnmp_get(Config) when is_list(Config) -> - Host = ?config(host, 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) ++ - " " ++ oid_str(?sysDescr_instance), - net_snmp(Cmd, ?SYS_DESC). + start_agent(Config), + ?SYS_DESC = snmpget(oid_str(?sysDescr_instance), Config), + ok. %%-------------------------------------------------------------------- erlang_agent_dual_ip_get() -> [{doc,"Test that we can access erlang snmp agent from both " "snmpnet ipv4 and snmpnet ipv6 manager at the same time"}]. erlang_agent_dual_ip_get(Config) when is_list(Config) -> - erlang_agent_netsnmp_get([{ip_version, ipv4} | Config]), - erlang_agent_netsnmp_get([{ip_version, ipv6} | Config]). + start_agent(Config), + + OidStr = oid_str(?sysDescr_instance), + ?SYS_DESC = snmpget(OidStr, [{ip_version, ipv4} | Config]), + ?SYS_DESC = snmpget(OidStr, [{ip_version, ipv6} | Config]), + ok. + %%-------------------------------------------------------------------- erlang_agent_netsnmp_inform(Config) when is_list(Config) -> Host = ?config(host, Config), IPVersion = ?config(ip_version, Config), DataDir = ?config(data_dir, Config), + + start_agent(Config), ok = snmpa:load_mib( snmp_master_agent, filename:join(DataDir, "TestTrapv2")), - 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), + SnmptrapdArgs = + ["-f", "-Lo", + "-M", DataDir, + "--disableAuthorization=yes", + "--snmpTrapdAddr=" ++ net_snmp_transport(IPVersion) ++ + Host ++ ":" ++ integer_to_list(?config(manager_port, Config))], + {ok, CheckMP} = re:compile("NET-SNMP version ", [anchored]), + ProgHandle = + start_program(snmptrapd, SnmptrapdArgs, CheckMP, Config), + + snmpa:send_notification( + snmp_master_agent, testTrapv22, {erlang_agent_test, self()}), + receive {snmp_targets, erlang_agent_test, Addresses} -> ct:pal("Notification sent to: ~p~n", [Addresses]) @@ -207,38 +231,116 @@ erlang_agent_netsnmp_inform(Config) when is_list(Config) -> {snmp_notification, erlang_agent_test, {no_response, _} = NoResponse} -> ct:fail(NoResponse) - end. + end, + + stop_program(ProgHandle). %%-------------------------------------------------------------------- %% Internal functions ------------------------------------------------ %%-------------------------------------------------------------------- -net_snmp(Cmd, Expect) -> - NetSnmpPort = open_port({spawn, Cmd}, [stderr_to_stdout]), - ct:pal("net_snmp started: ~s~n", [Cmd]), - receive - {NetSnmpPort, {data, Expect}} -> - ok; - Msg -> - ct:fail({{expected, {NetSnmpPort, {data, Expect}}}, - {got, Msg}}) - end, - catch erlang:port_close(NetSnmpPort). - -net_snmp_trapd(Cmd) -> - NetSnmpTrapdPort = open_port({spawn, Cmd}, [stderr_to_stdout]), - ct:pal("net_snmp_trapd started: ~s~n", [Cmd]), - NetSnmpTrapdPort. - -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) +snmpget(OidStr, Config) -> + Versions = ?config(snmp_versions, Config), + IPVersion = ?config(ip_version, Config), + Host = ?config(host, Config), + Port = ?config(agent_port, Config), + + Args = + ["-c", "public", net_snmp_version(Versions), + net_snmp_transport(IPVersion) ++ + Host ++ ":" ++ integer_to_list(Port), + OidStr], + ProgHandle = start_program(snmpget, Args, none, Config), + {_, line, Line} = get_program_output(ProgHandle), + stop_program(ProgHandle), + Line. + + +start_program(Prog, Args, StartCheckMP, Config) -> + Path = ?config(Prog, Config), + DataDir = ?config(data_dir, Config), + StartWrapper = filename:join(DataDir, "start_stop_wrapper"), + Parent = self(), + Pid = + spawn_link( + fun () -> + run_program(Parent, StartWrapper, [Path | Args]) + end), + start_check(Pid, erlang:monitor(process, Pid), StartCheckMP). + +start_check(Pid, Mon, none) -> + {Pid, Mon}; +start_check(Pid, Mon, StartCheckMP) -> + receive + {Pid, line, Line} -> + case re:run(Line, StartCheckMP, [{capture, none}]) of + match -> + {Pid, Mon}; + nomatch -> + start_check(Pid, Mon, StartCheckMP) + end; + {'DOWN', Mon, _, _, Reason} -> + ct:fail("Prog ~p start failed: ~p", [Pid, Reason]) + end. + +get_program_output({Pid, Mon}) -> + receive + {Pid, _, _} = Msg -> + Msg; + {'DOWN', Mon, _, _, Reason} -> + ct:fail("Prog ~p crashed: ~p", [Pid, Reason]) end. -app_env(_Case, Config) -> +stop_program({Pid, _} = Handle) -> + Pid ! {self(), stop}, + wait_program_stop(Handle). + +wait_program_stop({Pid, Mon}) -> + receive + {Pid, exit, ExitStatus} -> + receive + {'DOWN', Mon, _, _, _} -> + ExitStatus + end; + {'DOWN', Mon, _, _, Reason} -> + ct:fail("Prog stop: ~p", [Reason]) + end. + +run_program(Parent, StartWrapper, ProgAndArgs) -> + Port = + open_port( + {spawn_executable, StartWrapper}, + [{args, ProgAndArgs}, binary, stderr_to_stdout, {line, 80}, + exit_status]), + ct:pal("Prog ~p started: ~p", [Port, ProgAndArgs]), + run_program_loop(Parent, Port, []). + +run_program_loop(Parent, Port, Buf) -> + receive + {Parent, stop} -> + true = port_command(Port, <<"stop\n">>), + ct:pal("Prog ~p stop", [Port]), + run_program_loop(Parent, Port, Buf); + {Port, {data, {Flag, Data}}} -> + case Flag of + eol -> + Line = iolist_to_binary(lists:reverse(Buf, Data)), + ct:pal("Prog ~p output: ~s", [Port, Line]), + Parent ! {self(), line, Line}, + run_program_loop(Parent, Port, []); + noeol -> + run_program_loop(Parent, Port, [Data | Buf]) + end; + {Port, {exit_status,ExitStatus}} -> + ct:pal("Prog ~p exit: ~p", [Port, ExitStatus]), + catch port_close(Port), + Parent ! {self(), exit, ExitStatus}; + Unexpected -> + ct:pal("run_program_loop Unexpected: ~p", [Unexpected]), + run_program_loop(Parent, Port, Buf) + end. + + +app_env(Config) -> Dir = ?config(priv_dir, Config), Vsns = ?config(snmp_versions, Config), [{versions, Vsns}, @@ -249,7 +351,7 @@ app_env(_Case, Config) -> {dir, Dir}, {size, {10240, 10}}]}, {config, [{dir, Dir}, - {force_load, false}, + {force_load, true}, {verbosity, trace}]}, {local_db, [{repair, true}, {verbosity, silence}]}, @@ -288,7 +390,8 @@ net_snmp_version([v2 | _]) -> "-v2c"; net_snmp_version([v1 | _]) -> "-v1". -net_snmp_ip_version(ipv4) -> + +net_snmp_transport(ipv4) -> "udp:"; -net_snmp_ip_version(ipv6) -> +net_snmp_transport(ipv6) -> "udp6:". -- cgit v1.2.3 From 06c3bbdcff4af11aba54309bb09ecc3eed96d754 Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Fri, 4 Jul 2014 15:38:53 +0200 Subject: Test inform to dual transports --- lib/snmp/test/snmp_to_snmpnet_SUITE.erl | 148 +++++++++++++++++++++++--------- 1 file changed, 106 insertions(+), 42 deletions(-) (limited to 'lib/snmp/test/snmp_to_snmpnet_SUITE.erl') diff --git a/lib/snmp/test/snmp_to_snmpnet_SUITE.erl b/lib/snmp/test/snmp_to_snmpnet_SUITE.erl index fa92beb6b1..7a2b05c048 100644 --- a/lib/snmp/test/snmp_to_snmpnet_SUITE.erl +++ b/lib/snmp/test/snmp_to_snmpnet_SUITE.erl @@ -45,16 +45,22 @@ all() -> ]. groups() -> - [{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]} + [{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, + erlang_agent_dual_ip_inform]} ]. init_per_suite(Config) -> @@ -81,7 +87,7 @@ init_per_group(ipv6, Config) -> _ -> {skip, "Host does not support IPV6"} end; - +%% init_per_group(ipv4, Config) -> Dir = ?config(priv_dir, Config), Domain = transportDomainUdpIpv4, @@ -95,51 +101,44 @@ init_per_group(ipv4, Config) -> agent_config(Dir, Transports, Domain, TrapAddr, Versions), [{host, Host}, {snmp_versions, Versions}, {ip_version, ipv4} | Config]; - +%% init_per_group(dual_ip, Config) -> - case os:find_executable("snmpget") of - false -> - {skip, "snmpget not found"}; - Path -> + case find_executables([snmpget, snmptrapd], Config) of + NewConfig when is_list(NewConfig) -> case ct:require(ipv6_hosts) of ok -> Dir = ?config(priv_dir, Config), + Domain = transportDomainUdpIpv4, + AgentPort = ?config(agent_port, Config), + ManagerPort = ?config(manager_port, Config), {ok, Host} = inet:gethostname(), {ok, IPv4Addr} = inet:getaddr(Host, inet), {ok, IPv6Addr} = inet:getaddr(Host, inet6), - Domain = snmpUDPDomain, Transports = - [{Domain, {IPv4Addr, ?AGENT_PORT}}, - {transportDomainUdpIpv6, {IPv6Addr, ?AGENT_PORT}}], - TrapAddr = {IPv4Addr, 0}, + [{Domain, {IPv4Addr, AgentPort}}, + {transportDomainUdpIpv6, {IPv6Addr, AgentPort}}], + Targets = + [{Domain, {IPv4Addr, ManagerPort}}, + {transportDomainUdpIpv6, {IPv6Addr, ManagerPort}}], Versions = [v2], - agent_config( - Dir, Transports, Domain, TrapAddr, Versions), + agent_config(Dir, Transports, Targets, Versions), [{host, Host}, {port, ?AGENT_PORT}, - {snmp_versions, Versions}, - {snmpget, Path} | Config]; + {snmp_versions, Versions} + | NewConfig]; _ -> {skip, "Host does not support IPV6"} - end + end; + Other -> + Other end; - +%% init_per_group(get, Config) -> %% From Ubuntu package snmp - case os:find_executable("snmpget") of - false -> - {skip, "snmpget not found"}; - Path -> - [{snmpget, Path} | Config] - end; - + find_executables([snmpget], Config); +%% init_per_group(inform, Config) -> %% From Ubuntu package snmptrapfmt - case os:find_executable("snmptrapd") of - false -> - {skip, "snmptrapd not found"}; - Path -> - [{snmptrapd, Path} | Config] - end; + find_executables([snmptrapd], Config); init_per_group(_, Config) -> Config. @@ -167,6 +166,18 @@ end_per_testcase(_, Config) -> end, Config. +find_executables([], Config) -> + Config; +find_executables([Exec | Execs], Config) -> + case os:find_executable(atom_to_list(Exec)) of + false -> + {skip, Exec ++ " not found"}; + Path -> + find_executables( + Execs, + [{Exec, Path} | Config]) + end. + start_agent(Config) -> ok = application:load(snmp), ok = application:set_env(snmp, agent, app_env(Config)), @@ -213,9 +224,9 @@ erlang_agent_netsnmp_inform(Config) when is_list(Config) -> "--disableAuthorization=yes", "--snmpTrapdAddr=" ++ net_snmp_transport(IPVersion) ++ Host ++ ":" ++ integer_to_list(?config(manager_port, Config))], - {ok, CheckMP} = re:compile("NET-SNMP version ", [anchored]), + {ok, StartCheckMP} = re:compile("NET-SNMP version ", [anchored]), ProgHandle = - start_program(snmptrapd, SnmptrapdArgs, CheckMP, Config), + start_program(snmptrapd, SnmptrapdArgs, StartCheckMP, Config), snmpa:send_notification( snmp_master_agent, testTrapv22, {erlang_agent_test, self()}), @@ -235,6 +246,56 @@ erlang_agent_netsnmp_inform(Config) when is_list(Config) -> stop_program(ProgHandle). +%%-------------------------------------------------------------------- +erlang_agent_dual_ip_inform(Config) when is_list(Config) -> + Host = ?config(host, Config), + ManagerPort = ?config(manager_port, Config), + DataDir = ?config(data_dir, Config), + + start_agent(Config), + ok = + snmpa:load_mib( + snmp_master_agent, filename:join(DataDir, "TestTrapv2")), + + ManagerPortStr = integer_to_list(ManagerPort), + SnmptrapdArgs = + ["-f", "-Lo", + "-M", DataDir, + "--disableAuthorization=yes", + "--snmpTrapdAddr=" ++ + net_snmp_transport(ipv4) ++ Host ++ ":" ++ ManagerPortStr ++ + "," ++ + net_snmp_transport(ipv6) ++ Host ++ ":" ++ ManagerPortStr], + {ok, StartCheckMP} = re:compile("NET-SNMP version ", [anchored]), + ProgHandle = + start_program(snmptrapd, SnmptrapdArgs, StartCheckMP, Config), + + snmpa:send_notification( + snmp_master_agent, testTrapv22, {erlang_agent_test, self()}), + + receive + {snmp_targets, erlang_agent_test, Addresses} -> + ct:pal("Notification sent to: ~p~n", [Addresses]), + erlang_agent_dual_ip_inform_responses(Addresses) + end, + stop_program(ProgHandle). + +erlang_agent_dual_ip_inform_responses([]) -> + ok; +erlang_agent_dual_ip_inform_responses([Address | Addresses] = AAs) -> + receive + {snmp_notification, erlang_agent_test, + {got_response, Address}} -> + ct:pal("Got response from: ~p~n", [Address]), + erlang_agent_dual_ip_inform_responses(Addresses); + {snmp_notification, erlang_agent_test, + {no_response, _} = NoResponse} -> + ct:fail(NoResponse); + {snmp_notification, erlang_agent_test, _} = Unexpected -> + ct:pal("Unexpected response: ~p", [Unexpected]), + erlang_agent_dual_ip_inform_responses(AAs) + end. + %%-------------------------------------------------------------------- %% Internal functions ------------------------------------------------ %%-------------------------------------------------------------------- @@ -369,6 +430,9 @@ oid_str([Int | Rest], Acc) -> oid_str(Rest, Acc ++ "." ++ integer_to_list(Int)). agent_config(Dir, Transports, TargetDomain, TargetAddr, Versions) -> + agent_config(Dir, Transports, [{TargetDomain, TargetAddr}], Versions). +%% +agent_config(Dir, Transports, Targets, Versions) -> EngineID = ?AGENT_ENGIN_ID, MMS = ?DEFAULT_MAX_MESSAGE_SIZE, ok = snmp_config:write_agent_snmp_conf(Dir, Transports, EngineID, MMS), @@ -379,7 +443,7 @@ agent_config(Dir, Transports, TargetDomain, TargetAddr, Versions) -> Dir, "snmp_to_snmpnet_SUITE"), ok = snmp_config:write_agent_snmp_target_addr_conf( - Dir, TargetDomain, TargetAddr, Versions), + Dir, Targets, Versions), 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). -- cgit v1.2.3 From 8547d1fe580c714e15ab205d6b2635333ea380f8 Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Wed, 23 Jul 2014 15:42:20 +0200 Subject: Improve external snmp commands args --- lib/snmp/test/snmp_to_snmpnet_SUITE.erl | 120 ++++++++++++++++++-------------- 1 file changed, 68 insertions(+), 52 deletions(-) (limited to 'lib/snmp/test/snmp_to_snmpnet_SUITE.erl') diff --git a/lib/snmp/test/snmp_to_snmpnet_SUITE.erl b/lib/snmp/test/snmp_to_snmpnet_SUITE.erl index 7a2b05c048..78c3a53f89 100644 --- a/lib/snmp/test/snmp_to_snmpnet_SUITE.erl +++ b/lib/snmp/test/snmp_to_snmpnet_SUITE.erl @@ -16,7 +16,13 @@ %% %% %CopyrightEnd% %% -%% +%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% This test suite uses the following external programs: +%% snmpget From packet 'snmp' (in Ubuntu 12.04) +%% snmptrapd From packet 'snmpd' (in Ubuntu 12.04) +%% They originate from the Net-SNMP applications, see: +%% http://net-snmp.sourceforge.net/ + -module(snmp_to_snmpnet_SUITE). @@ -26,11 +32,14 @@ -include_lib("common_test/include/ct.hrl"). -include_lib("snmp/include/STANDARD-MIB.hrl"). --define(AGENT_ENGIN_ID, "ErlangSnmpAgent"). +-define(AGENT_ENGINE_ID, "ErlangSnmpAgent"). -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\"">>). + +expected(?sysDescr_instance = Oid, get) -> + OidStr = oid_str(Oid), + iolist_to_binary([OidStr | " = STRING: \"Erlang SNMP agent\""]). %%-------------------------------------------------------------------- %% Common Test interface functions ----------------------------------- @@ -192,7 +201,9 @@ erlang_agent_netsnmp_get() -> erlang_agent_netsnmp_get(Config) when is_list(Config) -> start_agent(Config), - ?SYS_DESC = snmpget(oid_str(?sysDescr_instance), Config), + Oid = ?sysDescr_instance, + Expected = expected(Oid, get), + Expected = snmpget(Oid, Config), ok. %%-------------------------------------------------------------------- @@ -201,10 +212,10 @@ erlang_agent_dual_ip_get() -> "snmpnet ipv4 and snmpnet ipv6 manager at the same time"}]. erlang_agent_dual_ip_get(Config) when is_list(Config) -> start_agent(Config), - - OidStr = oid_str(?sysDescr_instance), - ?SYS_DESC = snmpget(OidStr, [{ip_version, ipv4} | Config]), - ?SYS_DESC = snmpget(OidStr, [{ip_version, ipv6} | Config]), + Oid = ?sysDescr_instance, + Expected = expected(Oid, get), + Expected = snmpget(Oid, [{ip_version, ipv4} | Config]), + Expected = snmpget(Oid, [{ip_version, ipv6} | Config]), ok. %%-------------------------------------------------------------------- @@ -212,21 +223,14 @@ erlang_agent_netsnmp_inform(Config) when is_list(Config) -> Host = ?config(host, Config), IPVersion = ?config(ip_version, Config), DataDir = ?config(data_dir, Config), + Mib = "TestTrapv2", start_agent(Config), - ok = - snmpa:load_mib( - snmp_master_agent, filename:join(DataDir, "TestTrapv2")), - - SnmptrapdArgs = - ["-f", "-Lo", - "-M", DataDir, - "--disableAuthorization=yes", - "--snmpTrapdAddr=" ++ net_snmp_transport(IPVersion) ++ - Host ++ ":" ++ integer_to_list(?config(manager_port, Config))], - {ok, StartCheckMP} = re:compile("NET-SNMP version ", [anchored]), - ProgHandle = - start_program(snmptrapd, SnmptrapdArgs, StartCheckMP, Config), + ok = snmpa:load_mib(snmp_master_agent, filename:join(DataDir, Mib)), + + TrapAddr = net_snmp_transport(IPVersion) ++ Host ++ + ":" ++ integer_to_list(?config(manager_port, Config)), + ProgHandle = start_snmptrapd(Mib, TrapAddr, Config), snmpa:send_notification( snmp_master_agent, testTrapv22, {erlang_agent_test, self()}), @@ -251,24 +255,17 @@ erlang_agent_dual_ip_inform(Config) when is_list(Config) -> Host = ?config(host, Config), ManagerPort = ?config(manager_port, Config), DataDir = ?config(data_dir, Config), + Mib = "TestTrapv2", start_agent(Config), - ok = - snmpa:load_mib( - snmp_master_agent, filename:join(DataDir, "TestTrapv2")), + ok = snmpa:load_mib(snmp_master_agent, filename:join(DataDir, Mib)), ManagerPortStr = integer_to_list(ManagerPort), - SnmptrapdArgs = - ["-f", "-Lo", - "-M", DataDir, - "--disableAuthorization=yes", - "--snmpTrapdAddr=" ++ - net_snmp_transport(ipv4) ++ Host ++ ":" ++ ManagerPortStr ++ - "," ++ - net_snmp_transport(ipv6) ++ Host ++ ":" ++ ManagerPortStr], - {ok, StartCheckMP} = re:compile("NET-SNMP version ", [anchored]), - ProgHandle = - start_program(snmptrapd, SnmptrapdArgs, StartCheckMP, Config), + TrapAddrs = + net_snmp_transport(ipv4) ++ Host ++ ":" ++ ManagerPortStr ++ + "," ++ + net_snmp_transport(ipv6) ++ Host ++ ":" ++ ManagerPortStr, + ProgHandle = start_snmptrapd(Mib, TrapAddrs, Config), snmpa:send_notification( snmp_master_agent, testTrapv22, {erlang_agent_test, self()}), @@ -281,8 +278,14 @@ erlang_agent_dual_ip_inform(Config) when is_list(Config) -> stop_program(ProgHandle). erlang_agent_dual_ip_inform_responses([]) -> - ok; -erlang_agent_dual_ip_inform_responses([Address | Addresses] = AAs) -> + receive + {snmp_notification, erlang_agent_test, _} = Unexpected -> + ct:pal("Unexpected response: ~p", [Unexpected]), + erlang_agent_dual_ip_inform_responses([]) + after 0 -> + ok + end; +erlang_agent_dual_ip_inform_responses([Address | Addresses]) -> receive {snmp_notification, erlang_agent_test, {got_response, Address}} -> @@ -290,16 +293,13 @@ erlang_agent_dual_ip_inform_responses([Address | Addresses] = AAs) -> erlang_agent_dual_ip_inform_responses(Addresses); {snmp_notification, erlang_agent_test, {no_response, _} = NoResponse} -> - ct:fail(NoResponse); - {snmp_notification, erlang_agent_test, _} = Unexpected -> - ct:pal("Unexpected response: ~p", [Unexpected]), - erlang_agent_dual_ip_inform_responses(AAs) + ct:fail(NoResponse) end. %%-------------------------------------------------------------------- %% Internal functions ------------------------------------------------ %%-------------------------------------------------------------------- -snmpget(OidStr, Config) -> +snmpget(Oid, Config) -> Versions = ?config(snmp_versions, Config), IPVersion = ?config(ip_version, Config), Host = ?config(host, Config), @@ -307,14 +307,26 @@ snmpget(OidStr, Config) -> Args = ["-c", "public", net_snmp_version(Versions), - net_snmp_transport(IPVersion) ++ - Host ++ ":" ++ integer_to_list(Port), - OidStr], + "-m", "", + "-Cf", + net_snmp_transport(IPVersion)++Host++":"++ integer_to_list(Port), + oid_str(Oid)], ProgHandle = start_program(snmpget, Args, none, Config), {_, line, Line} = get_program_output(ProgHandle), stop_program(ProgHandle), Line. +start_snmptrapd(Mibs, TrapAddrs, Config) -> + DataDir = ?config(data_dir, Config), + MibDir = filename:join(code:lib_dir(snmp), "mibs"), + SnmptrapdArgs = + ["-f", "-Lo", "-C", + "-m", Mibs, + "-M", MibDir++":"++DataDir, + "--disableAuthorization=yes", + "--snmpTrapdAddr="++TrapAddrs], + {ok, StartCheckMP} = re:compile("NET-SNMP version ", [anchored]), + start_program(snmptrapd, SnmptrapdArgs, StartCheckMP, Config). start_program(Prog, Args, StartCheckMP, Config) -> Path = ?config(Prog, Config), @@ -421,19 +433,23 @@ app_env(Config) -> {note_store, [{verbosity, silence}]}, {net_if, [{verbosity, trace}]}]. -oid_str([Int | Rest]) -> - oid_str(Rest, integer_to_list(Int)). +oid_str([1 | Ints]) -> + "iso." ++ oid_str_tl(Ints); +oid_str(Ints) -> + oid_str_tl(Ints). -oid_str([], Acc) -> - Acc; -oid_str([Int | Rest], Acc) -> - oid_str(Rest, Acc ++ "." ++ integer_to_list(Int)). +oid_str_tl([]) -> + ""; +oid_str_tl([Int]) -> + integer_to_list(Int); +oid_str_tl([Int | Ints]) -> + integer_to_list(Int) ++ "." ++ oid_str_tl(Ints). agent_config(Dir, Transports, TargetDomain, TargetAddr, Versions) -> agent_config(Dir, Transports, [{TargetDomain, TargetAddr}], Versions). %% agent_config(Dir, Transports, Targets, Versions) -> - EngineID = ?AGENT_ENGIN_ID, + EngineID = ?AGENT_ENGINE_ID, MMS = ?DEFAULT_MAX_MESSAGE_SIZE, ok = snmp_config:write_agent_snmp_conf(Dir, Transports, EngineID, MMS), ok = snmp_config:write_agent_snmp_context_conf(Dir), -- cgit v1.2.3 From 87301df2f4d22153364f11d1c07a5be1e9423c13 Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Mon, 28 Jul 2014 16:32:55 +0200 Subject: Adjust test cases for daily builds --- lib/snmp/test/snmp_to_snmpnet_SUITE.erl | 65 +++++++++++++++++++++------------ 1 file changed, 42 insertions(+), 23 deletions(-) (limited to 'lib/snmp/test/snmp_to_snmpnet_SUITE.erl') diff --git a/lib/snmp/test/snmp_to_snmpnet_SUITE.erl b/lib/snmp/test/snmp_to_snmpnet_SUITE.erl index 78c3a53f89..a54fb58117 100644 --- a/lib/snmp/test/snmp_to_snmpnet_SUITE.erl +++ b/lib/snmp/test/snmp_to_snmpnet_SUITE.erl @@ -91,7 +91,8 @@ init_per_group(ipv6, Config) -> TrapAddr = {IpAddr, ManagerPort}, Versions = [v2], agent_config(Dir, Transports, Domain, TrapAddr, Versions), - [{host, Host}, {snmp_versions, Versions}, {ip_version, ipv6} + [{snmp_versions, Versions}, {ip_version, ipv6}, + {trapaddrs, [IpAddr]} | Config]; _ -> {skip, "Host does not support IPV6"} @@ -108,7 +109,8 @@ init_per_group(ipv4, Config) -> TrapAddr = {IpAddr, ManagerPort}, Versions = [v2], agent_config(Dir, Transports, Domain, TrapAddr, Versions), - [{host, Host}, {snmp_versions, Versions}, {ip_version, ipv4} + [{snmp_versions, Versions}, {ip_version, ipv4}, + {trapaddrs, [IpAddr]} | Config]; %% init_per_group(dual_ip, Config) -> @@ -131,8 +133,8 @@ init_per_group(dual_ip, Config) -> {transportDomainUdpIpv6, {IPv6Addr, ManagerPort}}], Versions = [v2], agent_config(Dir, Transports, Targets, Versions), - [{host, Host}, {port, ?AGENT_PORT}, - {snmp_versions, Versions} + [{port, ?AGENT_PORT}, {snmp_versions, Versions}, + {trapaddrs, [IPv4Addr, IPv6Addr]} | NewConfig]; _ -> {skip, "Host does not support IPV6"} @@ -178,9 +180,26 @@ end_per_testcase(_, Config) -> find_executables([], Config) -> Config; find_executables([Exec | Execs], Config) -> - case os:find_executable(atom_to_list(Exec)) of + ExecStr = atom_to_list(Exec), + case os:find_executable(ExecStr) of false -> - {skip, Exec ++ " not found"}; + find_sys_executables( + Execs, Config, Exec, ExecStr, + [["usr", "local", "sbin"], + ["usr", "sbin"], + ["sbin"]]); + Path -> + find_executables( + Execs, + [{Exec, Path} | Config]) + end. + +find_sys_executables(_Execs, _Config, _Exec, ExecStr, []) -> + {skip, ExecStr ++ " not found"}; +find_sys_executables(Execs, Config, Exec, ExecStr, [Dir | Dirs]) -> + case os:find_executable(filename:join(["/" | Dir] ++ [ExecStr])) of + false -> + find_sys_executables(Execs, Config, Exec, ExecStr, Dirs); Path -> find_executables( Execs, @@ -220,17 +239,15 @@ erlang_agent_dual_ip_get(Config) when is_list(Config) -> %%-------------------------------------------------------------------- erlang_agent_netsnmp_inform(Config) when is_list(Config) -> - Host = ?config(host, Config), - IPVersion = ?config(ip_version, Config), - DataDir = ?config(data_dir, Config), + [TrapAddr | _] = ?config(trapaddrs, Config), + DataDir = ?config(data_dir, Config), Mib = "TestTrapv2", start_agent(Config), ok = snmpa:load_mib(snmp_master_agent, filename:join(DataDir, Mib)), - TrapAddr = net_snmp_transport(IPVersion) ++ Host ++ - ":" ++ integer_to_list(?config(manager_port, Config)), - ProgHandle = start_snmptrapd(Mib, TrapAddr, Config), + TrapAddrStr = net_snmp_addr_str(TrapAddr, ?config(manager_port, Config)), + ProgHandle = start_snmptrapd(Mib, TrapAddrStr, Config), snmpa:send_notification( snmp_master_agent, testTrapv22, {erlang_agent_test, self()}), @@ -252,7 +269,7 @@ erlang_agent_netsnmp_inform(Config) when is_list(Config) -> %%-------------------------------------------------------------------- erlang_agent_dual_ip_inform(Config) when is_list(Config) -> - Host = ?config(host, Config), + [TrapAddr1, TrapAddr2 | _] = ?config(trapaddrs, Config), ManagerPort = ?config(manager_port, Config), DataDir = ?config(data_dir, Config), Mib = "TestTrapv2", @@ -260,11 +277,10 @@ erlang_agent_dual_ip_inform(Config) when is_list(Config) -> start_agent(Config), ok = snmpa:load_mib(snmp_master_agent, filename:join(DataDir, Mib)), - ManagerPortStr = integer_to_list(ManagerPort), TrapAddrs = - net_snmp_transport(ipv4) ++ Host ++ ":" ++ ManagerPortStr ++ + net_snmp_addr_str(TrapAddr1, ManagerPort) ++ "," ++ - net_snmp_transport(ipv6) ++ Host ++ ":" ++ ManagerPortStr, + net_snmp_addr_str(TrapAddr2, ManagerPort), ProgHandle = start_snmptrapd(Mib, TrapAddrs, Config), snmpa:send_notification( @@ -301,15 +317,14 @@ erlang_agent_dual_ip_inform_responses([Address | Addresses]) -> %%-------------------------------------------------------------------- snmpget(Oid, Config) -> Versions = ?config(snmp_versions, Config), - IPVersion = ?config(ip_version, Config), - Host = ?config(host, Config), + [TrapAddr | _] = ?config(trapaddrs, Config), Port = ?config(agent_port, Config), Args = ["-c", "public", net_snmp_version(Versions), "-m", "", "-Cf", - net_snmp_transport(IPVersion)++Host++":"++ integer_to_list(Port), + net_snmp_addr_str(TrapAddr, Port), oid_str(Oid)], ProgHandle = start_program(snmpget, Args, none, Config), {_, line, Line} = get_program_output(ProgHandle), @@ -471,7 +486,11 @@ net_snmp_version([v2 | _]) -> net_snmp_version([v1 | _]) -> "-v1". -net_snmp_transport(ipv4) -> - "udp:"; -net_snmp_transport(ipv6) -> - "udp6:". +net_snmp_addr_str(IPv4Addr, Port) when tuple_size(IPv4Addr) =:= 4 -> + "udp:" ++ + inet_parse:ntoa(IPv4Addr) ++ ":" ++ + integer_to_list(Port); +net_snmp_addr_str(IPv6Addr, Port) when tuple_size(IPv6Addr) =:= 8 -> + "udp6:[" ++ + inet_parse:ntoa(IPv6Addr) ++ "]:" ++ + integer_to_list(Port). -- cgit v1.2.3 From fbc5e6a9a58e6d923442e260003e0c6d554749d0 Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Tue, 29 Jul 2014 11:11:10 +0200 Subject: Fix testcase for really dual ip --- lib/snmp/test/snmp_to_snmpnet_SUITE.erl | 170 +++++++++++--------------------- 1 file changed, 59 insertions(+), 111 deletions(-) (limited to 'lib/snmp/test/snmp_to_snmpnet_SUITE.erl') diff --git a/lib/snmp/test/snmp_to_snmpnet_SUITE.erl b/lib/snmp/test/snmp_to_snmpnet_SUITE.erl index a54fb58117..69d54570ea 100644 --- a/lib/snmp/test/snmp_to_snmpnet_SUITE.erl +++ b/lib/snmp/test/snmp_to_snmpnet_SUITE.erl @@ -68,8 +68,8 @@ groups() -> {inform, [], [erlang_agent_netsnmp_inform]}, {dual_ip, [], - [erlang_agent_dual_ip_get, - erlang_agent_dual_ip_inform]} + [erlang_agent_netsnmp_get, + erlang_agent_netsnmp_inform]} ]. init_per_suite(Config) -> @@ -81,61 +81,20 @@ end_per_suite(_Config) -> init_per_group(ipv6, Config) -> case ct:require(ipv6_hosts) of ok -> - Dir = ?config(priv_dir, Config), - Domain = transportDomainUdpIpv6, - AgentPort = ?config(agent_port, Config), - ManagerPort = ?config(manager_port, Config), - {ok, Host} = inet:gethostname(), - {ok, IpAddr} = inet:getaddr(Host, inet6), - Transports = [{Domain, {IpAddr, AgentPort}}], - TrapAddr = {IpAddr, ManagerPort}, - Versions = [v2], - agent_config(Dir, Transports, Domain, TrapAddr, Versions), - [{snmp_versions, Versions}, {ip_version, ipv6}, - {trapaddrs, [IpAddr]} - | Config]; + init_per_group_ip([inet6], Config); _ -> {skip, "Host does not support IPV6"} end; %% init_per_group(ipv4, Config) -> - Dir = ?config(priv_dir, Config), - Domain = transportDomainUdpIpv4, - AgentPort = ?config(agent_port, Config), - ManagerPort = ?config(manager_port, Config), - {ok, Host} = inet:gethostname(), - {ok, IpAddr} = inet:getaddr(Host, inet), - Transports = [{Domain, {IpAddr, AgentPort}}], - TrapAddr = {IpAddr, ManagerPort}, - Versions = [v2], - agent_config(Dir, Transports, Domain, TrapAddr, Versions), - [{snmp_versions, Versions}, {ip_version, ipv4}, - {trapaddrs, [IpAddr]} - | Config]; + init_per_group_ip([inet], Config); %% init_per_group(dual_ip, Config) -> case find_executables([snmpget, snmptrapd], Config) of NewConfig when is_list(NewConfig) -> case ct:require(ipv6_hosts) of ok -> - Dir = ?config(priv_dir, Config), - Domain = transportDomainUdpIpv4, - AgentPort = ?config(agent_port, Config), - ManagerPort = ?config(manager_port, Config), - {ok, Host} = inet:gethostname(), - {ok, IPv4Addr} = inet:getaddr(Host, inet), - {ok, IPv6Addr} = inet:getaddr(Host, inet6), - Transports = - [{Domain, {IPv4Addr, AgentPort}}, - {transportDomainUdpIpv6, {IPv6Addr, AgentPort}}], - Targets = - [{Domain, {IPv4Addr, ManagerPort}}, - {transportDomainUdpIpv6, {IPv6Addr, ManagerPort}}], - Versions = [v2], - agent_config(Dir, Transports, Targets, Versions), - [{port, ?AGENT_PORT}, {snmp_versions, Versions}, - {trapaddrs, [IPv4Addr, IPv6Addr]} - | NewConfig]; + init_per_group_ip([inet, inet6], NewConfig); _ -> {skip, "Host does not support IPV6"} end; @@ -153,6 +112,29 @@ init_per_group(inform, Config) -> init_per_group(_, Config) -> Config. +init_per_group_ip(Families, Config) -> + Dir = ?config(priv_dir, Config), + AgentPort = ?config(agent_port, Config), + ManagerPort = ?config(manager_port, Config), + Versions = [v2], + {ok, Host} = inet:gethostname(), + Transports = + [begin + {ok, Addr} = inet:getaddr(Host, Family), + {domain(Family), {Addr, AgentPort}} + end || Family <- Families], + Targets = + [begin + {ok, Addr} = inet:getaddr(Host, Family), + {domain(Family), {Addr, ManagerPort}} + end || Family <- Families], + agent_config(Dir, Transports, Targets, Versions), + [{port, ?AGENT_PORT}, {snmp_versions, Versions}, + {transports, Transports}, {targets, Targets} + | Config]. + + + end_per_group(_GroupName, Config) -> Config. @@ -219,69 +201,23 @@ erlang_agent_netsnmp_get() -> "from snmpnet manager"}]. erlang_agent_netsnmp_get(Config) when is_list(Config) -> + Transports = ?config(transports, Config), start_agent(Config), Oid = ?sysDescr_instance, Expected = expected(Oid, get), - Expected = snmpget(Oid, Config), - ok. - -%%-------------------------------------------------------------------- -erlang_agent_dual_ip_get() -> - [{doc,"Test that we can access erlang snmp agent from both " - "snmpnet ipv4 and snmpnet ipv6 manager at the same time"}]. -erlang_agent_dual_ip_get(Config) when is_list(Config) -> - start_agent(Config), - Oid = ?sysDescr_instance, - Expected = expected(Oid, get), - Expected = snmpget(Oid, [{ip_version, ipv4} | Config]), - Expected = snmpget(Oid, [{ip_version, ipv6} | Config]), + [Expected = snmpget(Oid, Transport, Config) + || Transport <- Transports], ok. %%-------------------------------------------------------------------- erlang_agent_netsnmp_inform(Config) when is_list(Config) -> - [TrapAddr | _] = ?config(trapaddrs, Config), - DataDir = ?config(data_dir, Config), - Mib = "TestTrapv2", - - start_agent(Config), - ok = snmpa:load_mib(snmp_master_agent, filename:join(DataDir, Mib)), - - TrapAddrStr = net_snmp_addr_str(TrapAddr, ?config(manager_port, Config)), - ProgHandle = start_snmptrapd(Mib, TrapAddrStr, Config), - - snmpa:send_notification( - snmp_master_agent, testTrapv22, {erlang_agent_test, self()}), - - 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 response from: ~p~n", [Address]), - ok; - {snmp_notification, erlang_agent_test, {no_response, _} = - NoResponse} -> - ct:fail(NoResponse) - end, - - stop_program(ProgHandle). - -%%-------------------------------------------------------------------- -erlang_agent_dual_ip_inform(Config) when is_list(Config) -> - [TrapAddr1, TrapAddr2 | _] = ?config(trapaddrs, Config), - ManagerPort = ?config(manager_port, Config), DataDir = ?config(data_dir, Config), Mib = "TestTrapv2", start_agent(Config), ok = snmpa:load_mib(snmp_master_agent, filename:join(DataDir, Mib)), - TrapAddrs = - net_snmp_addr_str(TrapAddr1, ManagerPort) ++ - "," ++ - net_snmp_addr_str(TrapAddr2, ManagerPort), - ProgHandle = start_snmptrapd(Mib, TrapAddrs, Config), + ProgHandle = start_snmptrapd(Mib, Config), snmpa:send_notification( snmp_master_agent, testTrapv22, {erlang_agent_test, self()}), @@ -289,24 +225,24 @@ erlang_agent_dual_ip_inform(Config) when is_list(Config) -> receive {snmp_targets, erlang_agent_test, Addresses} -> ct:pal("Notification sent to: ~p~n", [Addresses]), - erlang_agent_dual_ip_inform_responses(Addresses) + erlang_agent_netsnmp_inform_responses(Addresses) end, stop_program(ProgHandle). -erlang_agent_dual_ip_inform_responses([]) -> +erlang_agent_netsnmp_inform_responses([]) -> receive {snmp_notification, erlang_agent_test, _} = Unexpected -> ct:pal("Unexpected response: ~p", [Unexpected]), - erlang_agent_dual_ip_inform_responses([]) + erlang_agent_netsnmp_inform_responses([]) after 0 -> ok end; -erlang_agent_dual_ip_inform_responses([Address | Addresses]) -> +erlang_agent_netsnmp_inform_responses([Address | Addresses]) -> receive {snmp_notification, erlang_agent_test, {got_response, Address}} -> ct:pal("Got response from: ~p~n", [Address]), - erlang_agent_dual_ip_inform_responses(Addresses); + erlang_agent_netsnmp_inform_responses(Addresses); {snmp_notification, erlang_agent_test, {no_response, _} = NoResponse} -> ct:fail(NoResponse) @@ -315,31 +251,30 @@ erlang_agent_dual_ip_inform_responses([Address | Addresses]) -> %%-------------------------------------------------------------------- %% Internal functions ------------------------------------------------ %%-------------------------------------------------------------------- -snmpget(Oid, Config) -> +snmpget(Oid, Transport, Config) -> Versions = ?config(snmp_versions, Config), - [TrapAddr | _] = ?config(trapaddrs, Config), - Port = ?config(agent_port, Config), Args = ["-c", "public", net_snmp_version(Versions), "-m", "", "-Cf", - net_snmp_addr_str(TrapAddr, Port), + net_snmp_addr_str(Transport), oid_str(Oid)], ProgHandle = start_program(snmpget, Args, none, Config), {_, line, Line} = get_program_output(ProgHandle), stop_program(ProgHandle), Line. -start_snmptrapd(Mibs, TrapAddrs, Config) -> +start_snmptrapd(Mibs, Config) -> DataDir = ?config(data_dir, Config), MibDir = filename:join(code:lib_dir(snmp), "mibs"), + Targets = ?config(targets, Config), SnmptrapdArgs = ["-f", "-Lo", "-C", "-m", Mibs, "-M", MibDir++":"++DataDir, "--disableAuthorization=yes", - "--snmpTrapdAddr="++TrapAddrs], + "--snmpTrapdAddr=" ++ net_snmp_addr_str(Targets)], {ok, StartCheckMP} = re:compile("NET-SNMP version ", [anchored]), start_program(snmptrapd, SnmptrapdArgs, StartCheckMP, Config). @@ -486,11 +421,24 @@ net_snmp_version([v2 | _]) -> net_snmp_version([v1 | _]) -> "-v1". -net_snmp_addr_str(IPv4Addr, Port) when tuple_size(IPv4Addr) =:= 4 -> +domain(inet) -> + transportDomainUdpIpv4; +domain(inet6) -> + transportDomainUdpIpv6. + +net_snmp_addr_str([Target | Targets]) -> + net_snmp_addr_str(Target) ++ + case Targets of + [] -> + []; + [_ | _] -> + "," ++ net_snmp_addr_str(Targets) + end; +net_snmp_addr_str({transportDomainUdpIpv4, {Addr, Port}}) -> "udp:" ++ - inet_parse:ntoa(IPv4Addr) ++ ":" ++ + inet_parse:ntoa(Addr) ++ ":" ++ integer_to_list(Port); -net_snmp_addr_str(IPv6Addr, Port) when tuple_size(IPv6Addr) =:= 8 -> +net_snmp_addr_str({transportDomainUdpIpv6, {Addr, Port}}) -> "udp6:[" ++ - inet_parse:ntoa(IPv6Addr) ++ "]:" ++ + inet_parse:ntoa(Addr) ++ "]:" ++ integer_to_list(Port). -- cgit v1.2.3 From 010bbdacbab4d4bfff7a7c59968aa333f081e7c5 Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Wed, 30 Jul 2014 10:10:38 +0200 Subject: Rearrange test suite group structure --- lib/snmp/test/snmp_to_snmpnet_SUITE.erl | 83 ++++++++++++++------------------- 1 file changed, 36 insertions(+), 47 deletions(-) (limited to 'lib/snmp/test/snmp_to_snmpnet_SUITE.erl') diff --git a/lib/snmp/test/snmp_to_snmpnet_SUITE.erl b/lib/snmp/test/snmp_to_snmpnet_SUITE.erl index 69d54570ea..6e9c57bce9 100644 --- a/lib/snmp/test/snmp_to_snmpnet_SUITE.erl +++ b/lib/snmp/test/snmp_to_snmpnet_SUITE.erl @@ -50,7 +50,8 @@ suite() -> [{ct_hooks,[ts_install_cth]}]. all() -> [ {group, ipv4}, - {group, ipv6} + {group, ipv6}, + {group, ipv4_ipv6} ]. groups() -> @@ -60,16 +61,17 @@ groups() -> ]}, {ipv6, [], [{group, get}, - {group, inform}, - {group, dual_ip} + {group, inform} + ]}, + {ipv4_ipv6, [], + [{group, get}, + {group, inform} ]}, + %% {get, [], [erlang_agent_netsnmp_get]}, {inform, [], - [erlang_agent_netsnmp_inform]}, - {dual_ip, [], - [erlang_agent_netsnmp_get, - erlang_agent_netsnmp_inform]} + [erlang_agent_netsnmp_inform]} ]. init_per_suite(Config) -> @@ -78,40 +80,31 @@ init_per_suite(Config) -> end_per_suite(_Config) -> ok. -init_per_group(ipv6, Config) -> - case ct:require(ipv6_hosts) of - ok -> - init_per_group_ip([inet6], Config); - _ -> - {skip, "Host does not support IPV6"} - end; -%% init_per_group(ipv4, Config) -> init_per_group_ip([inet], Config); -%% -init_per_group(dual_ip, Config) -> - case find_executables([snmpget, snmptrapd], Config) of - NewConfig when is_list(NewConfig) -> - case ct:require(ipv6_hosts) of - ok -> - init_per_group_ip([inet, inet6], NewConfig); - _ -> - {skip, "Host does not support IPV6"} - end; - Other -> - Other - end; +init_per_group(ipv6, Config) -> + init_per_group_ipv6([inet6], Config); +init_per_group(ipv4_ipv6, Config) -> + init_per_group_ipv6([inet, inet6], Config); %% init_per_group(get, Config) -> %% From Ubuntu package snmp - find_executables([snmpget], Config); -%% + find_executable(snmpget, Config); init_per_group(inform, Config) -> - %% From Ubuntu package snmptrapfmt - find_executables([snmptrapd], Config); + %% From Ubuntu package snmpd + find_executable(snmptrapd, Config); +%% init_per_group(_, Config) -> Config. +init_per_group_ipv6(Families, Config) -> + case ct:require(ipv6_hosts) of + ok -> + init_per_group_ip(Families, Config); + _ -> + {skip, "Host does not support IPV6"} + end. + init_per_group_ip(Families, Config) -> Dir = ?config(priv_dir, Config), AgentPort = ?config(agent_port, Config), @@ -159,33 +152,29 @@ end_per_testcase(_, Config) -> end, Config. -find_executables([], Config) -> - Config; -find_executables([Exec | Execs], Config) -> +find_executable(Exec, Config) -> ExecStr = atom_to_list(Exec), case os:find_executable(ExecStr) of false -> - find_sys_executables( - Execs, Config, Exec, ExecStr, + %% The sbin dirs are not in the PATH on all platforms... + find_sys_executable( + Exec, ExecStr, [["usr", "local", "sbin"], ["usr", "sbin"], - ["sbin"]]); + ["sbin"]], + Config); Path -> - find_executables( - Execs, - [{Exec, Path} | Config]) + [{Exec, Path} | Config] end. -find_sys_executables(_Execs, _Config, _Exec, ExecStr, []) -> +find_sys_executable(_Exec, ExecStr, [], _Config) -> {skip, ExecStr ++ " not found"}; -find_sys_executables(Execs, Config, Exec, ExecStr, [Dir | Dirs]) -> +find_sys_executable(Exec, ExecStr, [Dir | Dirs], Config) -> case os:find_executable(filename:join(["/" | Dir] ++ [ExecStr])) of false -> - find_sys_executables(Execs, Config, Exec, ExecStr, Dirs); + find_sys_executable(Exec, ExecStr, Dirs, Config); Path -> - find_executables( - Execs, - [{Exec, Path} | Config]) + [{Exec, Path} | Config] end. start_agent(Config) -> -- cgit v1.2.3