aboutsummaryrefslogtreecommitdiffstats
path: root/lib/common_test/test/ct_snmp_SUITE.erl
blob: 9e4bbedcfb69844dd8f2162d9fa49fb17c58bed6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
%%--------------------------------------------------------------------
%% %CopyrightBegin%
%%
%% Copyright Ericsson AB 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
%% 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%
%%
%%----------------------------------------------------------------------
%% File: ct_snmp_SUITE.erl
%%
%% Description:
%%    This file contains the test cases for the ct_snmp API.
%%
%% @author Support
%% @doc Test  of SNMP support in common_test
%% @end
%%----------------------------------------------------------------------
%%----------------------------------------------------------------------
-module(ct_snmp_SUITE).
-include_lib("common_test/include/ct.hrl").
-include_lib("snmp/include/STANDARD-MIB.hrl").
-include_lib("snmp/include/snmp_types.hrl").

-compile(export_all).

%% Default timetrap timeout (set in init_per_testcase).
-define(default_timeout, ?t:minutes(1)).

%% SNMP user stuff
-behaviour(snmpm_user).
-export([handle_error/3,
	 handle_agent/5,
	 handle_pdu/4,
	 handle_trap/3,
	 handle_inform/3,
	 handle_report/3]).


suite() ->
    [{require, snmp_mgr_agent, snmp},
     {require, snmp_app_cfg, snmp_app}].

all() ->
    [start_stop,
    {group,get_set}].


groups() ->
    [{get_set,[get_values,get_next_values,set_values]}].

init_per_group(get_set, Config) ->
    ok = ct_snmp:start(Config,snmp_mgr_agent,snmp_app_cfg),
    Config.

end_per_group(get_set, Config) ->
    ok = ct_snmp:stop(Config),
    Config.

init_per_testcase(_Case, Config) ->
    Dog = test_server:timetrap(?default_timeout),
    [{watchdog, Dog}|Config].

end_per_testcase(_Case, Config) ->
    Dog=?config(watchdog, Config),
    test_server:timetrap_cancel(Dog),
    ok.

init_per_suite(Config) ->
    Config.

end_per_suite(Config) ->
    Config.

break(_Config) ->
    test_server:break(""),
    ok.

start_stop(Config) ->
    ok = ct_snmp:start(Config,snmp_mgr_agent,snmp_app_cfg),
    timer:sleep(1000),
    {snmp,_,_} = lists:keyfind(snmp,1,application:which_applications()),
    [_|_] = filelib:wildcard("*/*.conf",?config(priv_dir,Config)),

    ok = ct_snmp:stop(Config),
    timer:sleep(1000),
    false = lists:keyfind(snmp,1,application:which_applications()),
    [] = filelib:wildcard("*/*.conf",?config(priv_dir,Config)),
    ok.

get_values(_Config) ->
    Oids1 = [?sysDescr_instance, ?sysName_instance],
    {noError,_,V1} = ct_snmp:get_values(agent_name,Oids1,snmp_mgr_agent),
    [#varbind{oid=?sysDescr_instance,value="Erlang SNMP agent"},
     #varbind{oid=?sysName_instance,value="ct_test"}] = V1,
    ok.

get_next_values(_Config) ->
    Oids2 = [?system],
    {noError,_,V2} = ct_snmp:get_next_values(agent_name,Oids2,snmp_mgr_agent),
    [#varbind{oid=?sysDescr_instance,value="Erlang SNMP agent"}] = V2,
    ok.

set_values(Config) ->
    Oid3 = ?sysName_instance,
    NewName = "ct_test changed by " ++ atom_to_list(?MODULE),
    VarsAndVals = [{Oid3,s,NewName}],
    {noError,_,_} =
	ct_snmp:set_values(agent_name,VarsAndVals,snmp_mgr_agent,Config),

    Oids4 = [?sysName_instance],
    {noError,_,V4} = ct_snmp:get_values(agent_name,Oids4,snmp_mgr_agent),
    [#varbind{oid=?sysName_instance,value=NewName}] = V4,

    ok.


%%%-----------------------------------------------------------------
%%% SNMP Manager User callback
handle_error(ReqId, Reason, UserData) ->
    erlang:display({handle_error,ReqId, Reason, UserData}),
    ignore.

handle_agent(Addr, Port, Type, SnmpInfo, UserData) ->
    erlang:display({handle_agent,Addr, Port, Type, SnmpInfo, UserData}),
    ignore.

handle_pdu(TargetName, ReqId, SnmpPduInfo, UserData) ->
    erlang:display({handle_pdu,TargetName, ReqId, SnmpPduInfo, UserData}),
    ignore.

handle_trap(TargetName, SnmpTrapInfo, UserData) ->
    erlang:display({handle_trap,TargetName, SnmpTrapInfo, UserData}),
    ignore.

handle_inform(TargetName, SnmpInformInfo, UserData) ->
    erlang:display({handle_inform,TargetName, SnmpInformInfo, UserData}),
    ignore.

handle_report(TargetName, SnmpReportInfo, UserData) ->
    erlang:display({handle_report,TargetName, SnmpReportInfo, UserData}),
    ignore.