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.
- checksums.yaml +7 -0
- data/.gitignore +4 -0
- data/.rubocop.yml +81 -1
- data/.travis.yml +9 -0
- data/CHANGELOG.md +72 -6
- data/CONTRIBUTING.md +32 -7
- data/README.md +70 -7
- data/Rakefile +17 -0
- data/bin/check_metric_limits.rb +109 -0
- data/bin/git/hooks/commit-msg/enforce_style +81 -0
- data/bin/git/hooks/hook_lib +108 -0
- data/bin/git/hooks/hooks-wrapper +38 -0
- data/bin/git/hooks/post-flow-hotfix-start/update-version +24 -0
- data/bin/git/hooks/post-flow-release-finish/update-version +29 -0
- data/bin/git/hooks/post-flow-release-start/update-version +19 -0
- data/bin/git/hooks/post-merge/update-hooks +6 -0
- data/bin/git/hooks/post-rewrite/update-hooks +6 -0
- data/bin/git/hooks/pre-commit/rubocop +20 -0
- data/bin/git/hooks/pre-commit/validate-diffs +31 -0
- data/bin/git/hooks/pre-push/check-changelog +24 -0
- data/bin/git/hooks/pre-push/rubocop +7 -0
- data/bin/git/update-hooks +65 -0
- data/cisco_node_utils.gemspec +9 -3
- data/docs/README-develop-best-practices.md +404 -0
- data/docs/README-develop-node-utils-APIs.md +215 -365
- data/docs/README-maintainers.md +33 -3
- data/docs/template-router.rb +89 -91
- data/docs/template-test_router.rb +52 -55
- data/lib/.rubocop.yml +18 -0
- data/lib/cisco_node_utils.rb +2 -19
- data/lib/cisco_node_utils/README_YAML.md +1 -9
- data/lib/cisco_node_utils/bgp.rb +664 -0
- data/lib/cisco_node_utils/bgp_af.rb +530 -0
- data/lib/cisco_node_utils/bgp_neighbor.rb +425 -0
- data/lib/cisco_node_utils/bgp_neighbor_af.rb +709 -0
- data/lib/cisco_node_utils/cisco_cmn_utils.rb +59 -25
- data/lib/cisco_node_utils/command_reference.rb +72 -74
- data/lib/cisco_node_utils/command_reference_common.yaml +174 -9
- data/lib/cisco_node_utils/command_reference_common_bgp.yaml +535 -0
- data/lib/cisco_node_utils/command_reference_n7k.yaml +4 -0
- data/lib/cisco_node_utils/command_reference_n9k.yaml +0 -9
- data/lib/cisco_node_utils/configparser_lib.rb +152 -147
- data/lib/cisco_node_utils/dns_domain.rb +79 -0
- data/lib/cisco_node_utils/domain_name.rb +71 -0
- data/lib/cisco_node_utils/interface.rb +167 -161
- data/lib/cisco_node_utils/interface_ospf.rb +78 -81
- data/lib/cisco_node_utils/name_server.rb +64 -0
- data/lib/cisco_node_utils/node.rb +154 -198
- data/lib/cisco_node_utils/node_util.rb +61 -0
- data/lib/cisco_node_utils/ntp_config.rb +65 -0
- data/lib/cisco_node_utils/ntp_server.rb +76 -0
- data/lib/cisco_node_utils/platform.rb +174 -165
- data/lib/cisco_node_utils/radius_global.rb +146 -0
- data/lib/cisco_node_utils/radius_server.rb +295 -0
- data/lib/cisco_node_utils/router_ospf.rb +59 -63
- data/lib/cisco_node_utils/router_ospf_vrf.rb +226 -210
- data/lib/cisco_node_utils/snmpcommunity.rb +52 -58
- data/lib/cisco_node_utils/snmpgroup.rb +22 -23
- data/lib/cisco_node_utils/snmpserver.rb +99 -103
- data/lib/cisco_node_utils/snmpuser.rb +294 -274
- data/lib/cisco_node_utils/syslog_server.rb +92 -0
- data/lib/cisco_node_utils/syslog_settings.rb +69 -0
- data/lib/cisco_node_utils/tacacs_server.rb +137 -133
- data/lib/cisco_node_utils/tacacs_server_host.rb +84 -87
- data/lib/cisco_node_utils/version.rb +2 -1
- data/lib/cisco_node_utils/vlan.rb +28 -31
- data/lib/cisco_node_utils/vrf.rb +80 -0
- data/lib/cisco_node_utils/vtp.rb +100 -97
- data/lib/cisco_node_utils/yum.rb +15 -17
- data/tests/.rubocop.yml +15 -0
- data/tests/basetest.rb +81 -36
- data/tests/ciscotest.rb +38 -78
- data/{lib/cisco_node_utils → tests}/platform_info.rb +12 -8
- data/{lib/cisco_node_utils → tests}/platform_info.yaml +1 -1
- data/tests/test_bgp_af.rb +920 -0
- data/tests/test_bgp_neighbor.rb +403 -0
- data/tests/test_bgp_neighbor_af.rb +589 -0
- data/tests/test_command_config.rb +65 -62
- data/tests/test_command_reference.rb +31 -45
- data/tests/test_dns_domain.rb +113 -0
- data/tests/test_domain_name.rb +86 -0
- data/tests/test_interface.rb +424 -548
- data/tests/test_interface_ospf.rb +248 -432
- data/tests/test_interface_svi.rb +56 -79
- data/tests/test_interface_switchport.rb +196 -272
- data/tests/test_name_server.rb +85 -0
- data/tests/test_node.rb +7 -6
- data/tests/test_node_ext.rb +133 -186
- data/tests/test_ntp_config.rb +49 -0
- data/tests/test_ntp_server.rb +74 -0
- data/tests/test_platform.rb +58 -37
- data/tests/test_radius_global.rb +78 -0
- data/tests/test_radius_server.rb +185 -0
- data/tests/test_router_bgp.rb +838 -0
- data/tests/test_router_ospf.rb +49 -80
- data/tests/test_router_ospf_vrf.rb +274 -392
- data/tests/test_snmpcommunity.rb +128 -172
- data/tests/test_snmpgroup.rb +12 -14
- data/tests/test_snmpserver.rb +160 -189
- data/tests/test_snmpuser.rb +568 -717
- data/tests/test_syslog_server.rb +88 -0
- data/tests/test_syslog_settings.rb +54 -0
- data/tests/test_tacacs_server.rb +113 -148
- data/tests/test_tacacs_server_host.rb +108 -161
- data/tests/test_vlan.rb +63 -79
- data/tests/test_vrf.rb +92 -0
- data/tests/test_vtp.rb +108 -126
- data/tests/test_yum.rb +47 -41
- metadata +92 -56
- data/.rubocop_todo.yml +0 -293
- data/docs/.rubocop.yml +0 -13
- data/docs/template-feature.rb +0 -45
- data/docs/template-test_feature.rb +0 -51
- 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
|
-
|
|
16
|
-
|
|
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
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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.
|
|
35
|
+
hosts.each_value(&:destroy)
|
|
35
36
|
hosts = TacacsServerHost.hosts
|
|
36
37
|
|
|
37
|
-
assert_empty(hosts,
|
|
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[
|
|
43
|
-
hosts_hash[
|
|
43
|
+
hosts_hash['testhost1'] = 1138
|
|
44
|
+
hosts_hash['testhost2'] = DEFAULT_TACACS_SERVER_HOST_PORT
|
|
44
45
|
|
|
45
|
-
hosts_hash.each
|
|
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,
|
|
52
|
-
hosts_hash.each
|
|
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.
|
|
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)
|
|
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)
|
|
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(
|
|
78
|
-
|
|
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
|
-
|
|
85
|
-
|
|
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
|
-
|
|
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
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
assert_equal(host_name,
|
|
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
|
-
|
|
98
|
+
config("tacacs-server host #{@host_name}")
|
|
108
99
|
|
|
109
|
-
|
|
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
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
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.
|
|
109
|
+
hosts.each_value(&:destroy)
|
|
125
110
|
end
|
|
126
111
|
|
|
127
112
|
def test_tacacsserverhost_get_name_formats
|
|
128
|
-
host_name =
|
|
129
|
-
host_ip =
|
|
113
|
+
host_name = 'testhost.example.com'
|
|
114
|
+
host_ip = '192.168.1.1'
|
|
130
115
|
|
|
131
|
-
|
|
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 =
|
|
138
|
-
|
|
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.
|
|
138
|
+
hosts.each_value(&:destroy)
|
|
156
139
|
end
|
|
157
140
|
|
|
158
141
|
def test_tacacsserverhost_get_port
|
|
159
|
-
|
|
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,
|
|
146
|
+
assert_equal(port, host.port, 'Error: Tacacs Host port incorrect')
|
|
165
147
|
|
|
166
148
|
# when configured
|
|
167
149
|
port = 1138
|
|
168
|
-
|
|
169
|
-
|
|
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(
|
|
157
|
+
host = TacacsServerHost.new('testhost')
|
|
179
158
|
|
|
180
159
|
port = DEFAULT_TACACS_SERVER_HOST_PORT
|
|
181
160
|
assert_equal(port, TacacsServerHost.default_port,
|
|
182
|
-
|
|
161
|
+
'Error: Tacacs Host default port incorrect')
|
|
183
162
|
host.destroy
|
|
184
163
|
end
|
|
185
164
|
|
|
186
165
|
def test_tacacsserverhost_set_port
|
|
187
|
-
|
|
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 =
|
|
193
|
-
|
|
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
|
-
|
|
196
|
-
assert_equal(port,
|
|
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
|
-
|
|
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,
|
|
188
|
+
assert_equal(timeout, host.timeout, 'Error: Tacacs Host timeout incorrect')
|
|
217
189
|
|
|
218
190
|
# when configured
|
|
219
191
|
timeout = 30
|
|
220
|
-
|
|
221
|
-
|
|
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(
|
|
199
|
+
host = TacacsServerHost.new('testhost')
|
|
231
200
|
|
|
232
201
|
timeout = DEFAULT_TACACS_SERVER_HOST_TIMEOUT
|
|
233
202
|
assert_equal(timeout, TacacsServerHost.default_timeout,
|
|
234
|
-
|
|
203
|
+
'Error: Tacacs Host default timeout incorrect')
|
|
235
204
|
host.destroy
|
|
236
205
|
end
|
|
237
206
|
|
|
238
207
|
def test_tacacsserverhost_set_timeout
|
|
239
|
-
|
|
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 =
|
|
245
|
-
|
|
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
|
-
|
|
250
|
-
assert_equal(timeout, host.timeout,
|
|
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
|
-
|
|
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 =
|
|
262
|
-
|
|
263
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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(
|
|
253
|
+
host = TacacsServerHost.new('testhost')
|
|
294
254
|
|
|
295
255
|
assert_equal(TACACS_SERVER_ENC_NONE,
|
|
296
256
|
TacacsServerHost.default_encryption_type,
|
|
297
|
-
|
|
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
|
-
|
|
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
|
-
|
|
267
|
+
'Error: Tacacs Host encryption password incorrect')
|
|
309
268
|
|
|
310
269
|
# when configured
|
|
311
|
-
pass =
|
|
312
|
-
sh_run_pass =
|
|
313
|
-
|
|
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
|
-
|
|
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(
|
|
279
|
+
host = TacacsServerHost.new('testhost')
|
|
324
280
|
|
|
325
|
-
assert_equal(
|
|
326
|
-
|
|
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
|
-
|
|
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 =
|
|
337
|
-
sh_run_pass =
|
|
291
|
+
pass = 'TEST'
|
|
292
|
+
sh_run_pass = 'WAWY'
|
|
338
293
|
host.encryption_key_set(enctype, pass)
|
|
339
294
|
|
|
340
|
-
line =
|
|
341
|
-
|
|
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
|
-
|
|
299
|
+
'Error: Tacacs Host encryption type mismatch')
|
|
346
300
|
assert_equal(sh_run_enctype, host.encryption_type,
|
|
347
|
-
|
|
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
|
-
|
|
305
|
+
'Error: Tacacs Host encryption password mismatch')
|
|
352
306
|
assert_equal(sh_run_pass, host.encryption_password,
|
|
353
|
-
|
|
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
|
-
|
|
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 =
|
|
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 =
|
|
382
|
-
|
|
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
|
-
|
|
333
|
+
'Error: Tacacs Host encryption type incorrect')
|
|
387
334
|
assert_equal(pass, host.encryption_password,
|
|
388
|
-
|
|
335
|
+
'Error: Tacacs Host encryption password incorrect')
|
|
389
336
|
host.destroy
|
|
390
337
|
end
|
|
391
338
|
end
|