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
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Minitest for SyslogServer 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/syslog_server'
|
|
20
|
+
|
|
21
|
+
# TestSyslogServer - Minitest for SyslogServer node utility.
|
|
22
|
+
class TestSyslogServer < CiscoTestCase
|
|
23
|
+
def setup
|
|
24
|
+
# setup runs at the beginning of each test
|
|
25
|
+
super
|
|
26
|
+
no_syslogserver
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def teardown
|
|
30
|
+
# teardown runs at the end of each test
|
|
31
|
+
no_syslogserver
|
|
32
|
+
super
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def no_syslogserver
|
|
36
|
+
# Turn the feature off for a clean test.
|
|
37
|
+
config('no logging server 1.2.3.4',
|
|
38
|
+
'no logging server 2.3.4.5',
|
|
39
|
+
'no vrf context red')
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# TESTS
|
|
43
|
+
|
|
44
|
+
def test_syslogserver_create_destroy_single
|
|
45
|
+
id = '1.2.3.4'
|
|
46
|
+
refute_includes(Cisco::SyslogServer.syslogservers, id)
|
|
47
|
+
|
|
48
|
+
server = Cisco::SyslogServer.new(id, 2, 'default', true)
|
|
49
|
+
assert_includes(Cisco::SyslogServer.syslogservers, id)
|
|
50
|
+
assert_equal(Cisco::SyslogServer.syslogservers[id], server)
|
|
51
|
+
|
|
52
|
+
server.destroy
|
|
53
|
+
refute_includes(Cisco::SyslogServer.syslogservers, id)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def test_syslogserver_create_destroy_multiple
|
|
57
|
+
id = '1.2.3.4'
|
|
58
|
+
id2 = '2.3.4.5'
|
|
59
|
+
refute_includes(Cisco::SyslogServer.syslogservers, id)
|
|
60
|
+
refute_includes(Cisco::SyslogServer.syslogservers, id2)
|
|
61
|
+
|
|
62
|
+
server = Cisco::SyslogServer.new(id, 2, 'default', true)
|
|
63
|
+
server2 = Cisco::SyslogServer.new(id2, 2, 'default', true)
|
|
64
|
+
assert_includes(Cisco::SyslogServer.syslogservers, id)
|
|
65
|
+
assert_equal(Cisco::SyslogServer.syslogservers[id], server)
|
|
66
|
+
assert_includes(Cisco::SyslogServer.syslogservers, id2)
|
|
67
|
+
assert_equal(Cisco::SyslogServer.syslogservers[id2], server2)
|
|
68
|
+
|
|
69
|
+
server.destroy
|
|
70
|
+
server2.destroy
|
|
71
|
+
refute_includes(Cisco::SyslogServer.syslogservers, id)
|
|
72
|
+
refute_includes(Cisco::SyslogServer.syslogservers, id2)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def test_syslogserver_create_destroy_single_vrf
|
|
76
|
+
config('vrf context red')
|
|
77
|
+
id = '1.2.3.4'
|
|
78
|
+
|
|
79
|
+
refute_includes(Cisco::SyslogServer.syslogservers, id)
|
|
80
|
+
|
|
81
|
+
server = Cisco::SyslogServer.new(id, 2, 'red', true)
|
|
82
|
+
assert_includes(Cisco::SyslogServer.syslogservers, id)
|
|
83
|
+
assert_equal(Cisco::SyslogServer.syslogservers[id], server)
|
|
84
|
+
|
|
85
|
+
server.destroy
|
|
86
|
+
refute_includes(Cisco::SyslogServer.syslogservers, id)
|
|
87
|
+
end
|
|
88
|
+
end
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Minitest for SyslogSetting 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/syslog_settings'
|
|
20
|
+
|
|
21
|
+
# TestSyslogSetting - Minitest for SyslogSetting node utility.
|
|
22
|
+
class TestSyslogSettings < CiscoTestCase
|
|
23
|
+
def setup
|
|
24
|
+
# setup runs at the beginning of each test
|
|
25
|
+
super
|
|
26
|
+
no_syslogsettings
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def teardown
|
|
30
|
+
# teardown runs at the end of each test
|
|
31
|
+
no_syslogsettings
|
|
32
|
+
super
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def no_syslogsettings
|
|
36
|
+
# Turn the feature off for a clean test.
|
|
37
|
+
config('no logging timestamp seconds')
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# TESTS
|
|
41
|
+
|
|
42
|
+
def test_syslogsettings_create
|
|
43
|
+
syslog_setting = Cisco::SyslogSettings.new('default')
|
|
44
|
+
assert_includes(Cisco::SyslogSettings.syslogsettings, 'default')
|
|
45
|
+
assert_equal(Cisco::SyslogSettings.syslogsettings['default'],
|
|
46
|
+
syslog_setting)
|
|
47
|
+
|
|
48
|
+
syslog_setting.timestamp = 'milliseconds'
|
|
49
|
+
assert_equal(Cisco::SyslogSettings.syslogsettings['default'].timestamp,
|
|
50
|
+
'milliseconds')
|
|
51
|
+
assert_equal(syslog_setting.timestamp,
|
|
52
|
+
'milliseconds')
|
|
53
|
+
end
|
|
54
|
+
end
|
data/tests/test_tacacs_server.rb
CHANGED
|
@@ -12,47 +12,43 @@
|
|
|
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'
|
|
17
17
|
|
|
18
|
+
# TestTacacsServer - Minitest for TacacsServer node utility
|
|
18
19
|
class TestTacacsServer < CiscoTestCase
|
|
19
|
-
def
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
line = /#{cmd}/.match(s)
|
|
20
|
+
def assert_tacacsserver_feature
|
|
21
|
+
assert_show_match(command: 'show run all | no-more',
|
|
22
|
+
pattern: /feature tacacs\+/)
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
def get_tacacsserver_match_line(name)
|
|
29
|
-
s = @device.cmd("show run tacacs all | no-more ; show run aaa all | no-more")
|
|
30
|
-
cmd = "tacacs-server"
|
|
31
|
-
pattern = (/#{cmd} #{name}/)
|
|
32
|
-
line = pattern.match(s)
|
|
25
|
+
def refute_tacacsserver_feature
|
|
26
|
+
refute_show_match(command: 'show run all | no-more',
|
|
27
|
+
pattern: /feature tacacs\+/)
|
|
33
28
|
end
|
|
34
29
|
|
|
35
|
-
def
|
|
36
|
-
|
|
37
|
-
|
|
30
|
+
def setup
|
|
31
|
+
super
|
|
32
|
+
# Most commands appear under 'show run tacacs all' but the
|
|
33
|
+
# 'directed-request' command is under 'show run aaa all'
|
|
34
|
+
@default_show_command = 'show run tacacs all | no-more ; ' \
|
|
35
|
+
'show run aaa all | no-more'
|
|
38
36
|
end
|
|
39
37
|
|
|
40
38
|
def test_tacacsserver_create_valid
|
|
41
39
|
tacacs = TacacsServer.new
|
|
42
|
-
|
|
43
|
-
refute_nil(line, "Error: Tacacs feature not set")
|
|
40
|
+
assert_tacacsserver_feature
|
|
44
41
|
tacacs.destroy
|
|
45
42
|
end
|
|
46
43
|
|
|
47
44
|
def test_tacacsserver_get_encryption_type
|
|
48
|
-
|
|
49
|
-
node.cache_flush
|
|
45
|
+
config('no feature tacacs+', 'feature tacacs+')
|
|
50
46
|
encryption_type = TACACS_SERVER_ENC_UNKNOWN
|
|
51
47
|
# Get encryption password when not configured
|
|
52
48
|
tacacs = TacacsServer.new
|
|
53
49
|
assert_equal(encryption_type,
|
|
54
50
|
tacacs.encryption_type,
|
|
55
|
-
|
|
51
|
+
'Error: Tacacs Server, encryption type incorrect')
|
|
56
52
|
tacacs.destroy
|
|
57
53
|
|
|
58
54
|
# Get encryption password when configured
|
|
@@ -60,26 +56,19 @@ class TestTacacsServer < CiscoTestCase
|
|
|
60
56
|
# This one is needed since the 'sh run' will always display the type
|
|
61
57
|
# differently than the used encryption config type.
|
|
62
58
|
sh_run_encryption_type = TACACS_SERVER_ENC_CISCO_TYPE_7
|
|
63
|
-
|
|
64
|
-
s = @device.cmd("feature tacacs+")
|
|
65
|
-
s = @device.cmd("tacacs-server key #{encryption_type} TEST")
|
|
66
|
-
s = @device.cmd("end")
|
|
67
|
-
node.cache_flush
|
|
59
|
+
config('feature tacacs+', "tacacs-server key #{encryption_type} TEST")
|
|
68
60
|
|
|
69
61
|
tacacs = TacacsServer.new
|
|
70
62
|
assert_equal(sh_run_encryption_type,
|
|
71
63
|
tacacs.encryption_type,
|
|
72
|
-
|
|
64
|
+
'Error: Tacacs Server, encryption type incorrect')
|
|
73
65
|
|
|
74
66
|
encryption_type = TACACS_SERVER_ENC_CISCO_TYPE_7
|
|
75
|
-
|
|
76
|
-
s = @device.cmd("tacacs-server key #{encryption_type} TEST")
|
|
77
|
-
s = @device.cmd("end")
|
|
78
|
-
node.cache_flush
|
|
67
|
+
config("tacacs-server key #{encryption_type} TEST")
|
|
79
68
|
|
|
80
69
|
assert_equal(sh_run_encryption_type,
|
|
81
70
|
tacacs.encryption_type,
|
|
82
|
-
|
|
71
|
+
'Error: Tacacs Server, encryption type incorrect')
|
|
83
72
|
tacacs.destroy
|
|
84
73
|
end
|
|
85
74
|
|
|
@@ -87,41 +76,37 @@ class TestTacacsServer < CiscoTestCase
|
|
|
87
76
|
# Ruby can use defines, but only they're not initialized from an enum
|
|
88
77
|
assert_equal(TACACS_SERVER_ENC_NONE,
|
|
89
78
|
TacacsServer.default_encryption_type,
|
|
90
|
-
|
|
79
|
+
'Error: Tacacs Server, default encryption incorrect')
|
|
91
80
|
end
|
|
92
81
|
|
|
93
82
|
def test_tacacsserver_get_encryption_password
|
|
94
83
|
# Get encryption password when not configured
|
|
95
|
-
|
|
96
|
-
node.cache_flush
|
|
84
|
+
config('no feature tacacs+')
|
|
97
85
|
tacacs = TacacsServer.new
|
|
98
|
-
assert_equal(node.config_get_default(
|
|
86
|
+
assert_equal(node.config_get_default('tacacs_server',
|
|
87
|
+
'encryption_password'),
|
|
99
88
|
tacacs.encryption_password,
|
|
100
|
-
|
|
89
|
+
'Error: Tacacs Server, encryption password incorrect')
|
|
101
90
|
tacacs.destroy
|
|
102
91
|
|
|
103
92
|
# Get encryption password when configured
|
|
104
|
-
sh_run_encryption_password =
|
|
93
|
+
sh_run_encryption_password = 'WAWY'
|
|
105
94
|
encryption_type = TACACS_SERVER_ENC_NONE
|
|
106
95
|
# This one is needed since the 'sh run' will always display the password
|
|
107
96
|
# differently than the used encryption config type.
|
|
108
|
-
|
|
109
|
-
s = @device.cmd("feature tacacs+")
|
|
110
|
-
s = @device.cmd("tacacs-server key #{encryption_type} TEST")
|
|
111
|
-
s = @device.cmd("end")
|
|
112
|
-
# Flush the cache since we've modified the device
|
|
113
|
-
node.cache_flush
|
|
97
|
+
config('feature tacacs+', "tacacs-server key #{encryption_type} TEST")
|
|
114
98
|
tacacs = TacacsServer.new
|
|
115
99
|
assert_equal(sh_run_encryption_password,
|
|
116
100
|
tacacs.encryption_password,
|
|
117
|
-
|
|
101
|
+
'Error: Tacacs Server, encryption password incorrect')
|
|
118
102
|
tacacs.destroy
|
|
119
103
|
end
|
|
120
104
|
|
|
121
105
|
def test_tacacsserver_get_default_encryption_password
|
|
122
|
-
assert_equal(node.config_get_default(
|
|
106
|
+
assert_equal(node.config_get_default('tacacs_server',
|
|
107
|
+
'encryption_password'),
|
|
123
108
|
TacacsServer.default_encryption_password,
|
|
124
|
-
|
|
109
|
+
'Error: Tacacs Server, default encryption password incorrect')
|
|
125
110
|
end
|
|
126
111
|
|
|
127
112
|
def test_tacacsserver_key_set
|
|
@@ -129,69 +114,67 @@ class TestTacacsServer < CiscoTestCase
|
|
|
129
114
|
# This one is needed since the 'sh run' will always display the type
|
|
130
115
|
# differently than the used encryption config type.
|
|
131
116
|
sh_run_encryption_type = TACACS_SERVER_ENC_CISCO_TYPE_7
|
|
132
|
-
password =
|
|
117
|
+
password = 'TEST_NEW'
|
|
133
118
|
|
|
134
119
|
tacacs = TacacsServer.new
|
|
135
120
|
tacacs.encryption_key_set(enc_type, password)
|
|
136
121
|
# Get the password from the running config since its encoded
|
|
137
|
-
line =
|
|
138
|
-
|
|
122
|
+
line = assert_show_match(
|
|
123
|
+
pattern: /tacacs-server key\s#{sh_run_encryption_type}\s".*"/,
|
|
124
|
+
msg: 'Error: Tacacs Server, key not configured')
|
|
139
125
|
# Extract encrypted password, and git rid of the "" around the pasword
|
|
140
126
|
md = line.to_s
|
|
141
|
-
encrypted_password = md.to_s.split(
|
|
127
|
+
encrypted_password = md.to_s.split(' ').last.tr('\"', '')
|
|
142
128
|
# Extract encryption type
|
|
143
129
|
md = /tacacs-server\skey\s\d/.match(line.to_s)
|
|
144
|
-
encrypted_type = md.to_s.split(
|
|
130
|
+
encrypted_type = md.to_s.split(' ').last.to_i
|
|
145
131
|
assert_equal(encrypted_type, tacacs.encryption_type,
|
|
146
|
-
|
|
132
|
+
'Error: Tacacs Server, encryption type incorrect')
|
|
147
133
|
assert_equal(encrypted_password, tacacs.encryption_password,
|
|
148
|
-
|
|
134
|
+
'Error: Tacacs Server, encryption password incorrect')
|
|
149
135
|
tacacs.destroy
|
|
150
136
|
end
|
|
151
137
|
|
|
152
138
|
def test_tacacsserver_key_unconfigure
|
|
153
|
-
|
|
154
|
-
node.cache_flush
|
|
139
|
+
config('no feature tacacs+')
|
|
155
140
|
enc_type = TACACS_SERVER_ENC_NONE
|
|
156
141
|
# This one is needed since the 'sh run' will always display the type
|
|
157
142
|
# differently than the used encryption config type.
|
|
158
143
|
sh_run_encryption_type = TACACS_SERVER_ENC_CISCO_TYPE_7
|
|
159
|
-
password =
|
|
144
|
+
password = 'TEST_NEW'
|
|
160
145
|
|
|
161
146
|
tacacs = TacacsServer.new
|
|
162
147
|
tacacs.encryption_key_set(enc_type, password)
|
|
163
|
-
|
|
164
|
-
|
|
148
|
+
assert_show_match(
|
|
149
|
+
pattern: /tacacs-server key\s#{sh_run_encryption_type}\s".*"/,
|
|
150
|
+
msg: 'Error: Tacacs Server, key not configured')
|
|
165
151
|
|
|
166
152
|
enc_type = TACACS_SERVER_ENC_UNKNOWN
|
|
167
|
-
password =
|
|
153
|
+
password = ''
|
|
168
154
|
tacacs.encryption_key_set(enc_type, password)
|
|
169
|
-
|
|
170
|
-
|
|
155
|
+
refute_show_match(
|
|
156
|
+
pattern: /tacacs-server key\s#{sh_run_encryption_type}\s".*"/,
|
|
157
|
+
msg: 'Error: Tacacs Server, key configured')
|
|
171
158
|
tacacs.destroy
|
|
172
159
|
end
|
|
173
160
|
|
|
174
161
|
def test_tacacsserver_get_timeout
|
|
175
162
|
tacacs = TacacsServer.new
|
|
176
|
-
timeout = node.config_get_default(
|
|
163
|
+
timeout = node.config_get_default('tacacs_server', 'timeout')
|
|
177
164
|
assert_equal(timeout, tacacs.timeout,
|
|
178
|
-
|
|
165
|
+
'Error: Tacacs Server, timeout not default')
|
|
179
166
|
|
|
180
167
|
timeout = 35
|
|
181
|
-
|
|
182
|
-
s = @device.cmd("tacacs-server timeout #{timeout}")
|
|
183
|
-
s = @device.cmd("end")
|
|
184
|
-
# Flush the cache since we've modified the device
|
|
185
|
-
node.cache_flush
|
|
168
|
+
config("tacacs-server timeout #{timeout}")
|
|
186
169
|
assert_equal(timeout, tacacs.timeout,
|
|
187
|
-
|
|
170
|
+
'Error: Tacacs Server, timeout not configured')
|
|
188
171
|
tacacs.destroy
|
|
189
172
|
end
|
|
190
173
|
|
|
191
174
|
def test_tacacsserver_get_default_timeout
|
|
192
|
-
assert_equal(node.config_get_default(
|
|
175
|
+
assert_equal(node.config_get_default('tacacs_server', 'timeout'),
|
|
193
176
|
TacacsServer.default_timeout,
|
|
194
|
-
|
|
177
|
+
'Error: Tacacs Server, default timeout incorrect')
|
|
195
178
|
end
|
|
196
179
|
|
|
197
180
|
def test_tacacsserver_set_timeout
|
|
@@ -199,14 +182,14 @@ class TestTacacsServer < CiscoTestCase
|
|
|
199
182
|
|
|
200
183
|
tacacs = TacacsServer.new
|
|
201
184
|
tacacs.timeout = timeout
|
|
202
|
-
line =
|
|
185
|
+
line = assert_show_match(pattern: /tacacs-server timeout\s.*/,
|
|
186
|
+
msg: 'Error: timeout not configured')
|
|
203
187
|
# Extract timeout
|
|
204
188
|
md = /tacacs-server\stimeout\s\d*/.match(line.to_s)
|
|
205
|
-
sh_run_timeout = md.to_s.split(
|
|
189
|
+
sh_run_timeout = md.to_s.split(' ').last.to_i
|
|
206
190
|
# Need a better way to extract the timeout
|
|
207
|
-
refute_nil(line, "Error: Tacacs Server, timeout not configured")
|
|
208
191
|
assert_equal(sh_run_timeout, tacacs.timeout,
|
|
209
|
-
|
|
192
|
+
'Error: Tacacs Server, timeout value incorrect')
|
|
210
193
|
|
|
211
194
|
# Invalid case
|
|
212
195
|
timeout = 80
|
|
@@ -218,25 +201,21 @@ class TestTacacsServer < CiscoTestCase
|
|
|
218
201
|
|
|
219
202
|
def test_tacacsserver_get_deadtime
|
|
220
203
|
tacacs = TacacsServer.new
|
|
221
|
-
deadtime = node.config_get_default(
|
|
204
|
+
deadtime = node.config_get_default('tacacs_server', 'deadtime')
|
|
222
205
|
assert_equal(deadtime, tacacs.deadtime,
|
|
223
|
-
|
|
206
|
+
'Error: Tacacs Server, deadtime not default')
|
|
224
207
|
|
|
225
208
|
deadtime = 850
|
|
226
|
-
|
|
227
|
-
s = @device.cmd("tacacs-server deadtime #{deadtime}")
|
|
228
|
-
s = @device.cmd("end")
|
|
229
|
-
# Flush the cache since we've modified the device
|
|
230
|
-
node.cache_flush
|
|
209
|
+
config("tacacs-server deadtime #{deadtime}")
|
|
231
210
|
assert_equal(deadtime, tacacs.deadtime,
|
|
232
|
-
|
|
211
|
+
'Error: Tacacs Server, deadtime not configured')
|
|
233
212
|
tacacs.destroy
|
|
234
213
|
end
|
|
235
214
|
|
|
236
215
|
def test_tacacsserver_get_default_deadtime
|
|
237
|
-
assert_equal(node.config_get_default(
|
|
216
|
+
assert_equal(node.config_get_default('tacacs_server', 'deadtime'),
|
|
238
217
|
TacacsServer.default_deadtime,
|
|
239
|
-
|
|
218
|
+
'Error: Tacacs Server, default deadtime incorrect')
|
|
240
219
|
end
|
|
241
220
|
|
|
242
221
|
def test_tacacsserver_set_deadtime
|
|
@@ -244,13 +223,13 @@ class TestTacacsServer < CiscoTestCase
|
|
|
244
223
|
|
|
245
224
|
tacacs = TacacsServer.new
|
|
246
225
|
tacacs.deadtime = deadtime
|
|
247
|
-
line =
|
|
226
|
+
line = assert_show_match(pattern: /tacacs-server deadtime\s.*/,
|
|
227
|
+
msg: 'Error: deadtime not configured')
|
|
248
228
|
# Extract deadtime
|
|
249
229
|
md = /tacacs-server\sdeadtime\s\d*/.match(line.to_s)
|
|
250
|
-
sh_run_deadtime = md.to_s.split(
|
|
251
|
-
refute_nil(line, "Error: Tacacs Server, deadtime not configured")
|
|
230
|
+
sh_run_deadtime = md.to_s.split(' ').last.to_i
|
|
252
231
|
assert_equal(sh_run_deadtime, tacacs.deadtime,
|
|
253
|
-
|
|
232
|
+
'Error: Tacacs Server, deadtime incorrect')
|
|
254
233
|
# Invalid case
|
|
255
234
|
deadtime = 2450
|
|
256
235
|
assert_raises(Cisco::CliError) do
|
|
@@ -260,60 +239,55 @@ class TestTacacsServer < CiscoTestCase
|
|
|
260
239
|
end
|
|
261
240
|
|
|
262
241
|
def test_tacacsserver_get_directed_request
|
|
263
|
-
|
|
264
|
-
# Flush the cache since we've modified the device
|
|
265
|
-
node.cache_flush
|
|
242
|
+
config('feature tacacs', 'tacacs-server directed-request')
|
|
266
243
|
tacacs = TacacsServer.new
|
|
267
244
|
assert(tacacs.directed_request?,
|
|
268
|
-
|
|
245
|
+
'Error: Tacacs Server, directed-request not set')
|
|
269
246
|
|
|
270
|
-
|
|
271
|
-
node.cache_flush
|
|
247
|
+
config('no tacacs-server directed-request')
|
|
272
248
|
refute(tacacs.directed_request?,
|
|
273
|
-
|
|
249
|
+
'Error: Tacacs Server, directed-request set')
|
|
274
250
|
tacacs.destroy
|
|
275
251
|
end
|
|
276
252
|
|
|
277
253
|
def test_tacacsserver_get_default_directed_request
|
|
278
|
-
assert_equal(node.config_get_default(
|
|
254
|
+
assert_equal(node.config_get_default('tacacs_server', 'directed_request'),
|
|
279
255
|
TacacsServer.default_directed_request,
|
|
280
|
-
|
|
256
|
+
'Error: Tacacs Server, default directed-request incorrect')
|
|
281
257
|
end
|
|
282
258
|
|
|
283
259
|
def test_tacacsserver_set_directed_request
|
|
284
|
-
|
|
260
|
+
config('feature tacacs', 'tacacs-server directed-request')
|
|
285
261
|
state = true
|
|
286
262
|
tacacs = TacacsServer.new
|
|
287
263
|
tacacs.directed_request = state
|
|
288
|
-
|
|
289
|
-
|
|
264
|
+
assert_show_match(pattern: /tacacs-server directed-request/,
|
|
265
|
+
msg: 'directed-request not configured')
|
|
290
266
|
assert(tacacs.directed_request?,
|
|
291
|
-
|
|
267
|
+
'Error: Tacacs Server, directed-request not set')
|
|
292
268
|
|
|
293
269
|
# Turn it off
|
|
294
|
-
|
|
295
|
-
node.cache_flush
|
|
270
|
+
config('no tacacs-server directed-request')
|
|
296
271
|
refute(tacacs.directed_request?,
|
|
297
|
-
|
|
272
|
+
'Error: Tacacs Server, directed-request set')
|
|
298
273
|
|
|
299
274
|
# Turn it back on then go to default
|
|
300
|
-
|
|
301
|
-
state = node.config_get_default(
|
|
275
|
+
config('no tacacs-server directed-request')
|
|
276
|
+
state = node.config_get_default('tacacs_server', 'directed_request')
|
|
302
277
|
tacacs.directed_request = state
|
|
303
|
-
line =
|
|
304
|
-
|
|
305
|
-
"Error: Tacacs Server, default directed-request not configured")
|
|
278
|
+
line = assert_show_match(pattern: /no tacacs-server directed-request/,
|
|
279
|
+
msg: 'default directed-request not configed')
|
|
306
280
|
|
|
307
281
|
# Extract the state of directed-request
|
|
308
|
-
sh_run_directed_request = line.to_s.split(
|
|
309
|
-
assert_equal(
|
|
310
|
-
|
|
282
|
+
sh_run_directed_request = line.to_s.split(' ').first
|
|
283
|
+
assert_equal('no', sh_run_directed_request,
|
|
284
|
+
'Error: Tacacs Server, directed-request not unconfigured')
|
|
311
285
|
|
|
312
286
|
refute(tacacs.directed_request?,
|
|
313
|
-
|
|
287
|
+
'Error: Tacacs Server, directed-request set')
|
|
314
288
|
|
|
315
289
|
# Invalid case
|
|
316
|
-
state =
|
|
290
|
+
state = 'TEST'
|
|
317
291
|
assert_raises(TypeError) do
|
|
318
292
|
tacacs.directed_request = state
|
|
319
293
|
end
|
|
@@ -321,53 +295,46 @@ class TestTacacsServer < CiscoTestCase
|
|
|
321
295
|
end
|
|
322
296
|
|
|
323
297
|
def test_tacacsserver_get_source_interface
|
|
324
|
-
|
|
325
|
-
s = @device.cmd("no ip tacacs source-interface")
|
|
326
|
-
s = @device.cmd("end")
|
|
298
|
+
config('no ip tacacs source-interface')
|
|
327
299
|
tacacs = TacacsServer.new
|
|
328
|
-
intf = node.config_get_default(
|
|
300
|
+
intf = node.config_get_default('tacacs_server', 'source_interface')
|
|
329
301
|
assert_equal(intf, tacacs.source_interface,
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
intf =
|
|
333
|
-
|
|
334
|
-
s = @device.cmd("ip tacacs source-interface #{intf}")
|
|
335
|
-
s = @device.cmd("end")
|
|
336
|
-
# Flush the cache since we've modified the device
|
|
337
|
-
node.cache_flush
|
|
302
|
+
'Error: Tacacs Server, source-interface set')
|
|
303
|
+
|
|
304
|
+
intf = 'Ethernet1/1'
|
|
305
|
+
config("ip tacacs source-interface #{intf}")
|
|
338
306
|
assert_equal(intf, tacacs.source_interface,
|
|
339
|
-
|
|
307
|
+
'Error: Tacacs Server, source-interface not correct')
|
|
340
308
|
tacacs.destroy
|
|
341
309
|
end
|
|
342
310
|
|
|
343
311
|
def test_tacacsserver_get_default_source_interface
|
|
344
|
-
assert_equal(node.config_get_default(
|
|
312
|
+
assert_equal(node.config_get_default('tacacs_server', 'source_interface'),
|
|
345
313
|
TacacsServer.default_source_interface,
|
|
346
|
-
|
|
314
|
+
'Error: Tacacs Server, default source-interface incorrect')
|
|
347
315
|
end
|
|
348
316
|
|
|
349
317
|
def test_tacacsserver_set_source_interface
|
|
350
|
-
|
|
351
|
-
node.
|
|
352
|
-
intf = node.config_get_default("tacacs_server", "source_interface")
|
|
318
|
+
config('feature tacacs+', 'no ip tacacs source-int')
|
|
319
|
+
intf = node.config_get_default('tacacs_server', 'source_interface')
|
|
353
320
|
tacacs = TacacsServer.new
|
|
354
321
|
assert_equal(intf, tacacs.source_interface,
|
|
355
|
-
|
|
322
|
+
'Error: Tacacs Server, source-interface set')
|
|
356
323
|
|
|
357
|
-
intf =
|
|
324
|
+
intf = 'Ethernet1/1'
|
|
358
325
|
tacacs.source_interface = intf
|
|
359
|
-
line =
|
|
326
|
+
line = assert_show_match(pattern: /ip tacacs source-interface #{intf}/,
|
|
327
|
+
msg: 'source-interface not configured')
|
|
360
328
|
# Extract source-interface
|
|
361
|
-
sh_run_source_interface = line.to_s.split(
|
|
362
|
-
refute_nil(line, "Error: Tacacs Server, source-interface not configured")
|
|
329
|
+
sh_run_source_interface = line.to_s.split(' ').last
|
|
363
330
|
assert_equal(sh_run_source_interface, tacacs.source_interface,
|
|
364
|
-
|
|
331
|
+
'Error: Tacacs Server, source-interface not correct')
|
|
365
332
|
|
|
366
333
|
# Now bring it back to default
|
|
367
|
-
intf = node.config_get_default(
|
|
334
|
+
intf = node.config_get_default('tacacs_server', 'source_interface')
|
|
368
335
|
tacacs.source_interface = intf
|
|
369
|
-
|
|
370
|
-
|
|
336
|
+
assert_show_match(pattern: /no ip tacacs source-interface/,
|
|
337
|
+
msg: 'source-interface not default')
|
|
371
338
|
|
|
372
339
|
# Invalid case
|
|
373
340
|
state = true
|
|
@@ -379,10 +346,8 @@ class TestTacacsServer < CiscoTestCase
|
|
|
379
346
|
|
|
380
347
|
def test_tacacsserver_destroy
|
|
381
348
|
tacacs = TacacsServer.new
|
|
382
|
-
|
|
383
|
-
refute_nil(line, "Error: Tacacs feature not set")
|
|
349
|
+
assert_tacacsserver_feature
|
|
384
350
|
tacacs.destroy
|
|
385
|
-
|
|
386
|
-
assert_nil(line, "Error: Tacacs feature still present")
|
|
351
|
+
refute_tacacsserver_feature
|
|
387
352
|
end
|
|
388
353
|
end
|