cisco_node_utils 0.9.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 (64) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +2 -0
  3. data/.rubocop.yml +3 -0
  4. data/.rubocop_todo.yml +293 -0
  5. data/CHANGELOG.md +5 -0
  6. data/CONTRIBUTING.md +31 -0
  7. data/Gemfile +4 -0
  8. data/LICENSE +201 -0
  9. data/README.md +113 -0
  10. data/Rakefile +4 -0
  11. data/cisco_node_utils.gemspec +30 -0
  12. data/lib/cisco_node_utils.rb +33 -0
  13. data/lib/cisco_node_utils/README_YAML.md +333 -0
  14. data/lib/cisco_node_utils/cisco_cmn_utils.rb +92 -0
  15. data/lib/cisco_node_utils/command_reference.rb +415 -0
  16. data/lib/cisco_node_utils/command_reference_common.yaml +845 -0
  17. data/lib/cisco_node_utils/command_reference_n3064.yaml +13 -0
  18. data/lib/cisco_node_utils/command_reference_n7k.yaml +48 -0
  19. data/lib/cisco_node_utils/command_reference_n9k.yaml +35 -0
  20. data/lib/cisco_node_utils/configparser_lib.rb +196 -0
  21. data/lib/cisco_node_utils/interface.rb +501 -0
  22. data/lib/cisco_node_utils/interface_ospf.rb +241 -0
  23. data/lib/cisco_node_utils/node.rb +673 -0
  24. data/lib/cisco_node_utils/platform.rb +184 -0
  25. data/lib/cisco_node_utils/platform_info.rb +58 -0
  26. data/lib/cisco_node_utils/platform_info.yaml +10 -0
  27. data/lib/cisco_node_utils/router_ospf.rb +96 -0
  28. data/lib/cisco_node_utils/router_ospf_vrf.rb +258 -0
  29. data/lib/cisco_node_utils/snmpcommunity.rb +91 -0
  30. data/lib/cisco_node_utils/snmpgroup.rb +55 -0
  31. data/lib/cisco_node_utils/snmpserver.rb +150 -0
  32. data/lib/cisco_node_utils/snmpuser.rb +342 -0
  33. data/lib/cisco_node_utils/tacacs_server.rb +175 -0
  34. data/lib/cisco_node_utils/tacacs_server_host.rb +128 -0
  35. data/lib/cisco_node_utils/version.rb +17 -0
  36. data/lib/cisco_node_utils/vlan.rb +153 -0
  37. data/lib/cisco_node_utils/vtp.rb +127 -0
  38. data/lib/cisco_node_utils/yum.rb +84 -0
  39. data/tests/basetest.rb +93 -0
  40. data/tests/ciscotest.rb +136 -0
  41. data/tests/cmd_config.yaml +51 -0
  42. data/tests/cmd_config_invalid.yaml +16 -0
  43. data/tests/test_all_cisco.rb +46 -0
  44. data/tests/test_command_config.rb +192 -0
  45. data/tests/test_command_reference.rb +222 -0
  46. data/tests/test_interface.rb +1017 -0
  47. data/tests/test_interface_ospf.rb +763 -0
  48. data/tests/test_interface_svi.rb +267 -0
  49. data/tests/test_interface_switchport.rb +722 -0
  50. data/tests/test_node.rb +108 -0
  51. data/tests/test_node_ext.rb +450 -0
  52. data/tests/test_platform.rb +188 -0
  53. data/tests/test_router_ospf.rb +164 -0
  54. data/tests/test_router_ospf_vrf.rb +753 -0
  55. data/tests/test_snmpcommunity.rb +344 -0
  56. data/tests/test_snmpgroup.rb +71 -0
  57. data/tests/test_snmpserver.rb +443 -0
  58. data/tests/test_snmpuser.rb +803 -0
  59. data/tests/test_tacacs_server.rb +388 -0
  60. data/tests/test_tacacs_server_host.rb +391 -0
  61. data/tests/test_vlan.rb +264 -0
  62. data/tests/test_vtp.rb +319 -0
  63. data/tests/test_yum.rb +106 -0
  64. metadata +188 -0
@@ -0,0 +1,188 @@
1
+ # Copyright (c) 2015 Cisco and/or its affiliates.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require File.expand_path("../ciscotest", __FILE__)
16
+ require File.expand_path("../../lib/cisco_node_utils/platform", __FILE__)
17
+
18
+ class TestPlatform < CiscoTestCase
19
+ def test_system_image
20
+ s = @device.cmd('show version | i image').scan(/ (\S+)$/).flatten.first
21
+ assert_equal(s, Platform.system_image)
22
+ end
23
+
24
+ def test_packages
25
+ # [['pack1', 'state1'], ['pack2', 'state2'], ...]
26
+ # 'state' should always be a variant of Active or Inactive
27
+ pkgs = @device.cmd('sh inst patch | no-more')
28
+ .scan(/\n(\S+)\s+(\S*[aA]ctive.*)\n/)
29
+ # convert to hash with key pkg_name and value pkg_state
30
+ pkg_hsh = {}
31
+ pkgs.each { |p| pkg_hsh[p[0]] = p[1].downcase }
32
+ assert_equal(pkg_hsh, Platform.packages)
33
+ end
34
+
35
+ def test_hardware_type
36
+ s = @device.cmd('sh ver | no-m').scan(/Hardware\n\s+(.*)\n/).flatten.first
37
+ # hardware type returns a different value depending on whether you use the
38
+ # ascii or show output of nxapi, but show appears to be substring of ascii
39
+ assert(s.include?(Platform.hardware_type),
40
+ "Expected '#{s}' to contain '#{Platform.hardware_type}'")
41
+ end
42
+
43
+ def test_cpu
44
+ s = @device.cmd('sh ver | no-m').scan(/Hardware\n\s+.*\n\s+(.*) with/).flatten.first
45
+ assert_equal(s, Platform.cpu)
46
+ end
47
+
48
+ def test_memory
49
+ arr = @device.cmd('sh sys reso').scan(/(\S+) total.* (\S+) used.* (\S+) free/).flatten
50
+ mem_hsh = { 'total' => arr[0],
51
+ 'used' => arr[1],
52
+ 'free' => arr[2], }
53
+ # used and free memory change rapidly, compare total and sums of free + used
54
+ assert_equal(mem_hsh['total'], Platform.memory['total'])
55
+ assert_equal(
56
+ mem_hsh['used'].to_i + mem_hsh['free'].to_i,
57
+ Platform.memory['used'].to_i + Platform.memory['free'].to_i
58
+ )
59
+ # assert(Platform.memory.has_key?('used'), "Platform memory has no key 'used'")
60
+ # assert(Platform.memory.has_key?('free'), "Platform memory has no key 'free'")
61
+ end
62
+
63
+ def test_board
64
+ s = @device.cmd('sh ver | no-m').scan(/Board ID (\S+)/).flatten.first
65
+ assert_equal(s, Platform.board)
66
+ end
67
+
68
+ def test_uptime
69
+ s = @device.cmd('sh ver | no-m').scan(/uptime is (.*)/).flatten.first
70
+ # compare without seconds
71
+ assert_equal(s.gsub(/\d+ sec/, ''), Platform.uptime.gsub(/\d+ sec/, ''))
72
+ end
73
+
74
+ def test_last_reset
75
+ s = @device.cmd('sh ver | no-m').scan(/usecs after\s+(.*)/).flatten.first
76
+ assert_equal(s, Platform.last_reset)
77
+ end
78
+
79
+ def test_reset_reason
80
+ s = @device.cmd('sh ver | no-m').scan(/Reason: (.*)/).flatten.first
81
+ assert_equal(s, Platform.reset_reason)
82
+ end
83
+
84
+ # switch#show inventory
85
+ # NAME: "Chassis", DESCR: "Nexus9000 C9396PX Chassis"
86
+ # PID: N9K-C9396PX , VID: V02 , SN: xxxxxxxxxxx
87
+ #
88
+ # NAME: "Slot 1", DESCR: "1/10G SFP+ Ethernet Module"
89
+ # PID: N9K-C9396PX , VID: V02 , SN: xxxxxxxxxxx
90
+ #
91
+ # NAME: "Slot 2", DESCR: "40G Ethernet Expansion Module"
92
+ # PID: N9K-M12PQ , VID: V01 , SN: xxxxxxxxxxx
93
+ # (...)
94
+ # NAME: "Power Supply 1", DESCR: "Nexus9000 C9396PX Chassis Power Supply"
95
+ # PID: N9K-PAC-650W , VID: V01 , SN: xxxxxxxxxxx
96
+ # (...)
97
+ # NAME: "Fan 1", DESCR: "Nexus9000 C9396PX Chassis Fan Module"
98
+ # PID: N9K-C9300-FAN2 , VID: V01 , SN: N/A
99
+ #
100
+ # Everything from DESCR onwards follows the same general format so we
101
+ # can define a single base regexp and extend it as needed for Chassis, Slot,
102
+ # Power Supply, and Fan inventory entries.
103
+ @@inv_cmn_re = /.*DESCR:\s+"(.*)"\s*\nPID:\s+(\S+).*VID:\s+(\S+).*SN:\s+(\S+)/
104
+
105
+ def test_chassis
106
+ arr = @device.cmd('sh inv | no-m').scan(/NAME:\s+"Chassis"#{@@inv_cmn_re}/)
107
+ arr = arr.flatten
108
+ # convert to hash
109
+ chas_hsh = { 'descr' => arr[0],
110
+ 'pid' => arr[1],
111
+ 'vid' => arr[2],
112
+ 'sn' => arr[3], }
113
+ assert_equal(chas_hsh, Platform.chassis)
114
+ end
115
+
116
+ def test_slots
117
+ slots_arr_arr = @device.cmd('sh inv | no-m')
118
+ .scan(/NAME:\s+"(Slot \d+)"#{@@inv_cmn_re}/)
119
+ # convert to array of slot hashes
120
+ slots_hsh_hsh = {}
121
+ slots_arr_arr.each { |slot|
122
+ slots_hsh_hsh[slot[0]] = { 'descr' => slot[1],
123
+ 'pid' => slot[2],
124
+ 'vid' => slot[3],
125
+ 'sn' => slot[4], }
126
+ }
127
+ assert_equal(slots_hsh_hsh, Platform.slots)
128
+ end
129
+
130
+ def test_power_supplies
131
+ pwr_arr_arr = @device.cmd('sh inv | no-m')
132
+ .scan(/NAME:\s+"(Power Supply \d+)"#{@@inv_cmn_re}/)
133
+ refute_empty(pwr_arr_arr, "Regex scan failed to match show inventory output")
134
+
135
+ # convert to array of power supply hashes
136
+ pwr_hsh_hsh = {}
137
+ pwr_arr_arr.each { |pwr|
138
+ pwr_hsh_hsh[pwr[0]] = { 'descr' => pwr[1],
139
+ 'pid' => pwr[2],
140
+ 'vid' => pwr[3],
141
+ 'sn' => pwr[4], }
142
+ }
143
+ assert_equal(pwr_hsh_hsh, Platform.power_supplies)
144
+ end
145
+
146
+ def test_fans
147
+ fan_arr_arr = @device.cmd('sh inv | no-m')
148
+ .scan(/NAME:\s+"(Fan \d+)"#{@@inv_cmn_re}/)
149
+ refute_empty(fan_arr_arr, "Regex scan failed to match show inventory output")
150
+
151
+ # convert to array of fan hashes
152
+ fan_hsh_hsh = {}
153
+ fan_arr_arr.each { |fan|
154
+ fan_hsh_hsh[fan[0]] = { 'descr' => fan[1],
155
+ 'pid' => fan[2],
156
+ 'vid' => fan[3],
157
+ 'sn' => fan[4], }
158
+ }
159
+ assert_equal(fan_hsh_hsh, Platform.fans)
160
+ end
161
+
162
+ def test_virtual_services
163
+ # this would be beyond ugly to parse from ascii, utilize config_get
164
+ vir_arr = node.config_get("virtual_service", "services")
165
+ vir_arr = [vir_arr] if vir_arr.is_a? Hash
166
+ # convert to expected format
167
+ vir_hsh_hsh = {}
168
+ unless vir_arr.nil?
169
+ vir_arr.each { |serv|
170
+ vir_hsh_hsh[serv['name']] = {
171
+ 'package_info' => { 'name' => serv['package_name'],
172
+ 'path' => serv['ova_path'], },
173
+ 'application' => { 'name' => serv['application_name'],
174
+ 'version' => serv['application_version'],
175
+ 'descr' => serv['application_description'], },
176
+ 'signing' => { 'key_type' => serv['key_type'],
177
+ 'method' => serv['signing_method'], },
178
+ 'licensing' => { 'name' => serv['licensing_name'],
179
+ 'version' => serv['licensing_version'], },
180
+ 'reservation' => { 'disk' => serv['disk_reservation'],
181
+ 'memory' => serv['memory_reservation'],
182
+ 'cpu' => serv['cpu_reservation'], },
183
+ }
184
+ }
185
+ end
186
+ assert_equal(vir_hsh_hsh, Platform.virtual_services)
187
+ end
188
+ end
@@ -0,0 +1,164 @@
1
+ # Copyright (c) 2014-2015 Cisco and/or its affiliates.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require File.expand_path("../ciscotest", __FILE__)
16
+ require File.expand_path("../../lib/cisco_node_utils/router_ospf", __FILE__)
17
+
18
+ class TestRouterOspf < CiscoTestCase
19
+ def routerospf_routers_destroy(routers)
20
+ routers.each { |name, router| router.destroy }
21
+ end
22
+
23
+ def get_routerospf_match_line(name)
24
+ s = @device.cmd("show run | include '^router ospf .*'")
25
+ cmd = "router ospf"
26
+ line = /#{cmd}\s#{name}/.match(s)
27
+ end
28
+
29
+ def test_routerospf_collection_empty
30
+ s = @device.cmd("configure terminal")
31
+ s = @device.cmd("no feature ospf")
32
+ s = @device.cmd("end")
33
+ node.cache_flush
34
+ routers = RouterOspf.routers
35
+ assert_equal(true, routers.empty?(),
36
+ "RouterOspf collection is not empty")
37
+ end
38
+
39
+ def test_routerospf_collection_not_empty
40
+ s = @device.cmd("configure terminal")
41
+ s = @device.cmd("feature ospf")
42
+ s = @device.cmd("router ospf TestOSPF")
43
+ s = @device.cmd("router ospf 100")
44
+ s = @device.cmd("end")
45
+ node.cache_flush
46
+ routers = RouterOspf.routers
47
+ assert_equal(false, routers.empty?(),
48
+ "RouterOspf collection is empty")
49
+ # validate the collection
50
+ routers.each do |name, router|
51
+ line = get_routerospf_match_line(name)
52
+ assert_equal(false, line.nil?)
53
+ end
54
+ routerospf_routers_destroy(routers)
55
+ routers=nil
56
+ end
57
+
58
+ def test_routerospf_create_name_zero_length
59
+ assert_raises(ArgumentError) do
60
+ ospf = RouterOspf.new("")
61
+ end
62
+ end
63
+
64
+ def test_routerospf_create_valid
65
+ name = "ospfTest"
66
+ ospf = RouterOspf.new(name)
67
+ line = get_routerospf_match_line(name)
68
+ # puts "cfg line: #{line}"
69
+ assert_equal(false, line.nil?,
70
+ "Error: 'router ospf ospfTest' not configured")
71
+ ospf.destroy
72
+ end
73
+
74
+ def test_routerospf_create_valid_no_feature
75
+ name = "ospfTest"
76
+ ospf = RouterOspf.new(name)
77
+ line = get_routerospf_match_line(name)
78
+ # puts "cfg line: #{line}"
79
+ assert_equal(false, line.nil?,
80
+ "Error: 'router ospf ospfTest' not configured")
81
+ ospf.destroy
82
+
83
+ s = @device.cmd("show run all | no-more")
84
+ cmd = "feature ospf"
85
+ line = /#{cmd}/.match(s)
86
+ assert_equal(true, line.nil?,
87
+ "Error: 'feature ospf' still configured")
88
+ end
89
+
90
+ def test_routerospf_create_valid_multiple
91
+ name = "ospfTest_1"
92
+ ospf_1 = RouterOspf.new(name)
93
+ line = get_routerospf_match_line(name)
94
+ # puts "cfg line: #{line}"
95
+ assert_equal(false, line.nil?,
96
+ "Error: 'router ospf ospfTest_1' not configured")
97
+
98
+ name = "ospfTest_2"
99
+ ospf_2 = RouterOspf.new(name)
100
+ line = get_routerospf_match_line(name)
101
+ # puts "cfg line: #{line}"
102
+ assert_equal(false, line.nil?,
103
+ "Error: 'router ospf ospfTest_1' not configured")
104
+
105
+ ospf_1.destroy
106
+ ospf_2.destroy
107
+ end
108
+
109
+ def test_routerospf_get_name
110
+ name = "ospfTest"
111
+ ospf = RouterOspf.new(name)
112
+ line = get_routerospf_match_line(name)
113
+ # puts "cfg line: #{line}"
114
+ name = line.to_s.split(" ").last
115
+ # puts "name from cli: #{name}"
116
+ # puts "name from get: #{routerospf.name}"
117
+ assert_equal(name, ospf.name,
118
+ "Error: router name not correct")
119
+ ospf.destroy
120
+ end
121
+
122
+ def test_routerospf_destroy
123
+ name = "ospfTest"
124
+ ospf = RouterOspf.new(name)
125
+ ospf.destroy
126
+ line = get_routerospf_match_line(name)
127
+ # puts "cfg line: #{line}"
128
+ assert_equal(true, line.nil?,
129
+ "Error: 'router ospf ospfTest' not destroyed")
130
+ end
131
+
132
+ def test_routerospf_create_valid_multiple_delete_one
133
+ name = "ospfTest_1"
134
+ ospf_1 = RouterOspf.new(name)
135
+ line = get_routerospf_match_line(name)
136
+ # puts "cfg line: #{line}"
137
+ assert_equal(false, line.nil?,
138
+ "Error: #{name}, not configured")
139
+
140
+ name = "ospfTest_2"
141
+ ospf_2 = RouterOspf.new(name)
142
+ line = get_routerospf_match_line(name)
143
+ # puts "cfg line: #{line}"
144
+ assert_equal(false, line.nil?,
145
+ "Error: #{name}, not configured")
146
+
147
+ ospf_1.destroy
148
+
149
+ # Remove one router then check that we only have one router left
150
+ routers = RouterOspf.routers
151
+ assert_equal(false, routers.empty?(),
152
+ "Error: RouterOspf collection is empty")
153
+ assert_equal(1, routers.size(),
154
+ "Error: RouterOspf collection is not one")
155
+ assert_equal(true, routers.key?(name),
156
+ "Error: #{name}, not found in the collection")
157
+ # validate the collection
158
+ line = get_routerospf_match_line(name)
159
+ assert_equal(false, line.nil?,
160
+ "Error: #{name}, instance not found")
161
+ ospf_2.destroy
162
+ routers = nil
163
+ end
164
+ end
@@ -0,0 +1,753 @@
1
+ # Copyright (c) 2014-2015 Cisco and/or its affiliates.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require File.expand_path("../ciscotest", __FILE__)
16
+ require File.expand_path("../../lib/cisco_node_utils/router_ospf", __FILE__)
17
+ require File.expand_path("../../lib/cisco_node_utils/router_ospf_vrf", __FILE__)
18
+
19
+ class TestRouterOspfVrf < CiscoTestCase
20
+ def setup
21
+ # Disable feature ospf before each test to ensure we
22
+ # are starting with a clean slate for each test.
23
+ super
24
+ @device.cmd("configure terminal")
25
+ @device.cmd("no feature ospf")
26
+ @device.cmd("end")
27
+ node.cache_flush
28
+ end
29
+
30
+ # @option routers [Cisco::RouterOspf] list of objects
31
+ def ospf_routers_destroy(routers)
32
+ routers.each { |name, router|
33
+ router.destroy
34
+ }
35
+ end
36
+
37
+ # @option vrfs [Cisco::RouterOspfVrf] list of objects
38
+ # @option routername [String] ospf instance name
39
+ def ospf_vrfs_destroy(vrfs, routername)
40
+ vrfs[routername].each { |name, vrf|
41
+ vrf.destroy if vrf.name != "default"
42
+ }
43
+ end
44
+
45
+ def get_routerospfvrf_match_line(router, vrfname)
46
+ s = @device.cmd("show run all | no-more")
47
+ cmd = "router ospf"
48
+ pattern = /#{cmd}\s#{router}/
49
+ # no match found, return nil
50
+ return nil if (md = pattern.match(s)).nil?
51
+
52
+ # match found but default vrf
53
+ return "default" if (vrfname == "default")
54
+
55
+ # assign post match
56
+ s = md.post_match
57
+ # non default case, check vf exist
58
+ s.each_line do | line |
59
+ next unless (/^\s+$/).match(line).nil?
60
+
61
+ # check whether we in 2 space
62
+ ml = (/^\s+(.*)/).match(line)
63
+ return nil if ml.nil?
64
+
65
+ # check wether we found vrf
66
+ ml = (/vrf\s#{vrfname}/).match(line)
67
+ return ml unless ml.nil?
68
+ end # s.each
69
+ end
70
+
71
+ def get_routerospfvrf_match_submode_line(router, vrfname, mtline)
72
+ s = @device.cmd("show run all | no-more")
73
+ cmd = "router ospf"
74
+ pattern = /#{cmd}\s#{router}/
75
+ vrf_found = false
76
+
77
+ # no match found, return nil
78
+ return nil if (md = pattern.match(s)).nil?
79
+ s = md.post_match
80
+ # match found, so loop through the config and
81
+ # find appropriate default or exact vrf
82
+ s.each_line do | line |
83
+ # if line is empty then move on to next line
84
+ next unless (/^\s+$/).match(line).nil?
85
+
86
+ # check whether we in 2 space
87
+ ml = (/^\s+(.*)/).match(line)
88
+ return nil if ml.nil?
89
+
90
+ # for default vrf we do not expect any vrfname present
91
+ # on the device, hence return nil.
92
+ if (vrfname == "default")
93
+ ml = (/vrf\s(.*)$/).match(line)
94
+ return nil unless ml.nil?
95
+ else
96
+ # for non-default vrf, find the match if not find one
97
+ if vrf_found == false
98
+ ml = (/vrf\s#{vrfname}/).match(line)
99
+ next if ml.nil?
100
+ vrf_found = true
101
+ else
102
+ # This is new vrf, hence return nil
103
+ ml = (/vrf\s(.*)$/).match(line)
104
+ return nil unless ml.nil?
105
+ end
106
+ end
107
+
108
+ # if match found then return line
109
+ ml = mtline.match(line)
110
+ return ml unless ml.nil?
111
+ end # s.each
112
+ end
113
+
114
+ def example_test_match_line
115
+ puts "vrf 1: #{get_routerospfvrf_match_line("ospfTest", "default")}"
116
+ puts "next vrf!!!!!!!!!!!!!"
117
+ puts "vrf 2: #{get_routerospfvrf_match_line("TestOSPF", "vrftest")}"
118
+ puts "next vrf!!!!!!!!!!!!!"
119
+ puts "vrf 3: #{get_routerospfvrf_match_line("TestOSPF", "testvrf")}"
120
+ puts "next vrf!!!!!!!!!!!!!"
121
+ puts "vrf 4: #{get_routerospfvrf_match_line("ospfTest", "testvrf")}"
122
+ end
123
+
124
+ def example_test_match_submode_line
125
+ pattern = (/\s+timers throttle lsa (.*)/)
126
+ puts "vrf submode timer lsa: #{get_routerospfvrf_match_submode_line("ospfTest", "default", pattern)}"
127
+ puts "vrf submode timer lsa: #{get_routerospfvrf_match_submode_line("TestOSPF", "vrftest1", pattern)}"
128
+ puts "vrf submode timer spf1: #{get_routerospfvrf_match_submode_line("ospftest", "vrftest", pattern)}"
129
+ pattern = (/\s+router-id (.*)/)
130
+ puts "vrf submode: #{get_routerospfvrf_match_submode_line("ospfTest", "testvrf", pattern)}"
131
+ end
132
+
133
+ def create_routerospf(ospfname="ospfTest")
134
+ routerospf = RouterOspf.new(ospfname)
135
+ end
136
+
137
+ def create_routerospfvrf(router="Wolfpack", name="default")
138
+ vrf = RouterOspfVrf.new(router, name)
139
+ end
140
+
141
+ def test_routerospfvrf_collection_size
142
+ create_routerospfvrf("green")
143
+ vrfs = RouterOspfVrf.vrfs
144
+ assert_equal(1, vrfs.size(),
145
+ "Error: Collection is not one")
146
+ create_routerospfvrf("green", "NC_State")
147
+ vrfs = RouterOspfVrf.vrfs
148
+ assert_equal(2, vrfs["green"].size(),
149
+ "Error: Collection is not two")
150
+ create_routerospfvrf("green", "Duke")
151
+ create_routerospfvrf("green", "Carolina")
152
+ vrfs = RouterOspfVrf.vrfs
153
+ assert_equal(4, vrfs["green"].size(),
154
+ "Error: Collection is not four")
155
+ ospf_routers_destroy(RouterOspf.routers)
156
+ vrfs = RouterOspfVrf.vrfs
157
+ assert_equal(0, vrfs.size(),
158
+ "Error: Collection is not zero")
159
+ end
160
+
161
+ def test_routerospfvrf_collection_not_empty_valid
162
+ ospf_h = Hash.new { |h, k| h[k] = {} }
163
+ ospf_h["ospfTest"] = {
164
+ :vrf => "default", :cov => 90,
165
+ :cot => RouterOspfVrf::OSPF_AUTO_COST[:mbps], :dm => 15000,
166
+ :id => "9.0.0.2", :l1=>130, :l2 => 530, :l3 => 1030, :s1 => 300,
167
+ :s2 => 600, :s3 => 1100
168
+ }
169
+ ospf_h["bxb300"] = {
170
+ :vrf => "default", :cov => 200,
171
+ :cot => RouterOspfVrf::OSPF_AUTO_COST[:mbps], :dm => 10000,
172
+ :id => "10.0.0.3", :l1=>130, :l2 => 530, :l3 => 1030, :s1 => 300,
173
+ :s2 => 600, :s3 => 1100
174
+ }
175
+ # pre-populate values
176
+ ospf_h.each do | k, v|
177
+ # Assuming all values are in hash
178
+ s = @device.cmd("configure terminal")
179
+ s = @device.cmd("feature ospf")
180
+ s = @device.cmd("router ospf #{k}")
181
+ s = @device.cmd("vrf #{v[:vrf]}")
182
+ s = @device.cmd("auto-cost reference-bandwidth #{v[:cov]}")
183
+ s = @device.cmd("default-metric #{v[:dm]}")
184
+ s = @device.cmd("router-id #{v[:id]}")
185
+ s = @device.cmd("timers throttle lsa #{v[:l1]} #{v[:l2]} #{v[:l3]}")
186
+ s = @device.cmd("timers throttle spf #{v[:s1]} #{v[:s2]} #{v[:s3]}")
187
+ s = @device.cmd("end")
188
+ node.cache_flush
189
+ end
190
+
191
+ routers = RouterOspf.routers
192
+ # validate the collection
193
+ routers.each do |routername, router|
194
+ vrfs = RouterOspfVrf.vrfs
195
+ refute_empty(vrfs, "Error: Collection is empty")
196
+ hv = ospf_h.fetch(routername.to_s)
197
+ next if hv.nil?
198
+ vrfs[routername].each do | name, vrf|
199
+ auto_cost_value = [] << hv[:cov] << hv[:cot]
200
+ assert_equal(hv[:vrf], vrf.name,
201
+ "Error: Collection, vrf name")
202
+ assert_equal(auto_cost_value, vrf.auto_cost,
203
+ "Error: Collection, auto cost")
204
+ assert_equal(hv[:dm], vrf.default_metric,
205
+ "Error: Collection, default metric")
206
+ assert_equal(hv[:id], vrf.router_id,
207
+ "Error: Collection, router id")
208
+ lsa = [] << hv[:l1] << hv[:l2] << hv[:l3]
209
+ assert_equal(lsa, vrf.timer_throttle_lsa,
210
+ "Error: Collection, timer throttle lsa")
211
+ spf = [] << hv[:s1] << hv[:s2] << hv[:s3]
212
+ assert_equal(spf, vrf.timer_throttle_spf,
213
+ "Error: Collection, timer throttle spf")
214
+ end
215
+ ospf_vrfs_destroy(vrfs, routername)
216
+ vrfs=nil
217
+ end
218
+ ospf_routers_destroy(routers)
219
+ routers=nil
220
+ end
221
+
222
+ def test_routerospfvrf_create_vrf_nil
223
+ assert_raises(TypeError) do
224
+ routerospf = RouterOspfVrf.new(nil, "testvrf")
225
+ end
226
+ end
227
+
228
+ def test_routerospfvrf_create_name_zero_length
229
+ routerospf = RouterOspf.new("testOspf")
230
+ assert_raises(ArgumentError) do
231
+ routerospfvrf = RouterOspfVrf.new("testOspf", "")
232
+ end
233
+ routerospf.destroy
234
+ end
235
+
236
+ def test_routerospfvrf_create_valid
237
+ ospfname = "ospfTest"
238
+ # routerospf = RouterOspf.new(ospfname)
239
+ vrfname = "default"
240
+ vrf = RouterOspfVrf.new(ospfname, vrfname)
241
+ line = get_routerospfvrf_match_line(ospfname, vrfname)
242
+ refute_nil(line, "Error: #{vrfname} vrf, does not exist in CLI")
243
+ assert_equal(vrfname, vrf.name,
244
+ "Error: #{vrfname} vrf, create failed")
245
+ vrf.parent.destroy
246
+ end
247
+
248
+ def test_routerospfvrf_get_parent_name
249
+ routerospf = create_routerospf
250
+ vrf = create_routerospfvrf(routerospf.name)
251
+ assert_equal(routerospf.name, vrf.parent.name,
252
+ "Error: Parent value is not correct")
253
+ routerospf.destroy
254
+ end
255
+
256
+ def test_routerospfvrf_get_name
257
+ vrfname = "default"
258
+ vrf = create_routerospfvrf("green")
259
+ line = get_routerospfvrf_match_line("green", vrfname)
260
+ assert_equal(vrfname, line,
261
+ "Error: #{vrfname} vrf,name mismatch")
262
+ assert_equal(vrfname, vrf.name,
263
+ "Error: #{vrfname} vrf, name get value mismatch")
264
+ vrf.parent.destroy
265
+ end
266
+
267
+ def test_routerospfvrf_destroy
268
+ vrfname = "default"
269
+ vrf = create_routerospfvrf
270
+ assert_raises(RuntimeError) do
271
+ vrf.destroy
272
+ end
273
+ line = get_routerospfvrf_match_line(vrf.parent.name, vrfname)
274
+ assert_equal(vrfname, line,
275
+ "Error: #{vrfname} vrf, destroy failed")
276
+ vrf.parent.destroy
277
+ end
278
+
279
+ def test_routerospfvrf_auto_cost
280
+ vrf = create_routerospfvrf
281
+ auto_cost_value = [400000, RouterOspfVrf::OSPF_AUTO_COST[:mbps]]
282
+ # set auto-cost
283
+ vrf.auto_cost_set(auto_cost_value[0], :mbps)
284
+ pattern = (/\s+auto-cost reference-bandwidth #{auto_cost_value[0]}/)
285
+ line = get_routerospfvrf_match_submode_line(vrf.parent.name,
286
+ vrf.name, pattern)
287
+ refute_nil(line, "Error: auto-cost, missing in CLI")
288
+ assert_equal(auto_cost_value, vrf.auto_cost,
289
+ "Error: auto-cost, get value mismatch")
290
+ vrf.parent.destroy
291
+ end
292
+
293
+ def test_routerospfvrf_auto_cost_multiple_vrf
294
+ routerospf = create_routerospf
295
+ vrf = create_routerospfvrf(routerospf.name)
296
+ vrf1 = create_routerospfvrf(routerospf.name, "testvrf")
297
+ auto_cost_value = [600000, RouterOspfVrf::OSPF_AUTO_COST[:mbps]]
298
+ # set auto-cost
299
+ vrf.auto_cost_set(auto_cost_value[0], :mbps)
300
+ pattern = (/\s+auto-cost reference-bandwidth #{auto_cost_value[0]}/)
301
+ line = get_routerospfvrf_match_submode_line(routerospf.name,
302
+ vrf.name, pattern)
303
+ refute_nil(line, "Error: #{vrf.name} vrf, auto-cost missing in CLI")
304
+ assert_equal(auto_cost_value, vrf.auto_cost,
305
+ "Error: #{vrf.name} vrf, auto-cost get value mismatch")
306
+
307
+ # vrf 1
308
+ auto_cost_value = [500000, RouterOspfVrf::OSPF_AUTO_COST[:mbps]]
309
+ pattern = (/\s+auto-cost reference-bandwidth #{auto_cost_value[0]}/)
310
+ # set cost
311
+ vrf1.auto_cost_set(auto_cost_value[0], :mbps)
312
+ line = get_routerospfvrf_match_submode_line(routerospf.name,
313
+ vrf1.name, pattern)
314
+ refute_nil(line, "Error: #{vrf1.name} vrf, auto-cost missing in CLI")
315
+ assert_equal(auto_cost_value, vrf1.auto_cost,
316
+ "Error: #{vrf1.name} vrf, auto-cost get value mismatch")
317
+ routerospf.destroy
318
+ end
319
+
320
+ def test_routerospfvrf_get_default_auto_cost
321
+ vrf = create_routerospfvrf
322
+ # NXOS specific
323
+ auto_cost_value = [40, RouterOspfVrf::OSPF_AUTO_COST[:gbps]]
324
+ assert_equal(auto_cost_value, vrf.default_auto_cost,
325
+ "Error: default auto-cost get value mismatch")
326
+ assert_equal(auto_cost_value, vrf.auto_cost,
327
+ "Error: auto-cost get value default mismatch")
328
+ vrf.parent.destroy
329
+ end
330
+
331
+ def test_routerospfvrf_default_metric
332
+ vrf = create_routerospfvrf
333
+ metric = 30000
334
+ vrf.default_metric = metric
335
+ pattern = (/\s+default-metric #{metric}/)
336
+ line = get_routerospfvrf_match_submode_line(vrf.parent.name,
337
+ vrf.name, pattern)
338
+ refute_nil(line, "Error: #{vrf.name} vrf, default-metric missing in CLI")
339
+ assert_equal(metric, vrf.default_metric,
340
+ "Error: #{vrf.name} vrf, default-metric get value mismatch")
341
+ # set default metric
342
+ vrf.default_metric = vrf.default_default_metric
343
+ line = get_routerospfvrf_match_submode_line(vrf.parent.name,
344
+ vrf.name, pattern)
345
+ assert_nil(line,
346
+ "Error: #{vrf.name}] vrf, default default-metric set failed")
347
+ vrf.parent.destroy
348
+ end
349
+
350
+ def test_routerospfvrf_default_metric_multiple_vrf
351
+ routerospf = create_routerospf
352
+ vrf = create_routerospfvrf(routerospf.name)
353
+ vrf1 = create_routerospfvrf(routerospf.name, "testvrf")
354
+ metric = 35000
355
+ # set metric
356
+ vrf.default_metric = metric
357
+ pattern = (/\s+default-metric #{metric}/)
358
+ line = get_routerospfvrf_match_submode_line(routerospf.name,
359
+ vrf.name, pattern)
360
+ refute_nil(line, "Error: #{vrf.name} vrf, default-metric missing in CLI")
361
+ assert_equal(metric, vrf.default_metric,
362
+ "Error: #{vrf.name} vrf, default-metric get value mismatch")
363
+
364
+ # vrf 1
365
+ metric = 25000
366
+ vrf1.default_metric = metric
367
+ pattern = (/\s+default-metric #{metric}/)
368
+ line = get_routerospfvrf_match_submode_line(routerospf.name,
369
+ vrf1.name, pattern)
370
+ refute_nil(line, "Error: #{vrf1.name} vrf, default-metric missing in CLI")
371
+ assert_equal(metric, vrf1.default_metric,
372
+ "Error: #{vrf1.name} vrf, default-metric get value mismatch")
373
+
374
+ routerospf.destroy
375
+ end
376
+
377
+ def test_routerospfvrf_log_adjacency_changes
378
+ vrf = create_routerospfvrf
379
+
380
+ assert_equal(:none, vrf.log_adjacency,
381
+ "Error: log-adjacency get value mismatch")
382
+
383
+ vrf.log_adjacency = :log
384
+ pattern = (/\s+log-adjacency-changes/)
385
+ line = get_routerospfvrf_match_submode_line(vrf.parent.name,
386
+ vrf.name, pattern)
387
+ refute_nil(line, "Error: log-adjacency missing in CLI")
388
+ assert_equal(:log, vrf.log_adjacency,
389
+ "Error: log-adjacency get value mismatch")
390
+
391
+ vrf.log_adjacency = :detail
392
+ pattern = (/\s+log-adjacency-changes detail/)
393
+ line = get_routerospfvrf_match_submode_line(vrf.parent.name,
394
+ vrf.name, pattern)
395
+ refute_nil(line,
396
+ "Error: #{vrf.name} vrf, log-adjacency detail missing in CLI")
397
+ assert_equal(:detail, vrf.log_adjacency,
398
+ "Error: #{vrf.name} vrf, log-adjacency detail get value mismatch")
399
+
400
+ # set default log adjacency
401
+ vrf.log_adjacency = vrf.default_log_adjacency
402
+ pattern = (/\s+log-adjacency-changes(.*)/)
403
+ line = get_routerospfvrf_match_submode_line(vrf.parent.name,
404
+ vrf.name, pattern)
405
+ assert_nil(line, "Error: #{vrf.name} vrf, default log-adjacency set failed")
406
+ vrf.parent.destroy
407
+ end
408
+
409
+ def test_routerospfvrf_log_adjacency_multiple_vrf
410
+ routerospf = create_routerospf
411
+ vrf = create_routerospfvrf(routerospf.name)
412
+ vrf1 = create_routerospfvrf(routerospf.name, "testvrf")
413
+ # set log_adjacency
414
+ vrf.log_adjacency = :log
415
+ pattern = (/\s+log-adjacency-changes/)
416
+ line = get_routerospfvrf_match_submode_line(routerospf.name,
417
+ vrf.name, pattern)
418
+
419
+ refute_nil(line, "Error: #{vrf.name} vrf, log-adjacency missing in CLI")
420
+ assert_equal(:log, vrf.log_adjacency,
421
+ "Error: #{vrf.name} vrf, log-adjacency get value mismatch")
422
+
423
+ # vrf 1
424
+ # set log_adjacency
425
+ vrf1.log_adjacency = :detail
426
+ pattern = (/\s+log-adjacency-changes/)
427
+ line = get_routerospfvrf_match_submode_line(routerospf.name,
428
+ vrf1.name, pattern)
429
+
430
+ refute_nil(line, "Error: #{vrf1.name} vrf, log-adjacency missing in CLI")
431
+ assert_equal(:detail, vrf1.log_adjacency,
432
+ "Error: #{vrf1.name} vrf, log-adjacency get value mismatch")
433
+
434
+ routerospf.destroy
435
+ end
436
+
437
+ def test_routerospfvrf_log_adjacency_multiple_vrf_2
438
+ routerospf = create_routerospf
439
+ vrf_default = create_routerospfvrf(routerospf.name)
440
+ vrf1 = create_routerospfvrf(routerospf.name, "testvrf")
441
+ # DO NOT set log_adjacency for default vrf
442
+ # DO set log_adjacency for non-default vrf
443
+ # set log_adjacency
444
+ vrf1.log_adjacency = :detail
445
+ pattern = (/\s+log-adjacency-changes/)
446
+ line = get_routerospfvrf_match_submode_line(routerospf.name,
447
+ vrf1.name, pattern)
448
+
449
+ refute_nil(line, "Error: #{vrf1.name} vrf, log-adjacency missing in CLI")
450
+ assert_equal(:detail, vrf1.log_adjacency,
451
+ "Error: #{vrf1.name} vrf, log-adjacency get value mismatch")
452
+
453
+ # Make sure default vrf is set to :none
454
+ assert_equal(:none, vrf_default.log_adjacency,
455
+ "Error: #{vrf_default.name} vrf_default, log-adjacency get value mismatch")
456
+
457
+ routerospf.destroy
458
+ end
459
+
460
+ def test_routerospfvrf_router_id
461
+ vrf = create_routerospfvrf
462
+ id = "8.1.1.3"
463
+ vrf.router_id = id
464
+ pattern = (/\s+router-id #{id}/)
465
+ line = get_routerospfvrf_match_submode_line(vrf.parent.name,
466
+ vrf.name, pattern)
467
+ refute_nil(line, "Error: #{vrf.name} vrf, router-id missing in CLI")
468
+ assert_equal(id, vrf.router_id,
469
+ "Error: #{vrf.name} vrf, router-id get value mismatch")
470
+ # set default router id
471
+ vrf.router_id = vrf.default_router_id
472
+ line = get_routerospfvrf_match_submode_line(vrf.parent.name,
473
+ vrf.name, pattern)
474
+ assert_nil(line, "Error: #{vrf.name} vrf, set default router-id failed")
475
+ vrf.parent.destroy
476
+ end
477
+
478
+ def test_routerospfvrf_router_id_multiple_vrf
479
+ routerospf = create_routerospf
480
+ vrf = create_routerospfvrf(routerospf.name)
481
+ vrf1 = create_routerospfvrf(routerospf.name, "testvrf")
482
+ id = "8.1.1.3"
483
+ # set id
484
+ vrf.router_id = id
485
+ pattern = (/\s+router-id #{id}/)
486
+ line = get_routerospfvrf_match_submode_line(routerospf.name,
487
+ vrf.name, pattern)
488
+ refute_nil(line, "Error: #{vrf.name} vrf, router-id missing in CLI")
489
+ assert_equal(id, vrf.router_id,
490
+ "Error: #{vrf.name} vrf, router-id get value mismatch")
491
+
492
+ # vrf 1
493
+ id = "10.1.1.3"
494
+ # set id
495
+ vrf1.router_id = id
496
+ pattern = (/\s+router-id #{id}/)
497
+ line = get_routerospfvrf_match_submode_line(routerospf.name,
498
+ vrf1.name, pattern)
499
+ refute_nil(line, "Error: #{vrf1.name} vrf, router-id missing in CLI")
500
+ assert_equal(id, vrf1.router_id,
501
+ "Error: #{vrf1.name} vrf, router-id get value mismatch")
502
+
503
+ routerospf.destroy
504
+ end
505
+
506
+ def test_routerospfvrf_timer_throttle_lsa
507
+ vrf = create_routerospfvrf
508
+ lsa = [] << 100 << 500 << 1000
509
+ vrf.timer_throttle_lsa_set(lsa[0], lsa[1], lsa[2])
510
+ # vrf.send(:timer_throttle_lsa=, lsa[0], lsa[1], lsa[2])
511
+ pattern = (/\s+timers throttle lsa #{lsa[0]} #{lsa[1]} #{lsa[2]}/)
512
+ line = get_routerospfvrf_match_submode_line(vrf.parent.name,
513
+ vrf.name, pattern)
514
+ refute_nil(line,
515
+ "Error: #{vrf.name} vrf, timer throttle lsa missing in CLI")
516
+ assert_equal(lsa, vrf.timer_throttle_lsa,
517
+ "Error: #{vrf.name} vrf, timer throttle lsa get values mismatch")
518
+ vrf.parent.destroy
519
+ end
520
+
521
+ def test_routerospfvrf_timer_throttle_lsa_multiple_vrf
522
+ routerospf = create_routerospf
523
+ vrf = create_routerospfvrf(routerospf.name)
524
+ vrf1 = create_routerospfvrf(routerospf.name, "testvrf")
525
+ lsa = [] << 100 << 500 << 1000
526
+ # set lsa
527
+ vrf.timer_throttle_lsa_set(lsa[0], lsa[1], lsa[2])
528
+ # vrf.send(:timer_throttle_lsa=, lsa[0], lsa[1], lsa[2])
529
+ pattern = (/\s+timers throttle lsa #{lsa[0]} #{lsa[1]} #{lsa[2]}/)
530
+ line = get_routerospfvrf_match_submode_line(routerospf.name,
531
+ vrf.name, pattern)
532
+ refute_nil(line,
533
+ "Error: #{vrf.name} vrf, timer throttle lsa missing in CLI")
534
+ assert_equal(lsa, vrf.timer_throttle_lsa,
535
+ "Error: #{vrf.name} vrf, timer throttle lsa get values mismatch")
536
+
537
+ lsa = [] << 300 << 700 << 2000
538
+ # set lsa
539
+ vrf1.timer_throttle_lsa_set(lsa[0], lsa[1], lsa[2])
540
+ # vrf1.send(:timer_throttle_lsa=, lsa[0], lsa[1], lsa[2])
541
+ pattern = (/\s+timers throttle lsa #{lsa[0]} #{lsa[1]} #{lsa[2]}/)
542
+ line = get_routerospfvrf_match_submode_line(routerospf.name,
543
+ vrf1.name, pattern)
544
+ refute_nil(line,
545
+ "Error: #{vrf1.name} vrf, timer throttle lsa missing in CLI")
546
+ assert_equal(lsa, vrf1.timer_throttle_lsa,
547
+ "Error: #{vrf1.name} vrf, timer throttle lsa get values mismatch")
548
+
549
+ routerospf.destroy
550
+ end
551
+
552
+ def test_routerospfvrf_get_default_timer_throttle_lsa
553
+ vrf = create_routerospfvrf
554
+ lsa = [0, 5000, 5000]
555
+ assert_equal(lsa[0], vrf.timer_throttle_lsa_start,
556
+ "Error: #{vrf.name} vrf, timer throttle lsa start not correct")
557
+ assert_equal(lsa[1], vrf.timer_throttle_lsa_hold,
558
+ "Error: #{vrf.name} vrf, timer throttle lsa hold not correct")
559
+ assert_equal(lsa[2], vrf.timer_throttle_lsa_max,
560
+ "Error: #{vrf.name} vrf, timer throttle lsa max not correct")
561
+ assert_equal(lsa[0], vrf.default_timer_throttle_lsa_start,
562
+ "Error: default timer throttle lsa start not correct")
563
+ assert_equal(lsa[1], vrf.default_timer_throttle_lsa_hold,
564
+ "Error: default timer throttle lsa hold not correct")
565
+ assert_equal(lsa[2], vrf.default_timer_throttle_lsa_max,
566
+ "Error: default timer throttle lsa max not correct")
567
+ vrf.parent.destroy
568
+ end
569
+
570
+ def test_routerospfvrf_timer_throttle_spf
571
+ vrf = create_routerospfvrf
572
+ spf = [250, 500, 1000]
573
+ # vrf.send(:timer_throttle_spf=, spf[0], spf[1], spf[2])
574
+ vrf.timer_throttle_spf_set(spf[0], spf[1], spf[2])
575
+ pattern = (/\s+timers throttle spf #{spf[0]} #{spf[1]} #{spf[2]}/)
576
+ line = get_routerospfvrf_match_submode_line(vrf.parent.name,
577
+ vrf.name, pattern)
578
+ refute_nil(line,
579
+ "Error: #{vrf.name} vrf, timer throttle spf missing in CLI")
580
+ assert_equal(spf, vrf.timer_throttle_spf,
581
+ "Error: #{vrf.name} vrf, timer throttle spf get values mismatch")
582
+ vrf.parent.destroy
583
+ end
584
+
585
+ def test_routerospfvrf_timer_throttle_spf_multiple_vrf
586
+ routerospf = create_routerospf
587
+ vrf = create_routerospfvrf(routerospf.name)
588
+ vrf1 = create_routerospfvrf(routerospf.name, "testvrf")
589
+ spf = [] << 250 << 500 << 1000
590
+ # set spf
591
+ vrf.timer_throttle_spf_set(spf[0], spf[1], spf[2])
592
+ # vrf.send(:timer_throttle_spf=, spf[0], spf[1], spf[2])
593
+ pattern = (/\s+timers throttle spf #{spf[0]} #{spf[1]} #{spf[2]}/)
594
+ line = get_routerospfvrf_match_submode_line(routerospf.name,
595
+ vrf.name, pattern)
596
+ refute_nil(line,
597
+ "Error: #{vrf.name} vrf, timer throttle spf missing in CLI")
598
+ assert_equal(spf, vrf.timer_throttle_spf,
599
+ "Error: #{vrf.name} vrf, timer throttle spf get values mismatch")
600
+
601
+ spf = [] << 300 << 700 << 2000
602
+ # set spf
603
+ vrf1.timer_throttle_spf_set(spf[0], spf[1], spf[2])
604
+ # vrf1.send(:timer_throttle_spf=, spf[0], spf[1], spf[2])
605
+ pattern = (/\s+timers throttle spf #{spf[0]} #{spf[1]} #{spf[2]}/)
606
+ line = get_routerospfvrf_match_submode_line(routerospf.name,
607
+ vrf1.name, pattern)
608
+ refute_nil(line,
609
+ "Error: #{vrf1.name} vrf, timer throttle spf missing in CLI")
610
+ assert_equal(spf, vrf1.timer_throttle_spf,
611
+ "Error: #{vrf1.name} vrf, timer throttle spf get values mismatch")
612
+
613
+ routerospf.destroy
614
+ end
615
+
616
+ def test_routerospfvrf_get_default_timer_throttle_spf
617
+ vrf = create_routerospfvrf
618
+ spf = [200, 1000, 5000]
619
+ assert_equal(spf[0], vrf.default_timer_throttle_spf_start,
620
+ "Error: default timer throttle spf not correct")
621
+ assert_equal(spf[1], vrf.default_timer_throttle_spf_hold,
622
+ "Error: default timer throttle hold not correct")
623
+ assert_equal(spf[2], vrf.default_timer_throttle_spf_max,
624
+ "Error: default timer throttle max not correct")
625
+ assert_equal(spf[0], vrf.timer_throttle_spf_start,
626
+ "Error: #{vrf.name} vrf, default timer throttle spf not correct")
627
+ assert_equal(spf[1], vrf.timer_throttle_spf_hold,
628
+ "Error: #{vrf.name} vrf, default timer throttle hold not correct")
629
+ assert_equal(spf[2], vrf.timer_throttle_spf_max,
630
+ "Error: #{vrf.name} vrf, default timer throttle max not correct")
631
+ vrf.parent.destroy
632
+ end
633
+
634
+ def test_routerospfvrf_create_valid_destroy_default
635
+ ospfname = "ospfTest"
636
+ routerospf = RouterOspf.new(ospfname)
637
+ vrfname = "default"
638
+ vrf = RouterOspfVrf.new(routerospf.name, vrfname)
639
+ line = get_routerospfvrf_match_line(ospfname, vrfname)
640
+ refute_nil(line, "Error: #{vrfname} vrf, does not exist in CLI")
641
+ assert_equal(vrfname, vrf.name,
642
+ "Error: #{vrfname} vrf, create failed")
643
+ assert_raises(RuntimeError) do
644
+ vrf.destroy
645
+ end
646
+ routerospf.destroy
647
+ end
648
+
649
+ def test_routerospfvrf_collection_router_multi_vrfs
650
+ ospf_h = Hash.new { |h, k| h[k] = {} }
651
+ ospf_h["ospfTest"] = {
652
+ "default" => {
653
+ :vrf => "default", :cov => 90,
654
+ :cot => RouterOspfVrf::OSPF_AUTO_COST[:mbps], :dm => 15000,
655
+ :id => "9.0.0.2", :l1=>130, :l2 => 530, :l3 => 1030, :s1 => 300,
656
+ :s2 => 600, :s3 => 1100
657
+ },
658
+ }
659
+
660
+ ospf_h["bxb300"] = {
661
+ "default" => {
662
+ :vrf => "default", :cov =>200,
663
+ :cot => RouterOspfVrf::OSPF_AUTO_COST[:mbps], :dm => 10000,
664
+ :id => "10.0.0.3", :l1=>130, :l2 => 530, :l3 => 1030, :s1 => 300,
665
+ :s2 => 600, :s3 => 1100
666
+ },
667
+ "nondefault" => {
668
+ :vrf => "nondefault", :cov => 300,
669
+ :cot => RouterOspfVrf::OSPF_AUTO_COST[:mbps], :dm => 30000,
670
+ :id => "10.0.0.4", :l1=>230, :l2 => 730, :l3 => 2030, :s1 => 400,
671
+ :s2 => 700, :s3 => 2100
672
+ }
673
+ }
674
+
675
+ s = @device.cmd("configure terminal")
676
+ s = @device.cmd("feature ospf")
677
+ s = @device.cmd("end")
678
+ # pre-populate values
679
+ ospf_h.each do | k, v|
680
+ # Assuming all values are in hash
681
+ s = @device.cmd("configure terminal")
682
+ s = @device.cmd("router ospf #{k}")
683
+ v.each do | k1, v1|
684
+ # puts "!!!!!k1: v1 vrf: #{k1} : !!!#{v1[:vrf]}"
685
+ s = @device.cmd("vrf #{v1[:vrf]}") if (k1 != "default")
686
+ s = @device.cmd("auto-cost reference-bandwidth #{v1[:cov]}")
687
+ s = @device.cmd("default-metric #{v1[:dm]}")
688
+ s = @device.cmd("router-id #{v1[:id]}")
689
+ s = @device.cmd("timers throttle lsa #{v1[:l1]} #{v1[:l2]} #{v1[:l3]}")
690
+ s = @device.cmd("timers throttle spf #{v1[:s1]} #{v1[:s2]} #{v1[:s3]}")
691
+ s = @device.cmd("exit") if (k1 != "default")
692
+ end
693
+ s = @device.cmd("end")
694
+ end
695
+ node.cache_flush
696
+
697
+ routers = RouterOspf.routers
698
+ # validate the collection
699
+ routers.each do |routername, router|
700
+ vrfs = RouterOspfVrf.vrfs
701
+ refute_empty(vrfs, "Error: Collection is empty")
702
+ puts "%Error: ospf_h does not have hash key #{routername}" unless ospf_h.key?(routername)
703
+ ospfh = ospf_h.fetch(routername)
704
+ vrfs[routername].each do | name, vrf|
705
+ puts "%Error: hash key #{routername} not found" unless ospfh.key?(name)
706
+ hv = ospfh.fetch(name)
707
+ auto_cost_value = [] << hv[:cov] << hv[:cot]
708
+ assert_equal(hv[:vrf], vrf.name,
709
+ "Error: Collection, vrf name")
710
+ assert_equal(auto_cost_value, vrf.auto_cost,
711
+ "Error: Collection, auto cost")
712
+ assert_equal(hv[:dm], vrf.default_metric,
713
+ "Error: Collection, default metric")
714
+ assert_equal(hv[:id], vrf.router_id,
715
+ "Error: Collection, router id")
716
+ lsa = [] << hv[:l1] << hv[:l2] << hv[:l3]
717
+ assert_equal(lsa, vrf.timer_throttle_lsa,
718
+ "Error: Collection, timer throttle lsa")
719
+ spf = [] << hv[:s1] << hv[:s2] << hv[:s3]
720
+ assert_equal(spf, vrf.timer_throttle_spf,
721
+ "Error: Collection, timer throttle spf")
722
+ end
723
+ ospf_vrfs_destroy(vrfs, routername)
724
+ vrfs=nil
725
+ end
726
+ ospf_routers_destroy(routers)
727
+ routers=nil
728
+ end
729
+
730
+ def test_routerospfvrf_timer_throttle_lsa_start_hold_max
731
+ vrf = create_routerospfvrf
732
+ vrf.timer_throttle_lsa_set(250, 900, 5001)
733
+ assert_equal(250, vrf.timer_throttle_lsa_start,
734
+ "Error: #{vrf.name} vrf, start timer throttle lsa not correct")
735
+ assert_equal(900, vrf.timer_throttle_lsa_hold,
736
+ "Error: #{vrf.name} vrf, hold timer throttle lsa not correct")
737
+ assert_equal(5001, vrf.timer_throttle_lsa_max,
738
+ "Error: #{vrf.name} vrf, max timer throttle lsa not correct")
739
+ vrf.parent.destroy
740
+ end
741
+
742
+ def test_routerospfvrf_timer_throttle_spf_start_hold_max
743
+ vrf = create_routerospfvrf
744
+ vrf.timer_throttle_spf_set(250, 900, 5001)
745
+ assert_equal(250, vrf.timer_throttle_spf_start,
746
+ "Error: #{vrf.name} vrf, start timer throttle spf not correct")
747
+ assert_equal(900, vrf.timer_throttle_spf_hold,
748
+ "Error: #{vrf.name} vrf, hold timer throttle spf not correct")
749
+ assert_equal(5001, vrf.timer_throttle_spf_max,
750
+ "Error: #{vrf.name} vrf, max timer throttle spf not correct")
751
+ vrf.parent.destroy
752
+ end
753
+ end