158
163
%%======================================================================
160
165
% "The top snmp manager config test case";
167
[{group, start_and_stop}, {group, normal_op},
171
[{start_and_stop, [],
172
[simple_start_and_stop,
173
start_without_mandatory_opts1,
174
start_without_mandatory_opts2,
175
start_with_all_valid_opts, start_with_unknown_opts,
176
start_with_incorrect_opts,
177
start_with_invalid_manager_conf_file1,
178
start_with_invalid_users_conf_file1,
179
start_with_invalid_agents_conf_file1,
180
start_with_invalid_usm_conf_file1]},
187
{group, stats_counter}]},
188
{system, [], [simple_system_op]},
190
[register_user_using_file,
191
register_user_using_function,
192
register_user_failed_using_function1]},
194
[register_agent_using_file,
195
register_agent_using_function,
196
register_agent_failed_using_function1]},
198
[register_usm_user_using_file,
199
register_usm_user_using_function,
200
register_usm_user_failed_using_function1,
201
update_usm_user_info]},
202
{counter, [], [create_and_increment]},
203
{stats_counter, [], [stats_create_and_increment]},
204
{tickets, [], [otp_7219, {group, otp_8395}]},
206
[otp_8395_1, otp_8395_2, otp_8395_3, otp_8395_4]}].
208
init_per_group(_GroupName, Config) ->
211
end_per_group(_GroupName, Config) ->
169
216
%%======================================================================
170
217
%% Test functions
171
218
%%======================================================================
173
start_and_stop(doc) ->
174
"A collection of start and stop tests";
175
start_and_stop(suite) ->
177
simple_start_and_stop,
178
start_without_mandatory_opts1,
179
start_without_mandatory_opts2,
180
start_with_all_valid_opts,
181
start_with_unknown_opts,
182
start_with_incorrect_opts,
183
start_with_invalid_manager_conf_file1,
184
start_with_invalid_users_conf_file1,
185
start_with_invalid_agents_conf_file1,
186
start_with_invalid_usm_conf_file1
1439
1477
p("[test 54] write usm config file with invalid auth-key (4)"),
1440
1478
Usm54 = setelement(4, Usm51, "[1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,kalle]"),
1441
1479
write_usm_conf(ConfDir, [Usm54]),
1442
%% ?line ok = crypto:start(), %% Varf�r k�r den redan?
1443
?line crypto:start(), %% Make sure it's started...
1480
?line maybe_start_crypto(), %% Make sure it's started...
1444
1481
?line {error, Reason54} = config_start(Opts),
1445
?line ok = crypto:stop(),
1482
?line ok = maybe_stop_crypto(),
1446
1483
p("start failed (as expected): ~p", [Reason54]),
1447
1484
?line {failed_check, _, _, _, {invalid_auth_key, _}} = Reason54,
1448
1485
await_config_not_running(),
1487
1524
p("[test 59] write usm config file with invalid auth-key (9)"),
1488
1525
Usm59 = setelement(4, Usm57, "[1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,ka]"),
1489
1526
write_usm_conf(ConfDir, [Usm59]),
1490
?line ok = crypto:start(),
1527
?line ok = maybe_start_crypto(),
1491
1528
?line {error, Reason59} = config_start(Opts),
1492
?line ok = crypto:stop(),
1529
?line ok = maybe_stop_crypto(),
1493
1530
p("start failed (as expected): ~p", [Reason59]),
1494
1531
?line {failed_check, _, _, _, {invalid_auth_key, _}} = Reason59,
1495
1532
await_config_not_running(),
1498
p("[test 5A] write usm config file with valid auth-key when crypto not started (10)"),
1499
Usm5A = setelement(4, Usm57, "[1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0]"),
1500
write_usm_conf(ConfDir, [Usm5A]),
1501
?line {error, Reason5A} = config_start(Opts),
1502
p("start failed (as expected): ~p", [Reason5A]),
1503
?line {failed_check, _, _, _, {unsupported_crypto, _}} = Reason5A,
1504
await_config_not_running(),
1535
%% <CRYPTO-MODIFICATIONS>
1536
%% The crypto application do no longer need to be started
1537
%% explicitly (all of it is as of R14 implemented with NIFs).
1538
case (catch crypto:version()) of
1539
{'EXIT', {undef, _}} ->
1540
p("[test 5A] write usm config file with valid auth-key "
1541
"when crypto not started (10)"),
1542
Usm5A = setelement(4,
1544
"[1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0]"),
1545
write_usm_conf(ConfDir, [Usm5A]),
1546
?line {error, Reason5A} = config_start(Opts),
1547
p("start failed (as expected): ~p", [Reason5A]),
1548
?line {failed_check, _, _, _, {unsupported_crypto, _}} = Reason5A,
1549
await_config_not_running();
1551
%% This function is only present in version 2.0 or greater.
1552
%% The crypto app no longer needs to be explicitly started
1555
%% </CRYPTO-MODIFICATIONS>
1507
1558
p("[test 61] write usm config file with invalid priv-protocol (1)"),
1561
1612
p("[test 74] write usm config file with invalid priv-key (4)"),
1562
1613
Usm74 = setelement(6, Usm71, "[1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,kalle]"),
1563
1614
write_usm_conf(ConfDir, [Usm74]),
1564
?line ok = crypto:start(),
1615
?line ok = maybe_start_crypto(),
1565
1616
?line {error, Reason74} = config_start(Opts),
1566
?line ok = crypto:stop(),
1617
?line ok = maybe_stop_crypto(),
1567
1618
p("start failed (as expected): ~p", [Reason74]),
1568
1619
?line {failed_check, _, _, _, {invalid_priv_key, _}} = Reason74,
1569
1620
await_config_not_running(),
1587
1638
await_config_not_running(),
1590
p("[test 77] write usm config file with valid priv-key when crypto not started (7)"),
1591
Usm77 = setelement(6, Usm71, "[1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6]"),
1592
write_usm_conf(ConfDir, [Usm77]),
1593
?line {error, Reason77} = config_start(Opts),
1594
p("start failed (as expected): ~p", [Reason77]),
1595
?line {failed_check, _, _, _, {unsupported_crypto, _}} = Reason77,
1596
await_config_not_running(),
1641
%% <CRYPTO-MODIFICATIONS>
1642
%% The crypto application do no longer need to be started
1643
%% explicitly (all of it is as of R14 implemented with NIFs).
1644
case (catch crypto:version()) of
1645
{'EXIT', {undef, _}} ->
1646
p("[test 77] write usm config file with valid priv-key "
1647
"when crypto not started (7)"),
1648
Usm77 = setelement(6, Usm71, "[1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6]"),
1649
write_usm_conf(ConfDir, [Usm77]),
1650
?line {error, Reason77} = config_start(Opts),
1651
p("start failed (as expected): ~p", [Reason77]),
1652
?line {failed_check, _, _, _, {unsupported_crypto, _}} = Reason77,
1653
await_config_not_running();
1655
%% This function is only present in version 2.0 or greater.
1656
%% The crypto app no longer needs to be explicitly started
1659
%% </CRYPTO-MODIFICATIONS>
1599
1662
p("[test 78] write usm config file with invalid usm (1)"),
1600
1663
write_usm_conf2(ConfDir, "{\"bmkEngine\", \"swiusmcf\"}."),
1601
1664
?line {error, Reason81} = config_start(Opts),
2355
otp_8395_1(suite) -> [];
2358
otp_8395_1(Conf) when is_list(Conf) ->
2359
put(tname, otp_8395_1),
2361
process_flag(trap_exit, true),
2362
otp8395(Conf, false, ok),
2365
otp_8395_2(suite) -> [];
2368
otp_8395_2(Conf) when is_list(Conf) ->
2369
put(tname, otp_8395_2),
2371
process_flag(trap_exit, true),
2372
otp8395(Conf, true, ok),
2375
otp_8395_3(suite) -> [];
2378
otp_8395_3(Conf) when is_list(Conf) ->
2379
put(tname, otp_8395_3),
2381
process_flag(trap_exit, true),
2382
otp8395(Conf, gurka, error),
2385
otp8395(Conf, SeqNoVal, Expect) ->
2386
ConfDir = ?config(manager_conf_dir, Conf),
2387
DbDir = ?config(manager_db_dir, Conf),
2388
LogDir = ?config(manager_log_dir, Conf),
2389
StdMibDir = filename:join(code:priv_dir(snmp), "mibs") ++ "/",
2391
write_manager_conf(ConfDir),
2393
%% Third set of options (no versions):
2395
NetIfOpts = [{module, snmpm_net_if},
2397
{options, [{recbuf, 30000},
2399
{no_reuse, false}]}],
2400
ServerOpts = [{timeout, 10000}, {verbosity, trace}],
2401
NoteStoreOpts = [{timeout, 20000}, {verbosity, trace}],
2402
ConfigOpts = [{dir, ConfDir}, {verbosity, trace}, {db_dir, DbDir}],
2403
Mibs = [join(StdMibDir, "SNMP-NOTIFICATION-MIB"),
2404
join(StdMibDir, "SNMP-USER-BASED-SM-MIB")],
2406
ATL = [{type, read_write},
2412
Opts = [{config, ConfigOpts},
2413
{net_if, NetIfOpts},
2414
{server, ServerOpts},
2415
{note_store, NoteStoreOpts},
2416
{audit_trail_log, ATL},
2421
case config_start(Opts) of
2422
{ok, _Pid} when (Expect =:= ok) ->
2423
?line ok = config_stop(),
2425
{ok, _Pid} when (Expect =/= ok) ->
2427
exit({unexpected_started_config, SeqNoVal});
2428
_Error when (Expect =/= ok) ->
2430
Error when (Expect =:= ok) ->
2431
exit({unexpected_failed_starting_config, SeqNoVal, Error})
2437
otp_8395_4(suite) -> [];
2440
otp_8395_4(Conf) when is_list(Conf) ->
2441
put(tname, otp_8395_4),
2443
process_flag(trap_exit, true),
2445
snmp:print_version_info(),
2447
ConfDir = ?config(manager_conf_dir, Conf),
2448
DbDir = ?config(manager_db_dir, Conf),
2449
LogDir = ?config(manager_log_dir, Conf),
2450
StdMibDir = filename:join(code:priv_dir(snmp), "mibs") ++ "/",
2452
write_manager_conf(ConfDir),
2454
%% Third set of options (no versions):
2456
NetIfOpts = [{module, snmpm_net_if},
2458
{options, [{recbuf, 30000},
2460
{no_reuse, false}]}],
2461
ServerOpts = [{timeout, 10000}, {verbosity, trace}],
2462
NoteStoreOpts = [{timeout, 20000}, {verbosity, trace}],
2463
ConfigOpts = [{dir, ConfDir}, {verbosity, trace}, {db_dir, DbDir}],
2464
Mibs = [join(StdMibDir, "SNMP-NOTIFICATION-MIB"),
2465
join(StdMibDir, "SNMP-USER-BASED-SM-MIB")],
2467
ATL = [{type, read_write},
2473
Opts = [{config, ConfigOpts},
2474
{net_if, NetIfOpts},
2475
{server, ServerOpts},
2476
{note_store, NoteStoreOpts},
2477
{audit_trail_log, ATL},
2482
?line {ok, _Pid} = config_start(Opts),
2484
Counter = otp_8395_4,
2489
%% At this call the counter does *not* exist. The call creates
2490
%% it with the initial value!
2493
Val1 = otp8395_incr_counter(Counter, Initial, Increment, Max),
2495
%% Now it exist, make sure another call does the expected increment
2497
Val2 = Initial + Increment,
2498
Val2 = otp8395_incr_counter(Counter, Initial, Increment, Max),
2500
?line ok = config_stop(),
2506
otp8395_incr_counter(Counter, Initial, Increment, Max) ->
2507
snmpm_config:increment_counter(Counter, Initial, Increment, Max).
2350
2510
%%======================================================================
2351
2511
%% Internal functions
2352
2512
%%======================================================================
2503
2663
write_conf_file(Dir, File, Str) ->
2504
?line {ok, Fd} = file:open(filename:join(Dir, File), write),
2505
?line ok = io:format(Fd, "~s", [Str]),
2664
case file:open(filename:join(Dir, File), write) of
2666
?line ok = io:format(Fd, "~s", [Str]),
2670
[{dir, Dir, case (catch file:read_file_info(Dir)) of
2677
exit({failed_writing_conf_file, Info, Reason})
2681
maybe_start_crypto() ->
2682
case (catch crypto:version()) of
2683
{'EXIT', {undef, _}} ->
2684
%% This is the version of crypto before the NIFs...
2687
%% No need to start this version of crypto..
2691
maybe_stop_crypto() ->
2692
case (catch crypto:version()) of
2693
{'EXIT', {undef, _}} ->
2694
%% This is the version of crypto before the NIFs...
2697
%% There is nothing to stop in this version of crypto..
2704
verify_dir_existing(DirName, Dir) ->
2705
case file:read_file_info(Dir) of
2709
exit({non_existing_dir, DirName, Dir, Reason})