cisco_node_utils 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -0,0 +1,49 @@
|
|
1
|
+
#
|
2
|
+
# Minitest for NtpConfig class
|
3
|
+
#
|
4
|
+
# Copyright (c) 2015 Cisco and/or its affiliates.
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
|
18
|
+
require_relative 'ciscotest'
|
19
|
+
require_relative '../lib/cisco_node_utils/ntp_config'
|
20
|
+
|
21
|
+
# TestNtpConfig - Minitest for NtpConfig node utility.
|
22
|
+
class TestNtpConfig < CiscoTestCase
|
23
|
+
def setup
|
24
|
+
# setup runs at the beginning of each test
|
25
|
+
super
|
26
|
+
no_ntpconfig
|
27
|
+
end
|
28
|
+
|
29
|
+
def no_ntpconfig
|
30
|
+
# Turn the feature off for a clean test.
|
31
|
+
config("no ntp source-interface #{interfaces[0]}")
|
32
|
+
end
|
33
|
+
|
34
|
+
# TESTS
|
35
|
+
|
36
|
+
def test_ntpconfig_create_destroy_single
|
37
|
+
id = 'default'
|
38
|
+
|
39
|
+
ntp = Cisco::NtpConfig.new(id)
|
40
|
+
assert_includes(Cisco::NtpConfig.ntpconfigs, id)
|
41
|
+
assert_equal(Cisco::NtpConfig.ntpconfigs[id], ntp)
|
42
|
+
|
43
|
+
ntp.source_interface = interfaces[1]
|
44
|
+
assert_equal(Cisco::NtpConfig.ntpconfigs[id].source_interface,
|
45
|
+
interfaces[1].downcase)
|
46
|
+
assert_equal(Cisco::NtpConfig.ntpconfigs[id].source_interface,
|
47
|
+
ntp.source_interface)
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
#
|
2
|
+
# Minitest for NtpServer class
|
3
|
+
#
|
4
|
+
# Copyright (c) 2014-2015 Cisco and/or its affiliates.
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
|
18
|
+
require_relative 'ciscotest'
|
19
|
+
require_relative '../lib/cisco_node_utils/ntp_server'
|
20
|
+
|
21
|
+
# TestNtpServer - Minitest for NtpServer node utility.
|
22
|
+
class TestNtpServer < CiscoTestCase
|
23
|
+
def setup
|
24
|
+
# setup runs at the beginning of each test
|
25
|
+
super
|
26
|
+
no_ntpserver_uk
|
27
|
+
end
|
28
|
+
|
29
|
+
def teardown
|
30
|
+
# teardown runs at the end of each test
|
31
|
+
no_ntpserver_uk
|
32
|
+
super
|
33
|
+
end
|
34
|
+
|
35
|
+
def no_ntpserver_uk
|
36
|
+
# Turn the feature off for a clean test.
|
37
|
+
config('no ntpserver 130.88.203.12',
|
38
|
+
'no ntpserver 194.207.34.9')
|
39
|
+
end
|
40
|
+
|
41
|
+
# TESTS
|
42
|
+
|
43
|
+
def test_ntpserver_create_destroy_single_ipv4
|
44
|
+
id = '130.88.203.12'
|
45
|
+
refute_includes(Cisco::NtpServer.ntpservers, id)
|
46
|
+
|
47
|
+
ntp = Cisco::NtpServer.new(id, false)
|
48
|
+
assert_includes(Cisco::NtpServer.ntpservers, id)
|
49
|
+
assert_equal(Cisco::NtpServer.ntpservers[id], ntp)
|
50
|
+
|
51
|
+
ntp.destroy
|
52
|
+
refute_includes(Cisco::NtpServer.ntpservers, id)
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_ntpserver_create_destroy_multiple
|
56
|
+
id1 = '130.88.203.12'
|
57
|
+
id2 = '194.207.34.9'
|
58
|
+
refute_includes(Cisco::NtpServer.ntpservers, id1)
|
59
|
+
refute_includes(Cisco::NtpServer.ntpservers, id2)
|
60
|
+
|
61
|
+
ntp1 = Cisco::NtpServer.new(id1, false)
|
62
|
+
ntp2 = Cisco::NtpServer.new(id2, true)
|
63
|
+
refute_equal(ntp1, ntp2)
|
64
|
+
assert_includes(Cisco::NtpServer.ntpservers, id1)
|
65
|
+
assert_includes(Cisco::NtpServer.ntpservers, id2)
|
66
|
+
assert_equal(Cisco::NtpServer.ntpservers[id1], ntp1)
|
67
|
+
assert_equal(Cisco::NtpServer.ntpservers[id2], ntp2)
|
68
|
+
|
69
|
+
ntp1.destroy
|
70
|
+
ntp2.destroy
|
71
|
+
refute_includes(Cisco::NtpServer.ntpservers, id1)
|
72
|
+
refute_includes(Cisco::NtpServer.ntpservers, id2)
|
73
|
+
end
|
74
|
+
end
|
data/tests/test_platform.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
|
-
|
16
|
-
|
15
|
+
require_relative 'ciscotest'
|
16
|
+
require_relative '../lib/cisco_node_utils/platform'
|
17
17
|
|
18
|
+
# TestPlatform - Minitest for Platform class
|
18
19
|
class TestPlatform < CiscoTestCase
|
19
20
|
def test_system_image
|
20
21
|
s = @device.cmd('show version | i image').scan(/ (\S+)$/).flatten.first
|
@@ -37,27 +38,29 @@ class TestPlatform < CiscoTestCase
|
|
37
38
|
# hardware type returns a different value depending on whether you use the
|
38
39
|
# ascii or show output of nxapi, but show appears to be substring of ascii
|
39
40
|
assert(s.include?(Platform.hardware_type),
|
40
|
-
|
41
|
+
"Expected '#{s}' to contain '#{Platform.hardware_type}'")
|
41
42
|
end
|
42
43
|
|
43
44
|
def test_cpu
|
44
|
-
s = @device.cmd('sh ver | no-m').scan(
|
45
|
+
s = @device.cmd('sh ver | no-m').scan(
|
46
|
+
/Hardware\n\s+.*\n\s+(.*) with/).flatten.first
|
45
47
|
assert_equal(s, Platform.cpu)
|
46
48
|
end
|
47
49
|
|
48
50
|
def test_memory
|
49
|
-
arr = @device.cmd('sh sys reso').scan(
|
51
|
+
arr = @device.cmd('sh sys reso').scan(
|
52
|
+
/(\S+) total.* (\S+) used.* (\S+) free/).flatten
|
50
53
|
mem_hsh = { 'total' => arr[0],
|
51
54
|
'used' => arr[1],
|
52
|
-
'free' => arr[2]
|
55
|
+
'free' => arr[2] }
|
53
56
|
# used and free memory change rapidly, compare total and sums of free + used
|
54
57
|
assert_equal(mem_hsh['total'], Platform.memory['total'])
|
55
|
-
assert_equal(
|
56
|
-
|
57
|
-
|
58
|
-
)
|
59
|
-
# assert(Platform.memory.has_key?('
|
60
|
-
#
|
58
|
+
assert_equal(mem_hsh['used'].to_i + mem_hsh['free'].to_i,
|
59
|
+
Platform.memory['used'].to_i + Platform.memory['free'].to_i)
|
60
|
+
# assert(Platform.memory.has_key?('used'),
|
61
|
+
# "Platform memory has no key 'used'")
|
62
|
+
# assert(Platform.memory.has_key?('free'),
|
63
|
+
# "Platform memory has no key 'free'")
|
61
64
|
end
|
62
65
|
|
63
66
|
def test_board
|
@@ -100,88 +103,106 @@ class TestPlatform < CiscoTestCase
|
|
100
103
|
# Everything from DESCR onwards follows the same general format so we
|
101
104
|
# can define a single base regexp and extend it as needed for Chassis, Slot,
|
102
105
|
# Power Supply, and Fan inventory entries.
|
103
|
-
|
106
|
+
def inv_cmn_re
|
107
|
+
/.*DESCR:\s+"(.*)"\s*\nPID:\s+(\S+).*VID:\s+(\S+).*SN:\s+(\S+)/
|
108
|
+
end
|
104
109
|
|
105
110
|
def test_chassis
|
106
|
-
arr = @device.cmd('sh inv | no-m').scan(/NAME:\s+"Chassis"#{
|
111
|
+
arr = @device.cmd('sh inv | no-m').scan(/NAME:\s+"Chassis"#{inv_cmn_re}/)
|
107
112
|
arr = arr.flatten
|
108
113
|
# convert to hash
|
109
114
|
chas_hsh = { 'descr' => arr[0],
|
110
115
|
'pid' => arr[1],
|
111
116
|
'vid' => arr[2],
|
112
|
-
'sn' => arr[3],
|
117
|
+
'sn' => arr[3],
|
118
|
+
}
|
113
119
|
assert_equal(chas_hsh, Platform.chassis)
|
114
120
|
end
|
115
121
|
|
116
122
|
def test_slots
|
117
123
|
slots_arr_arr = @device.cmd('sh inv | no-m')
|
118
|
-
.scan(/NAME:\s+"(Slot \d+)"#{
|
124
|
+
.scan(/NAME:\s+"(Slot \d+)"#{inv_cmn_re}/)
|
119
125
|
# convert to array of slot hashes
|
120
126
|
slots_hsh_hsh = {}
|
121
|
-
slots_arr_arr.each
|
127
|
+
slots_arr_arr.each do |slot|
|
122
128
|
slots_hsh_hsh[slot[0]] = { 'descr' => slot[1],
|
123
129
|
'pid' => slot[2],
|
124
130
|
'vid' => slot[3],
|
125
|
-
'sn' => slot[4],
|
126
|
-
|
131
|
+
'sn' => slot[4],
|
132
|
+
}
|
133
|
+
end
|
127
134
|
assert_equal(slots_hsh_hsh, Platform.slots)
|
128
135
|
end
|
129
136
|
|
130
137
|
def test_power_supplies
|
131
138
|
pwr_arr_arr = @device.cmd('sh inv | no-m')
|
132
|
-
.scan(/NAME:\s+"(Power Supply \d+)"#{
|
133
|
-
refute_empty(pwr_arr_arr,
|
139
|
+
.scan(/NAME:\s+"(Power Supply \d+)"#{inv_cmn_re}/)
|
140
|
+
refute_empty(pwr_arr_arr,
|
141
|
+
'Regex scan failed to match show inventory output')
|
134
142
|
|
135
143
|
# convert to array of power supply hashes
|
136
144
|
pwr_hsh_hsh = {}
|
137
|
-
pwr_arr_arr.each
|
145
|
+
pwr_arr_arr.each do |pwr|
|
138
146
|
pwr_hsh_hsh[pwr[0]] = { 'descr' => pwr[1],
|
139
147
|
'pid' => pwr[2],
|
140
148
|
'vid' => pwr[3],
|
141
|
-
'sn' => pwr[4],
|
142
|
-
|
149
|
+
'sn' => pwr[4],
|
150
|
+
}
|
151
|
+
end
|
143
152
|
assert_equal(pwr_hsh_hsh, Platform.power_supplies)
|
144
153
|
end
|
145
154
|
|
146
155
|
def test_fans
|
147
156
|
fan_arr_arr = @device.cmd('sh inv | no-m')
|
148
|
-
.scan(/NAME:\s+"(Fan \d+)"#{
|
149
|
-
refute_empty(fan_arr_arr,
|
157
|
+
.scan(/NAME:\s+"(Fan \d+)"#{inv_cmn_re}/)
|
158
|
+
refute_empty(fan_arr_arr,
|
159
|
+
'Regex scan failed to match show inventory output')
|
150
160
|
|
151
161
|
# convert to array of fan hashes
|
152
162
|
fan_hsh_hsh = {}
|
153
|
-
fan_arr_arr.each
|
163
|
+
fan_arr_arr.each do |fan|
|
154
164
|
fan_hsh_hsh[fan[0]] = { 'descr' => fan[1],
|
155
165
|
'pid' => fan[2],
|
156
166
|
'vid' => fan[3],
|
157
|
-
'sn' => fan[4],
|
158
|
-
|
167
|
+
'sn' => fan[4],
|
168
|
+
}
|
169
|
+
end
|
159
170
|
assert_equal(fan_hsh_hsh, Platform.fans)
|
160
171
|
end
|
161
172
|
|
162
173
|
def test_virtual_services
|
174
|
+
skip('Skip test: No virtual-services installed') unless
|
175
|
+
@device.cmd('show virtual-service list')[/Name\s+Status\s+Package Name/]
|
176
|
+
|
163
177
|
# this would be beyond ugly to parse from ascii, utilize config_get
|
164
|
-
vir_arr = node.config_get(
|
178
|
+
vir_arr = node.config_get('virtual_service', 'services')
|
165
179
|
vir_arr = [vir_arr] if vir_arr.is_a? Hash
|
166
180
|
# convert to expected format
|
167
181
|
vir_hsh_hsh = {}
|
168
182
|
unless vir_arr.nil?
|
169
|
-
vir_arr.each
|
183
|
+
vir_arr.each do |serv|
|
184
|
+
# rubocop:disable Style/AlignHash, Style/ExtraSpacing
|
170
185
|
vir_hsh_hsh[serv['name']] = {
|
171
186
|
'package_info' => { 'name' => serv['package_name'],
|
172
|
-
'path' => serv['ova_path'],
|
187
|
+
'path' => serv['ova_path'],
|
188
|
+
},
|
173
189
|
'application' => { 'name' => serv['application_name'],
|
174
190
|
'version' => serv['application_version'],
|
175
|
-
'descr' => serv['application_description'],
|
191
|
+
'descr' => serv['application_description'],
|
192
|
+
},
|
176
193
|
'signing' => { 'key_type' => serv['key_type'],
|
177
|
-
'method' => serv['signing_method'],
|
194
|
+
'method' => serv['signing_method'],
|
195
|
+
},
|
178
196
|
'licensing' => { 'name' => serv['licensing_name'],
|
179
|
-
'version' => serv['licensing_version'],
|
197
|
+
'version' => serv['licensing_version'],
|
198
|
+
},
|
180
199
|
'reservation' => { 'disk' => serv['disk_reservation'],
|
181
200
|
'memory' => serv['memory_reservation'],
|
182
|
-
'cpu' => serv['cpu_reservation'],
|
201
|
+
'cpu' => serv['cpu_reservation'],
|
202
|
+
},
|
183
203
|
}
|
184
|
-
|
204
|
+
# rubocop:enable Style/AlignHash, Style/ExtraSpacing
|
205
|
+
end
|
185
206
|
end
|
186
207
|
assert_equal(vir_hsh_hsh, Platform.virtual_services)
|
187
208
|
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
#
|
2
|
+
# Minitest for RadiusGlobal class
|
3
|
+
#
|
4
|
+
# Copyright (c) 2014-2015 Cisco and/or its affiliates.
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
|
18
|
+
require_relative 'ciscotest'
|
19
|
+
require_relative '../lib/cisco_node_utils/radius_global'
|
20
|
+
|
21
|
+
# TestRadiusGlobal - Minitest for RadiusGlobal node utility.
|
22
|
+
class TestRadiusGlobal < CiscoTestCase
|
23
|
+
def setup
|
24
|
+
# setup runs at the beginning of each test
|
25
|
+
super
|
26
|
+
no_radius_global
|
27
|
+
end
|
28
|
+
|
29
|
+
def teardown
|
30
|
+
# teardown runs at the end of each test
|
31
|
+
no_radius_global
|
32
|
+
super
|
33
|
+
end
|
34
|
+
|
35
|
+
def no_radius_global
|
36
|
+
# Turn the feature off for a clean test.
|
37
|
+
config('no radius-server timeout 2',
|
38
|
+
'no radius-server retransmit 3')
|
39
|
+
end
|
40
|
+
|
41
|
+
# TESTS
|
42
|
+
|
43
|
+
def test_radius_global
|
44
|
+
id = 'default'
|
45
|
+
|
46
|
+
global = Cisco::RadiusGlobal.new(id)
|
47
|
+
assert_includes(Cisco::RadiusGlobal.radius_global, id)
|
48
|
+
assert_equal(Cisco::RadiusGlobal.radius_global[id], global)
|
49
|
+
|
50
|
+
# Default Checking
|
51
|
+
assert_equal(global.timeout, global.default_timeout)
|
52
|
+
assert_equal(global.retransmit_count, global.default_retransmit_count)
|
53
|
+
|
54
|
+
global.retransmit_count = 3
|
55
|
+
assert_equal(Cisco::RadiusGlobal.radius_global[id].retransmit_count,
|
56
|
+
3)
|
57
|
+
assert_equal(global.retransmit_count,
|
58
|
+
3)
|
59
|
+
|
60
|
+
global.timeout = 2
|
61
|
+
assert_equal(Cisco::RadiusGlobal.radius_global[id].timeout,
|
62
|
+
2)
|
63
|
+
assert_equal(global.timeout,
|
64
|
+
2)
|
65
|
+
|
66
|
+
global.key_set('44444444', nil)
|
67
|
+
assert_equal(Cisco::RadiusGlobal.radius_global[id].key,
|
68
|
+
'44444444')
|
69
|
+
assert_equal(global.key,
|
70
|
+
'44444444')
|
71
|
+
|
72
|
+
# Setting back to default and re-checking
|
73
|
+
global.timeout = global.default_timeout
|
74
|
+
global.retransmit_count = global.default_retransmit_count
|
75
|
+
assert_equal(global.timeout, global.default_timeout)
|
76
|
+
assert_equal(global.retransmit_count, global.default_retransmit_count)
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,185 @@
|
|
1
|
+
#
|
2
|
+
# Minitest for RadiusServer class
|
3
|
+
#
|
4
|
+
# Copyright (c) 2014-2015 Cisco and/or its affiliates.
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
|
18
|
+
require_relative 'ciscotest'
|
19
|
+
require_relative '../lib/cisco_node_utils/radius_server'
|
20
|
+
|
21
|
+
# TestRadiusServer - Minitest for RadiusServer node utility.
|
22
|
+
class TestRadiusServer < CiscoTestCase
|
23
|
+
def setup
|
24
|
+
# setup runs at the beginning of each test
|
25
|
+
super
|
26
|
+
no_radiusserver
|
27
|
+
end
|
28
|
+
|
29
|
+
def teardown
|
30
|
+
# teardown runs at the end of each test
|
31
|
+
no_radiusserver
|
32
|
+
super
|
33
|
+
end
|
34
|
+
|
35
|
+
def no_radiusserver
|
36
|
+
# Turn the feature off for a clean test.
|
37
|
+
config('no radius-server host 8.8.8.8',
|
38
|
+
'no radius-server host 9.9.9.9')
|
39
|
+
end
|
40
|
+
|
41
|
+
# TESTS
|
42
|
+
|
43
|
+
def test_radiusserver_create_destroy_single
|
44
|
+
id = '8.8.8.8'
|
45
|
+
refute_includes(Cisco::RadiusServer.radiusservers, id)
|
46
|
+
|
47
|
+
server = Cisco::RadiusServer.new(id, true)
|
48
|
+
assert_includes(Cisco::RadiusServer.radiusservers, id)
|
49
|
+
assert_equal(Cisco::RadiusServer.radiusservers[id], server)
|
50
|
+
|
51
|
+
# Default checking
|
52
|
+
assert_equal(server.acct_port, server.default_acct_port)
|
53
|
+
assert_equal(server.auth_port, server.default_auth_port)
|
54
|
+
assert_equal(server.accounting, server.default_accounting)
|
55
|
+
assert_equal(server.authentication, server.default_authentication)
|
56
|
+
|
57
|
+
server.accounting = true
|
58
|
+
assert(Cisco::RadiusServer.radiusservers[id].accounting)
|
59
|
+
|
60
|
+
server.authentication = true
|
61
|
+
assert(Cisco::RadiusServer.radiusservers[id].authentication)
|
62
|
+
|
63
|
+
server.acct_port = 44
|
64
|
+
assert_equal(Cisco::RadiusServer.radiusservers[id].acct_port,
|
65
|
+
44)
|
66
|
+
|
67
|
+
server.auth_port = 55
|
68
|
+
assert_equal(Cisco::RadiusServer.radiusservers[id].auth_port,
|
69
|
+
55)
|
70
|
+
|
71
|
+
server.retransmit_count = 3
|
72
|
+
assert_equal(Cisco::RadiusServer.radiusservers[id].retransmit_count,
|
73
|
+
3)
|
74
|
+
|
75
|
+
server.key_set('44444444', nil)
|
76
|
+
assert_equal(Cisco::RadiusServer.radiusservers[id].key,
|
77
|
+
'44444444')
|
78
|
+
|
79
|
+
# Setting back to default and re-checking
|
80
|
+
server.acct_port = server.default_acct_port
|
81
|
+
server.auth_port = server.default_auth_port
|
82
|
+
server.accounting = server.default_accounting
|
83
|
+
server.authentication = server.default_authentication
|
84
|
+
assert_equal(server.acct_port, server.default_acct_port)
|
85
|
+
assert_equal(server.auth_port, server.default_auth_port)
|
86
|
+
assert_equal(server.accounting, server.default_accounting)
|
87
|
+
assert_equal(server.authentication, server.default_authentication)
|
88
|
+
|
89
|
+
server.destroy
|
90
|
+
refute_includes(Cisco::RadiusServer.radiusservers, id)
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_radiusserver_create_destroy_multiple
|
94
|
+
id = '8.8.8.8'
|
95
|
+
id2 = '9.9.9.9'
|
96
|
+
refute_includes(Cisco::RadiusServer.radiusservers, id)
|
97
|
+
refute_includes(Cisco::RadiusServer.radiusservers, id2)
|
98
|
+
|
99
|
+
server = Cisco::RadiusServer.new(id, true)
|
100
|
+
server2 = Cisco::RadiusServer.new(id2, true)
|
101
|
+
assert_includes(Cisco::RadiusServer.radiusservers, id)
|
102
|
+
assert_equal(Cisco::RadiusServer.radiusservers[id], server)
|
103
|
+
assert_includes(Cisco::RadiusServer.radiusservers, id2)
|
104
|
+
assert_equal(Cisco::RadiusServer.radiusservers[id2], server2)
|
105
|
+
|
106
|
+
# Default checking
|
107
|
+
assert_equal(server.acct_port, server.default_acct_port)
|
108
|
+
assert_equal(server.auth_port, server.default_auth_port)
|
109
|
+
assert_equal(server.accounting, server.default_accounting)
|
110
|
+
assert_equal(server.authentication, server.default_authentication)
|
111
|
+
assert_equal(server2.acct_port, server2.default_acct_port)
|
112
|
+
assert_equal(server2.auth_port, server2.default_auth_port)
|
113
|
+
assert_equal(server2.accounting, server2.default_accounting)
|
114
|
+
assert_equal(server2.authentication, server2.default_authentication)
|
115
|
+
|
116
|
+
server.accounting = true
|
117
|
+
assert(Cisco::RadiusServer.radiusservers[id].accounting)
|
118
|
+
|
119
|
+
server.authentication = true
|
120
|
+
assert(Cisco::RadiusServer.radiusservers[id].authentication)
|
121
|
+
|
122
|
+
server.acct_port = 44
|
123
|
+
assert_equal(Cisco::RadiusServer.radiusservers[id].acct_port,
|
124
|
+
44)
|
125
|
+
|
126
|
+
server.auth_port = 55
|
127
|
+
assert_equal(Cisco::RadiusServer.radiusservers[id].auth_port,
|
128
|
+
55)
|
129
|
+
|
130
|
+
server.retransmit_count = 3
|
131
|
+
assert_equal(Cisco::RadiusServer.radiusservers[id].retransmit_count,
|
132
|
+
3)
|
133
|
+
|
134
|
+
server.key_set('44444444', nil)
|
135
|
+
assert_equal(Cisco::RadiusServer.radiusservers[id].key,
|
136
|
+
'44444444')
|
137
|
+
assert_equal(server.key,
|
138
|
+
'44444444')
|
139
|
+
|
140
|
+
server2.accounting = true
|
141
|
+
assert(Cisco::RadiusServer.radiusservers[id2].accounting)
|
142
|
+
|
143
|
+
server2.authentication = true
|
144
|
+
assert(Cisco::RadiusServer.radiusservers[id2].authentication)
|
145
|
+
|
146
|
+
server2.acct_port = 44
|
147
|
+
assert_equal(Cisco::RadiusServer.radiusservers[id2].acct_port,
|
148
|
+
44)
|
149
|
+
|
150
|
+
server2.auth_port = 55
|
151
|
+
assert_equal(Cisco::RadiusServer.radiusservers[id2].auth_port,
|
152
|
+
55)
|
153
|
+
|
154
|
+
server2.retransmit_count = 3
|
155
|
+
assert_equal(Cisco::RadiusServer.radiusservers[id2].retransmit_count,
|
156
|
+
3)
|
157
|
+
|
158
|
+
server2.key_set('44444444', nil)
|
159
|
+
assert_equal(Cisco::RadiusServer.radiusservers[id2].key,
|
160
|
+
'44444444')
|
161
|
+
|
162
|
+
# Setting back to default and re-checking
|
163
|
+
server.acct_port = server.default_acct_port
|
164
|
+
server.auth_port = server.default_auth_port
|
165
|
+
server.accounting = server.default_accounting
|
166
|
+
server.authentication = server.default_authentication
|
167
|
+
server2.acct_port = server2.default_acct_port
|
168
|
+
server2.auth_port = server2.default_auth_port
|
169
|
+
server2.accounting = server2.default_accounting
|
170
|
+
server2.authentication = server2.default_authentication
|
171
|
+
assert_equal(server.acct_port, server.default_acct_port)
|
172
|
+
assert_equal(server.auth_port, server.default_auth_port)
|
173
|
+
assert_equal(server.accounting, server.default_accounting)
|
174
|
+
assert_equal(server.authentication, server.default_authentication)
|
175
|
+
assert_equal(server2.acct_port, server2.default_acct_port)
|
176
|
+
assert_equal(server2.auth_port, server2.default_auth_port)
|
177
|
+
assert_equal(server2.accounting, server2.default_accounting)
|
178
|
+
assert_equal(server2.authentication, server2.default_authentication)
|
179
|
+
|
180
|
+
server.destroy
|
181
|
+
server2.destroy
|
182
|
+
refute_includes(Cisco::RadiusServer.radiusservers, id)
|
183
|
+
refute_includes(Cisco::RadiusServer.radiusservers, id2)
|
184
|
+
end
|
185
|
+
end
|