cisco_node_utils 1.0.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +4 -0
  3. data/.rubocop.yml +81 -1
  4. data/.travis.yml +9 -0
  5. data/CHANGELOG.md +72 -6
  6. data/CONTRIBUTING.md +32 -7
  7. data/README.md +70 -7
  8. data/Rakefile +17 -0
  9. data/bin/check_metric_limits.rb +109 -0
  10. data/bin/git/hooks/commit-msg/enforce_style +81 -0
  11. data/bin/git/hooks/hook_lib +108 -0
  12. data/bin/git/hooks/hooks-wrapper +38 -0
  13. data/bin/git/hooks/post-flow-hotfix-start/update-version +24 -0
  14. data/bin/git/hooks/post-flow-release-finish/update-version +29 -0
  15. data/bin/git/hooks/post-flow-release-start/update-version +19 -0
  16. data/bin/git/hooks/post-merge/update-hooks +6 -0
  17. data/bin/git/hooks/post-rewrite/update-hooks +6 -0
  18. data/bin/git/hooks/pre-commit/rubocop +20 -0
  19. data/bin/git/hooks/pre-commit/validate-diffs +31 -0
  20. data/bin/git/hooks/pre-push/check-changelog +24 -0
  21. data/bin/git/hooks/pre-push/rubocop +7 -0
  22. data/bin/git/update-hooks +65 -0
  23. data/cisco_node_utils.gemspec +9 -3
  24. data/docs/README-develop-best-practices.md +404 -0
  25. data/docs/README-develop-node-utils-APIs.md +215 -365
  26. data/docs/README-maintainers.md +33 -3
  27. data/docs/template-router.rb +89 -91
  28. data/docs/template-test_router.rb +52 -55
  29. data/lib/.rubocop.yml +18 -0
  30. data/lib/cisco_node_utils.rb +2 -19
  31. data/lib/cisco_node_utils/README_YAML.md +1 -9
  32. data/lib/cisco_node_utils/bgp.rb +664 -0
  33. data/lib/cisco_node_utils/bgp_af.rb +530 -0
  34. data/lib/cisco_node_utils/bgp_neighbor.rb +425 -0
  35. data/lib/cisco_node_utils/bgp_neighbor_af.rb +709 -0
  36. data/lib/cisco_node_utils/cisco_cmn_utils.rb +59 -25
  37. data/lib/cisco_node_utils/command_reference.rb +72 -74
  38. data/lib/cisco_node_utils/command_reference_common.yaml +174 -9
  39. data/lib/cisco_node_utils/command_reference_common_bgp.yaml +535 -0
  40. data/lib/cisco_node_utils/command_reference_n7k.yaml +4 -0
  41. data/lib/cisco_node_utils/command_reference_n9k.yaml +0 -9
  42. data/lib/cisco_node_utils/configparser_lib.rb +152 -147
  43. data/lib/cisco_node_utils/dns_domain.rb +79 -0
  44. data/lib/cisco_node_utils/domain_name.rb +71 -0
  45. data/lib/cisco_node_utils/interface.rb +167 -161
  46. data/lib/cisco_node_utils/interface_ospf.rb +78 -81
  47. data/lib/cisco_node_utils/name_server.rb +64 -0
  48. data/lib/cisco_node_utils/node.rb +154 -198
  49. data/lib/cisco_node_utils/node_util.rb +61 -0
  50. data/lib/cisco_node_utils/ntp_config.rb +65 -0
  51. data/lib/cisco_node_utils/ntp_server.rb +76 -0
  52. data/lib/cisco_node_utils/platform.rb +174 -165
  53. data/lib/cisco_node_utils/radius_global.rb +146 -0
  54. data/lib/cisco_node_utils/radius_server.rb +295 -0
  55. data/lib/cisco_node_utils/router_ospf.rb +59 -63
  56. data/lib/cisco_node_utils/router_ospf_vrf.rb +226 -210
  57. data/lib/cisco_node_utils/snmpcommunity.rb +52 -58
  58. data/lib/cisco_node_utils/snmpgroup.rb +22 -23
  59. data/lib/cisco_node_utils/snmpserver.rb +99 -103
  60. data/lib/cisco_node_utils/snmpuser.rb +294 -274
  61. data/lib/cisco_node_utils/syslog_server.rb +92 -0
  62. data/lib/cisco_node_utils/syslog_settings.rb +69 -0
  63. data/lib/cisco_node_utils/tacacs_server.rb +137 -133
  64. data/lib/cisco_node_utils/tacacs_server_host.rb +84 -87
  65. data/lib/cisco_node_utils/version.rb +2 -1
  66. data/lib/cisco_node_utils/vlan.rb +28 -31
  67. data/lib/cisco_node_utils/vrf.rb +80 -0
  68. data/lib/cisco_node_utils/vtp.rb +100 -97
  69. data/lib/cisco_node_utils/yum.rb +15 -17
  70. data/tests/.rubocop.yml +15 -0
  71. data/tests/basetest.rb +81 -36
  72. data/tests/ciscotest.rb +38 -78
  73. data/{lib/cisco_node_utils → tests}/platform_info.rb +12 -8
  74. data/{lib/cisco_node_utils → tests}/platform_info.yaml +1 -1
  75. data/tests/test_bgp_af.rb +920 -0
  76. data/tests/test_bgp_neighbor.rb +403 -0
  77. data/tests/test_bgp_neighbor_af.rb +589 -0
  78. data/tests/test_command_config.rb +65 -62
  79. data/tests/test_command_reference.rb +31 -45
  80. data/tests/test_dns_domain.rb +113 -0
  81. data/tests/test_domain_name.rb +86 -0
  82. data/tests/test_interface.rb +424 -548
  83. data/tests/test_interface_ospf.rb +248 -432
  84. data/tests/test_interface_svi.rb +56 -79
  85. data/tests/test_interface_switchport.rb +196 -272
  86. data/tests/test_name_server.rb +85 -0
  87. data/tests/test_node.rb +7 -6
  88. data/tests/test_node_ext.rb +133 -186
  89. data/tests/test_ntp_config.rb +49 -0
  90. data/tests/test_ntp_server.rb +74 -0
  91. data/tests/test_platform.rb +58 -37
  92. data/tests/test_radius_global.rb +78 -0
  93. data/tests/test_radius_server.rb +185 -0
  94. data/tests/test_router_bgp.rb +838 -0
  95. data/tests/test_router_ospf.rb +49 -80
  96. data/tests/test_router_ospf_vrf.rb +274 -392
  97. data/tests/test_snmpcommunity.rb +128 -172
  98. data/tests/test_snmpgroup.rb +12 -14
  99. data/tests/test_snmpserver.rb +160 -189
  100. data/tests/test_snmpuser.rb +568 -717
  101. data/tests/test_syslog_server.rb +88 -0
  102. data/tests/test_syslog_settings.rb +54 -0
  103. data/tests/test_tacacs_server.rb +113 -148
  104. data/tests/test_tacacs_server_host.rb +108 -161
  105. data/tests/test_vlan.rb +63 -79
  106. data/tests/test_vrf.rb +92 -0
  107. data/tests/test_vtp.rb +108 -126
  108. data/tests/test_yum.rb +47 -41
  109. metadata +92 -56
  110. data/.rubocop_todo.yml +0 -293
  111. data/docs/.rubocop.yml +0 -13
  112. data/docs/template-feature.rb +0 -45
  113. data/docs/template-test_feature.rb +0 -51
  114. data/tests/test_all_cisco.rb +0 -46
@@ -0,0 +1,838 @@
1
+ #!/usr/bin/env ruby
2
+ # RouterBgp Unit Tests
3
+ #
4
+ # Mike Wiebe, June, 2015
5
+ #
6
+ # Copyright (c) 2015 Cisco and/or its affiliates.
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+
20
+ require_relative 'ciscotest'
21
+ require_relative '../lib/cisco_node_utils/bgp'
22
+
23
+ # TestRouterBgp - Minitest for RouterBgp class
24
+ class TestRouterBgp < CiscoTestCase
25
+ def setup
26
+ # Disable feature bgp before each test to ensure we
27
+ # are starting with a clean slate for each test.
28
+ super
29
+ config('no feature bgp')
30
+ end
31
+
32
+ def get_routerbgp_match_line(as_number, vrf='default')
33
+ s = @device.cmd("show run | section '^router bgp .*'")
34
+ if vrf == 'default'
35
+ line = /router bgp\s#{as_number}/.match(s)
36
+ else
37
+ line = /vrf #{vrf}/.match(s)
38
+ end
39
+ line
40
+ end
41
+
42
+ def test_routerbgp_collection_empty
43
+ config('no feature bgp')
44
+ node.cache_flush
45
+ routers = RouterBgp.routers
46
+ assert_empty(routers, 'RouterBgp collection is not empty')
47
+ end
48
+
49
+ def test_routerbgp_collection_not_empty
50
+ config('feature bgp',
51
+ 'router bgp 55',
52
+ 'vrf blue',
53
+ 'vrf red',
54
+ 'vrf white')
55
+ routers = RouterBgp.routers
56
+ refute_empty(routers, 'RouterBgp collection is empty')
57
+ # validate the collection
58
+ routers.each do |asnum, vrfs|
59
+ line = get_routerbgp_match_line(asnum)
60
+ refute_nil(line)
61
+ vrfs.each_key do |name|
62
+ unless name == 'default'
63
+ line = get_routerbgp_match_line(asnum, name)
64
+ refute_nil(line)
65
+ end
66
+ end
67
+ end
68
+ end
69
+
70
+ def test_routerbgp_create_asnum_invalid
71
+ ['', 55.5, 'Fifty_Five'].each do |test|
72
+ assert_raises(ArgumentError, "#{test} not a valid asn") do
73
+ RouterBgp.new(test)
74
+ end
75
+ end
76
+ end
77
+
78
+ def test_routerbgp_create_vrf_invalid
79
+ ['', 55].each do |test|
80
+ assert_raises(ArgumentError, "#{test} not a valid vrf name") do
81
+ RouterBgp.new(88, test)
82
+ end
83
+ end
84
+ end
85
+
86
+ def test_routerbgp_create_vrfname_zero_length
87
+ asnum = 55
88
+ assert_raises(ArgumentError) do
89
+ RouterBgp.new(asnum, '')
90
+ end
91
+ end
92
+
93
+ def test_routerbgp_create_valid
94
+ asnum = 55
95
+ bgp = RouterBgp.new(asnum)
96
+ line = get_routerbgp_match_line(asnum)
97
+ refute_nil(line, "Error: 'router bgp #{asnum}' not configured")
98
+ bgp.destroy
99
+
100
+ vrf = 'wolfpack'
101
+ bgp = RouterBgp.new(asnum, vrf)
102
+ line = get_routerbgp_match_line(asnum, vrf)
103
+ refute_nil(line, "Error: 'router bgp #{asnum}' vrf '#{vrf}' not configured")
104
+ bgp.destroy
105
+ end
106
+
107
+ def test_routerbgp_create_valid_asn
108
+ [1, 4_294_967_295, '55', '1.0', '1.65535',
109
+ '65535.0', '65535.65535'].each do |test|
110
+ bgp = RouterBgp.new(test)
111
+ test = RouterBgp.dot_to_big(test.to_s) if test.is_a? String
112
+ line = get_routerbgp_match_line(test)
113
+ refute_nil(line, "Error: 'router bgp #{test}' not configured")
114
+ bgp.destroy
115
+
116
+ vrf = 'Duke'
117
+ bgp = RouterBgp.new(test, vrf)
118
+ test = RouterBgp.dot_to_big(test.to_s) if test.is_a? String
119
+ line = get_routerbgp_match_line(test, vrf)
120
+ refute_nil(line,
121
+ "Error: 'router bgp #{test}' vrf '#{vrf}' not configured")
122
+ bgp.destroy
123
+ end
124
+ end
125
+
126
+ def test_routerbgp_create_valid_no_feature
127
+ asnum = 55
128
+ bgp = RouterBgp.new(asnum)
129
+ line = get_routerbgp_match_line(asnum)
130
+ refute_nil(line, "Error: 'router bgp #{asnum}' not configured")
131
+ bgp.destroy
132
+
133
+ s = @device.cmd('show run all | no-more')
134
+ line = /"feature bgp"/.match(s)
135
+ assert_nil(line, "Error: 'feature bgp' still configured")
136
+ end
137
+
138
+ def test_routerbgp_create_invalid_multiple
139
+ asnum = 55
140
+ bgp1 = RouterBgp.new(asnum)
141
+ line = get_routerbgp_match_line(asnum)
142
+ refute_nil(line, "Error: 'router bgp #{asnum}' not configured")
143
+
144
+ # Only one bgp instance supported so try to create another.
145
+ assert_raises(RuntimeError) do
146
+ bgp2 = RouterBgp.new(88)
147
+ bgp2.destroy unless bgp2.nil?
148
+ end
149
+
150
+ bgp1.destroy
151
+ end
152
+
153
+ def test_routerbgp_get_asnum
154
+ asnum = 55
155
+ bgp = RouterBgp.new(asnum)
156
+ line = get_routerbgp_match_line(asnum)
157
+ asnum = line.to_s.split(' ').last.to_i
158
+ assert_equal(asnum, bgp.asnum,
159
+ 'Error: router asnum not correct')
160
+ bgp.destroy
161
+ end
162
+
163
+ def test_routerbgp_destroy
164
+ asnum = 55
165
+ bgp = RouterBgp.new(asnum)
166
+ bgp.destroy
167
+ line = get_routerbgp_match_line(asnum)
168
+ assert_nil(line, "Error: 'router bgp #{asnum}' not destroyed")
169
+ end
170
+
171
+ def test_routerbgp_set_get_bestpath
172
+ %w(test_default test_vrf).each do |t|
173
+ if t == 'test_default'
174
+ asnum = 55
175
+ vrf = 'default'
176
+ bgp = RouterBgp.new(asnum)
177
+ else
178
+ asnum = 99
179
+ vrf = 'yamllll'
180
+ bgp = RouterBgp.new(asnum, vrf)
181
+ end
182
+ bgp.bestpath_always_compare_med = true
183
+ assert(bgp.bestpath_always_compare_med, "vrf #{vrf}: "\
184
+ 'bgp bestpath_always_compare_med should be enabled')
185
+ bgp.bestpath_aspath_multipath_relax = true
186
+ assert(bgp.bestpath_aspath_multipath_relax, "vrf #{vrf}: "\
187
+ 'bgp bestpath_aspath_multipath_relax should be enabled')
188
+ bgp.bestpath_compare_routerid = true
189
+ assert(bgp.bestpath_compare_routerid, "vrf #{vrf}: "\
190
+ 'bgp bestpath_compare_routerid should be enabled')
191
+ bgp.bestpath_cost_community_ignore = true
192
+ assert(bgp.bestpath_cost_community_ignore, "vrf #{vrf}: "\
193
+ 'bgp bestpath_cost_community_ignore should be enabled')
194
+ bgp.bestpath_med_confed = true
195
+ assert(bgp.bestpath_med_confed, "vrf #{vrf}: "\
196
+ 'bgp bestpath_med_confed should be enabled')
197
+ bgp.bestpath_med_missing_as_worst = true
198
+ assert(bgp.bestpath_med_missing_as_worst, "vrf #{vrf}: "\
199
+ 'bgp bestpath_med_missing_as_worst should be enabled')
200
+ bgp.bestpath_med_non_deterministic = true
201
+ assert(bgp.bestpath_med_non_deterministic, "vrf #{vrf}: "\
202
+ 'bgp bestpath_med_non_deterministic should be enabled')
203
+
204
+ bgp.bestpath_always_compare_med = false
205
+ refute(bgp.bestpath_always_compare_med, "vrf #{vrf}: "\
206
+ 'bgp bestpath_always_compare_med should be disabled')
207
+ bgp.bestpath_aspath_multipath_relax = false
208
+ refute(bgp.bestpath_aspath_multipath_relax, "vrf #{vrf}: "\
209
+ 'bgp bestpath_aspath_multipath_relax should be disabled')
210
+ bgp.bestpath_compare_routerid = false
211
+ refute(bgp.bestpath_compare_routerid, "vrf #{vrf}: "\
212
+ 'bgp bestpath_compare_routerid should be disabled')
213
+ bgp.bestpath_cost_community_ignore = false
214
+ refute(bgp.bestpath_cost_community_ignore, "vrf #{vrf}: "\
215
+ 'bgp bestpath_cost_community_ignore should be disabled')
216
+ bgp.bestpath_med_confed = false
217
+ refute(bgp.bestpath_med_confed, "vrf #{vrf}: "\
218
+ 'bgp bestpath_med_confed should be disabled')
219
+ bgp.bestpath_med_missing_as_worst = false
220
+ refute(bgp.bestpath_med_missing_as_worst, "vrf #{vrf}: "\
221
+ 'bgp bestpath_med_missing_as_worst should be disabled')
222
+ bgp.bestpath_med_non_deterministic = false
223
+ refute(bgp.bestpath_med_non_deterministic, "vrf #{vrf}: "\
224
+ 'bgp bestpath_med_non_deterministic should be disabled')
225
+ bgp.destroy
226
+ end
227
+ end
228
+
229
+ def test_routerbgp_get_bestpath_not_configured
230
+ %w(test_default test_vrf).each do |t|
231
+ if t == 'test_default'
232
+ asnum = 55
233
+ vrf = 'default'
234
+ bgp = RouterBgp.new(asnum)
235
+ else
236
+ asnum = 99
237
+ vrf = 'yamllll'
238
+ bgp = RouterBgp.new(asnum, vrf)
239
+ end
240
+ refute(bgp.bestpath_always_compare_med, "vrf #{vrf}: "\
241
+ 'bgp bestpath_always_compare_med should *NOT* be enabled')
242
+ refute(bgp.bestpath_aspath_multipath_relax, "vrf #{vrf}: "\
243
+ 'bgp bestpath_aspath_multipath_relax should *NOT* be enabled')
244
+ refute(bgp.bestpath_compare_routerid, "vrf #{vrf}: "\
245
+ 'bgp bestpath_compare_routerid should be *NOT* enabled')
246
+ refute(bgp.bestpath_cost_community_ignore, "vrf #{vrf}: "\
247
+ 'bgp bestpath_cost_community_ignore should *NOT* be enabled')
248
+ refute(bgp.bestpath_med_confed, "vrf #{vrf}: "\
249
+ 'bgp bestpath_med_confed should *NOT* be enabled')
250
+ refute(bgp.bestpath_med_missing_as_worst, "vrf #{vrf}: "\
251
+ 'bgp bestpath_med_missing_as_worst should *NOT* be enabled')
252
+ refute(bgp.bestpath_med_non_deterministic, "vrf #{vrf}: "\
253
+ 'bgp bestpath_med_non_deterministic should *NOT* be enabled')
254
+ bgp.destroy
255
+ end
256
+ end
257
+
258
+ def test_routerbgp_default_bestpath
259
+ asnum = 55
260
+ bgp = RouterBgp.new(asnum)
261
+ refute(bgp.default_bestpath_always_compare_med,
262
+ 'default value for bestpath_always_compare_med should be false')
263
+ refute(bgp.default_bestpath_aspath_multipath_relax,
264
+ 'default value for bestpath_aspath_multipath_relax should be false')
265
+ refute(bgp.default_bestpath_compare_routerid,
266
+ 'default value for bestpath_compare_routerid should be false')
267
+ refute(bgp.default_bestpath_cost_community_ignore,
268
+ 'default value for bestpath_cost_community_ignore should be false')
269
+ refute(bgp.default_bestpath_med_confed,
270
+ 'default value for bestpath_med_confed should be false')
271
+ refute(bgp.default_bestpath_med_missing_as_worst,
272
+ 'default value for bestpath_med_missing_as_worst should be false')
273
+ refute(bgp.default_bestpath_med_non_deterministic,
274
+ 'default value for bestpath_med_non_deterministic should be false')
275
+ bgp.destroy
276
+ end
277
+
278
+ def test_routerbgp_set_get_cluster_id
279
+ %w(test_default test_vrf).each do |t|
280
+ if t == 'test_default'
281
+ asnum = 55
282
+ vrf = 'default'
283
+ bgp = RouterBgp.new(asnum)
284
+ else
285
+ asnum = 99
286
+ vrf = 'yamllll'
287
+ bgp = RouterBgp.new(asnum, vrf)
288
+ end
289
+ bgp.cluster_id = 34
290
+ assert_equal('34', bgp.cluster_id,
291
+ "vrf #{vrf}: bgp cluster_id should be set to '34'")
292
+ bgp.cluster_id = '1.2.3.4'
293
+ assert_equal('1.2.3.4', bgp.cluster_id,
294
+ "vrf #{vrf}: bgp cluster_id should be set to '1.2.3.4'")
295
+ bgp.cluster_id = ''
296
+ assert_empty(bgp.cluster_id,
297
+ "vrf #{vrf}: bgp cluster_id should *NOT* be configured")
298
+ bgp.destroy
299
+ end
300
+ end
301
+
302
+ def test_routerbgp_get_cluster_id_not_configured
303
+ asnum = 55
304
+ bgp = RouterBgp.new(asnum)
305
+ assert_empty(bgp.cluster_id,
306
+ 'bgp cluster_id should *NOT* be configured')
307
+ bgp.destroy
308
+ end
309
+
310
+ def test_routerbgp_default_cluster_id
311
+ asnum = 55
312
+ bgp = RouterBgp.new(asnum)
313
+ assert_empty(bgp.default_cluster_id,
314
+ 'bgp cluster_id default value should be empty')
315
+ bgp.destroy
316
+ end
317
+
318
+ def test_routerbgp_set_get_enforce_first_as
319
+ asnum = 55
320
+ bgp = RouterBgp.new(asnum)
321
+ bgp.enforce_first_as = true
322
+ assert(bgp.enforce_first_as,
323
+ 'bgp enforce-first-as should be enabled')
324
+ bgp.enforce_first_as = false
325
+ refute(bgp.enforce_first_as,
326
+ 'bgp enforce-first-as should be disabled')
327
+ bgp.destroy
328
+ end
329
+
330
+ def test_routerbgp_default_enforce_first_as
331
+ asnum = 55
332
+ bgp = RouterBgp.new(asnum)
333
+ assert(bgp.enforce_first_as,
334
+ 'bgp enforce-first-as value should be enabled = true')
335
+ bgp.destroy
336
+ end
337
+
338
+ def test_routerbgp_set_get_graceful_restart
339
+ %w(test_default test_vrf).each do |t|
340
+ if t == 'test_default'
341
+ asnum = 55
342
+ vrf = 'default'
343
+ bgp = RouterBgp.new(asnum)
344
+ else
345
+ asnum = 99
346
+ vrf = 'yamllll'
347
+ bgp = RouterBgp.new(asnum, vrf)
348
+ end
349
+ bgp.graceful_restart = true
350
+ assert(bgp.graceful_restart,
351
+ "vrf #{vrf}: bgp graceful restart should be enabled")
352
+ bgp.graceful_restart_timers_restart = 55
353
+ assert_equal(55, bgp.graceful_restart_timers_restart,
354
+ "vrf #{vrf}: bgp graceful restart timers restart" \
355
+ "should be set to '55'")
356
+ bgp.graceful_restart_timers_stalepath_time = 77
357
+ assert_equal(77, bgp.graceful_restart_timers_stalepath_time,
358
+ "vrf #{vrf}: bgp graceful restart timers stalepath time" \
359
+ "should be set to '77'")
360
+ bgp.graceful_restart_helper = true
361
+ assert(bgp.graceful_restart_helper,
362
+ "vrf #{vrf}: bgp graceful restart helper should be enabled")
363
+
364
+ bgp.graceful_restart = false
365
+ refute(bgp.graceful_restart,
366
+ "vrf #{vrf}: bgp graceful_restart should be disabled")
367
+ bgp.graceful_restart_timers_restart = 120
368
+ assert_equal(120, bgp.graceful_restart_timers_restart,
369
+ "vrf #{vrf}: bgp graceful restart timers restart" \
370
+ "should be set to default value of '120'")
371
+ bgp.graceful_restart_timers_stalepath_time = 300
372
+ assert_equal(300, bgp.graceful_restart_timers_stalepath_time,
373
+ "vrf #{vrf}: bgp graceful restart timers stalepath time" \
374
+ "should be set to default value of '300'")
375
+ bgp.graceful_restart_helper = false
376
+ refute(bgp.graceful_restart_helper,
377
+ "vrf #{vrf}: bgp graceful restart helper should be disabled")
378
+ bgp.destroy
379
+ end
380
+ end
381
+
382
+ def test_routerbgp_default_graceful_restart
383
+ asnum = 55
384
+ bgp = RouterBgp.new(asnum)
385
+ assert(bgp.default_graceful_restart,
386
+ 'bgp graceful restart default value should be enabled = true')
387
+ assert_equal(120, bgp.default_graceful_restart_timers_restart,
388
+ "bgp graceful restart default timer value should be '120'")
389
+ assert_equal(300, bgp.default_graceful_restart_timers_stalepath_time,
390
+ "bgp graceful restart default timer value should be '300'")
391
+ refute(bgp.default_graceful_restart_helper,
392
+ 'graceful restart helper default value should be enabled = false')
393
+ end
394
+
395
+ def test_routerbgp_set_get_confederation_id
396
+ %w(test_default test_vrf).each do |t|
397
+ if t == 'test_default'
398
+ asnum = 55
399
+ vrf = 'default'
400
+ bgp = RouterBgp.new(asnum)
401
+ else
402
+ asnum = 99
403
+ vrf = 'yamllll'
404
+ bgp = RouterBgp.new(asnum, vrf)
405
+ end
406
+ bgp.confederation_id = 77
407
+ assert_equal('77', bgp.confederation_id,
408
+ "vrf #{vrf}: bgp confederation_id should be set to '77'")
409
+ bgp.confederation_id = ''
410
+ assert_empty(bgp.confederation_id, "vrf #{vrf}: " \
411
+ 'bgp confederation_id should *NOT* be configured')
412
+ bgp.destroy
413
+ end
414
+ end
415
+
416
+ def test_routerbgp_set_get_confed_id_uu76828
417
+ asnum = 55
418
+ bgp = RouterBgp.new(asnum)
419
+ bgp.confederation_id = 55.77
420
+ assert_equal('55.77', bgp.confederation_id,
421
+ "bgp confederation_id should be set to '55.77'")
422
+ end
423
+
424
+ def test_routerbgp_get_confederation_id_not_configured
425
+ asnum = 55
426
+ bgp = RouterBgp.new(asnum)
427
+ assert_empty(bgp.confederation_id,
428
+ 'bgp confederation_id should *NOT* be configured')
429
+ bgp.destroy
430
+ end
431
+
432
+ def test_routerbgp_default_confederation_id
433
+ asnum = 55
434
+ bgp = RouterBgp.new(asnum)
435
+ assert_empty(bgp.default_confederation_id,
436
+ 'bgp confederation_id default value should be empty')
437
+ bgp.destroy
438
+ end
439
+
440
+ def test_routerbgp_set_get_confederation_peers
441
+ %w(test_default test_vrf).each do |t|
442
+ if t == 'test_default'
443
+ asnum = 55
444
+ vrf = 'default'
445
+ bgp = RouterBgp.new(asnum)
446
+ else
447
+ asnum = 99
448
+ vrf = 'yamllll'
449
+ bgp = RouterBgp.new(asnum, vrf)
450
+ end
451
+ # Confederation peer configuration requires that a
452
+ # confederation id be configured first so the expectation
453
+ # in the next test is an empty peer list
454
+ bgp.confederation_id = 55
455
+ assert_empty(bgp.confederation_peers,
456
+ "vrf #{vrf}: bgp confederation_peers list should be empty")
457
+ bgp.confederation_peers_set(15)
458
+ assert_equal('15', bgp.confederation_peers,
459
+ "vrf #{vrf}: bgp confederation_peers list should be '15'")
460
+ bgp.confederation_peers_set(16)
461
+ assert_equal('16', bgp.confederation_peers,
462
+ "vrf #{vrf}: bgp confederation_peers list should be '16'")
463
+ bgp.confederation_peers_set(55.77)
464
+ assert_equal('55.77', bgp.confederation_peers,
465
+ "vrf #{vrf}: bgp confederation_peers list should be" \
466
+ "'55.77'")
467
+ bgp.confederation_peers_set('15 16 55.77 18 555 299')
468
+ assert_equal('15 16 55.77 18 555 299',
469
+ bgp.confederation_peers,
470
+ "vrf #{vrf}: bgp confederation_peers list should be" \
471
+ "'15 16 55.77 18 555 299'")
472
+ bgp.confederation_peers_set('')
473
+ assert_empty(bgp.confederation_peers,
474
+ "vrf #{vrf}: bgp confederation_peers list should be empty")
475
+ bgp.destroy
476
+ end
477
+ end
478
+
479
+ def test_routerbgp_get_confederation_peers_not_configured
480
+ asnum = 55
481
+ bgp = RouterBgp.new(asnum)
482
+ assert_empty(bgp.confederation_peers,
483
+ 'bgp confederation_peers list should *NOT* be configured')
484
+ bgp.destroy
485
+ end
486
+
487
+ def test_routerbgp_default_confederation_peers
488
+ asnum = 55
489
+ bgp = RouterBgp.new(asnum)
490
+ assert_empty(bgp.default_confederation_peers,
491
+ 'bgp confederation_peers default value should be empty')
492
+ bgp.destroy
493
+ end
494
+
495
+ def test_routerbgp_set_get_log_neighbor_changes
496
+ %w(test_default test_vrf).each do |t|
497
+ if t == 'test_default'
498
+ asnum = 55
499
+ vrf = 'default'
500
+ bgp = RouterBgp.new(asnum)
501
+ else
502
+ asnum = 99
503
+ vrf = 'yamllll'
504
+ bgp = RouterBgp.new(asnum, vrf)
505
+ end
506
+ bgp.log_neighbor_changes = true
507
+ assert(bgp.log_neighbor_changes,
508
+ "vrf #{vrf}: bgp log_neighbor_changes should be enabled")
509
+ bgp.log_neighbor_changes = false
510
+ refute(bgp.log_neighbor_changes,
511
+ "vrf #{vrf}: bgp log_neighbor_changes should be disabled")
512
+ bgp.destroy
513
+ end
514
+ end
515
+
516
+ def test_routerbgp_get_log_neighbor_changes_not_configured
517
+ asnum = 55
518
+ bgp = RouterBgp.new(asnum)
519
+ refute(bgp.log_neighbor_changes,
520
+ 'bgp log_neighbor_changes should be disabled')
521
+ bgp.destroy
522
+ end
523
+
524
+ def test_routerbgp_default_log_neighbor_changes
525
+ asnum = 55
526
+ bgp = RouterBgp.new(asnum)
527
+ refute(bgp.default_log_neighbor_changes,
528
+ 'bgp log_neighbor_changes default value should be false')
529
+ bgp.destroy
530
+ end
531
+
532
+ def test_routerbgp_set_get_maxas_limit
533
+ %w(test_default test_vrf).each do |t|
534
+ if t == 'test_default'
535
+ asnum = 55
536
+ vrf = 'default'
537
+ bgp = RouterBgp.new(asnum)
538
+ else
539
+ asnum = 99
540
+ vrf = 'yamllll'
541
+ bgp = RouterBgp.new(asnum, vrf)
542
+ end
543
+ bgp.maxas_limit = 50
544
+ assert_equal(50, bgp.maxas_limit,
545
+ "vrf #{vrf}: bgp maxas-limit should be set to '50'")
546
+ bgp.maxas_limit = bgp.default_maxas_limit
547
+ assert_equal(bgp.default_maxas_limit, bgp.maxas_limit,
548
+ "vrf #{vrf}: bgp maxas-limit should be set to default value")
549
+ bgp.destroy
550
+ end
551
+ end
552
+
553
+ def test_routerbgp_default_maxas_limit
554
+ asnum = 55
555
+ bgp = RouterBgp.new(asnum)
556
+ assert_equal(bgp.default_maxas_limit, bgp.maxas_limit,
557
+ 'bgp maxas-limit should be default value')
558
+ bgp.destroy
559
+ end
560
+
561
+ def test_routerbgp_set_get_neighbor_fib_down_accelerate
562
+ %w(test_default test_vrf).each do |t|
563
+ if t == 'test_default'
564
+ asnum = 55
565
+ vrf = 'default'
566
+ bgp = RouterBgp.new(asnum)
567
+ else
568
+ asnum = 99
569
+ vrf = 'yamllll'
570
+ bgp = RouterBgp.new(asnum, vrf)
571
+ end
572
+ bgp.neighbor_fib_down_accelerate = true
573
+ assert(bgp.neighbor_fib_down_accelerate,
574
+ "vrf #{vrf}: bgp neighbor_fib_down_accelerate should be enabled")
575
+ bgp.neighbor_fib_down_accelerate = false
576
+ refute(bgp.neighbor_fib_down_accelerate,
577
+ "vrf #{vrf}: bgp neighbor_fib_down_accelerate should be disabled")
578
+ bgp.destroy
579
+ end
580
+ end
581
+
582
+ def test_routerbgp_get_neighbor_fib_down_accelerate_not_configured
583
+ asnum = 55
584
+ bgp = RouterBgp.new(asnum)
585
+ refute(bgp.neighbor_fib_down_accelerate,
586
+ 'bgp neighbor_fib_down_accelerate should be disabled')
587
+ bgp.destroy
588
+ end
589
+
590
+ def test_routerbgp_default_neighbor_fib_down_accelerate
591
+ asnum = 55
592
+ bgp = RouterBgp.new(asnum)
593
+ refute(bgp.default_neighbor_fib_down_accelerate,
594
+ 'bgp neighbor_fib_down_accelerate default value should be false')
595
+ bgp.destroy
596
+ end
597
+
598
+ def test_routerbgp_set_get_reconnect_interval
599
+ %w(test_default test_vrf).each do |t|
600
+ if t == 'test_default'
601
+ asnum = 55
602
+ vrf = 'default'
603
+ bgp = RouterBgp.new(asnum)
604
+ else
605
+ asnum = 99
606
+ vrf = 'yamllll'
607
+ bgp = RouterBgp.new(asnum, vrf)
608
+ end
609
+ bgp.reconnect_interval = 34
610
+ assert_equal(34, bgp.reconnect_interval,
611
+ "vrf #{vrf}: bgp reconnect_interval should be set to '34'")
612
+ bgp.reconnect_interval = 60
613
+ assert_equal(60, bgp.reconnect_interval,
614
+ "vrf #{vrf}: bgp reconnect_interval should be set to '60'")
615
+ bgp.destroy
616
+ end
617
+ end
618
+
619
+ def test_routerbgp_get_reconnect_interval_default
620
+ asnum = 55
621
+ bgp = RouterBgp.new(asnum)
622
+ assert_equal(60, bgp.reconnect_interval,
623
+ "reconnect_interval should be set to default value of '60'")
624
+ bgp.destroy
625
+ end
626
+
627
+ def test_routerbgp_set_get_router_id
628
+ %w(test_default test_vrf).each do |t|
629
+ if t == 'test_default'
630
+ asnum = 55
631
+ vrf = 'default'
632
+ bgp = RouterBgp.new(asnum)
633
+ else
634
+ asnum = 99
635
+ vrf = 'yamllll'
636
+ bgp = RouterBgp.new(asnum, vrf)
637
+ end
638
+ bgp.router_id = '1.2.3.4'
639
+ assert_equal('1.2.3.4', bgp.router_id,
640
+ "vrf #{vrf}: bgp router_id should be set to '1.2.3.4'")
641
+ bgp.router_id = ''
642
+ assert_empty(bgp.router_id,
643
+ "vrf #{vrf}: bgp router_id should *NOT* be configured")
644
+ bgp.destroy
645
+ end
646
+ end
647
+
648
+ def test_routerbgp_get_router_id_not_configured
649
+ asnum = 55
650
+ bgp = RouterBgp.new(asnum)
651
+ assert_empty(bgp.router_id,
652
+ 'bgp router_id should *NOT* be configured')
653
+ bgp.destroy
654
+ end
655
+
656
+ def test_routerbgp_default_router_id
657
+ asnum = 55
658
+ bgp = RouterBgp.new(asnum)
659
+ assert_empty(bgp.default_router_id,
660
+ 'bgp router_id default value should be empty')
661
+ bgp.destroy
662
+ end
663
+
664
+ def test_routerbgp_set_get_shutdown
665
+ # NOTE: Shutdown command only applies under
666
+ # default vrf
667
+ asnum = 55
668
+ bgp = RouterBgp.new(asnum)
669
+ bgp.shutdown = true
670
+ assert(bgp.shutdown, 'bgp should be shutdown')
671
+ bgp.shutdown = false
672
+ refute(bgp.shutdown, "bgp should in 'no shutdown' state")
673
+ bgp.destroy
674
+ end
675
+
676
+ def test_routerbgp_get_shutdown_not_configured
677
+ asnum = 55
678
+ bgp = RouterBgp.new(asnum)
679
+ refute(bgp.shutdown,
680
+ "bgp should be in 'no shutdown' state")
681
+ bgp.destroy
682
+ end
683
+
684
+ def test_routerbgp_default_shutdown
685
+ asnum = 55
686
+ bgp = RouterBgp.new(asnum)
687
+ refute(bgp.default_shutdown,
688
+ 'bgp shutdown default value should be false')
689
+ bgp.destroy
690
+ end
691
+
692
+ def test_routerbgp_set_get_suppress_fib_pending
693
+ %w(test_default test_vrf).each do |t|
694
+ if t == 'test_default'
695
+ asnum = 55
696
+ vrf = 'default'
697
+ bgp = RouterBgp.new(asnum)
698
+ else
699
+ asnum = 99
700
+ vrf = 'yamllll'
701
+ bgp = RouterBgp.new(asnum, vrf)
702
+ end
703
+ bgp.suppress_fib_pending = true
704
+ assert(bgp.suppress_fib_pending,
705
+ "vrf #{vrf}: bgp suppress_fib_pending should be enabled")
706
+ bgp.suppress_fib_pending = false
707
+ refute(bgp.suppress_fib_pending,
708
+ "vrf #{vrf}: bgp suppress_fib_pending should be disabled")
709
+ bgp.destroy
710
+ end
711
+ end
712
+
713
+ def test_routerbgp_get_suppress_fib_pending_not_configured
714
+ asnum = 55
715
+ bgp = RouterBgp.new(asnum)
716
+ refute(bgp.suppress_fib_pending,
717
+ 'bgp suppress_fib_pending should be disabled')
718
+ bgp.destroy
719
+ end
720
+
721
+ def test_routerbgp_default_suppress_fib_pending
722
+ asnum = 55
723
+ bgp = RouterBgp.new(asnum)
724
+ refute(bgp.default_suppress_fib_pending,
725
+ 'bgp suppress_fib_pending default value should be false')
726
+ bgp.destroy
727
+ end
728
+
729
+ def test_routerbgp_set_get_timer_bestpath_limit
730
+ %w(test_default test_vrf).each do |t|
731
+ if t == 'test_default'
732
+ asnum = 55
733
+ vrf = 'default'
734
+ bgp = RouterBgp.new(asnum)
735
+ else
736
+ asnum = 99
737
+ vrf = 'yamllll'
738
+ bgp = RouterBgp.new(asnum, vrf)
739
+ end
740
+ bgp.timer_bestpath_limit_set(34)
741
+ assert_equal(34, bgp.timer_bestpath_limit, "vrf #{vrf}: " \
742
+ "bgp timer_bestpath_limit should be set to '34'")
743
+ bgp.timer_bestpath_limit_set(300)
744
+ assert_equal(300, bgp.timer_bestpath_limit, "vrf #{vrf}: " \
745
+ "bgp timer_bestpath_limit should be set to '300'")
746
+ bgp.destroy
747
+ end
748
+ end
749
+
750
+ def test_routerbgp_get_timer_bestpath_limit_default
751
+ asnum = 55
752
+ bgp = RouterBgp.new(asnum)
753
+ assert_equal(300, bgp.timer_bestpath_limit,
754
+ "timer_bestpath_limit should be default value of '300'")
755
+ bgp.destroy
756
+ end
757
+
758
+ def test_routerbgp_set_get_timer_bestpath_limit_always
759
+ %w(test_default test_vrf).each do |t|
760
+ if t == 'test_default'
761
+ asnum = 55
762
+ vrf = 'default'
763
+ bgp = RouterBgp.new(asnum)
764
+ else
765
+ asnum = 99
766
+ vrf = 'yamllll'
767
+ bgp = RouterBgp.new(asnum, vrf)
768
+ end
769
+ bgp.timer_bestpath_limit_set(34, true)
770
+ assert(bgp.timer_bestpath_limit_always,
771
+ "vrf #{vrf}: bgp timer_bestpath_limit_always should be enabled")
772
+ bgp.timer_bestpath_limit_set(34, false)
773
+ refute(bgp.timer_bestpath_limit_always,
774
+ "vrf #{vrf}: bgp timer_bestpath_limit_always should be disabled")
775
+ bgp.destroy
776
+ end
777
+ end
778
+
779
+ def test_routerbgp_get_timer_bestpath_limit_always_not_configured
780
+ asnum = 55
781
+ bgp = RouterBgp.new(asnum)
782
+ refute(bgp.timer_bestpath_limit_always,
783
+ 'bgp timer_bestpath_limit_always should be disabled')
784
+ bgp.destroy
785
+ end
786
+
787
+ def test_routerbgp_default_timer_bestpath_limit_always
788
+ asnum = 55
789
+ bgp = RouterBgp.new(asnum)
790
+ refute(bgp.default_timer_bestpath_limit_always,
791
+ 'bgp timer_bestpath_limit_always default value should be false')
792
+ bgp.destroy
793
+ end
794
+
795
+ def test_routerbgp_set_get_timer_bgp_keepalive_hold
796
+ %w(test_default test_vrf).each do |t|
797
+ if t == 'test_default'
798
+ asnum = 55
799
+ vrf = 'default'
800
+ bgp = RouterBgp.new(asnum)
801
+ else
802
+ asnum = 99
803
+ vrf = 'yamllll'
804
+ bgp = RouterBgp.new(asnum, vrf)
805
+ end
806
+ bgp.timer_bgp_keepalive_hold_set(25, 45)
807
+ assert_equal(%w(25 45), bgp.timer_bgp_keepalive_hold, "vrf #{vrf}: " \
808
+ "keepalive and hold values should be '25 and 45'")
809
+ bgp.timer_bgp_keepalive_hold_set(60, 180)
810
+ assert_equal(%w(60 180), bgp.timer_bgp_keepalive_hold, "vrf #{vrf}: " \
811
+ "keepalive and hold values should be '60 and 180'")
812
+ assert_equal(60, bgp.timer_bgp_keepalive, "vrf #{vrf}: " \
813
+ "keepalive value should be '60'")
814
+ assert_equal(180, bgp.timer_bgp_holdtime, "vrf #{vrf}: " \
815
+ "keepalive value should be '180'")
816
+ bgp.timer_bgp_keepalive_hold_set(500, 3600)
817
+ assert_equal(%w(500 3600), bgp.timer_bgp_keepalive_hold, "vrf #{vrf}: " \
818
+ "keepalive and hold values should be '500 and 3600'")
819
+ assert_equal(500, bgp.timer_bgp_keepalive, "vrf #{vrf}: " \
820
+ "keepalive value should be '500'")
821
+ assert_equal(3600, bgp.timer_bgp_holdtime, "vrf #{vrf}: " \
822
+ "keepalive value should be '3600'")
823
+ bgp.destroy
824
+ end
825
+ end
826
+
827
+ def test_routerbgp_default_timer_keepalive_hold_default
828
+ asnum = 55
829
+ bgp = RouterBgp.new(asnum)
830
+ assert_equal(%w(60 180), bgp.default_timer_bgp_keepalive_hold,
831
+ 'bgp timer_bestpath_timer_keepalive_hold_default values ' \
832
+ "should be '60' and '180'")
833
+ assert_equal(%w(60 180), bgp.timer_bgp_keepalive_hold,
834
+ 'bgp timer_bestpath_timer_keepalive_hold_default should be' \
835
+ "set to default values of '60' and '180'")
836
+ bgp.destroy
837
+ end
838
+ end