From 3747724e6f4f69796938534c4f5d2e5849c7a3e1 Mon Sep 17 00:00:00 2001 From: Siri Hansen Date: Thu, 20 Sep 2012 17:36:55 +0200 Subject: [common_test] Remove calls to undefined functions from ct_snmp --- lib/common_test/src/ct_snmp.erl | 57 +++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 25 deletions(-) (limited to 'lib/common_test/src') diff --git a/lib/common_test/src/ct_snmp.erl b/lib/common_test/src/ct_snmp.erl index 8fe63e8ed1..e3e8bc6f60 100644 --- a/lib/common_test/src/ct_snmp.erl +++ b/lib/common_test/src/ct_snmp.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2004-2010. All Rights Reserved. +%% Copyright Ericsson AB 2004-2012. 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 @@ -250,10 +250,8 @@ stop(Config) -> %%% %%% @doc Issues a synchronous snmp get request. get_values(Agent, Oids, MgrAgentConfName) -> - [Uid, AgentIp, AgentUdpPort | _] = - agent_conf(Agent, MgrAgentConfName), - {ok, SnmpReply, _} = - snmpm:g(Uid, AgentIp, AgentUdpPort, Oids), + [Uid | _] = agent_conf(Agent, MgrAgentConfName), + {ok, SnmpReply, _} = snmpm:sync_get2(Uid, target_name(Agent), Oids), SnmpReply. %%% @spec get_next_values(Agent, Oids, MgrAgentConfName) -> SnmpReply @@ -265,10 +263,8 @@ get_values(Agent, Oids, MgrAgentConfName) -> %%% %%% @doc Issues a synchronous snmp get next request. get_next_values(Agent, Oids, MgrAgentConfName) -> - [Uid, AgentIp, AgentUdpPort | _] = - agent_conf(Agent, MgrAgentConfName), - {ok, SnmpReply, _} = - snmpm:gn(Uid, AgentIp, AgentUdpPort, Oids), + [Uid | _] = agent_conf(Agent, MgrAgentConfName), + {ok, SnmpReply, _} = snmpm:sync_get_next2(Uid, target_name(Agent), Oids), SnmpReply. %%% @spec set_values(Agent, VarsAndVals, MgrAgentConfName, Config) -> SnmpReply @@ -282,13 +278,11 @@ get_next_values(Agent, Oids, MgrAgentConfName) -> %%% @doc Issues a synchronous snmp set request. set_values(Agent, VarsAndVals, MgrAgentConfName, Config) -> PrivDir = ?config(priv_dir, Config), - [Uid, AgentIp, AgentUdpPort | _] = - agent_conf(Agent, MgrAgentConfName), + [Uid | _] = agent_conf(Agent, MgrAgentConfName), Oids = lists:map(fun({Oid, _, _}) -> Oid end, VarsAndVals), - {ok, SnmpGetReply, _} = - snmpm:g(Uid, AgentIp, AgentUdpPort, Oids), - {ok, SnmpSetReply, _} = - snmpm:s(Uid, AgentIp, AgentUdpPort, VarsAndVals), + TargetName = target_name(Agent), + {ok, SnmpGetReply, _} = snmpm:sync_get2(Uid, TargetName, Oids), + {ok, SnmpSetReply, _} = snmpm:sync_set2(Uid, TargetName, VarsAndVals), case SnmpSetReply of {noError, 0, _} when PrivDir /= false -> log(PrivDir, Agent, SnmpGetReply, VarsAndVals); @@ -348,7 +342,7 @@ register_agents(MgrAgentConfName, ManagedAgents) -> NewSnmpVals = lists:keyreplace(managed_agents, 1, SnmpVals, {managed_agents, ManagedAgents}), ct_config:update_config(MgrAgentConfName, {snmp, NewSnmpVals}), - setup_managed_agents(ManagedAgents). + setup_managed_agents(MgrAgentConfName,ManagedAgents). %%% @spec register_usm_users(MgrAgentConfName, UsmUsers) -> ok | {error, Reason} %%% @@ -535,7 +529,7 @@ manager_register(true, MgrAgentConfName) -> setup_usm_users(UsmUsers, EngineID), setup_users(Users), - setup_managed_agents(Agents). + setup_managed_agents(MgrAgentConfName,Agents). %%%--------------------------------------------------------------------------- setup_users(Users) -> @@ -543,10 +537,11 @@ setup_users(Users) -> snmpm:register_user(Id, Module, Data) end, Users). %%%--------------------------------------------------------------------------- -setup_managed_agents([]) -> +setup_managed_agents(_,[]) -> ok; -setup_managed_agents([{_, [Uid, AgentIp, AgentUdpPort, AgentConf]} | +setup_managed_agents(AgentConfName, + [{AgentName, [Uid, AgentIp, AgentUdpPort, AgentConf0]} | Rest]) -> NewAgentIp = case AgentIp of IpTuple when is_tuple(IpTuple) -> @@ -556,12 +551,19 @@ setup_managed_agents([{_, [Uid, AgentIp, AgentUdpPort, AgentConf]} | [IpTuple|_] = Hostent#hostent.h_addr_list, IpTuple end, - ok = snmpm:register_agent(Uid, NewAgentIp, AgentUdpPort), - lists:foreach(fun({Item, Val}) -> - snmpm:update_agent_info(Uid, NewAgentIp, - AgentUdpPort, Item, Val) - end, AgentConf), - setup_managed_agents(Rest). + AgentConf = + case lists:keymember(engine_id,1,AgentConf0) of + true -> + AgentConf0; + false -> + DefaultEngineID = ct:get_config({AgentConfName,agent_engine_id}, + ?AGENT_ENGINE_ID), + [{engine_id,DefaultEngineID}|AgentConf0] + end, + ok = snmpm:register_agent(Uid, target_name(AgentName), + [{address,NewAgentIp},{port,AgentUdpPort} | + AgentConf]), + setup_managed_agents(AgentConfName,Rest). %%%--------------------------------------------------------------------------- setup_usm_users(UsmUsers, EngineID)-> lists:foreach(fun({UsmUser, Conf}) -> @@ -769,3 +771,8 @@ override_vacm(Config, VacmConf) -> File = filename:join(Dir,"vacm.conf"), file:delete(File), snmp_config:write_agent_vacm_config(Dir, "", VacmConf). + +%%%--------------------------------------------------------------------------- + +target_name(Agent) -> + atom_to_list(Agent). -- cgit v1.2.3 From 53b3095adb6478c63da1ef5ef7f3006e4fd614ef Mon Sep 17 00:00:00 2001 From: Siri Hansen Date: Fri, 21 Sep 2012 09:20:27 +0200 Subject: [common_test] Change NotifType to atom instead of string MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit OTP-10432 In call to snmp_config:write_agent_snmp_files, the NotifType argument was earlier a string. This has been changed to an atom since it failed in snmp application and notify·conf was not created. --- lib/common_test/src/ct_snmp.erl | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'lib/common_test/src') diff --git a/lib/common_test/src/ct_snmp.erl b/lib/common_test/src/ct_snmp.erl index e3e8bc6f60..6ff21645c9 100644 --- a/lib/common_test/src/ct_snmp.erl +++ b/lib/common_test/src/ct_snmp.erl @@ -480,9 +480,8 @@ setup_agent(true, AgentConfName, SnmpConfName, file:make_dir(DbDir), snmp_config:write_agent_snmp_files(ConfDir, Vsns, ManagerIP, TrapUdp, AgentIP, AgentUdp, SysName, - atom_to_list(NotifType), - SecType, Passwd, AgentEngineID, - AgentMaxMsgSize), + NotifType, SecType, Passwd, + AgentEngineID, AgentMaxMsgSize), override_default_configuration(Config, AgentConfName), -- cgit v1.2.3 From c73625b031181d8c0ca65760ae44a1dbae4400df Mon Sep 17 00:00:00 2001 From: Siri Hansen Date: Fri, 21 Sep 2012 10:09:49 +0200 Subject: [common_test] Use ct_snmp 'agent_vsns' config value in snmp app config OTP-10432 Config parameter 'agent_vsns' in ct_snmp was ONLY used in call to snmp_config:write_agent_snmp_files. There it is only used for deciding if usm config shall be written (if v3 is included) or not. The value of 'agent_vsns' was NOT added to the snmp application's agent configuration, so the snmp application's own default value would be used - this is [v1,v2,v3]. The result was that if v3 was not included in 'agent_vsns', then usm.conf was not written, but when starting the agent it would complain that this file did not exist since snmp's default versions are all [v1,v2,v3]. This has been corrected - the 'agent_vsns' value is now inserted in the snmp application agent configuration as {versions,AgentVsns}. --- lib/common_test/src/ct_snmp.erl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib/common_test/src') diff --git a/lib/common_test/src/ct_snmp.erl b/lib/common_test/src/ct_snmp.erl index 6ff21645c9..02f849201d 100644 --- a/lib/common_test/src/ct_snmp.erl +++ b/lib/common_test/src/ct_snmp.erl @@ -490,7 +490,8 @@ setup_agent(true, AgentConfName, SnmpConfName, {verbosity, trace}]}, {agent_type, master}, {agent_verbosity, trace}, - {net_if, [{verbosity, trace}]}], + {net_if, [{verbosity, trace}]}, + {versions, Vsns}], ct:get_config({SnmpConfName,agent})), application:set_env(snmp, agent, SnmpEnv). %%%--------------------------------------------------------------------------- -- cgit v1.2.3