~ubuntu-branches/ubuntu/trusty/erlang/trusty

« back to all changes in this revision

Viewing changes to lib/snmp/test/snmp_manager_config_test.erl

  • Committer: Bazaar Package Importer
  • Author(s): Clint Byrum
  • Date: 2011-05-05 15:48:43 UTC
  • mfrom: (3.5.13 sid)
  • Revision ID: james.westby@ubuntu.com-20110505154843-0om6ekzg6m7ugj27
Tags: 1:14.b.2-dfsg-3ubuntu1
* Merge from debian unstable.  Remaining changes:
  - Drop libwxgtk2.8-dev build dependency. Wx isn't in main, and not
    supposed to.
  - Drop erlang-wx binary.
  - Drop erlang-wx dependency from -megaco, -common-test, and -reltool, they
    do not really need wx. Also drop it from -debugger; the GUI needs wx,
    but it apparently has CLI bits as well, and is also needed by -megaco,
    so let's keep the package for now.
  - debian/patches/series: Do what I meant, and enable build-options.patch
    instead.
* Additional changes:
  - Drop erlang-wx from -et
* Dropped Changes:
  - patches/pcre-crash.patch: CVE-2008-2371: outer level option with
    alternatives caused crash. (Applied Upstream)
  - fix for ssl certificate verification in newSSL: 
    ssl_cacertfile_fix.patch (Applied Upstream)
  - debian/patches/series: Enable native.patch again, to get stripped beam
    files and reduce the package size again. (build-options is what
    actually accomplished this)
  - Remove build-options.patch on advice from upstream and because it caused
    odd build failures.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
%% 
2
2
%% %CopyrightBegin%
3
 
%% 
4
 
%% Copyright Ericsson AB 2004-2009. All Rights Reserved.
5
 
%% 
 
3
%%
 
4
%% Copyright Ericsson AB 2004-2011. All Rights Reserved.
 
5
%%
6
6
%% The contents of this file are subject to the Erlang Public License,
7
7
%% Version 1.1, (the "License"); you may not use this file except in
8
8
%% compliance with the License. You should have received a copy of the
9
9
%% Erlang Public License along with this software. If not, it can be
10
10
%% retrieved online at http://www.erlang.org/.
11
 
%% 
 
11
%%
12
12
%% Software distributed under the License is distributed on an "AS IS"
13
13
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
14
14
%% the License for the specific language governing rights and limitations
15
15
%% under the License.
16
 
%% 
 
16
%%
17
17
%% %CopyrightEnd%
18
18
%% 
19
19
 
31
31
%%----------------------------------------------------------------------
32
32
%% Include files
33
33
%%----------------------------------------------------------------------
34
 
-include("test_server.hrl").
 
34
-include_lib("test_server/include/test_server.hrl").
35
35
-include("snmp_test_lib.hrl").
36
36
-include_lib("snmp/src/manager/snmpm_usm.hrl").
37
37
 
42
42
%% -compile(export_all).
43
43
 
44
44
-export([
45
 
         all/1, 
46
 
         init_per_testcase/2, fin_per_testcase/2,
 
45
        all/0,groups/0,init_per_group/2,end_per_group/2, 
 
46
         init_per_testcase/2, end_per_testcase/2,
47
47
 
48
 
         start_and_stop/1,
 
48
        
49
49
 
50
50
         simple_start_and_stop/1,
51
51
         start_without_mandatory_opts1/1,
58
58
         start_with_invalid_agents_conf_file1/1,
59
59
         start_with_invalid_usm_conf_file1/1,
60
60
 
61
 
         normal_op/1,
 
61
        
62
62
 
63
 
         system/1,
 
63
        
64
64
         simple_system_op/1,
65
65
 
66
 
         users/1,
 
66
        
67
67
         register_user_using_file/1,
68
68
         register_user_using_function/1,
69
69
         register_user_failed_using_function1/1,
70
70
 
71
 
         agents/1,
 
71
        
72
72
         register_agent_using_file/1,
73
73
         register_agent_using_function/1,
74
74
         register_agent_failed_using_function1/1,
75
75
 
76
 
         usm_users/1,
 
76
        
77
77
         register_usm_user_using_file/1,
78
78
         register_usm_user_using_function/1,
79
79
         register_usm_user_failed_using_function1/1,
80
80
         update_usm_user_info/1, 
81
81
 
82
 
         counter/1,
 
82
        
83
83
         create_and_increment/1,
84
84
 
85
 
         stats_counter/1,
 
85
        
86
86
         stats_create_and_increment/1,
87
87
 
88
 
         tickets/1,
89
 
         otp_7219/1
 
88
        
 
89
         otp_7219/1, 
 
90
         
 
91
         otp_8395_1/1, 
 
92
         otp_8395_2/1, 
 
93
         otp_8395_3/1, 
 
94
         otp_8395_4/1
90
95
 
91
96
        ]).
92
97
 
145
150
     {manager_log_dir,  MgrLogDir} | Config].
146
151
 
147
152
 
148
 
fin_per_testcase(Case, Config) when is_list(Config) ->
149
 
    p("fin_per_testcase -> Case: ~p", [Case]),
 
153
end_per_testcase(Case, Config) when is_list(Config) ->
 
154
    p("end_per_testcase -> Case: ~p", [Case]),
150
155
    %% The cleanup is removed due to some really discusting NFS behaviour...
151
156
    %% CaseTopDir = ?config(manager_dir, Config),
152
157
    %% ?line ok = ?DEL_DIR(CaseTopDir),
158
163
%%======================================================================
159
164
% all(doc) ->
160
165
%     "The top snmp manager config test case";
161
 
all(suite) ->
162
 
    [
163
 
     start_and_stop,
164
 
     normal_op,
165
 
     tickets
166
 
    ].
 
166
all() -> 
 
167
[{group, start_and_stop}, {group, normal_op},
 
168
 {group, tickets}].
 
169
 
 
170
groups() -> 
 
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]},
 
181
     {normal_op, [],
 
182
      [{group, system}, 
 
183
       {group, agents}, 
 
184
       {group, users},
 
185
       {group, usm_users}, 
 
186
       {group, counter},
 
187
       {group, stats_counter}]},
 
188
     {system, [], [simple_system_op]},
 
189
     {users, [],
 
190
      [register_user_using_file, 
 
191
       register_user_using_function,
 
192
       register_user_failed_using_function1]},
 
193
     {agents, [],
 
194
      [register_agent_using_file,
 
195
       register_agent_using_function,
 
196
       register_agent_failed_using_function1]},
 
197
     {usm_users, [],
 
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}]},
 
205
     {otp_8395, [],
 
206
      [otp_8395_1, otp_8395_2, otp_8395_3, otp_8395_4]}].
 
207
 
 
208
init_per_group(_GroupName, Config) ->
 
209
        Config.
 
210
 
 
211
end_per_group(_GroupName, Config) ->
 
212
        Config.
 
213
 
167
214
 
168
215
 
169
216
%%======================================================================
170
217
%% Test functions
171
218
%%======================================================================
172
219
 
173
 
start_and_stop(doc) ->
174
 
    "A collection of start and stop tests";
175
 
start_and_stop(suite) ->
176
 
    [
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
187
 
    ].
188
220
 
189
221
 
190
222
%% 
789
821
    p("start"),
790
822
    process_flag(trap_exit, true),
791
823
    ConfDir = ?config(manager_conf_dir, Conf),
792
 
    DbDir = ?config(manager_db_dir, Conf),
 
824
    DbDir   = ?config(manager_db_dir, Conf),
 
825
 
 
826
    verify_dir_existing(conf, ConfDir),
 
827
    verify_dir_existing(db,   DbDir),
793
828
 
794
829
    Opts = [{versions, [v1]}, 
795
830
            {config, [{verbosity, trace}, {dir, ConfDir}, {db_dir, DbDir}]}],
890
925
    p("start"),
891
926
    process_flag(trap_exit, true),
892
927
    ConfDir = ?config(manager_conf_dir, Conf),
893
 
    DbDir = ?config(manager_db_dir, Conf),
 
928
    DbDir   = ?config(manager_db_dir, Conf),
 
929
 
 
930
    verify_dir_existing(conf, ConfDir),
 
931
    verify_dir_existing(db,   DbDir),
894
932
 
895
933
    Opts = [{versions, [v1]}, 
896
934
            {config, [{verbosity, trace}, {dir, ConfDir}, {db_dir, DbDir}]}],
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(),
1496
1533
 
1497
1534
    %% --
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, 
 
1543
                               Usm57, 
 
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();
 
1550
        _ ->
 
1551
            %% This function is only present in version 2.0 or greater.
 
1552
            %% The crypto app no longer needs to be explicitly started
 
1553
            ok
 
1554
    end,
 
1555
    %% </CRYPTO-MODIFICATIONS>
1505
1556
 
1506
1557
    %% --
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(),
1588
1639
 
1589
1640
    %% --
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();
 
1654
        _ ->
 
1655
            %% This function is only present in version 2.0 or greater.
 
1656
            %% The crypto app no longer needs to be explicitly started
 
1657
            ok
 
1658
    end,
 
1659
    %% </CRYPTO-MODIFICATIONS>
1597
1660
 
1598
 
     %% --
 
1661
    %% --
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),
1611
1674
%% ---
1612
1675
%% 
1613
1676
 
1614
 
normal_op(doc) ->
1615
 
    "A collection of tests for normal operation";
1616
 
normal_op(suite) ->
1617
 
    [
1618
 
     system,
1619
 
     agents,
1620
 
     users,
1621
 
     usm_users,
1622
 
     counter,
1623
 
     stats_counter
1624
 
    ].
1625
1677
 
1626
1678
 
1627
1679
%% 
1628
1680
%% ---
1629
1681
%% 
1630
1682
 
1631
 
system(doc) ->
1632
 
    "Various system related operations with the snmp manager config";
1633
 
system(suite) ->
1634
 
    [
1635
 
     simple_system_op
1636
 
    ].
1637
1683
 
1638
1684
simple_system_op(suite) -> [];
1639
1685
simple_system_op(doc) -> 
1672
1718
%% ---
1673
1719
%% 
1674
1720
 
1675
 
users(doc) ->
1676
 
    "Various users related operations with the snmp manager config";
1677
 
users(suite) ->
1678
 
    [
1679
 
     register_user_using_file,
1680
 
     register_user_using_function,
1681
 
     register_user_failed_using_function1
1682
 
    ].
1683
1721
 
1684
1722
 
1685
1723
%% 
1734
1772
%% ---
1735
1773
%% 
1736
1774
 
1737
 
agents(doc) ->
1738
 
    "Various agents related operations with the snmp manager config";
1739
 
agents(suite) ->
1740
 
    [
1741
 
     register_agent_using_file,
1742
 
     register_agent_using_function,
1743
 
     register_agent_failed_using_function1
1744
 
    ].
1745
1775
 
1746
1776
 
1747
1777
%% 
1920
1950
%% ---
1921
1951
%% 
1922
1952
 
1923
 
usm_users(doc) ->
1924
 
    "Various USM users related operations with the snmp manager config";
1925
 
usm_users(suite) ->
1926
 
    [
1927
 
     register_usm_user_using_file,
1928
 
     register_usm_user_using_function,
1929
 
     register_usm_user_failed_using_function1,
1930
 
     update_usm_user_info
1931
 
    ].
1932
1953
 
1933
1954
 
1934
1955
%% 
2012
2033
    %% --
2013
2034
    p("done"),
2014
2035
    ok.
2015
 
%% ?SKIP(not_yet_implemented).
2016
2036
 
2017
2037
 
2018
2038
%% 
2178
2198
%% ---
2179
2199
%% 
2180
2200
 
2181
 
counter(doc) ->
2182
 
    "Various counter related operations with the snmp manager config";
2183
 
counter(suite) ->
2184
 
    [
2185
 
     create_and_increment
2186
 
    ].
2187
2201
 
2188
2202
 
2189
2203
%% 
2228
2242
%% ---
2229
2243
%% 
2230
2244
 
2231
 
stats_counter(doc) ->
2232
 
    "Various statistic counter related operations with the "
2233
 
        "snmp manager config";
2234
 
stats_counter(suite) ->
2235
 
    [
2236
 
     stats_create_and_increment
2237
 
    ].
2238
2245
 
2239
2246
 
2240
2247
%% 
2293
2300
%% Ticket test-cases
2294
2301
%%======================================================================
2295
2302
 
2296
 
tickets(suite) ->
2297
 
    [
2298
 
     otp_7219
2299
 
    ].
2300
2303
 
2301
2304
 
2302
2305
otp_7219(suite) ->
2347
2350
    ok.
2348
2351
 
2349
2352
 
 
2353
 
 
2354
 
 
2355
otp_8395_1(suite) -> [];
 
2356
otp_8395_1(doc) ->
 
2357
    "OTP-8395(1)";
 
2358
otp_8395_1(Conf) when is_list(Conf) ->
 
2359
    put(tname, otp_8395_1),
 
2360
    p("start"),
 
2361
    process_flag(trap_exit, true),
 
2362
    otp8395(Conf, false, ok),
 
2363
    ok.
 
2364
 
 
2365
otp_8395_2(suite) -> [];
 
2366
otp_8395_2(doc) ->
 
2367
    "OTP-8395(2)";
 
2368
otp_8395_2(Conf) when is_list(Conf) ->
 
2369
    put(tname, otp_8395_2),
 
2370
    p("start"),
 
2371
    process_flag(trap_exit, true),
 
2372
    otp8395(Conf, true, ok),
 
2373
    ok.
 
2374
 
 
2375
otp_8395_3(suite) -> [];
 
2376
otp_8395_3(doc) ->
 
2377
    "OTP-8395(3)";
 
2378
otp_8395_3(Conf) when is_list(Conf) ->
 
2379
    put(tname, otp_8395_3),
 
2380
    p("start"),
 
2381
    process_flag(trap_exit, true),
 
2382
    otp8395(Conf, gurka, error),
 
2383
    ok.
 
2384
 
 
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") ++ "/",
 
2390
    
 
2391
    write_manager_conf(ConfDir),
 
2392
    
 
2393
    %% Third set of options (no versions):
 
2394
    p("all options"),
 
2395
    NetIfOpts  = [{module,    snmpm_net_if}, 
 
2396
                  {verbosity, trace},
 
2397
                  {options,   [{recbuf,   30000},
 
2398
                               {bind_to,  false},
 
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")],
 
2405
    Prio = normal,
 
2406
    ATL  = [{type,   read_write}, 
 
2407
            {dir,    LogDir}, 
 
2408
            {size,   {10,10240}},
 
2409
            {repair, true},
 
2410
            {seqno,  SeqNoVal}],
 
2411
    Vsns = [v1,v2,v3],
 
2412
    Opts = [{config,          ConfigOpts},
 
2413
            {net_if,          NetIfOpts},
 
2414
            {server,          ServerOpts},
 
2415
            {note_store,      NoteStoreOpts},
 
2416
            {audit_trail_log, ATL},
 
2417
            {priority,        Prio}, 
 
2418
            {mibs,            Mibs},
 
2419
            {versions,        Vsns}],
 
2420
    
 
2421
    case config_start(Opts) of
 
2422
        {ok, _Pid} when (Expect =:= ok) ->
 
2423
            ?line ok = config_stop(),
 
2424
            ok;
 
2425
        {ok, _Pid} when (Expect =/= ok) ->
 
2426
            config_stop(),
 
2427
            exit({unexpected_started_config, SeqNoVal});
 
2428
        _Error when (Expect =/= ok) ->
 
2429
            ok; 
 
2430
        Error when (Expect =:= ok) ->
 
2431
            exit({unexpected_failed_starting_config, SeqNoVal, Error})
 
2432
    end,
 
2433
    p("done"),
 
2434
    ok.
 
2435
 
 
2436
 
 
2437
otp_8395_4(suite) -> [];
 
2438
otp_8395_4(doc) ->
 
2439
    "OTP-8395(4)";
 
2440
otp_8395_4(Conf) when is_list(Conf) ->
 
2441
    put(tname, otp_8395_4),
 
2442
    p("start"),
 
2443
    process_flag(trap_exit, true),
 
2444
 
 
2445
    snmp:print_version_info(),
 
2446
 
 
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") ++ "/",
 
2451
    
 
2452
    write_manager_conf(ConfDir),
 
2453
    
 
2454
    %% Third set of options (no versions):
 
2455
    p("all options"),
 
2456
    NetIfOpts  = [{module,    snmpm_net_if}, 
 
2457
                  {verbosity, trace},
 
2458
                  {options,   [{recbuf,   30000},
 
2459
                               {bind_to,  false},
 
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")],
 
2466
    Prio = normal,
 
2467
    ATL  = [{type,   read_write}, 
 
2468
            {dir,    LogDir}, 
 
2469
            {size,   {10,10240}},
 
2470
            {repair, true},
 
2471
            {seqno,  true}],
 
2472
    Vsns = [v1,v2,v3],
 
2473
    Opts = [{config,          ConfigOpts},
 
2474
            {net_if,          NetIfOpts},
 
2475
            {server,          ServerOpts},
 
2476
            {note_store,      NoteStoreOpts},
 
2477
            {audit_trail_log, ATL},
 
2478
            {priority,        Prio}, 
 
2479
            {mibs,            Mibs},
 
2480
            {versions,        Vsns}],
 
2481
    
 
2482
    ?line {ok, _Pid} = config_start(Opts),
 
2483
    
 
2484
    Counter   = otp_8395_4, 
 
2485
    Initial   = 10,
 
2486
    Increment = 2, 
 
2487
    Max       = 20,
 
2488
    
 
2489
    %% At this call the counter does *not* exist. The call creates
 
2490
    %% it with the initial value!
 
2491
 
 
2492
    Val1 = Initial, 
 
2493
    Val1 = otp8395_incr_counter(Counter, Initial, Increment, Max),
 
2494
 
 
2495
    %% Now it exist, make sure another call does the expected increment
 
2496
    
 
2497
    Val2 = Initial + Increment, 
 
2498
    Val2 = otp8395_incr_counter(Counter, Initial, Increment, Max),
 
2499
 
 
2500
    ?line ok = config_stop(),
 
2501
 
 
2502
    p("done"),
 
2503
    ok.
 
2504
    
 
2505
 
 
2506
otp8395_incr_counter(Counter, Initial, Increment, Max) ->
 
2507
    snmpm_config:increment_counter(Counter, Initial, Increment, Max).
 
2508
 
 
2509
 
2350
2510
%%======================================================================
2351
2511
%% Internal functions
2352
2512
%%======================================================================
2501
2661
 
2502
2662
 
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]),
2506
 
    file:close(Fd).
 
2664
    case file:open(filename:join(Dir, File), write) of
 
2665
        {ok, Fd} ->
 
2666
            ?line ok = io:format(Fd, "~s", [Str]),
 
2667
            file:close(Fd);
 
2668
        {error, Reason} ->
 
2669
            Info = 
 
2670
                [{dir, Dir, case (catch file:read_file_info(Dir)) of
 
2671
                                {ok, FI} -> 
 
2672
                                    FI;
 
2673
                                _ ->
 
2674
                                    undefined
 
2675
                            end},
 
2676
                 {file, File}], 
 
2677
            exit({failed_writing_conf_file, Info, Reason})
 
2678
    end.
 
2679
 
 
2680
 
 
2681
maybe_start_crypto() ->
 
2682
    case (catch crypto:version()) of
 
2683
        {'EXIT', {undef, _}} ->
 
2684
            %% This is the version of crypto before the NIFs...
 
2685
            ?CRYPTO_START();
 
2686
        _ ->
 
2687
            %% No need to start this version of crypto..
 
2688
            ok
 
2689
    end.
 
2690
 
 
2691
maybe_stop_crypto() ->
 
2692
    case (catch crypto:version()) of
 
2693
        {'EXIT', {undef, _}} ->
 
2694
            %% This is the version of crypto before the NIFs...
 
2695
            crypto:stop();
 
2696
        _ ->
 
2697
            %% There is nothing to stop in this version of crypto..
 
2698
            ok
 
2699
    end.
 
2700
 
 
2701
 
 
2702
%% ------
 
2703
 
 
2704
verify_dir_existing(DirName, Dir) ->
 
2705
    case file:read_file_info(Dir) of
 
2706
        {ok, _} ->
 
2707
            ok;
 
2708
        {error, Reason} ->
 
2709
            exit({non_existing_dir, DirName, Dir, Reason})
 
2710
    end.
2507
2711
 
2508
2712
 
2509
2713
%% ------