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,85 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Minitest for NameServer 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/name_server'
|
|
20
|
+
|
|
21
|
+
# TestNameServer - Minitest for NameServer node utility.
|
|
22
|
+
class TestNameServer < CiscoTestCase
|
|
23
|
+
def setup
|
|
24
|
+
# setup runs at the beginning of each test
|
|
25
|
+
super
|
|
26
|
+
no_nameserver_google
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def teardown
|
|
30
|
+
# teardown runs at the end of each test
|
|
31
|
+
no_nameserver_google
|
|
32
|
+
super
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def no_nameserver_google
|
|
36
|
+
# Turn the feature off for a clean test.
|
|
37
|
+
config('no ip name-server 7.7.7.7',
|
|
38
|
+
'no ip name-server 2001:4860:4860::7777')
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# TESTS
|
|
42
|
+
|
|
43
|
+
def test_nameserver_create_destroy_single_ipv4
|
|
44
|
+
id = '7.7.7.7'
|
|
45
|
+
refute_includes(Cisco::NameServer.nameservers, id)
|
|
46
|
+
|
|
47
|
+
ns = Cisco::NameServer.new(id)
|
|
48
|
+
assert_includes(Cisco::NameServer.nameservers, id)
|
|
49
|
+
assert_equal(Cisco::NameServer.nameservers[id], ns)
|
|
50
|
+
|
|
51
|
+
ns.destroy
|
|
52
|
+
refute_includes(Cisco::NameServer.nameservers, id)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def test_nameserver_create_destroy_single_ipv6
|
|
56
|
+
id = '2001:4860:4860::7777'
|
|
57
|
+
refute_includes(Cisco::NameServer.nameservers, id)
|
|
58
|
+
|
|
59
|
+
ns = Cisco::NameServer.new(id)
|
|
60
|
+
assert_includes(Cisco::NameServer.nameservers, id)
|
|
61
|
+
assert_equal(Cisco::NameServer.nameservers[id], ns)
|
|
62
|
+
|
|
63
|
+
ns.destroy
|
|
64
|
+
refute_includes(Cisco::NameServer.nameservers, id)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def test_router_create_destroy_multiple
|
|
68
|
+
id1 = '7.7.7.7'
|
|
69
|
+
id2 = '2001:4860:4860::7777'
|
|
70
|
+
refute_includes(Cisco::NameServer.nameservers, id1)
|
|
71
|
+
refute_includes(Cisco::NameServer.nameservers, id2)
|
|
72
|
+
|
|
73
|
+
ns1 = Cisco::NameServer.new(id1)
|
|
74
|
+
ns2 = Cisco::NameServer.new(id2)
|
|
75
|
+
assert_includes(Cisco::NameServer.nameservers, id1)
|
|
76
|
+
assert_includes(Cisco::NameServer.nameservers, id2)
|
|
77
|
+
assert_equal(Cisco::NameServer.nameservers[id1], ns1)
|
|
78
|
+
assert_equal(Cisco::NameServer.nameservers[id2], ns2)
|
|
79
|
+
|
|
80
|
+
ns1.destroy
|
|
81
|
+
ns2.destroy
|
|
82
|
+
refute_includes(Cisco::NameServer.nameservers, id1)
|
|
83
|
+
refute_includes(Cisco::NameServer.nameservers, id2)
|
|
84
|
+
end
|
|
85
|
+
end
|
data/tests/test_node.rb
CHANGED
|
@@ -12,15 +12,16 @@
|
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
require_relative 'basetest'
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
require_relative '../lib/cisco_node_utils/node'
|
|
18
|
+
require_relative '../lib/cisco_node_utils/command_reference'
|
|
19
19
|
|
|
20
20
|
include Cisco
|
|
21
21
|
|
|
22
22
|
Node.lazy_connect = true # we'll specify the connection info later
|
|
23
23
|
|
|
24
|
+
# TestNode - Minitest for core functionality of Node class
|
|
24
25
|
class TestNode < TestCase
|
|
25
26
|
def setup
|
|
26
27
|
end
|
|
@@ -33,7 +34,7 @@ class TestNode < TestCase
|
|
|
33
34
|
|
|
34
35
|
def test_node_create_not_allowed
|
|
35
36
|
assert_raises(NoMethodError) do
|
|
36
|
-
|
|
37
|
+
Node.new
|
|
37
38
|
end
|
|
38
39
|
end
|
|
39
40
|
|
|
@@ -76,7 +77,7 @@ class TestNode < TestCase
|
|
|
76
77
|
def test_node_connect_username_zero_length
|
|
77
78
|
node = Node.instance
|
|
78
79
|
assert_raises(ArgumentError) do
|
|
79
|
-
node.connect(address,
|
|
80
|
+
node.connect(address, '', password)
|
|
80
81
|
end
|
|
81
82
|
end
|
|
82
83
|
|
|
@@ -97,7 +98,7 @@ class TestNode < TestCase
|
|
|
97
98
|
def test_node_connect_password_zero_length
|
|
98
99
|
node = Node.instance
|
|
99
100
|
assert_raises(ArgumentError) do
|
|
100
|
-
node.connect(address, username,
|
|
101
|
+
node.connect(address, username, '')
|
|
101
102
|
end
|
|
102
103
|
end
|
|
103
104
|
|
data/tests/test_node_ext.rb
CHANGED
|
@@ -12,12 +12,17 @@
|
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
require_relative 'ciscotest'
|
|
16
16
|
|
|
17
|
+
# TestNodeExt - Minitest for abstracted Node APIs
|
|
17
18
|
class TestNodeExt < CiscoTestCase
|
|
18
|
-
|
|
19
|
+
def assert_output_check(command: nil, pattern: nil, msg: nil, check: nil)
|
|
20
|
+
md = assert_show_match(command: command, pattern: pattern, msg: msg)
|
|
21
|
+
assert_equal(md[1], check, msg)
|
|
22
|
+
end
|
|
19
23
|
|
|
20
|
-
|
|
24
|
+
def show_run_ospf
|
|
25
|
+
"\
|
|
21
26
|
router ospf foo
|
|
22
27
|
vrf red
|
|
23
28
|
log-adjacency-changes
|
|
@@ -29,9 +34,10 @@ router ospf bar
|
|
|
29
34
|
!
|
|
30
35
|
router ospf baz
|
|
31
36
|
log-adjacency-changes detail"
|
|
37
|
+
end
|
|
32
38
|
|
|
33
39
|
def test_node_find_subconfig
|
|
34
|
-
result = find_subconfig(
|
|
40
|
+
result = find_subconfig(show_run_ospf, /router ospf bar/)
|
|
35
41
|
assert_equal("\
|
|
36
42
|
log-adjacency-changes
|
|
37
43
|
vrf red
|
|
@@ -41,7 +47,7 @@ vrf blue",
|
|
|
41
47
|
|
|
42
48
|
assert_nil(find_subconfig(result, /vrf blue/))
|
|
43
49
|
|
|
44
|
-
assert_equal(
|
|
50
|
+
assert_equal('log-adjacency-changes detail',
|
|
45
51
|
find_subconfig(result, /vrf red/))
|
|
46
52
|
|
|
47
53
|
assert_nil(find_subconfig(result, /vrf green/))
|
|
@@ -49,40 +55,40 @@ vrf blue",
|
|
|
49
55
|
|
|
50
56
|
def test_node_find_ascii
|
|
51
57
|
# Find an entry in the parent submode, ignoring nested submodes
|
|
52
|
-
assert_equal([
|
|
53
|
-
find_ascii(
|
|
58
|
+
assert_equal(['log-adjacency-changes'],
|
|
59
|
+
find_ascii(show_run_ospf, /^log-adjacency-changes.*$/,
|
|
54
60
|
/router ospf bar/))
|
|
55
61
|
# Find an entry in a nested submode
|
|
56
|
-
assert_equal([
|
|
57
|
-
find_ascii(
|
|
62
|
+
assert_equal(['log-adjacency-changes detail'],
|
|
63
|
+
find_ascii(show_run_ospf, /^log-adjacency-changes.*$/,
|
|
58
64
|
/router ospf bar/, /vrf red/))
|
|
59
65
|
# Submode exists but does not have a match
|
|
60
|
-
assert_nil(find_ascii(
|
|
66
|
+
assert_nil(find_ascii(show_run_ospf, /^log-adjacency-changes.*$/,
|
|
61
67
|
/router ospf bar/, /vrf blue/))
|
|
62
68
|
# Submode does not exist
|
|
63
|
-
assert_nil(find_ascii(
|
|
69
|
+
assert_nil(find_ascii(show_run_ospf, /^log-adjacency-changes.*$/,
|
|
64
70
|
/router ospf bar/, /vrf green/))
|
|
65
71
|
|
|
66
72
|
# Entry exists in submode only
|
|
67
|
-
assert_nil(find_ascii(
|
|
73
|
+
assert_nil(find_ascii(show_run_ospf, /^log-adjacency-changes.*$/,
|
|
68
74
|
/router ospf foo/))
|
|
69
75
|
end
|
|
70
76
|
|
|
71
77
|
def test_node_config_get
|
|
72
|
-
result = node.config_get(
|
|
78
|
+
result = node.config_get('show_version', 'system_image')
|
|
73
79
|
assert_equal(result, node.system)
|
|
74
80
|
end
|
|
75
81
|
|
|
76
82
|
def test_node_config_get_regexp_tokens
|
|
77
|
-
node.client.config([
|
|
78
|
-
node.client.config([
|
|
83
|
+
node.client.config(['interface loopback0', 'shutdown'])
|
|
84
|
+
node.client.config(['interface loopback1', 'no shutdown'])
|
|
79
85
|
|
|
80
|
-
result = node.config_get(
|
|
86
|
+
result = node.config_get('interface', 'shutdown', 'loopback1')
|
|
81
87
|
assert_nil(result)
|
|
82
88
|
end
|
|
83
89
|
|
|
84
90
|
def test_node_token_str_to_regexp
|
|
85
|
-
token = [
|
|
91
|
+
token = ['/%s/i', '/%s foo %s/', '/zzz/i']
|
|
86
92
|
args = %w(LoopBack2 no bar)
|
|
87
93
|
expected = [/LoopBack2/i, /no foo bar/, /zzz/i]
|
|
88
94
|
|
|
@@ -93,140 +99,120 @@ vrf blue",
|
|
|
93
99
|
|
|
94
100
|
def test_node_config_get_invalid
|
|
95
101
|
assert_raises IndexError do # no entry
|
|
96
|
-
|
|
102
|
+
node.config_get('feature', 'name')
|
|
97
103
|
end
|
|
98
104
|
assert_raises IndexError do # entry but no config_get
|
|
99
|
-
|
|
105
|
+
node.config_get('show_system', 'resources')
|
|
100
106
|
end
|
|
101
107
|
end
|
|
102
108
|
|
|
103
109
|
def test_node_config_get_default
|
|
104
|
-
result = node.config_get_default(
|
|
110
|
+
result = node.config_get_default('snmp_server', 'aaa_user_cache_timeout')
|
|
105
111
|
assert_equal(result, 3600)
|
|
106
112
|
end
|
|
107
113
|
|
|
108
114
|
def test_node_config_get_default_invalid
|
|
109
115
|
assert_raises IndexError do # no name entry
|
|
110
|
-
|
|
116
|
+
node.config_get_default('show_version', 'foobar')
|
|
111
117
|
end
|
|
112
118
|
assert_raises IndexError do # no feature entry
|
|
113
|
-
|
|
119
|
+
node.config_get_default('feature', 'name')
|
|
114
120
|
end
|
|
115
121
|
assert_raises IndexError do # no default_value defined
|
|
116
|
-
|
|
122
|
+
node.config_get_default('show_version', 'version')
|
|
117
123
|
end
|
|
118
124
|
end
|
|
119
125
|
|
|
120
126
|
def test_node_config_set
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
"", 100)
|
|
124
|
-
run = node.client.show("show run all | inc snmp")
|
|
127
|
+
node.config_set('snmp_server', 'aaa_user_cache_timeout', '', 100)
|
|
128
|
+
run = node.client.show('show run all | inc snmp')
|
|
125
129
|
val = find_one_ascii(run, /snmp-server aaa-user cache-timeout (\d+)/)
|
|
126
|
-
assert_equal(
|
|
130
|
+
assert_equal('100', val)
|
|
127
131
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
"no", 100)
|
|
131
|
-
run = node.client.show("show run all | inc snmp")
|
|
132
|
+
node.config_set('snmp_server', 'aaa_user_cache_timeout', 'no', 100)
|
|
133
|
+
run = node.client.show('show run all | inc snmp')
|
|
132
134
|
val = find_one_ascii(run, /snmp-server aaa-user cache-timeout (\d+)/)
|
|
133
|
-
assert_equal(
|
|
135
|
+
assert_equal('3600', val)
|
|
134
136
|
end
|
|
135
137
|
|
|
136
138
|
def test_node_config_set_invalid
|
|
137
139
|
assert_raises IndexError do
|
|
138
|
-
|
|
140
|
+
node.config_set('feature', 'name')
|
|
139
141
|
end
|
|
140
142
|
assert_raises IndexError do # feature exists but no config_set
|
|
141
|
-
|
|
143
|
+
node.config_set('show_version', 'system_image')
|
|
142
144
|
end
|
|
143
145
|
assert_raises ArgumentError do # not enough args
|
|
144
|
-
|
|
146
|
+
node.config_set('vtp', 'domain')
|
|
145
147
|
end
|
|
146
148
|
assert_raises ArgumentError do # too many args
|
|
147
|
-
|
|
149
|
+
node.config_set('vtp', 'domain', 'example.com', 'baz')
|
|
148
150
|
end
|
|
149
151
|
end
|
|
150
152
|
|
|
151
153
|
def test_node_cli_caching
|
|
152
|
-
|
|
154
|
+
# don't use config() here because we are testing caching and flushing
|
|
155
|
+
@device.cmd('conf t ; ip domain-name minitest ; end')
|
|
153
156
|
dom1 = node.domain_name
|
|
154
|
-
|
|
157
|
+
@device.cmd('conf t ; no ip domain-name minitest ; end')
|
|
155
158
|
dom2 = node.domain_name
|
|
156
159
|
assert_equal(dom1, dom2) # cached output was used for dom2
|
|
157
160
|
|
|
158
161
|
node.cache_flush
|
|
159
162
|
dom3 = node.domain_name
|
|
160
|
-
|
|
163
|
+
refute_equal(dom1, dom3)
|
|
161
164
|
end
|
|
162
165
|
|
|
163
166
|
def test_node_get_product_description
|
|
164
167
|
product_description = node.product_description
|
|
165
|
-
ref = cmd_ref.lookup(
|
|
166
|
-
assert(ref,
|
|
168
|
+
ref = cmd_ref.lookup('show_version', 'description')
|
|
169
|
+
assert(ref, 'Error, reference not found')
|
|
167
170
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
assert_equal(md[1], product_description,
|
|
173
|
-
"Error, Product description does not match")
|
|
171
|
+
assert_output_check(command: ref.test_config_get,
|
|
172
|
+
pattern: ref.test_config_get_regex,
|
|
173
|
+
check: product_description,
|
|
174
|
+
msg: 'Error, Product description does not match')
|
|
174
175
|
end
|
|
175
176
|
|
|
176
177
|
def test_node_get_product_id
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
assert(md, "Error, no match found for #{pattern}")
|
|
182
|
-
assert_equal(md[1], product_id,
|
|
183
|
-
"Error, Product id does not match")
|
|
178
|
+
assert_output_check(command: 'show inventory | no-more',
|
|
179
|
+
pattern: /NAME: \"Chassis\".*\nPID: (\S+)/,
|
|
180
|
+
check: node.product_id,
|
|
181
|
+
msg: 'Error, Product id does not match')
|
|
184
182
|
end
|
|
185
183
|
|
|
186
184
|
def test_node_get_product_version_id
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
assert(md, "Error, no match found for #{pattern}")
|
|
192
|
-
assert_equal(md[1], version_id,
|
|
193
|
-
"Error, Version id does not match")
|
|
185
|
+
assert_output_check(command: 'show inventory | no-more',
|
|
186
|
+
pattern: /NAME: \"Chassis\".*\n.*VID: (\w+)/,
|
|
187
|
+
check: node.product_version_id,
|
|
188
|
+
msg: 'Error, Version id does not match')
|
|
194
189
|
end
|
|
195
190
|
|
|
196
191
|
def test_node_get_product_serial_number
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
assert(md, "Error, no match found for #{pattern}")
|
|
202
|
-
assert_equal(md[1], serial_number,
|
|
203
|
-
"Error, Serial number does not match")
|
|
192
|
+
assert_output_check(command: 'show inventory | no-more',
|
|
193
|
+
pattern: /NAME: \"Chassis\".*\n.*SN: (\w+)/,
|
|
194
|
+
check: node.product_serial_number,
|
|
195
|
+
msg: 'Error, Serial number does not match')
|
|
204
196
|
end
|
|
205
197
|
|
|
206
198
|
def test_node_get_os
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
assert(md, "Error, no match found for #{pattern}")
|
|
212
|
-
assert_equal(md[1], os,
|
|
213
|
-
"Error, OS version does not match")
|
|
199
|
+
assert_output_check(command: 'show version | no-more',
|
|
200
|
+
pattern: /\n(Cisco.*)\n/,
|
|
201
|
+
check: node.os,
|
|
202
|
+
msg: 'Error, OS version does not match')
|
|
214
203
|
end
|
|
215
204
|
|
|
216
205
|
def test_node_get_os_version
|
|
217
|
-
|
|
218
|
-
ref
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
assert(md, "Error, no match found for #{pattern}")
|
|
224
|
-
assert_equal(md[1], os_version,
|
|
225
|
-
"Error, OS version does not match")
|
|
206
|
+
ref = cmd_ref.lookup('show_version', 'version')
|
|
207
|
+
assert(ref, 'Error, reference not found')
|
|
208
|
+
assert_output_check(command: ref.test_config_get,
|
|
209
|
+
pattern: ref.test_config_get_regex[1],
|
|
210
|
+
check: node.os_version,
|
|
211
|
+
msg: 'Error, OS version does not match')
|
|
226
212
|
end
|
|
227
213
|
|
|
228
214
|
def test_node_get_host_name_when_not_set
|
|
229
|
-
s = @device.cmd(
|
|
215
|
+
s = @device.cmd('show running-config all | no-more')
|
|
230
216
|
pattern = /.*\nhostname (\S+)/
|
|
231
217
|
md = pattern.match(s)
|
|
232
218
|
if md
|
|
@@ -243,31 +229,19 @@ vrf blue",
|
|
|
243
229
|
configured_name = nil
|
|
244
230
|
end
|
|
245
231
|
end
|
|
246
|
-
node.cache_flush
|
|
247
232
|
|
|
248
|
-
|
|
249
|
-
@device.cmd("no hostname") if (switchname == false)
|
|
250
|
-
@device.cmd("no switchname") if (switchname == true)
|
|
251
|
-
@device.cmd("end")
|
|
252
|
-
node.cache_flush
|
|
233
|
+
switchname ? config('no switchname') : config('no hostname')
|
|
253
234
|
|
|
254
235
|
name = node.host_name
|
|
255
|
-
assert_equal(
|
|
236
|
+
assert_equal('switch', name)
|
|
256
237
|
|
|
257
|
-
|
|
258
|
-
if
|
|
259
|
-
|
|
260
|
-
@device.cmd("switchname #{configured_name}") if (switchname == true)
|
|
261
|
-
else
|
|
262
|
-
@device.cmd("no hostname") if (switchname == false)
|
|
263
|
-
@device.cmd("no switchname") if (switchname == true)
|
|
264
|
-
end
|
|
265
|
-
@device.cmd("end")
|
|
266
|
-
node.cache_flush
|
|
238
|
+
return unless configured_name
|
|
239
|
+
config("hostname #{configured_name}") if (switchname == false)
|
|
240
|
+
config("switchname #{configured_name}") if (switchname == true)
|
|
267
241
|
end
|
|
268
242
|
|
|
269
243
|
def test_node_get_host_name_when_set
|
|
270
|
-
s = @device.cmd(
|
|
244
|
+
s = @device.cmd('show running-config all | no-more')
|
|
271
245
|
pattern = /.*\nhostname (\S+)/
|
|
272
246
|
md = pattern.match(s)
|
|
273
247
|
if md
|
|
@@ -285,27 +259,18 @@ vrf blue",
|
|
|
285
259
|
switchname = false
|
|
286
260
|
end
|
|
287
261
|
end
|
|
288
|
-
node.cache_flush
|
|
289
262
|
|
|
290
|
-
|
|
291
|
-
@device.cmd("hostname xyz") if (switchname == false)
|
|
292
|
-
@device.cmd("switchname xyz") if (switchname == true)
|
|
293
|
-
@device.cmd("end")
|
|
294
|
-
node.cache_flush
|
|
263
|
+
switchname ? config('switchname xyz') : config('hostname xyz')
|
|
295
264
|
|
|
296
265
|
host_name = node.host_name
|
|
297
|
-
assert_equal(
|
|
266
|
+
assert_equal('xyz', host_name)
|
|
298
267
|
|
|
299
|
-
@device.cmd("configure terminal")
|
|
300
268
|
if configured_name
|
|
301
|
-
|
|
302
|
-
|
|
269
|
+
config("hostname #{configured_name}") if (switchname == false)
|
|
270
|
+
config("switchname #{configured_name}") if (switchname == true)
|
|
303
271
|
else
|
|
304
|
-
|
|
305
|
-
@device.cmd("no switchname") if (switchname == true)
|
|
272
|
+
switchname ? config('no switchname') : config('no hostname')
|
|
306
273
|
end
|
|
307
|
-
@device.cmd("end")
|
|
308
|
-
node.cache_flush
|
|
309
274
|
end
|
|
310
275
|
|
|
311
276
|
def test_node_get_domain_name_when_not_set
|
|
@@ -318,28 +283,21 @@ vrf blue",
|
|
|
318
283
|
else
|
|
319
284
|
configured_domain_name = nil
|
|
320
285
|
end
|
|
321
|
-
node.cache_flush
|
|
322
286
|
|
|
323
|
-
|
|
324
|
-
@device.cmd("no ip domain-name #{configured_domain_name}")
|
|
325
|
-
@device.cmd("end")
|
|
326
|
-
node.cache_flush
|
|
287
|
+
config("no ip domain-name #{configured_domain_name}")
|
|
327
288
|
|
|
328
289
|
domain_name = node.domain_name
|
|
329
|
-
assert_equal(
|
|
290
|
+
assert_equal('', domain_name)
|
|
330
291
|
|
|
331
|
-
@device.cmd("configure terminal")
|
|
332
292
|
if configured_domain_name
|
|
333
|
-
|
|
293
|
+
config("ip domain-name #{configured_domain_name}")
|
|
334
294
|
else
|
|
335
|
-
|
|
295
|
+
config('no ip domain-name abc.com')
|
|
336
296
|
end
|
|
337
|
-
@device.cmd("end")
|
|
338
|
-
node.cache_flush
|
|
339
297
|
end
|
|
340
298
|
|
|
341
299
|
def test_node_get_domain_name_when_set
|
|
342
|
-
s = @device.cmd(
|
|
300
|
+
s = @device.cmd('show running-config | no-more')
|
|
343
301
|
pattern = /.*\nip domain-name (\S+)/
|
|
344
302
|
md = pattern.match(s)
|
|
345
303
|
if md
|
|
@@ -347,38 +305,35 @@ vrf blue",
|
|
|
347
305
|
else
|
|
348
306
|
configured_domain_name = nil
|
|
349
307
|
end
|
|
350
|
-
node.cache_flush
|
|
351
308
|
|
|
352
|
-
|
|
353
|
-
@device.cmd("ip domain-name abc.com")
|
|
354
|
-
@device.cmd("end")
|
|
355
|
-
node.cache_flush
|
|
309
|
+
config('ip domain-name abc.com')
|
|
356
310
|
|
|
357
311
|
domain_name = node.domain_name
|
|
358
|
-
assert_equal(
|
|
312
|
+
assert_equal('abc.com', domain_name)
|
|
359
313
|
|
|
360
|
-
@device.cmd("configure terminal")
|
|
361
314
|
if configured_domain_name
|
|
362
|
-
|
|
315
|
+
config("ip domain-name #{configured_domain_name}")
|
|
363
316
|
else
|
|
364
|
-
|
|
317
|
+
config('no ip domain-name abc.com')
|
|
365
318
|
end
|
|
366
|
-
@device.cmd("end")
|
|
367
|
-
node.cache_flush
|
|
368
319
|
end
|
|
369
320
|
|
|
370
321
|
def test_node_get_system_uptime
|
|
371
322
|
node.cache_flush
|
|
323
|
+
# rubocop:disable Metrics/LineLength
|
|
372
324
|
pattern = /.*System uptime:\s+(\d+) days, (\d+) hours, (\d+) minutes, (\d+) seconds/
|
|
325
|
+
# rubocop:enable Metrics/LineLength
|
|
373
326
|
|
|
374
|
-
|
|
327
|
+
md = assert_show_match(command: 'show system uptime | no-more',
|
|
328
|
+
pattern: pattern)
|
|
375
329
|
node_uptime = node.system_uptime
|
|
376
330
|
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
(md[
|
|
331
|
+
observed_system_uptime = (
|
|
332
|
+
(md[1].to_i * 86_400) +
|
|
333
|
+
(md[2].to_i * 3600) +
|
|
334
|
+
(md[3].to_i * 60) +
|
|
335
|
+
(md[4].to_i)
|
|
336
|
+
)
|
|
382
337
|
delta = node_uptime - observed_system_uptime
|
|
383
338
|
assert(delta < 10,
|
|
384
339
|
"Error, System uptime delta is (#{delta}), expected (delta < 10)")
|
|
@@ -386,42 +341,36 @@ vrf blue",
|
|
|
386
341
|
|
|
387
342
|
def test_node_get_last_reset_time
|
|
388
343
|
last_reset_time = node.last_reset_time
|
|
389
|
-
ref = cmd_ref.lookup(
|
|
390
|
-
assert(ref,
|
|
391
|
-
s = @device.cmd("#{ref.test_config_get}")
|
|
392
|
-
pattern = ref.test_config_get_regex
|
|
393
|
-
md = pattern.match(s)
|
|
344
|
+
ref = cmd_ref.lookup('show_version', 'last_reset_time')
|
|
345
|
+
assert(ref, 'Error, reference not found')
|
|
394
346
|
# N9k doesn't provide this info at present.
|
|
395
347
|
if !last_reset_time.empty?
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
348
|
+
assert_output_check(command: ref.test_config_get,
|
|
349
|
+
pattern: ref.test_config_get_regex,
|
|
350
|
+
check: last_reset_time,
|
|
351
|
+
msg: 'Error, Last reset time does not match')
|
|
399
352
|
else
|
|
400
|
-
|
|
353
|
+
refute_show_match(command: ref.test_config_get,
|
|
354
|
+
pattern: ref.test_config_get_regex,
|
|
355
|
+
msg: 'output found in ASCII but not in node')
|
|
401
356
|
end
|
|
402
357
|
end
|
|
403
358
|
|
|
404
359
|
def test_node_get_last_reset_reason
|
|
405
|
-
|
|
406
|
-
ref
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
refute_nil(md, "ERROR: last reset reason not shown")
|
|
412
|
-
assert(md, "Error, no match found for #{pattern}")
|
|
413
|
-
assert_equal(md[1], last_reset_reason,
|
|
414
|
-
"Error, Last reset reason does not match")
|
|
360
|
+
ref = cmd_ref.lookup('show_version', 'last_reset_reason')
|
|
361
|
+
assert(ref, 'Error, reference not found')
|
|
362
|
+
assert_output_check(command: ref.test_config_get,
|
|
363
|
+
pattern: ref.test_config_get_regex,
|
|
364
|
+
check: node.last_reset_reason,
|
|
365
|
+
msg: 'Error, Last reset reason does not match')
|
|
415
366
|
end
|
|
416
367
|
|
|
417
368
|
def test_node_get_system_cpu_utilization
|
|
418
369
|
cpu_utilization = node.system_cpu_utilization
|
|
419
|
-
ref = cmd_ref.lookup(
|
|
420
|
-
assert(ref,
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
md = pattern.match(s)
|
|
424
|
-
assert(md, "Error, md not populated, #{s}")
|
|
370
|
+
ref = cmd_ref.lookup('system', 'resources')
|
|
371
|
+
assert(ref, 'Error, reference not found')
|
|
372
|
+
md = assert_show_match(command: ref.test_config_get,
|
|
373
|
+
pattern: ref.test_config_get_regex)
|
|
425
374
|
observed_cpu_utilization = md[1].to_f + md[2].to_f
|
|
426
375
|
delta = cpu_utilization - observed_cpu_utilization
|
|
427
376
|
assert(delta > -15.0 && delta < 15.0,
|
|
@@ -429,22 +378,20 @@ vrf blue",
|
|
|
429
378
|
end
|
|
430
379
|
|
|
431
380
|
def test_node_get_boot
|
|
432
|
-
|
|
433
|
-
ref
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
"Error, Kickstart Image does not match")
|
|
381
|
+
ref = cmd_ref.lookup('show_version', 'boot_image')
|
|
382
|
+
assert(ref, 'Error, reference not found')
|
|
383
|
+
assert_output_check(command: ref.test_config_get,
|
|
384
|
+
pattern: ref.test_config_get_regex,
|
|
385
|
+
check: node.boot,
|
|
386
|
+
msg: 'Error, Kickstart Image does not match')
|
|
439
387
|
end
|
|
440
388
|
|
|
441
389
|
def test_node_get_system
|
|
442
|
-
|
|
443
|
-
ref
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
"Error, System Image does not match")
|
|
390
|
+
ref = cmd_ref.lookup('show_version', 'system_image')
|
|
391
|
+
assert(ref, 'Error, reference not found')
|
|
392
|
+
assert_output_check(command: ref.test_config_get,
|
|
393
|
+
pattern: ref.test_config_get_regex,
|
|
394
|
+
check: node.system,
|
|
395
|
+
msg: 'Error, System Image does not match')
|
|
449
396
|
end
|
|
450
397
|
end
|