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
@@ -12,189 +12,166 @@
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/tacacs_server_host", __FILE__)
15
+ require_relative 'ciscotest'
16
+ require_relative '../lib/cisco_node_utils/tacacs_server_host'
17
17
 
18
18
  include Cisco
19
19
 
20
20
  DEFAULT_TACACS_SERVER_HOST_PORT = 49
21
21
  DEFAULT_TACACS_SERVER_HOST_TIMEOUT = 0
22
- DEFAULT_TACACS_SERVER_HOST_ENCRYPTION_PASSWORD = ""
22
+ DEFAULT_TACACS_SERVER_HOST_ENCRYPTION_PASSWORD = ''
23
23
 
24
+ # TestTacacsServerHost - Minitest for TacacsServerHost node utility
24
25
  class TestTacacsServerHost < CiscoTestCase
25
- def get_tacacsserverhost_match_line(host_name)
26
- s = @device.cmd("show run all | no-more")
27
- cmd = "tacacs-server host"
28
- pattern = /#{cmd}\s(#{host_name})(.*)/
29
- pattern.match(s)
26
+ def setup
27
+ super
28
+ @host_name = 'testhost'
29
+ @default_show_command = 'show run all | inc "tacacs-server" | no-more'
30
+ @default_output_pattern = /tacacs-server host\s(#{@host_name})(.*)/
30
31
  end
31
32
 
32
33
  def test_tacacsserverhost_collection_empty
33
34
  hosts = TacacsServerHost.hosts
34
- hosts.each { |name, host| host.destroy }
35
+ hosts.each_value(&:destroy)
35
36
  hosts = TacacsServerHost.hosts
36
37
 
37
- assert_empty(hosts, "Error: Tacacs Host collection is not empty")
38
+ assert_empty(hosts, 'Error: Tacacs Host collection is not empty')
38
39
  end
39
40
 
40
41
  def test_tacacsserverhost_collection
41
42
  hosts_hash = {}
42
- hosts_hash["testhost1"] = 1138
43
- hosts_hash["testhost2"] = DEFAULT_TACACS_SERVER_HOST_PORT
43
+ hosts_hash['testhost1'] = 1138
44
+ hosts_hash['testhost2'] = DEFAULT_TACACS_SERVER_HOST_PORT
44
45
 
45
- hosts_hash.each { |name, port|
46
+ hosts_hash.each do |name, port|
46
47
  host = TacacsServerHost.new(name)
47
48
  host.port = port
48
- }
49
+ end
49
50
 
50
51
  hosts = TacacsServerHost.hosts
51
- refute_empty(hosts, "Error: Tacacs Host collection is empty")
52
- hosts_hash.each { |name, port|
52
+ refute_empty(hosts, 'Error: Tacacs Host collection is empty')
53
+ hosts_hash.each do |name, port|
53
54
  # host must have been created to be found in the list
54
55
  assert(hosts.include?(name),
55
56
  "Error: Tacacs Host #{name} not in collection")
56
57
  # port numbers differentiate the hosts
57
58
  assert_equal(port, hosts[name].port,
58
59
  "Error: Tacacs Host #{name} port mismatch")
59
- }
60
+ end
60
61
 
61
- hosts_hash.each { |name, host| hosts[name].destroy }
62
+ hosts_hash.each_key { |name| hosts[name].destroy }
62
63
  end
63
64
 
64
65
  def test_tacacsserverhost_create_server_nil
65
- assert_raises(TypeError) do
66
- host = TacacsServerHost.new(nil)
67
- end
66
+ assert_raises(TypeError) { TacacsServerHost.new(nil) }
68
67
  end
69
68
 
70
69
  def test_tacacsserverhost_create_name_zero_length
71
- assert_raises(ArgumentError) do
72
- host = TacacsServerHost.new("")
73
- end
70
+ assert_raises(ArgumentError) { TacacsServerHost.new('') }
74
71
  end
75
72
 
76
73
  def test_tacacsserverhost_create_valid
77
- host = TacacsServerHost.new("testhost")
78
- line = get_tacacsserverhost_match_line("testhost")
79
- refute_nil(line, "Error: Tacacs Host not created")
74
+ host = TacacsServerHost.new('testhost')
75
+ assert_show_match(msg: 'Error: Tacacs Host not created')
80
76
  host.destroy
81
77
  end
82
78
 
83
79
  def test_tacacsserverhost_destroy
84
- host_name = "testhost"
85
- host = TacacsServerHost.new(host_name)
86
- line = get_tacacsserverhost_match_line(host_name)
87
- refute_nil(line, "Error: Tacacs Host not created")
80
+ host = TacacsServerHost.new(@host_name)
81
+ assert_show_match(msg: 'Error: Tacacs Host not created')
88
82
  host.destroy
89
83
 
90
- line = get_tacacsserverhost_match_line(host_name)
91
- assert_nil(line, "Error: Tacacs Host still present")
84
+ refute_show_match(msg: 'Error: Tacacs Host still present')
92
85
  end
93
86
 
94
87
  def test_tacacsserverhost_get_name
95
- host_name = "testhost"
96
- host = TacacsServerHost.new(host_name)
97
- line = get_tacacsserverhost_match_line(host_name)
98
- refute_nil(line, "Error: Tacacs Host not found")
99
- assert_equal(host_name, line.captures[0],
100
- "Error: #{host_name} name mismatch")
101
- assert_equal(host_name, host.name,
102
- "Error: #{host_name} name get value mismatch")
88
+ host = TacacsServerHost.new(@host_name)
89
+ line = assert_show_match(msg: 'Error: Tacacs Host not found')
90
+ assert_equal(@host_name, line.captures[0],
91
+ "Error: #{@host_name} name mismatch")
92
+ assert_equal(@host_name, host.name,
93
+ "Error: #{@host_name} name get value mismatch")
103
94
  host.destroy
104
95
  end
105
96
 
106
97
  def test_tacacsserverhost_get_name_preconfigured
107
- host_name = "testhost"
98
+ config("tacacs-server host #{@host_name}")
108
99
 
109
- s = @device.cmd("configure terminal")
110
- s = @device.cmd("tacacs-server host #{host_name}")
111
- s = @device.cmd("end")
112
- node.cache_flush
113
-
114
- line = get_tacacsserverhost_match_line(host_name)
100
+ line = assert_show_match(msg: 'Error: Tacacs Host not found')
115
101
  hosts = TacacsServerHost.hosts()
116
102
 
117
- refute_nil(line, "Error: Tacacs Host not found")
118
- assert_equal(host_name, line.captures[0],
119
- "Error: #{host_name} name mismatch")
120
- refute_nil(hosts[host_name], "Error: #{host_name} not retrieved.")
121
- assert_equal(host_name, hosts[host_name].name,
122
- "Error: #{host_name} name get value mismatch")
103
+ assert_equal(@host_name, line.captures[0],
104
+ "Error: #{@host_name} name mismatch")
105
+ refute_nil(hosts[@host_name], "Error: #{@host_name} not retrieved.")
106
+ assert_equal(@host_name, hosts[@host_name].name,
107
+ "Error: #{@host_name} name get value mismatch")
123
108
 
124
- hosts.each { |name, host| host.destroy }
109
+ hosts.each_value(&:destroy)
125
110
  end
126
111
 
127
112
  def test_tacacsserverhost_get_name_formats
128
- host_name = "testhost.example.com"
129
- host_ip = "192.168.1.1"
113
+ host_name = 'testhost.example.com'
114
+ host_ip = '192.168.1.1'
130
115
 
131
- s = @device.cmd("configure terminal")
132
- s = @device.cmd("tacacs-server host #{host_name}")
133
- s = @device.cmd("tacacs-server host #{host_ip}")
134
- s = @device.cmd("end")
135
- node.cache_flush
116
+ config("tacacs-server host #{host_name}", "tacacs-server host #{host_ip}")
136
117
 
137
- line_name = get_tacacsserverhost_match_line(host_name)
138
- line_ip = get_tacacsserverhost_match_line(host_ip)
118
+ line_name = assert_show_match(
119
+ pattern: /tacacs-server host\s(testhost\.example\.com)(.*)/,
120
+ msg: 'Error: Tacacs Host not found')
121
+ line_ip = assert_show_match(
122
+ pattern: /tacacs-server host\s(192\.168\.1\.1)(.*)/,
123
+ msg: 'Error: Tacacs Host not found')
139
124
  hosts = TacacsServerHost.hosts
140
125
 
141
- refute_nil(line_name, "Error: Tacacs Host not found")
142
126
  assert_equal(host_name, line_name.captures[0],
143
127
  "Error: #{host_name} name mismatch")
144
128
  refute_nil(hosts[host_name], "Error: #{host_name} not retrieved.")
145
129
  assert_equal(host_name, hosts[host_name].name,
146
130
  "Error: #{host_name} name get value mismatch")
147
131
 
148
- refute_nil(line_ip, "Error: Tacacs Host not found")
149
132
  assert_equal(host_ip, line_ip.captures[0],
150
133
  "Error: #{host_ip} name mismatch")
151
134
  refute_nil(hosts[host_ip], "Error: #{host_ip} not retrieved.")
152
135
  assert_equal(host_ip, hosts[host_ip].name,
153
136
  "Error: #{host_ip} name get value mismatch")
154
137
 
155
- hosts.each { |name, host| host.destroy }
138
+ hosts.each_value(&:destroy)
156
139
  end
157
140
 
158
141
  def test_tacacsserverhost_get_port
159
- host_name = "testhost"
160
- host = TacacsServerHost.new(host_name)
142
+ host = TacacsServerHost.new(@host_name)
161
143
 
162
144
  # not previously configured
163
145
  port = DEFAULT_TACACS_SERVER_HOST_PORT
164
- assert_equal(port, host.port, "Error: Tacacs Host port incorrect")
146
+ assert_equal(port, host.port, 'Error: Tacacs Host port incorrect')
165
147
 
166
148
  # when configured
167
149
  port = 1138
168
- s = @device.cmd("configure terminal")
169
- s = @device.cmd("tacacs-server host #{host_name} port #{port}")
170
- s = @device.cmd("end")
171
- node.cache_flush
172
- assert_equal(port, host.port, "Error: Tacacs Host port incorrect")
150
+ config("tacacs-server host #{@host_name} port #{port}")
151
+ assert_equal(port, host.port, 'Error: Tacacs Host port incorrect')
173
152
 
174
153
  host.destroy
175
154
  end
176
155
 
177
156
  def test_tacacsserverhost_get_default_port
178
- host = TacacsServerHost.new("testhost")
157
+ host = TacacsServerHost.new('testhost')
179
158
 
180
159
  port = DEFAULT_TACACS_SERVER_HOST_PORT
181
160
  assert_equal(port, TacacsServerHost.default_port,
182
- "Error: Tacacs Host default port incorrect")
161
+ 'Error: Tacacs Host default port incorrect')
183
162
  host.destroy
184
163
  end
185
164
 
186
165
  def test_tacacsserverhost_set_port
187
- host_name = "testhost"
188
- host = TacacsServerHost.new(host_name)
166
+ host = TacacsServerHost.new(@host_name)
189
167
 
190
168
  port = 1138
191
169
  host.port = port
192
- line = get_tacacsserverhost_match_line(host_name)
193
- refute_nil(line, "Error: Tacacs Host not found")
170
+ line = assert_show_match(msg: 'Error: Tacacs Host not found')
171
+ assert_match(/port\s(\d*)/, line.captures[1])
194
172
  md = /port\s(\d*)/.match(line.captures[1])
195
- refute_nil(md, "Error: Tacacs Host port not found")
196
- assert_equal(port, md.captures[0].to_i, "Error: Tacacs Host port mismatch")
197
- assert_equal(port, host.port, "Error: Tacacs Host port incorrect")
173
+ assert_equal(port, md.captures[0].to_i, 'Error: Tacacs Host port mismatch')
174
+ assert_equal(port, host.port, 'Error: Tacacs Host port incorrect')
198
175
 
199
176
  host.destroy
200
177
  end
@@ -202,155 +179,132 @@ class TestTacacsServerHost < CiscoTestCase
202
179
  def test_tacacsserverhost_get_timeout
203
180
  # Cleanup first
204
181
  s = @device.cmd("show run | i 'tacacs.*timeout'")[/^tacacs.*timeout.*$/]
205
- if s
206
- s = @device.cmd("conf t ; no #{s} ; end")
207
- # puts "s is >#{s}<"
208
- node.cache_flush
209
- end
182
+ config("no #{s}") if s
210
183
 
211
- host_name = "testhost"
212
- host = TacacsServerHost.new(host_name)
184
+ host = TacacsServerHost.new(@host_name)
213
185
 
214
186
  # not previously configured
215
187
  timeout = DEFAULT_TACACS_SERVER_HOST_TIMEOUT
216
- assert_equal(timeout, host.timeout, "Error: Tacacs Host timeout incorrect")
188
+ assert_equal(timeout, host.timeout, 'Error: Tacacs Host timeout incorrect')
217
189
 
218
190
  # when configured
219
191
  timeout = 30
220
- s = @device.cmd("configure terminal")
221
- s = @device.cmd("tacacs-server host #{host_name} timeout #{timeout}")
222
- s = @device.cmd("end")
223
- node.cache_flush
224
- assert_equal(timeout, host.timeout, "Error: Tacacs Host timeout incorrect")
192
+ config("tacacs-server host #{@host_name} timeout #{timeout}")
193
+ assert_equal(timeout, host.timeout, 'Error: Tacacs Host timeout incorrect')
225
194
 
226
195
  host.destroy
227
196
  end
228
197
 
229
198
  def test_tacacsserverhost_get_default_timeout
230
- host = TacacsServerHost.new("testhost")
199
+ host = TacacsServerHost.new('testhost')
231
200
 
232
201
  timeout = DEFAULT_TACACS_SERVER_HOST_TIMEOUT
233
202
  assert_equal(timeout, TacacsServerHost.default_timeout,
234
- "Error: Tacacs Host default timeout incorrect")
203
+ 'Error: Tacacs Host default timeout incorrect')
235
204
  host.destroy
236
205
  end
237
206
 
238
207
  def test_tacacsserverhost_set_timeout
239
- host_name = "testhost"
240
- host = TacacsServerHost.new(host_name)
208
+ host = TacacsServerHost.new(@host_name)
241
209
 
242
210
  timeout = 30
243
211
  host.timeout = timeout
244
- line = get_tacacsserverhost_match_line(host_name)
245
- refute_nil(line, "Error: Tacacs Host not found")
212
+ line = assert_show_match(msg: 'Error: Tacacs Host not found')
213
+ assert_match(/timeout\s(\d*)/, line.captures[1])
246
214
  md = /timeout\s(\d*)/.match(line.captures[1])
247
- refute_nil(md, "Error: Tacacs Host timeout not found")
248
215
  assert_equal(timeout, md.captures[0].to_i,
249
- "Error: Tacacs Host timeout mismatch")
250
- assert_equal(timeout, host.timeout, "Error: Tacacs Host timeout incorrect")
216
+ 'Error: Tacacs Host timeout mismatch')
217
+ assert_equal(timeout, host.timeout, 'Error: Tacacs Host timeout incorrect')
251
218
 
252
219
  host.destroy
253
220
  end
254
221
 
255
222
  def test_tacacsserverhost_unset_timeout
256
- host_name = "testhost"
257
- host = TacacsServerHost.new(host_name)
223
+ host = TacacsServerHost.new(@host_name)
258
224
 
259
225
  timeout = DEFAULT_TACACS_SERVER_HOST_TIMEOUT
260
226
  host.timeout = timeout
261
- line = get_tacacsserverhost_match_line(host_name)
262
- refute_nil(line, "Error: Tacacs Host not found")
263
- md = /timeout\s(\d*)/.match(line.captures[1])
264
- assert_nil(md, "Error: Tacacs Host timeout found")
265
- assert_equal(timeout, host.timeout, "Error: Tacacs Host timeout incorrect")
227
+ line = assert_show_match(msg: 'Error: Tacacs Host not found')
228
+ refute_match(/timeout\s(\d*)/, line.captures[1])
229
+ assert_equal(timeout, host.timeout, 'Error: Tacacs Host timeout incorrect')
266
230
 
267
231
  host.destroy
268
232
  end
269
233
 
270
234
  def test_tacacsserverhost_get_encryption_type
271
- host_name = "testhost"
272
- host = TacacsServerHost.new(host_name)
235
+ host = TacacsServerHost.new(@host_name)
273
236
 
274
237
  # when not configured
275
238
  enctype = TACACS_SERVER_ENC_UNKNOWN
276
239
 
277
240
  assert_equal(enctype, host.encryption_type,
278
- "Error: Tacacs Host encryption type incorrect")
241
+ 'Error: Tacacs Host encryption type incorrect')
279
242
 
280
243
  # when configured
281
244
  enctype = TACACS_SERVER_ENC_NONE
282
245
  sh_run_enctype = TACACS_SERVER_ENC_CISCO_TYPE_7
283
- s = @device.cmd("configure terminal")
284
- s = @device.cmd("tacacs-server host #{host_name} key #{enctype} TEST")
285
- s = @device.cmd("end")
286
- node.cache_flush
246
+ config("tacacs-server host #{@host_name} key #{enctype} TEST")
287
247
  assert_equal(sh_run_enctype, host.encryption_type,
288
- "Error: Tacacs Host encryption type incorrect")
248
+ 'Error: Tacacs Host encryption type incorrect')
289
249
  host.destroy
290
250
  end
291
251
 
292
252
  def test_tacacsserverhost_get_default_encryption_type
293
- host = TacacsServerHost.new("testhost")
253
+ host = TacacsServerHost.new('testhost')
294
254
 
295
255
  assert_equal(TACACS_SERVER_ENC_NONE,
296
256
  TacacsServerHost.default_encryption_type,
297
- "Error: Tacacs Host default encryption type incorrect")
257
+ 'Error: Tacacs Host default encryption type incorrect')
298
258
  host.destroy
299
259
  end
300
260
 
301
261
  def test_tacacsserverhost_get_encryption_password
302
- host_name = "testhost"
303
- host = TacacsServerHost.new(host_name)
262
+ host = TacacsServerHost.new(@host_name)
304
263
 
305
264
  # when not configured
306
265
  pass = DEFAULT_TACACS_SERVER_HOST_ENCRYPTION_PASSWORD
307
266
  assert_equal(pass, host.encryption_password,
308
- "Error: Tacacs Host encryption password incorrect")
267
+ 'Error: Tacacs Host encryption password incorrect')
309
268
 
310
269
  # when configured
311
- pass = "TEST"
312
- sh_run_pass = "WAWY"
313
- s = @device.cmd("configure terminal")
314
- s = @device.cmd("tacacs-server host #{host_name} key 0 #{pass}")
315
- s = @device.cmd("end")
316
- node.cache_flush
270
+ pass = 'TEST'
271
+ sh_run_pass = 'WAWY'
272
+ config("tacacs-server host #{@host_name} key 0 #{pass}")
317
273
  assert_equal(sh_run_pass, host.encryption_password,
318
- "Error: Tacacs Host encryption password incorrect")
274
+ 'Error: Tacacs Host encryption password incorrect')
319
275
  host.destroy
320
276
  end
321
277
 
322
278
  def test_tacacsserverhost_get_default_encryption_password
323
- host = TacacsServerHost.new("testhost")
279
+ host = TacacsServerHost.new('testhost')
324
280
 
325
- assert_equal("", TacacsServerHost.default_encryption_password,
326
- "Error: Tacacs Host default encryption password incorrect")
281
+ assert_equal('', TacacsServerHost.default_encryption_password,
282
+ 'Error: Tacacs Host default encryption password incorrect')
327
283
  host.destroy
328
284
  end
329
285
 
330
286
  def test_tacacsserverhost_set_key
331
- host_name = "testhost"
332
- host = TacacsServerHost.new(host_name)
287
+ host = TacacsServerHost.new(@host_name)
333
288
 
334
289
  enctype = TACACS_SERVER_ENC_NONE
335
290
  sh_run_enctype = TACACS_SERVER_ENC_CISCO_TYPE_7
336
- pass = "TEST"
337
- sh_run_pass = "WAWY"
291
+ pass = 'TEST'
292
+ sh_run_pass = 'WAWY'
338
293
  host.encryption_key_set(enctype, pass)
339
294
 
340
- line = get_tacacsserverhost_match_line(host_name)
341
- refute_nil(line, "Error: Tacacs Host not found")
295
+ line = assert_show_match(msg: 'Error: Tacacs Host not found')
296
+ assert_match(/key\s(\d*)\s(\S*)/, line.captures[1])
342
297
  md = /key\s(\d*)\s(\S*)/.match(line.captures[1])
343
- refute_nil(md, "Error: Tacacs Host encryption not found")
344
298
  assert_equal(sh_run_enctype, md.captures[0].to_i,
345
- "Error: Tacacs Host encryption type mismatch")
299
+ 'Error: Tacacs Host encryption type mismatch')
346
300
  assert_equal(sh_run_enctype, host.encryption_type,
347
- "Error: Tacacs Host encryption type incorrect")
301
+ 'Error: Tacacs Host encryption type incorrect')
348
302
  # remove quotes surrounding the encrypted password
349
303
  pass_no_quotes = md.captures[1].gsub(/(?:^\")|(?:\"$)/, '')
350
304
  assert_equal(sh_run_pass, pass_no_quotes,
351
- "Error: Tacacs Host encryption password mismatch")
305
+ 'Error: Tacacs Host encryption password mismatch')
352
306
  assert_equal(sh_run_pass, host.encryption_password,
353
- "Error: Tacacs Host encryption password incorrect")
307
+ 'Error: Tacacs Host encryption password incorrect')
354
308
 
355
309
  host.destroy
356
310
  end
@@ -358,19 +312,14 @@ class TestTacacsServerHost < CiscoTestCase
358
312
  def test_tacacsserverhost_unset_key
359
313
  # Cleanup first
360
314
  s = @device.cmd("show run | i 'tacacs.*host'")[/^tacacs.*host.*$/]
361
- if s
362
- s = @device.cmd("conf t ; no #{s} ; end")
363
- # puts "s is >#{s}<"
364
- node.cache_flush
365
- end
315
+ config("no #{s}") if s
366
316
 
367
- host_name = "testhost"
368
- host = TacacsServerHost.new(host_name)
317
+ host = TacacsServerHost.new(@host_name)
369
318
 
370
319
  # First configure key value. Whether that can be passed
371
320
  # will be decided by test_tacacsserverhost_set_key
372
321
  enctype = TACACS_SERVER_ENC_NONE
373
- pass = "TEST"
322
+ pass = 'TEST'
374
323
  host.encryption_key_set(enctype, pass)
375
324
 
376
325
  # Now unconfigure the key and verify
@@ -378,14 +327,12 @@ class TestTacacsServerHost < CiscoTestCase
378
327
  pass = DEFAULT_TACACS_SERVER_HOST_ENCRYPTION_PASSWORD
379
328
  host.encryption_key_set(enctype, pass)
380
329
 
381
- line = get_tacacsserverhost_match_line(host_name)
382
- refute_nil(line, "Error: Tacacs Host not found")
383
- md = /key\s(\d*)\s(\S*)/.match(line.captures[1])
384
- assert_nil(md, "Error: Tacacs Host encryption found")
330
+ line = assert_show_match(msg: 'Error: Tacacs Host not found')
331
+ refute_match(/key\s(\d*)\s(\S*)/, line.captures[1])
385
332
  assert_equal(enctype, host.encryption_type,
386
- "Error: Tacacs Host encryption type incorrect")
333
+ 'Error: Tacacs Host encryption type incorrect')
387
334
  assert_equal(pass, host.encryption_password,
388
- "Error: Tacacs Host encryption password incorrect")
335
+ 'Error: Tacacs Host encryption password incorrect')
389
336
  host.destroy
390
337
  end
391
338
  end