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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
|
%%
%% %CopyrightBegin%
%%
%% Copyright Ericsson AB 2004-2012. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
%% You may obtain a copy of the License at
%%
%% http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing, software
%% distributed under the License is distributed on an "AS IS" BASIS,
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%% See the License for the specific language governing permissions and
%% limitations under the License.
%%
%% %CopyrightEnd%
%%
-module(os_mon_mib_SUITE).
%%-----------------------------------------------------------------
%% This suite can no longer be executed standalone, i.e. it must be
%% executed with common test. The reason is that ct_snmp is used
%% instead of the snmp application directly. The suite requires a
%% config file, os_mon_mib_SUITE.cfg, found in the same directory as
%% the suite.
%%
%% Execute with:
%% > ct_run -suite os_mon_mib_SUITE -config os_mon_mib_SUITE.cfg
%%-----------------------------------------------------------------
-include_lib("common_test/include/ct.hrl").
-include_lib("os_mon/include/OTP-OS-MON-MIB.hrl").
-include_lib("snmp/include/snmp_types.hrl").
% Test server specific exports
-export([all/0, suite/0, groups/0,
init_per_suite/1, end_per_suite/1]).
% Test cases must be exported.
-export([update_load_table/1]).
-export([get_mem_sys_mark/1, get_mem_proc_mark/1, get_disk_threshold/1,
get_load_table/1, get_disk_table/1,
real_snmp_request/1, load_unload/1]).
-export([sys_tot_mem/1, sys_used_mem/1, large_erl_process/1,
large_erl_process_mem/1, cpu_load/1, cpu_load5/1, cpu_load15/1,
os_wordsize/1, sys_tot_mem64/1, sys_used_mem64/1,
large_erl_process_mem64/1, disk_descr/1, disk_kbytes/1,
disk_capacity/1]).
-export([otp_6351/1, otp_7441/1]).
-define(TRAP_UDP, 5000).
-define(AGENT_UDP, 4000).
-define(CONF_FILE_VER, [v2]).
-define(SYS_NAME, "Test os_mon_mibs").
-define(MAX_MSG_SIZE, 484).
-define(ENGINE_ID, "mgrEngine").
-define(MGR_PORT, 5001).
%%---------------------------------------------------------------------
suite() ->
[{ct_hooks,[ts_install_cth]},
{timetrap,{minutes,6}},
{require, snmp_mgr_agent, snmp}].
all() ->
[load_unload, get_mem_sys_mark, get_mem_proc_mark,
get_disk_threshold, get_load_table,
{group, get_next_load_table}, get_disk_table,
{group, get_next_disk_table}, real_snmp_request,
update_load_table, {group, tickets}].
groups() ->
[{tickets, [], [otp_6351, otp_7441]},
{get_next_load_table, [],
[sys_tot_mem, sys_used_mem, large_erl_process,
large_erl_process_mem, cpu_load, cpu_load5, cpu_load15,
os_wordsize, sys_tot_mem64, sys_used_mem64,
large_erl_process_mem64]},
{get_next_disk_table, [],
[disk_descr, disk_kbytes, disk_capacity]}].
%%---------------------------------------------------------------------
%%--------------------------------------------------------------------
%% Function: init_per_suite(Config) -> Config
%% Config - [tuple()]
%% A list of key/value pairs, holding the test case configuration.
%% Description: Initiation before the whole suite
%%
%% Note: This function is free to add any key/value pairs to the Config
%% variable, but should NOT alter/remove any existing entries.
%%--------------------------------------------------------------------
init_per_suite(Config) ->
application:start(sasl),
application:start(mnesia),
application:start(os_mon),
ok = ct_snmp:start(Config,snmp_mgr_agent),
%% Load the mibs that should be tested
otp_mib:load(snmp_master_agent),
os_mon_mib:load(snmp_master_agent),
Config.
%%--------------------------------------------------------------------
%% Function: end_per_suite(Config) -> _
%% Config - [tuple()]
%% A list of key/value pairs, holding the test case configuration.
%% Description: Cleanup after the whole suite
%%--------------------------------------------------------------------
end_per_suite(Config) ->
PrivDir = proplists:get_value(priv_dir, Config),
ConfDir = filename:join(PrivDir,"conf"),
DbDir = filename:join(PrivDir,"db"),
MgrDir = filename:join(PrivDir, "mgr"),
%% Uload mibs
snmpa:unload_mibs(snmp_master_agent,["OTP-OS-MON-MIB"]),
otp_mib:unload(snmp_master_agent),
%% Clean up
application:stop(snmp),
application:stop(mnesia),
application:stop(os_mon),
del_dir(ConfDir),
del_dir(DbDir),
(catch del_dir(MgrDir)),
ok.
%%---------------------------------------------------------------------
%% Test cases
%%---------------------------------------------------------------------
%% Test to unload and the reload the OTP.mib
load_unload(Config) when is_list(Config) ->
os_mon_mib:unload(snmp_master_agent),
os_mon_mib:load(snmp_master_agent),
ok.
%%---------------------------------------------------------------------
%% check os_mon_mib:update_load_table error handling
update_load_table(Config) when is_list(Config) ->
Node = start_node(),
ok = rpc:call(Node,application,start,[sasl]),
ok = rpc:call(Node,application,start,[os_mon]),
ok = os_mon_mib:update_load_table(),
rpc:call(Node,application,stop,[os_mon]),
ok = os_mon_mib:update_load_table(),
stop_node(Node),
ok.
%% like update_load_table, when memsup_system_only==true
otp_6351(Config) when is_list(Config) ->
Node = start_node(),
ok = rpc:call(Node,application,start,[sasl]),
ok = rpc:call(Node,application,load,[os_mon]),
ok = rpc:call(Node,application,set_env,
[os_mon,memsup_system_only,true]),
ok = rpc:call(Node,application,start,[os_mon]),
Res = rpc:call(Node,os_mon_mib,get_load,[Node]),
if
is_tuple(Res), element(1, Res)==loadTable ->
ok;
true ->
ct:fail(Res)
end,
rpc:call(Node,application,stop,[os_mon]),
stop_node(Node),
ok.
%%---------------------------------------------------------------------
%% Simulates a get call to test the instrumentation function
%% for the loadMemorySystemWatermark variable.
get_mem_sys_mark(Config) when is_list(Config) ->
case os_mon_mib:mem_sys_mark(get) of
{value, SysMark} when is_integer(SysMark) ->
ok;
_ ->
ct:fail(sys_mark_value_not_integer)
end.
%%---------------------------------------------------------------------
%% Simulates a get call to test the instrumentation function
%% for the loadMemoryErlProcWatermark variable.
get_mem_proc_mark(Config) when is_list(Config) ->
case os_mon_mib:mem_proc_mark(get) of
{value, ProcMark} when is_integer(ProcMark) ->
ok;
_ ->
ct:fail(proc_mark_value_not_integer)
end.
%%---------------------------------------------------------------------
%% Simulates a get call to test the instrumentation function
%% for the diskAlmostFullThreshold variable.
get_disk_threshold(Config) when is_list(Config) ->
case os_mon_mib:disk_threshold(get) of
{value, ProcMark} when is_integer(ProcMark) ->
ok;
_ ->
ct:fail(disk_threshold_value_not_integer)
end.
%%---------------------------------------------------------------------
%%% Note that when we have a string key, as in loadTable, the
%%% instrumentation will deal with the [length(String), String]. We
%%% have to know about this, when short cutting SNMP and calling
%%% instrumentation functions directly as done in most test cases in
%%% this test suite
%% Simulates get calls to test the instrumentation function
%% for the loadTable
get_load_table(Config) when is_list(Config) ->
NodeStr = atom_to_list(node()),
NodeLen = length(NodeStr),
{_, _, {Pid, _}} = memsup:get_memory_data(),
PidStr = lists:flatten(io_lib:format("~w", [Pid])),
[{value, NodeStr},{value, PidStr}] =
os_mon_mib:load_table(get, [NodeLen | NodeStr],
[?loadErlNodeName, ?loadLargestErlProcess]),
Values = os_mon_mib:load_table(get, [NodeLen | NodeStr] ,
[?loadSystemTotalMemory,
?loadSystemUsedMemory,
?loadLargestErlProcessUsedMemory,
?loadCpuLoad,
?loadCpuLoad5,
?loadCpuLoad15,
?loadOsWordsize,
?loadSystemTotalMemory64,
?loadSystemUsedMemory64,
?loadLargestErlProcessUsedMemory64]),
IsInt = fun({value, Val}) when is_integer(Val) ->
true;
(_) ->
false
end,
NewValues = lists:filter(IsInt, Values),
case length(NewValues) of
10 ->
ok;
_ ->
ct:fail(value_not_integer)
end,
[{noValue,noSuchInstance}, {noValue,noSuchInstance},
{noValue,noSuchInstance}, {noValue,noSuchInstance},
{noValue,noSuchInstance}, {noValue,noSuchInstance},
{noValue,noSuchInstance}, {noValue,noSuchInstance},
{noValue,noSuchInstance}, {noValue,noSuchInstance},
{noValue,noSuchInstance}, {noValue,noSuchInstance}] =
os_mon_mib:load_table(get, [3, 102, 111, 111],
[?loadErlNodeName,
?loadSystemTotalMemory,
?loadSystemUsedMemory,
?loadLargestErlProcess,
?loadLargestErlProcessUsedMemory,
?loadCpuLoad,
?loadCpuLoad5,
?loadCpuLoad15,
?loadOsWordsize,
?loadSystemTotalMemory64,
?loadSystemUsedMemory64,
?loadLargestErlProcessUsedMemory64]),
ok.
%%---------------------------------------------------------------------
sys_tot_mem(Config) when is_list(Config) ->
[{[?loadSystemTotalMemory, Len | NodeStr], Mem}] =
os_mon_mib:load_table(get_next, [], [?loadSystemTotalMemory]),
Len = length(NodeStr),
true = lists:member(list_to_atom(NodeStr), [node() | nodes()]),
case Mem of
Mem when is_integer(Mem) ->
ok;
_ ->
ct:fail(sys_tot_mem_value_not_integer)
end.
sys_used_mem(Config) when is_list(Config) ->
[{[?loadSystemUsedMemory, Len | NodeStr], Mem}] =
os_mon_mib:load_table(get_next,[], [?loadSystemUsedMemory]),
Len = length(NodeStr),
true = lists:member(list_to_atom(NodeStr), [node() | nodes()]),
case Mem of
Mem when is_integer(Mem) ->
ok;
_ ->
ct:fail(sys_used_mem_value_not_integer)
end.
large_erl_process(Config) when is_list(Config) ->
{_, _, {Pid, _}} = memsup:get_memory_data(),
PidStr = lists:flatten(io_lib:format("~w", [Pid])),
[{[?loadLargestErlProcess, Len | NodeStr], PidStr}] =
os_mon_mib:load_table(get_next,[], [?loadLargestErlProcess]),
Len = length(NodeStr),
true = lists:member(list_to_atom(NodeStr), [node() | nodes()]),
ok.
large_erl_process_mem(Config) when is_list(Config) ->
[{[?loadLargestErlProcessUsedMemory, Len | NodeStr], Mem}] =
os_mon_mib:load_table(get_next,[],
[?loadLargestErlProcessUsedMemory]),
Len = length(NodeStr),
true = lists:member(list_to_atom(NodeStr), [node() | nodes()]),
case Mem of
Mem when is_integer(Mem) ->
ok;
_ ->
ct:fail(erl_pid_mem_value_not_integer)
end.
cpu_load(Config) when is_list(Config) ->
[{[?loadCpuLoad, Len | NodeStr], Load}] =
os_mon_mib:load_table(get_next,[], [?loadCpuLoad]),
Len = length(NodeStr),
true = lists:member(list_to_atom(NodeStr), [node() | nodes()]),
case Load of
Load when is_integer(Load) ->
ok;
_ ->
ct:fail(cpu_load_value_not_integer)
end.
cpu_load5(Config) when is_list(Config) ->
[{[?loadCpuLoad5, Len | NodeStr], Load}] =
os_mon_mib:load_table(get_next,[], [?loadCpuLoad5]),
Len = length(NodeStr),
true = lists:member(list_to_atom(NodeStr), [node() | nodes()]),
case Load of
Load when is_integer(Load) ->
ok;
_ ->
ct:fail(cpu_load5_value_not_integer)
end.
cpu_load15(Config) when is_list(Config) ->
[{[?loadCpuLoad15, Len | NodeStr], Load}] =
os_mon_mib:load_table(get_next,[], [?loadCpuLoad15]),
Len = length(NodeStr),
true = lists:member(list_to_atom(NodeStr), [node() | nodes()]),
case Load of
Load when is_integer(Load) ->
ok;
_ ->
ct:fail(cpu_load15_value_not_integer)
end.
os_wordsize(Config) when is_list(Config) ->
[{[?loadOsWordsize, Len | NodeStr], Wordsize}] =
os_mon_mib:load_table(get_next,[], [?loadOsWordsize]),
Len = length(NodeStr),
true = lists:member(list_to_atom(NodeStr), [node() | nodes()]),
case Wordsize of
Wordsize when is_integer(Wordsize) ->
ok;
_ ->
ct:fail(os_wordsize_value_not_integer)
end.
sys_tot_mem64(Config) when is_list(Config) ->
[{[?loadSystemTotalMemory64, Len | NodeStr], Mem}] =
os_mon_mib:load_table(get_next, [], [?loadSystemTotalMemory64]),
Len = length(NodeStr),
true = lists:member(list_to_atom(NodeStr), [node() | nodes()]),
case Mem of
Mem when is_integer(Mem) ->
ok;
_ ->
ct:fail(sys_tot_mem_value_not_integer)
end.
sys_used_mem64(Config) when is_list(Config) ->
[{[?loadSystemUsedMemory64, Len | NodeStr], Mem}] =
os_mon_mib:load_table(get_next,[], [?loadSystemUsedMemory64]),
Len = length(NodeStr),
true = lists:member(list_to_atom(NodeStr), [node() | nodes()]),
case Mem of
Mem when is_integer(Mem) ->
ok;
_ ->
ct:fail(sys_used_mem_value_not_integer)
end.
large_erl_process_mem64(Config) when is_list(Config) ->
[{[?loadLargestErlProcessUsedMemory64, Len | NodeStr], Mem}] =
os_mon_mib:load_table(get_next,[],
[?loadLargestErlProcessUsedMemory64]),
Len = length(NodeStr),
true = lists:member(list_to_atom(NodeStr), [node() | nodes()]),
case Mem of
Mem when is_integer(Mem) ->
ok;
_ ->
ct:fail(erl_pid_mem_value_not_integer)
end.
%%---------------------------------------------------------------------
%% Simulates get calls to test the instrumentation function
%% for the diskTable.
get_disk_table(Config) when is_list(Config) ->
DiskData = disksup:get_disk_data(),
DiskDataLen = length(DiskData),
if
DiskDataLen > 0 ->
[{value, Value}] =
os_mon_mib:disk_table(get, [1,1], [?diskDescr]),
case is_list(Value) of
true ->
ok;
false ->
ct:fail(value_not_a_string)
end,
Values = os_mon_mib:disk_table(get, [1,1],
[?diskId,
?diskKBytes,
?diskCapacity]),
IsInt = fun({value, Val}) when is_integer(Val) ->
true;
(_) ->
false
end,
NewValues = lists:filter(IsInt, Values),
case length(NewValues) of
3 ->
ok;
_ ->
ct:fail(value_not_integer)
end
end,
[{noValue,noSuchInstance}, {noValue,noSuchInstance},
{noValue,noSuchInstance}, {noValue,noSuchInstance}] =
os_mon_mib:disk_table(get, [1, DiskDataLen + 1], [?diskId,
?diskDescr,
?diskKBytes,
?diskCapacity]),
ok.
%%---------------------------------------------------------------------
disk_descr(Config) when is_list(Config) ->
[{[?diskDescr, 1,1], Descr}] =
os_mon_mib:disk_table(get_next, [], [?diskDescr]),
case Descr of
Descr when is_list(Descr) ->
ok;
_ ->
ct:fail(disk_descr_value_not_a_string)
end.
disk_kbytes(Config) when is_list(Config) ->
[{[?diskKBytes, 1,1], Kbytes}] =
os_mon_mib:disk_table(get_next,[], [?diskKBytes]),
case Kbytes of
Kbytes when is_integer(Kbytes) ->
ok;
_ ->
ct:fail(disk_kbytes_value_not_integer)
end.
disk_capacity(Config) when is_list(Config) ->
[{[?diskCapacity, 1,1], Capacity}] =
os_mon_mib:disk_table(get_next,[], [?diskCapacity]),
case Capacity of
Capacity when is_integer(Capacity) ->
ok;
_ ->
ct:fail(disk_capacity_value_not_integer)
end.
%%---------------------------------------------------------------------
%% Starts an snmp manager and sends a real snmp-request. i.e.
%% sends a udp message on the correct format.
real_snmp_request(Config) when is_list(Config) ->
NodStr = atom_to_list(node()),
Len = length(NodStr),
{_, _, {Pid, _}} = memsup:get_memory_data(),
PidStr = lists:flatten(io_lib:format("~w", [Pid])),
io:format("FOO: ~p~n", [PidStr]),
ok = snmp_get([?loadEntry ++
[?loadLargestErlProcess, Len | NodStr]],
PidStr),
ok = snmp_get_next([?loadEntry ++
[?loadSystemUsedMemory, Len | NodStr]],
?loadEntry ++ [?loadSystemUsedMemory + 1, Len
| NodStr], PidStr),
ok = snmp_set([?loadEntry ++ [?loadLargestErlProcess, Len | NodStr]],
s, "<0.101.0>", Config),
ok.
%% Starts an snmp manager and requests total memory. Was previously
%% integer32 which was errornous on 64 bit machines.
otp_7441(Config) when is_list(Config) ->
NodStr = atom_to_list(node()),
Len = length(NodStr),
Oids = [Oid|_] = [?loadEntry ++ [?loadSystemTotalMemory, Len | NodStr]],
{noError,0,[#varbind{oid = Oid, variabletype = 'Unsigned32'}]} =
ct_snmp:get_values(os_mon_mib_test, Oids, snmp_mgr_agent),
ok.
%%---------------------------------------------------------------------
%% Internal functions
%%---------------------------------------------------------------------
start_node() ->
Pa = filename:dirname(code:which(?MODULE)),
{ok,Node} = test_server:start_node(testnisse, slave, [{args, " -pa " ++ Pa}]),
Node.
stop_node(Node) ->
test_server:stop_node(Node).
del_dir(Dir) ->
io:format("Deleting: ~s~n",[Dir]),
{ok, Files} = file:list_dir(Dir),
FullPathFiles = lists:map(fun(File) -> filename:join(Dir, File) end,
Files),
lists:foreach(fun file:delete/1, FullPathFiles),
file:del_dir(Dir).
%%---------------------------------------------------------------------
snmp_get(Oids = [Oid |_], Result) ->
{noError,0,[#varbind{oid = Oid,
variabletype = 'OCTET STRING',
value = Result}]} =
ct_snmp:get_values(os_mon_mib_test, Oids, snmp_mgr_agent),
ok.
snmp_get_next(Oids, NextOid, Result) ->
{noError,0,[#varbind{oid = NextOid,
variabletype = 'OCTET STRING',
value = Result}]} =
ct_snmp:get_next_values(os_mon_mib_test, Oids, snmp_mgr_agent),
ok.
snmp_set(Oid, ValuType, Value, Config) ->
{notWritable, _, _} =
ct_snmp:set_values(os_mon_mib_test, [{Oid, ValuType, Value}],
snmp_mgr_agent, Config),
ok.
|