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
data/tests/test_vlan.rb CHANGED
@@ -12,77 +12,71 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
- require File.expand_path("../ciscotest", __FILE__)
16
- require File.expand_path("../../lib/cisco_node_utils/vlan", __FILE__)
17
- require File.expand_path("../../lib/cisco_node_utils/interface", __FILE__)
15
+ require_relative 'ciscotest'
16
+ require_relative '../lib/cisco_node_utils/vlan'
17
+ require_relative '../lib/cisco_node_utils/interface'
18
18
 
19
19
  include Cisco
20
20
 
21
+ # TestVlan - Minitest for Vlan node utility
21
22
  class TestVlan < CiscoTestCase
22
23
  def interface_ethernet_default(ethernet_id)
23
- s = @device.cmd("configure terminal")
24
- s = @device.cmd("default interface ethernet #{ethernet_id}")
25
- s = @device.cmd("end")
26
- node.cache_flush
24
+ config("default interface ethernet #{ethernet_id}")
27
25
  end
28
26
 
29
27
  def test_vlan_collection_not_empty
30
28
  vlans = Vlan.vlans
31
- assert_equal(false, vlans.empty?(), "VLAN collection is empty")
32
- assert(vlans.key?("1"), "VLAN 1 does not exist")
29
+ assert_equal(false, vlans.empty?, 'VLAN collection is empty')
30
+ assert(vlans.key?('1'), 'VLAN 1 does not exist')
33
31
  end
34
32
 
35
33
  def test_vlan_create_invalid
36
- e = assert_raises(CliError) do
37
- v = Vlan.new(5000)
38
- end
34
+ e = assert_raises(CliError) { Vlan.new(5000) }
39
35
  assert_match(/Invalid value.range/, e.message)
40
36
  end
41
37
 
42
38
  def test_vlan_create_invalid_non_numeric_vlan
43
- e = assert_raises(ArgumentError) do
44
- v = Vlan.new("fred")
45
- end
39
+ e = assert_raises(ArgumentError) { Vlan.new('fred') }
46
40
  assert_match(/Invalid value.non-numeric/, e.message)
47
41
  end
48
42
 
49
43
  def test_vlan_create_and_destroy
50
44
  v = Vlan.new(1000)
51
45
  vlans = Vlan.vlans
52
- assert(vlans.key?("1000"), "Error: failed to create vlan 1000")
46
+ assert(vlans.key?('1000'), 'Error: failed to create vlan 1000')
53
47
 
54
48
  v.destroy
55
49
  vlans = Vlan.vlans
56
- refute(vlans.key?("1000"), "Error: failed to destroy vlan 1000")
50
+ refute(vlans.key?('1000'), 'Error: failed to destroy vlan 1000')
57
51
  end
58
52
 
59
53
  def test_vlan_name_default_1000
60
54
  v = Vlan.new(1000)
61
55
  assert_equal(v.default_vlan_name, v.vlan_name,
62
- "Error: Vlan name not initialized to default")
56
+ 'Error: Vlan name not initialized to default')
63
57
 
64
- name = "Uplink-Chicago"
58
+ name = 'Uplink-Chicago'
65
59
  v.vlan_name = name
66
60
  assert_equal(name, v.vlan_name, "Error: Vlan name not updated to #{name}")
67
61
 
68
62
  v.vlan_name = v.default_vlan_name
69
63
  assert_equal(v.default_vlan_name, v.vlan_name,
70
- "Error: Vlan name not restored to default")
64
+ 'Error: Vlan name not restored to default')
71
65
  v.destroy
72
66
  end
73
67
 
74
68
  def test_vlan_name_default_40
75
69
  v = Vlan.new(40)
76
70
  assert_equal(v.default_vlan_name, v.vlan_name,
77
- "Error: Vlan name not initialized to default")
71
+ 'Error: Vlan name not initialized to default')
78
72
 
79
- name = "Uplink-Chicago"
73
+ name = 'Uplink-Chicago'
80
74
  v.vlan_name = name
81
75
  assert_equal(name, v.vlan_name, "Error: Vlan name not updated to #{name}")
82
76
 
83
77
  v.vlan_name = v.default_vlan_name
84
78
  assert_equal(v.default_vlan_name, v.vlan_name,
85
- "Error: Vlan name not restored to default")
79
+ 'Error: Vlan name not restored to default')
86
80
  v.destroy
87
81
  end
88
82
 
@@ -104,16 +98,16 @@ class TestVlan < CiscoTestCase
104
98
 
105
99
  def test_vlan_name_zero_length
106
100
  v = Vlan.new(1000)
107
- v.vlan_name = ""
108
- assert("", v.vlan_name)
101
+ v.vlan_name = ''
102
+ assert('', v.vlan_name)
109
103
  v.destroy
110
104
  end
111
105
 
112
106
  def test_vlan_name_length_valid
113
107
  v = Vlan.new(1000)
114
- alphabet = "abcdefghijklmnopqrstuvwxyz0123456789"
115
- name = ""
116
- 1.upto(VLAN_NAME_SIZE - 1) { | i |
108
+ alphabet = 'abcdefghijklmnopqrstuvwxyz0123456789'
109
+ name = ''
110
+ 1.upto(VLAN_NAME_SIZE - 1) do |i|
117
111
  begin
118
112
  name += alphabet[i % alphabet.size, 1]
119
113
  # puts "n is #{name}"
@@ -122,19 +116,18 @@ class TestVlan < CiscoTestCase
122
116
  assert_equal(name, v.vlan_name)
123
117
  end
124
118
  end
125
- }
119
+ end
126
120
  v.destroy
127
121
  end
128
122
 
129
123
  def test_vlan_name_too_long
130
124
  v = Vlan.new(1000)
131
- name = "a" * VLAN_NAME_SIZE
132
- assert_raises(RuntimeError, "vlan misconfig did not raise RuntimeError") do
125
+ name = 'a' * VLAN_NAME_SIZE
126
+ assert_raises(RuntimeError, 'vlan misconfig did not raise RuntimeError') do
133
127
  v.vlan_name = name
134
128
  end
135
- ref = cmd_ref.lookup("vlan", "name")
136
- assert(ref, "Error, reference not found for vlan name")
137
- ref = nil
129
+ ref = cmd_ref.lookup('vlan', 'name')
130
+ assert(ref, 'Error, reference not found for vlan name')
138
131
  v.destroy
139
132
  end
140
133
 
@@ -146,10 +139,10 @@ class TestVlan < CiscoTestCase
146
139
  v.destroy
147
140
  # start test
148
141
  v1 = Vlan.new(1000)
149
- v1.vlan_name = "test"
142
+ v1.vlan_name = 'test'
150
143
  v2 = Vlan.new(1001)
151
- assert_raises(RuntimeError, "vlan misconfig did not raise RuntimeError") do
152
- v2.vlan_name = "test"
144
+ assert_raises(RuntimeError, 'vlan misconfig did not raise RuntimeError') do
145
+ v2.vlan_name = 'test'
153
146
  end
154
147
  v1.destroy
155
148
  v2.destroy
@@ -157,14 +150,14 @@ class TestVlan < CiscoTestCase
157
150
 
158
151
  def test_vlan_state_extended
159
152
  v = Vlan.new(2000)
160
- v.state = "suspend"
153
+ v.state = 'suspend'
161
154
  v.destroy
162
155
  end
163
156
 
164
157
  def test_vlan_state_invalid
165
158
  v = Vlan.new(1000)
166
159
  assert_raises(RuntimeError) do
167
- v.state = "unknown"
160
+ v.state = 'unknown'
168
161
  end
169
162
  v.destroy
170
163
  end
@@ -172,42 +165,37 @@ class TestVlan < CiscoTestCase
172
165
  def test_vlan_state_valid
173
166
  states = %w(unknown active suspend)
174
167
  v = Vlan.new(1000)
175
- states.each { | start |
176
- states.each { | finish |
177
- if start != "unknown" &&
178
- finish != "unknown"
179
- v.state = start
180
- assert_equal(start, v.state, "start")
181
- v.state = finish
182
- assert_equal(finish, v.state, "finish")
183
- end
184
- }
185
- }
168
+ states.each do |start|
169
+ states.each do |finish|
170
+ next if start == 'unknown' || finish == 'unknown'
171
+ v.state = start
172
+ assert_equal(start, v.state, 'start')
173
+ v.state = finish
174
+ assert_equal(finish, v.state, 'finish')
175
+ end
176
+ end
186
177
  v.destroy
187
178
  end
188
179
 
189
180
  def test_vlan_shutdown_extended
190
181
  v = Vlan.new(2000)
191
- assert_raises(RuntimeError, "vlan misconfig did not raise RuntimeError") do
192
- v.shutdown = "shutdown"
182
+ assert_raises(RuntimeError, 'vlan misconfig did not raise RuntimeError') do
183
+ v.shutdown = 'shutdown'
193
184
  end
194
185
  v.destroy
195
186
  end
196
187
 
197
188
  def test_vlan_shutdown_valid
198
- shutdown_states = [
199
- true,
200
- false
201
- ]
189
+ shutdown_states = [true, false]
202
190
  v = Vlan.new(1000)
203
- shutdown_states.each { | start |
204
- shutdown_states.each { | finish |
191
+ shutdown_states.each do |start|
192
+ shutdown_states.each do |finish|
205
193
  v.shutdown = start
206
- assert_equal(start, v.shutdown, "start")
194
+ assert_equal(start, v.shutdown, 'start')
207
195
  v.shutdown = finish
208
- assert_equal(finish, v.shutdown, "finish")
209
- }
210
- }
196
+ assert_equal(finish, v.shutdown, 'finish')
197
+ end
198
+ end
211
199
  v.destroy
212
200
  end
213
201
 
@@ -216,21 +204,21 @@ class TestVlan < CiscoTestCase
216
204
  interfaces = Interface.interfaces
217
205
  interfaces_added_to_vlan = []
218
206
  count = 3
219
- interfaces.each { | name, interface |
220
- if interface.name.match(/ethernet/) && count > 0
221
- interfaces_added_to_vlan << name
222
- interface.switchport_mode = :access
223
- v.add_interface(interface)
224
- count -= 1
225
- end
226
- }
207
+ interfaces.each do |name, interface|
208
+ next unless interface.name.match(%r{ethernet[0-9/]}) && count > 0
209
+ interfaces_added_to_vlan << name
210
+ interface.switchport_mode = :access
211
+ v.add_interface(interface)
212
+ count -= 1
213
+ end
214
+ assert_equal(0, count)
227
215
 
228
216
  interfaces = v.interfaces
229
- interfaces.each { | name, interface |
217
+ interfaces.each do |name, interface|
230
218
  assert_includes(interfaces_added_to_vlan, name)
231
- assert_equal(v.vlan_id, interface.access_vlan, "Interface.access_vlan")
219
+ assert_equal(v.vlan_id, interface.access_vlan, 'Interface.access_vlan')
232
220
  v.remove_interface(interface)
233
- }
221
+ end
234
222
 
235
223
  interfaces = v.interfaces
236
224
  assert(interfaces.empty?)
@@ -241,9 +229,7 @@ class TestVlan < CiscoTestCase
241
229
  v = Vlan.new(1000)
242
230
  interface = Interface.new(interfaces[0])
243
231
  interface.switchport_mode = :disabled
244
- assert_raises(RuntimeError) {
245
- v.add_interface(interface)
246
- }
232
+ assert_raises(RuntimeError) { v.add_interface(interface) }
247
233
  v.destroy
248
234
  interface_ethernet_default(interfaces_id[0])
249
235
  end
@@ -254,9 +240,7 @@ class TestVlan < CiscoTestCase
254
240
  interface.switchport_mode = :access
255
241
  v.add_interface(interface)
256
242
  interface.switchport_mode = :disabled
257
- assert_raises(RuntimeError) {
258
- v.remove_interface(interface)
259
- }
243
+ assert_raises(RuntimeError) { v.remove_interface(interface) }
260
244
 
261
245
  v.destroy
262
246
  interface_ethernet_default(interfaces_id[0])
data/tests/test_vrf.rb ADDED
@@ -0,0 +1,92 @@
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_relative 'ciscotest'
16
+ require_relative '../lib/cisco_node_utils/vrf'
17
+
18
+ include Cisco
19
+
20
+ # TestVrf - Minitest for Vrf node utility class
21
+ class TestVrf < CiscoTestCase
22
+ VRF_NAME_SIZE = 33
23
+
24
+ def setup
25
+ super
26
+ vrfs = Vrf.vrfs
27
+ vrfs.each_value do |vrf|
28
+ next unless vrf.name =~ /^test_vrf/
29
+ config("no vrf context #{vrf.name}")
30
+ end
31
+ end
32
+
33
+ def test_vrf_collection_not_empty
34
+ vrfs = Vrf.vrfs
35
+ refute_empty(vrfs, 'VRF collection is empty')
36
+ assert(vrfs.key?('management'), 'VRF management does not exist')
37
+ end
38
+
39
+ def test_vrf_create_and_destroy
40
+ v = Vrf.new('test_vrf')
41
+ vrfs = Vrf.vrfs
42
+ assert(vrfs.key?('test_vrf'), 'Error: failed to create vrf test_vrf')
43
+
44
+ v.destroy
45
+ vrfs = Vrf.vrfs
46
+ refute(vrfs.key?('test_vrf'), 'Error: failed to destroy vrf test_vrf')
47
+ end
48
+
49
+ def test_vrf_name_type_invalid
50
+ assert_raises(TypeError, 'Wrong vrf name type did not raise type error') do
51
+ Vrf.new(1000)
52
+ end
53
+ end
54
+
55
+ def test_vrf_name_zero_length
56
+ assert_raises(Cisco::CliError, "Zero length name didn't raise CliError") do
57
+ Vrf.new('')
58
+ end
59
+ end
60
+
61
+ def test_vrf_name_too_long
62
+ name = 'a' * VRF_NAME_SIZE
63
+ assert_raises(Cisco::CliError,
64
+ 'vrf name misconfig did not raise CliError') do
65
+ Vrf.new(name)
66
+ end
67
+ end
68
+
69
+ def test_vrf_shutdown_valid
70
+ shutdown_states = [true, false]
71
+ v = Vrf.new('test_vrf_shutdown')
72
+ shutdown_states.each do |start|
73
+ shutdown_states.each do |finish|
74
+ v.shutdown = start
75
+ assert_equal(start, v.shutdown, 'start')
76
+ v.shutdown = finish
77
+ assert_equal(finish, v.shutdown, 'finish')
78
+ end
79
+ end
80
+ v.destroy
81
+ end
82
+
83
+ def test_vrf_description
84
+ vrf = Vrf.new('test_vrf_description')
85
+ vrf.description = 'tested by minitest'
86
+ assert_equal('tested by minitest', vrf.description,
87
+ 'failed to set description')
88
+ vrf.description = ' '
89
+ assert_empty(vrf.description, 'failed to remove description')
90
+ vrf.destroy
91
+ end
92
+ end
data/tests/test_vtp.rb CHANGED
@@ -12,9 +12,10 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
- require File.expand_path("../ciscotest", __FILE__)
16
- require File.expand_path("../../lib/cisco_node_utils/vtp", __FILE__)
15
+ require_relative 'ciscotest'
16
+ require_relative '../lib/cisco_node_utils/vtp'
17
17
 
18
+ # TestVtp - Minitest for Vtp node utility class
18
19
  class TestVtp < CiscoTestCase
19
20
  def setup
20
21
  super
@@ -29,8 +30,7 @@ class TestVtp < CiscoTestCase
29
30
  def no_feature_vtp
30
31
  # VTP will raise an error if the domain is configured twice so we need to
31
32
  # turn the feature off for a clean test.
32
- @device.cmd("conf t ; no feature vtp ; end")
33
- node.cache_flush()
33
+ config('no feature vtp')
34
34
  end
35
35
 
36
36
  def vtp_domain(domain)
@@ -45,73 +45,66 @@ class TestVtp < CiscoTestCase
45
45
  assert_equal(vtp.default_password, vtp.password)
46
46
  assert_equal(vtp.default_filename, vtp.filename)
47
47
  assert_equal(vtp.default_version, vtp.version)
48
- refute(Vtp.enabled, "VTP feature was unexpectedly enabled?")
48
+ refute(Vtp.enabled, 'VTP feature was unexpectedly enabled?')
49
49
  end
50
50
 
51
51
  def test_vtp_enabled_but_no_domain
52
52
  vtp = Vtp.new(false)
53
- @device.cmd("conf t ; feature vtp ; end")
54
- node.cache_flush()
53
+ config('feature vtp')
55
54
  assert(Vtp.enabled)
56
55
  assert_empty(vtp.domain)
57
56
  assert_equal(vtp.default_password, vtp.password)
58
57
  assert_equal(vtp.default_filename, vtp.filename)
59
58
  assert_equal(vtp.default_version, vtp.version)
60
59
  # Can set these without setting domain
61
- vtp.filename = "bootflash:/foo.bar"
62
- assert_equal("bootflash:/foo.bar", vtp.filename)
60
+ vtp.filename = 'bootflash:/foo.bar'
61
+ assert_equal('bootflash:/foo.bar', vtp.filename)
63
62
  vtp.version = 1
64
63
  assert_equal(1, vtp.version)
65
64
  # Can't set any of the below without setting a domain first
66
65
  assert_raises(RuntimeError) do
67
- vtp.password = "hello"
66
+ vtp.password = 'hello'
68
67
  end
69
68
  end
70
69
 
71
70
  def test_vtp_domain_enable_disable
72
71
  assert_empty(Vtp.domain)
73
- vtp = vtp_domain("enable")
74
- assert_equal("enable", Vtp.domain)
72
+ vtp = vtp_domain('enable')
73
+ assert_equal('enable', Vtp.domain)
75
74
  vtp.destroy
76
75
  assert_empty(Vtp.domain)
77
76
  end
78
77
 
79
78
  def test_vtp_create_valid
80
- vtp = vtp_domain("accounting")
79
+ vtp_domain('accounting')
81
80
  s = @device.cmd("show run vtp | incl '^vtp domain'")
82
81
  assert_match(/^vtp domain accounting/, s,
83
- "Error: failed to create vtp domain")
82
+ 'Error: failed to create vtp domain')
84
83
  end
85
84
 
86
85
  def test_vtp_domain_name_change
87
- vtp = vtp_domain("accounting")
88
- vtp_new = vtp_domain("uplink")
89
- assert_equal("uplink", vtp.domain,
90
- "Error: vtp domain name incorrect")
86
+ vtp = vtp_domain('accounting')
87
+ vtp_domain('uplink')
88
+ assert_equal('uplink', vtp.domain,
89
+ 'Error: vtp domain name incorrect')
91
90
  end
92
91
 
93
92
  def test_vtp_create_preconfig_no_change
94
- s = @device.cmd("configure terminal")
95
- s = @device.cmd("feature vtp")
96
- s = @device.cmd("vtp domain accounting")
97
- s = @device.cmd("end")
93
+ config('feature vtp', 'vtp domain accounting')
98
94
 
99
- # Flush the cache since we've modified the device
100
- node.cache_flush()
101
-
102
- vtp = vtp_domain("accounting")
103
- assert_equal("accounting", vtp.domain,
104
- "Error: vtp domain wrong")
95
+ vtp = vtp_domain('accounting')
96
+ assert_equal('accounting', vtp.domain,
97
+ 'Error: vtp domain wrong')
105
98
  end
106
99
 
107
100
  def test_vtp_create_double
108
- vtp = vtp_domain("accounting")
109
- vtp_new = vtp_domain("accounting")
101
+ vtp = vtp_domain('accounting')
102
+ vtp_new = vtp_domain('accounting')
110
103
 
111
- assert_equal("accounting", vtp.domain,
112
- "Error: vtp domain wrong")
113
- assert_equal("accounting", vtp_new.domain,
114
- "Error: vtp_new domain wrong")
104
+ assert_equal('accounting', vtp.domain,
105
+ 'Error: vtp domain wrong')
106
+ assert_equal('accounting', vtp_new.domain,
107
+ 'Error: vtp_new domain wrong')
115
108
  end
116
109
 
117
110
  def test_vtp_create_domain_invalid
@@ -128,171 +121,160 @@ class TestVtp < CiscoTestCase
128
121
 
129
122
  def test_vtp_create_domain_empty
130
123
  assert_raises(ArgumentError) do
131
- vtp_domain("")
124
+ vtp_domain('')
132
125
  end
133
126
  end
134
127
 
135
128
  def test_vtp_assignment
136
- vtp = vtp_domain("accounting")
137
- vtp.password = "copy_test"
138
- assert_equal("copy_test", vtp.password,
139
- "Error: vtp password not set")
129
+ vtp = vtp_domain('accounting')
130
+ vtp.password = 'copy_test'
131
+ assert_equal('copy_test', vtp.password,
132
+ 'Error: vtp password not set')
140
133
  vtp_extra = vtp
141
- assert_equal("copy_test", vtp_extra.password,
142
- "Error: vtp password not set")
134
+ assert_equal('copy_test', vtp_extra.password,
135
+ 'Error: vtp password not set')
143
136
  end
144
137
 
145
138
  def test_vtp_domain_get
146
- vtp = vtp_domain("accounting")
147
- assert_equal("accounting", vtp.domain,
148
- "Error: vtp domain incorrect")
139
+ vtp = vtp_domain('accounting')
140
+ assert_equal('accounting', vtp.domain,
141
+ 'Error: vtp domain incorrect')
149
142
  end
150
143
 
151
144
  def test_vtp_password_nil
152
- vtp = vtp_domain("accounting")
145
+ vtp = vtp_domain('accounting')
153
146
  assert_raises(TypeError) do
154
147
  vtp.password = nil
155
148
  end
156
149
  end
157
150
 
158
151
  def test_vtp_password_default
159
- vtp = vtp_domain("accounting")
160
- vtp.password = "test_me"
161
- assert_equal("test_me", vtp.password,
162
- "Error: vtp password not correct")
152
+ vtp = vtp_domain('accounting')
153
+ vtp.password = 'test_me'
154
+ assert_equal('test_me', vtp.password,
155
+ 'Error: vtp password not correct')
163
156
 
164
157
  vtp.password = vtp.default_password
165
- assert_equal(node.config_get_default("vtp", "password"), vtp.password,
166
- "Error: vtp password not correct")
158
+ assert_equal(node.config_get_default('vtp', 'password'), vtp.password,
159
+ 'Error: vtp password not correct')
167
160
  end
168
161
 
169
162
  def test_vtp_password_zero_length
170
- vtp = vtp_domain("accounting")
171
- vtp.password = ""
172
- assert_equal("", vtp.password,
173
- "Error: vtp password not empty")
163
+ vtp = vtp_domain('accounting')
164
+ vtp.password = ''
165
+ assert_equal('', vtp.password,
166
+ 'Error: vtp password not empty')
174
167
  end
175
168
 
176
169
  def test_vtp_password_get
177
- vtp = vtp_domain("accounting")
170
+ vtp = vtp_domain('accounting')
178
171
 
179
- s = @device.cmd("configure terminal")
180
- s = @device.cmd("vtp password cisco123")
181
- s = @device.cmd("end")
182
- # Flush the cache since we've modified the device
183
- node.cache_flush()
184
- assert_equal("cisco123", vtp.password,
185
- "Error: vtp password not correct")
172
+ config('vtp password cisco123')
173
+ assert_equal('cisco123', vtp.password,
174
+ 'Error: vtp password not correct')
186
175
  end
187
176
 
188
177
  def test_vtp_password_get_not_set
189
- vtp = vtp_domain("accounting")
190
- assert_equal("", vtp.password,
191
- "Error: vtp password not empty")
178
+ vtp = vtp_domain('accounting')
179
+ assert_equal('', vtp.password,
180
+ 'Error: vtp password not empty')
192
181
  end
193
182
 
194
183
  def test_vtp_password_clear
195
- vtp = vtp_domain("accounting")
196
- vtp.password = "cisco123"
197
- assert_equal("cisco123", vtp.password,
198
- "Error: vtp password not set")
184
+ vtp = vtp_domain('accounting')
185
+ vtp.password = 'cisco123'
186
+ assert_equal('cisco123', vtp.password,
187
+ 'Error: vtp password not set')
199
188
 
200
- vtp.password = ""
201
- assert_equal("", vtp.password,
202
- "Error: vtp default password not set")
189
+ vtp.password = ''
190
+ assert_equal('', vtp.password,
191
+ 'Error: vtp default password not set')
203
192
  end
204
193
 
205
194
  def test_vtp_password_valid
206
- vtp = vtp_domain("accounting")
207
- alphabet = "abcdefghijklmnopqrstuvwxyz0123456789"
208
- password = ""
209
- 1.upto(Vtp::MAX_VTP_PASSWORD_SIZE - 1) { | i |
210
- begin
211
- password += alphabet[i % alphabet.size, 1]
212
- vtp.password = password
213
- assert_equal(password.rstrip, vtp.password,
214
- "Error: vtp password not set")
215
- end
216
- }
195
+ vtp = vtp_domain('accounting')
196
+ alphabet = 'abcdefghijklmnopqrstuvwxyz0123456789'
197
+ password = ''
198
+ 1.upto(Vtp::MAX_VTP_PASSWORD_SIZE - 1) do |i|
199
+ password += alphabet[i % alphabet.size, 1]
200
+ vtp.password = password
201
+ assert_equal(password.rstrip, vtp.password,
202
+ 'Error: vtp password not set')
203
+ end
217
204
  end
218
205
 
219
206
  def test_vtp_password_too_long
220
- vtp = vtp_domain("accounting")
221
- password = "a"
222
- Vtp::MAX_VTP_PASSWORD_SIZE.times {
223
- password += "a"
224
- }
225
- assert_raises(ArgumentError) {
226
- vtp.password = password
227
- }
207
+ vtp = vtp_domain('accounting')
208
+ password = 'a' * (Vtp::MAX_VTP_PASSWORD_SIZE + 1)
209
+ assert_raises(ArgumentError) { vtp.password = password }
228
210
  end
229
211
 
230
212
  def test_vtp_password_special_characters
231
- vtp = vtp_domain("password")
213
+ vtp = vtp_domain('password')
232
214
  vtp.password = 'hello!//\\#%$x'
233
215
  assert_equal('hello!//\\#%$x', vtp.password)
234
216
  end
235
217
 
236
218
  def test_vtp_filename_nil
237
- vtp = vtp_domain("accounting")
219
+ vtp = vtp_domain('accounting')
238
220
  assert_raises(TypeError) do
239
221
  vtp.filename = nil
240
222
  end
241
223
  end
242
224
 
243
225
  def test_vtp_filename_valid
244
- vtp = vtp_domain("accounting")
245
- vtp.filename = "bootflash:/test.dat"
246
- assert_equal("bootflash:/test.dat", vtp.filename,
247
- "Error: vtp file content wrong")
226
+ vtp = vtp_domain('accounting')
227
+ vtp.filename = 'bootflash:/test.dat'
228
+ assert_equal('bootflash:/test.dat', vtp.filename,
229
+ 'Error: vtp file content wrong')
248
230
  end
249
231
 
250
232
  def test_vtp_filename_zero_length
251
- vtp = vtp_domain("accounting")
233
+ vtp = vtp_domain('accounting')
252
234
  vtp.filename = vtp.default_filename
253
- assert_equal(node.config_get_default("vtp", "filename"), vtp.filename,
254
- "Error: vtp file content wrong")
235
+ assert_equal(node.config_get_default('vtp', 'filename'), vtp.filename,
236
+ 'Error: vtp file content wrong')
255
237
 
256
238
  # send in 'no' to remove the config. That will cause the default
257
239
  # to get reapplied.
258
- vtp.filename = ""
259
- assert_equal(node.config_get_default("vtp", "filename"), vtp.filename,
260
- "Error: vtp file content wrong")
240
+ vtp.filename = ''
241
+ assert_equal(node.config_get_default('vtp', 'filename'), vtp.filename,
242
+ 'Error: vtp file content wrong')
261
243
  end
262
244
 
263
245
  def test_vtp_filename_auto_enable
264
246
  vtp = Vtp.new(false)
265
- refute(Vtp.enabled, "VTP should not be enabled")
266
- vtp.filename = "bootflash:/foo.bar"
247
+ refute(Vtp.enabled, 'VTP should not be enabled')
248
+ vtp.filename = 'bootflash:/foo.bar'
267
249
  assert(Vtp.enabled)
268
- assert_equal("bootflash:/foo.bar", vtp.filename)
250
+ assert_equal('bootflash:/foo.bar', vtp.filename)
269
251
  end
270
252
 
271
253
  def test_vtp_version_valid
272
- vtp = vtp_domain("accounting")
254
+ vtp = vtp_domain('accounting')
273
255
  vtp.version = vtp.default_version
274
- assert_equal(node.config_get_default("vtp", "version"), vtp.version,
275
- "Error: vtp version not default")
256
+ assert_equal(node.config_get_default('vtp', 'version'), vtp.version,
257
+ 'Error: vtp version not default')
276
258
  end
277
259
 
278
260
  def test_vtp_version3_valid
279
- vtp = vtp_domain("accounting")
261
+ vtp = vtp_domain('accounting')
280
262
 
281
- ref = cmd_ref.lookup("vtp", "version")
282
- assert(ref, "Error, reference not found for vtp version3")
263
+ ref = cmd_ref.lookup('vtp', 'version')
264
+ assert(ref, 'Error, reference not found for vtp version3')
283
265
 
284
- assert_result(ref.test_config_result(3), "Error: vtp version3 error") {
266
+ assert_result(ref.test_config_result(3), 'Error: vtp version3 error') do
285
267
  vtp.version = 3
286
268
  vtp.version
287
- }
288
-
289
- ref = nil
269
+ end
290
270
  end
291
271
 
292
272
  # Decides whether to check for a raised Exception or an equal value.
293
273
  def assert_result(expected_result, err_msg, &block)
294
274
  if /Error/ =~ expected_result.to_s
295
- expected_result = eval(expected_result) if expected_result.is_a?(String)
275
+ if expected_result.is_a?(String)
276
+ expected_result = Object.const_get(expected_result)
277
+ end
296
278
  assert_raises(expected_result, &block)
297
279
  else
298
280
  value = block.call
@@ -301,25 +283,25 @@ class TestVtp < CiscoTestCase
301
283
  end
302
284
 
303
285
  def test_vtp_version_invalid
304
- vtp = vtp_domain("accounting")
286
+ vtp = vtp_domain('accounting')
305
287
  assert_raises(Cisco::CliError) do
306
288
  vtp.version = 34
307
289
  end
308
290
  end
309
291
 
310
292
  def test_vtp_version_default
311
- vtp = vtp_domain("accounting")
293
+ vtp = vtp_domain('accounting')
312
294
  vtp.version = 2
313
295
  assert_equal(2, vtp.version,
314
- "Error: vtp version not correct")
296
+ 'Error: vtp version not correct')
315
297
  vtp.version = vtp.default_version
316
- assert_equal(node.config_get_default("vtp", "version"), vtp.version,
317
- "Error: vtp version not default")
298
+ assert_equal(node.config_get_default('vtp', 'version'), vtp.version,
299
+ 'Error: vtp version not default')
318
300
  end
319
301
 
320
302
  def test_vtp_version_auto_enable
321
303
  vtp = Vtp.new(false)
322
- refute(Vtp.enabled, "VTP should not be enabled")
304
+ refute(Vtp.enabled, 'VTP should not be enabled')
323
305
  vtp.version = 1
324
306
  assert(Vtp.enabled)
325
307
  assert_equal(1, vtp.version)
@@ -327,9 +309,9 @@ class TestVtp < CiscoTestCase
327
309
 
328
310
  def test_vtp_feature_enable_disable
329
311
  Vtp.new.enable
330
- assert(Vtp.enabled, "Error: vtp is not enabled")
312
+ assert(Vtp.enabled, 'Error: vtp is not enabled')
331
313
 
332
314
  Vtp.new.destroy
333
- refute(Vtp.enabled, "Error: vtp is not disabled")
315
+ refute(Vtp.enabled, 'Error: vtp is not disabled')
334
316
  end
335
317
  end