cisco_node_utils 0.9.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 +2 -0
- data/.rubocop.yml +3 -0
- data/.rubocop_todo.yml +293 -0
- data/CHANGELOG.md +5 -0
- data/CONTRIBUTING.md +31 -0
- data/Gemfile +4 -0
- data/LICENSE +201 -0
- data/README.md +113 -0
- data/Rakefile +4 -0
- data/cisco_node_utils.gemspec +30 -0
- data/lib/cisco_node_utils.rb +33 -0
- data/lib/cisco_node_utils/README_YAML.md +333 -0
- data/lib/cisco_node_utils/cisco_cmn_utils.rb +92 -0
- data/lib/cisco_node_utils/command_reference.rb +415 -0
- data/lib/cisco_node_utils/command_reference_common.yaml +845 -0
- data/lib/cisco_node_utils/command_reference_n3064.yaml +13 -0
- data/lib/cisco_node_utils/command_reference_n7k.yaml +48 -0
- data/lib/cisco_node_utils/command_reference_n9k.yaml +35 -0
- data/lib/cisco_node_utils/configparser_lib.rb +196 -0
- data/lib/cisco_node_utils/interface.rb +501 -0
- data/lib/cisco_node_utils/interface_ospf.rb +241 -0
- data/lib/cisco_node_utils/node.rb +673 -0
- data/lib/cisco_node_utils/platform.rb +184 -0
- data/lib/cisco_node_utils/platform_info.rb +58 -0
- data/lib/cisco_node_utils/platform_info.yaml +10 -0
- data/lib/cisco_node_utils/router_ospf.rb +96 -0
- data/lib/cisco_node_utils/router_ospf_vrf.rb +258 -0
- data/lib/cisco_node_utils/snmpcommunity.rb +91 -0
- data/lib/cisco_node_utils/snmpgroup.rb +55 -0
- data/lib/cisco_node_utils/snmpserver.rb +150 -0
- data/lib/cisco_node_utils/snmpuser.rb +342 -0
- data/lib/cisco_node_utils/tacacs_server.rb +175 -0
- data/lib/cisco_node_utils/tacacs_server_host.rb +128 -0
- data/lib/cisco_node_utils/version.rb +17 -0
- data/lib/cisco_node_utils/vlan.rb +153 -0
- data/lib/cisco_node_utils/vtp.rb +127 -0
- data/lib/cisco_node_utils/yum.rb +84 -0
- data/tests/basetest.rb +93 -0
- data/tests/ciscotest.rb +136 -0
- data/tests/cmd_config.yaml +51 -0
- data/tests/cmd_config_invalid.yaml +16 -0
- data/tests/test_all_cisco.rb +46 -0
- data/tests/test_command_config.rb +192 -0
- data/tests/test_command_reference.rb +222 -0
- data/tests/test_interface.rb +1017 -0
- data/tests/test_interface_ospf.rb +763 -0
- data/tests/test_interface_svi.rb +267 -0
- data/tests/test_interface_switchport.rb +722 -0
- data/tests/test_node.rb +108 -0
- data/tests/test_node_ext.rb +450 -0
- data/tests/test_platform.rb +188 -0
- data/tests/test_router_ospf.rb +164 -0
- data/tests/test_router_ospf_vrf.rb +753 -0
- data/tests/test_snmpcommunity.rb +344 -0
- data/tests/test_snmpgroup.rb +71 -0
- data/tests/test_snmpserver.rb +443 -0
- data/tests/test_snmpuser.rb +803 -0
- data/tests/test_tacacs_server.rb +388 -0
- data/tests/test_tacacs_server_host.rb +391 -0
- data/tests/test_vlan.rb +264 -0
- data/tests/test_vtp.rb +319 -0
- data/tests/test_yum.rb +106 -0
- metadata +188 -0
data/tests/test_node.rb
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
# Copyright (c) 2013-2015 Cisco and/or its affiliates.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require File.expand_path("../basetest", __FILE__)
|
16
|
+
|
17
|
+
require File.expand_path("../../lib/cisco_node_utils/node", __FILE__)
|
18
|
+
require File.expand_path("../../lib/cisco_node_utils/command_reference", __FILE__)
|
19
|
+
|
20
|
+
include Cisco
|
21
|
+
|
22
|
+
Node.lazy_connect = true # we'll specify the connection info later
|
23
|
+
|
24
|
+
class TestNode < TestCase
|
25
|
+
def setup
|
26
|
+
end
|
27
|
+
|
28
|
+
def teardown
|
29
|
+
GC.start
|
30
|
+
end
|
31
|
+
|
32
|
+
# As Node is now a singleton, we cannot instantiate it.
|
33
|
+
|
34
|
+
def test_node_create_not_allowed
|
35
|
+
assert_raises(NoMethodError) do
|
36
|
+
node = Node.new
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_node_connect_zero_arguments
|
41
|
+
node = Node.instance
|
42
|
+
# No UDS present on the test host, so default logic fails to connect
|
43
|
+
assert_raises(RuntimeError) do
|
44
|
+
node.connect
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_node_connect_one_argument
|
49
|
+
node = Node.instance
|
50
|
+
assert_raises(TypeError) do
|
51
|
+
node.connect(address)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_node_connect_two_arguments
|
56
|
+
node = Node.instance
|
57
|
+
assert_raises(TypeError) do
|
58
|
+
node.connect(username, password)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_node_connect_nil_username
|
63
|
+
node = Node.instance
|
64
|
+
assert_raises(TypeError) do
|
65
|
+
node.connect(address, nil, password)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_node_connect_invalid_username
|
70
|
+
node = Node.instance
|
71
|
+
assert_raises(TypeError) do
|
72
|
+
node.connect(address, node, password)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_node_connect_username_zero_length
|
77
|
+
node = Node.instance
|
78
|
+
assert_raises(ArgumentError) do
|
79
|
+
node.connect(address, "", password)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_node_connect_nil_password
|
84
|
+
node = Node.instance
|
85
|
+
assert_raises(TypeError) do
|
86
|
+
node.connect(address, username, nil)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_node_connect_invalid_password
|
91
|
+
node = Node.instance
|
92
|
+
assert_raises(TypeError) do
|
93
|
+
node.connect(address, username, node)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_node_connect_password_zero_length
|
98
|
+
node = Node.instance
|
99
|
+
assert_raises(ArgumentError) do
|
100
|
+
node.connect(address, username, "")
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_node_connect
|
105
|
+
node = Node.instance
|
106
|
+
node.connect(address, username, password)
|
107
|
+
end
|
108
|
+
end
|
@@ -0,0 +1,450 @@
|
|
1
|
+
# Copyright (c) 2013-2015 Cisco and/or its affiliates.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require File.expand_path("../ciscotest", __FILE__)
|
16
|
+
|
17
|
+
class TestNodeExt < CiscoTestCase
|
18
|
+
# Test cases for abstracted Node APIs
|
19
|
+
|
20
|
+
@@show_run_ospf = "\
|
21
|
+
router ospf foo
|
22
|
+
vrf red
|
23
|
+
log-adjacency-changes
|
24
|
+
router ospf bar
|
25
|
+
log-adjacency-changes
|
26
|
+
vrf red
|
27
|
+
log-adjacency-changes detail
|
28
|
+
vrf blue
|
29
|
+
!
|
30
|
+
router ospf baz
|
31
|
+
log-adjacency-changes detail"
|
32
|
+
|
33
|
+
def test_node_find_subconfig
|
34
|
+
result = find_subconfig(@@show_run_ospf, /router ospf bar/)
|
35
|
+
assert_equal("\
|
36
|
+
log-adjacency-changes
|
37
|
+
vrf red
|
38
|
+
log-adjacency-changes detail
|
39
|
+
vrf blue",
|
40
|
+
result)
|
41
|
+
|
42
|
+
assert_nil(find_subconfig(result, /vrf blue/))
|
43
|
+
|
44
|
+
assert_equal("log-adjacency-changes detail",
|
45
|
+
find_subconfig(result, /vrf red/))
|
46
|
+
|
47
|
+
assert_nil(find_subconfig(result, /vrf green/))
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_node_find_ascii
|
51
|
+
# Find an entry in the parent submode, ignoring nested submodes
|
52
|
+
assert_equal(["log-adjacency-changes"],
|
53
|
+
find_ascii(@@show_run_ospf, /^log-adjacency-changes.*$/,
|
54
|
+
/router ospf bar/))
|
55
|
+
# Find an entry in a nested submode
|
56
|
+
assert_equal(["log-adjacency-changes detail"],
|
57
|
+
find_ascii(@@show_run_ospf, /^log-adjacency-changes.*$/,
|
58
|
+
/router ospf bar/, /vrf red/))
|
59
|
+
# Submode exists but does not have a match
|
60
|
+
assert_nil(find_ascii(@@show_run_ospf, /^log-adjacency-changes.*$/,
|
61
|
+
/router ospf bar/, /vrf blue/))
|
62
|
+
# Submode does not exist
|
63
|
+
assert_nil(find_ascii(@@show_run_ospf, /^log-adjacency-changes.*$/,
|
64
|
+
/router ospf bar/, /vrf green/))
|
65
|
+
|
66
|
+
# Entry exists in submode only
|
67
|
+
assert_nil(find_ascii(@@show_run_ospf, /^log-adjacency-changes.*$/,
|
68
|
+
/router ospf foo/))
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_node_config_get
|
72
|
+
result = node.config_get("show_version", "system_image")
|
73
|
+
assert_equal(result, node.system)
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_node_config_get_regexp_tokens
|
77
|
+
node.client.config(["interface loopback0", "shutdown"])
|
78
|
+
node.client.config(["interface loopback1", "no shutdown"])
|
79
|
+
|
80
|
+
result = node.config_get("interface", "shutdown", "loopback1")
|
81
|
+
assert_nil(result)
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_node_token_str_to_regexp
|
85
|
+
token = ["/%s/i", "/%s foo %s/", "/zzz/i"]
|
86
|
+
args = %w(LoopBack2 no bar)
|
87
|
+
expected = [/LoopBack2/i, /no foo bar/, /zzz/i]
|
88
|
+
|
89
|
+
result = node.token_str_to_regexp(token, args)
|
90
|
+
# puts "intersection: #{result & expected}, diff: #{result - expected}"
|
91
|
+
assert_equal(expected, result)
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_node_config_get_invalid
|
95
|
+
assert_raises IndexError do # no entry
|
96
|
+
result = node.config_get("feature", "name")
|
97
|
+
end
|
98
|
+
assert_raises IndexError do # entry but no config_get
|
99
|
+
result = node.config_get("show_system", "resources")
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_node_config_get_default
|
104
|
+
result = node.config_get_default("snmp_server", "aaa_user_cache_timeout")
|
105
|
+
assert_equal(result, 3600)
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_node_config_get_default_invalid
|
109
|
+
assert_raises IndexError do # no name entry
|
110
|
+
result = node.config_get_default("show_version", "foobar")
|
111
|
+
end
|
112
|
+
assert_raises IndexError do # no feature entry
|
113
|
+
result = node.config_get_default("feature", "name")
|
114
|
+
end
|
115
|
+
assert_raises IndexError do # no default_value defined
|
116
|
+
result = node.config_get_default("show_version", "version")
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_node_config_set
|
121
|
+
result = node.config_set("snmp_server",
|
122
|
+
"aaa_user_cache_timeout",
|
123
|
+
"", 100)
|
124
|
+
run = node.client.show("show run all | inc snmp")
|
125
|
+
val = find_one_ascii(run, /snmp-server aaa-user cache-timeout (\d+)/)
|
126
|
+
assert_equal("100", val)
|
127
|
+
|
128
|
+
result = node.config_set("snmp_server",
|
129
|
+
"aaa_user_cache_timeout",
|
130
|
+
"no", 100)
|
131
|
+
run = node.client.show("show run all | inc snmp")
|
132
|
+
val = find_one_ascii(run, /snmp-server aaa-user cache-timeout (\d+)/)
|
133
|
+
assert_equal("3600", val)
|
134
|
+
end
|
135
|
+
|
136
|
+
def test_node_config_set_invalid
|
137
|
+
assert_raises IndexError do
|
138
|
+
result = node.config_set("feature", "name")
|
139
|
+
end
|
140
|
+
assert_raises IndexError do # feature exists but no config_set
|
141
|
+
result = node.config_set("show_version", "system_image")
|
142
|
+
end
|
143
|
+
assert_raises ArgumentError do # not enough args
|
144
|
+
result = node.config_set("vtp", "domain")
|
145
|
+
end
|
146
|
+
assert_raises ArgumentError do # too many args
|
147
|
+
result = node.config_set("vtp", "domain", "example.com", "baz")
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
def test_node_cli_caching
|
152
|
+
s = @device.cmd("conf t ; ip domain-name minitest ; end")
|
153
|
+
dom1 = node.domain_name
|
154
|
+
s = @device.cmd("conf t ; no ip domain-name minitest ; end")
|
155
|
+
dom2 = node.domain_name
|
156
|
+
assert_equal(dom1, dom2) # cached output was used for dom2
|
157
|
+
|
158
|
+
node.cache_flush
|
159
|
+
dom3 = node.domain_name
|
160
|
+
assert_not_equal(dom1, dom3)
|
161
|
+
end
|
162
|
+
|
163
|
+
def test_node_get_product_description
|
164
|
+
product_description = node.product_description
|
165
|
+
ref = cmd_ref.lookup("show_version", "description")
|
166
|
+
assert(ref, "Error, reference not found")
|
167
|
+
|
168
|
+
s = @device.cmd("#{ref.test_config_get}")
|
169
|
+
pattern = ref.test_config_get_regex
|
170
|
+
md = pattern.match(s)
|
171
|
+
assert(md, "Error, no match found for #{pattern}")
|
172
|
+
assert_equal(md[1], product_description,
|
173
|
+
"Error, Product description does not match")
|
174
|
+
end
|
175
|
+
|
176
|
+
def test_node_get_product_id
|
177
|
+
product_id = node.product_id
|
178
|
+
s = @device.cmd("show inventory | no-more")
|
179
|
+
pattern = /NAME: \"Chassis\".*\nPID: (\S+)/
|
180
|
+
md = pattern.match(s)
|
181
|
+
assert(md, "Error, no match found for #{pattern}")
|
182
|
+
assert_equal(md[1], product_id,
|
183
|
+
"Error, Product id does not match")
|
184
|
+
end
|
185
|
+
|
186
|
+
def test_node_get_product_version_id
|
187
|
+
version_id = node.product_version_id
|
188
|
+
s = @device.cmd("show inventory | no-more")
|
189
|
+
pattern = /NAME: \"Chassis\".*\n.*VID: (\w+)/
|
190
|
+
md = pattern.match(s)
|
191
|
+
assert(md, "Error, no match found for #{pattern}")
|
192
|
+
assert_equal(md[1], version_id,
|
193
|
+
"Error, Version id does not match")
|
194
|
+
end
|
195
|
+
|
196
|
+
def test_node_get_product_serial_number
|
197
|
+
serial_number = node.product_serial_number
|
198
|
+
s = @device.cmd("show inventory | no-more")
|
199
|
+
pattern = /NAME: \"Chassis\".*\n.*SN: (\w+)/
|
200
|
+
md = pattern.match(s)
|
201
|
+
assert(md, "Error, no match found for #{pattern}")
|
202
|
+
assert_equal(md[1], serial_number,
|
203
|
+
"Error, Serial number does not match")
|
204
|
+
end
|
205
|
+
|
206
|
+
def test_node_get_os
|
207
|
+
os = node.os
|
208
|
+
s = @device.cmd("show version | no-more")
|
209
|
+
pattern = /\n(Cisco.*)\n/
|
210
|
+
md = pattern.match(s)
|
211
|
+
assert(md, "Error, no match found for #{pattern}")
|
212
|
+
assert_equal(md[1], os,
|
213
|
+
"Error, OS version does not match")
|
214
|
+
end
|
215
|
+
|
216
|
+
def test_node_get_os_version
|
217
|
+
os_version = node.os_version
|
218
|
+
ref = cmd_ref.lookup("show_version", "version")
|
219
|
+
assert(ref, "Error, reference not found")
|
220
|
+
s = @device.cmd("#{ref.test_config_get}")
|
221
|
+
pattern = ref.test_config_get_regex[1]
|
222
|
+
md = pattern.match(s)
|
223
|
+
assert(md, "Error, no match found for #{pattern}")
|
224
|
+
assert_equal(md[1], os_version,
|
225
|
+
"Error, OS version does not match")
|
226
|
+
end
|
227
|
+
|
228
|
+
def test_node_get_host_name_when_not_set
|
229
|
+
s = @device.cmd("show running-config all | no-more")
|
230
|
+
pattern = /.*\nhostname (\S+)/
|
231
|
+
md = pattern.match(s)
|
232
|
+
if md
|
233
|
+
configured_name = md[1]
|
234
|
+
switchname = false
|
235
|
+
else
|
236
|
+
# No hostname configured. Lets check if we have switchname instead.
|
237
|
+
pattern = /.*\nswitchname (\S+)/
|
238
|
+
md = pattern.match(s)
|
239
|
+
if md
|
240
|
+
configured_name = md[1]
|
241
|
+
switchname = true
|
242
|
+
else
|
243
|
+
configured_name = nil
|
244
|
+
end
|
245
|
+
end
|
246
|
+
node.cache_flush
|
247
|
+
|
248
|
+
@device.cmd("configure terminal")
|
249
|
+
@device.cmd("no hostname") if (switchname == false)
|
250
|
+
@device.cmd("no switchname") if (switchname == true)
|
251
|
+
@device.cmd("end")
|
252
|
+
node.cache_flush
|
253
|
+
|
254
|
+
name = node.host_name
|
255
|
+
assert_equal("switch", name)
|
256
|
+
|
257
|
+
@device.cmd("configure terminal")
|
258
|
+
if configured_name
|
259
|
+
@device.cmd("hostname #{configured_name}") if (switchname == false)
|
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
|
267
|
+
end
|
268
|
+
|
269
|
+
def test_node_get_host_name_when_set
|
270
|
+
s = @device.cmd("show running-config all | no-more")
|
271
|
+
pattern = /.*\nhostname (\S+)/
|
272
|
+
md = pattern.match(s)
|
273
|
+
if md
|
274
|
+
configured_name = md[1]
|
275
|
+
switchname = false
|
276
|
+
else
|
277
|
+
# No hostname configured. Lets check if we have switchname instead.
|
278
|
+
pattern = /.*\nswitchname (\S+)/
|
279
|
+
md = pattern.match(s)
|
280
|
+
if md
|
281
|
+
configured_name = md[1]
|
282
|
+
switchname = true
|
283
|
+
else
|
284
|
+
configured_name = nil
|
285
|
+
switchname = false
|
286
|
+
end
|
287
|
+
end
|
288
|
+
node.cache_flush
|
289
|
+
|
290
|
+
@device.cmd("configure terminal")
|
291
|
+
@device.cmd("hostname xyz") if (switchname == false)
|
292
|
+
@device.cmd("switchname xyz") if (switchname == true)
|
293
|
+
@device.cmd("end")
|
294
|
+
node.cache_flush
|
295
|
+
|
296
|
+
host_name = node.host_name
|
297
|
+
assert_equal("xyz", host_name)
|
298
|
+
|
299
|
+
@device.cmd("configure terminal")
|
300
|
+
if configured_name
|
301
|
+
@device.cmd("hostname #{configured_name}") if (switchname == false)
|
302
|
+
@device.cmd("switchname #{configured_name}") if (switchname == true)
|
303
|
+
else
|
304
|
+
@device.cmd("no hostname") if (switchname == false)
|
305
|
+
@device.cmd("no switchname") if (switchname == true)
|
306
|
+
end
|
307
|
+
@device.cmd("end")
|
308
|
+
node.cache_flush
|
309
|
+
end
|
310
|
+
|
311
|
+
def test_node_get_domain_name_when_not_set
|
312
|
+
# Test with default vrf only
|
313
|
+
s = @device.cmd("show running-config | incl '^ip domain-name'")
|
314
|
+
pattern = /^ip domain-name (\S+)/
|
315
|
+
md = pattern.match(s)
|
316
|
+
if md
|
317
|
+
configured_domain_name = md[1]
|
318
|
+
else
|
319
|
+
configured_domain_name = nil
|
320
|
+
end
|
321
|
+
node.cache_flush
|
322
|
+
|
323
|
+
@device.cmd("configure terminal")
|
324
|
+
@device.cmd("no ip domain-name #{configured_domain_name}")
|
325
|
+
@device.cmd("end")
|
326
|
+
node.cache_flush
|
327
|
+
|
328
|
+
domain_name = node.domain_name
|
329
|
+
assert_equal("", domain_name)
|
330
|
+
|
331
|
+
@device.cmd("configure terminal")
|
332
|
+
if configured_domain_name
|
333
|
+
@device.cmd("ip domain-name #{configured_domain_name}")
|
334
|
+
else
|
335
|
+
@device.cmd("no ip domain-name abc.com")
|
336
|
+
end
|
337
|
+
@device.cmd("end")
|
338
|
+
node.cache_flush
|
339
|
+
end
|
340
|
+
|
341
|
+
def test_node_get_domain_name_when_set
|
342
|
+
s = @device.cmd("show running-config | no-more")
|
343
|
+
pattern = /.*\nip domain-name (\S+)/
|
344
|
+
md = pattern.match(s)
|
345
|
+
if md
|
346
|
+
configured_domain_name = md[1]
|
347
|
+
else
|
348
|
+
configured_domain_name = nil
|
349
|
+
end
|
350
|
+
node.cache_flush
|
351
|
+
|
352
|
+
@device.cmd("configure terminal")
|
353
|
+
@device.cmd("ip domain-name abc.com")
|
354
|
+
@device.cmd("end")
|
355
|
+
node.cache_flush
|
356
|
+
|
357
|
+
domain_name = node.domain_name
|
358
|
+
assert_equal("abc.com", domain_name)
|
359
|
+
|
360
|
+
@device.cmd("configure terminal")
|
361
|
+
if configured_domain_name
|
362
|
+
@device.cmd("ip domain-name #{configured_domain_name}")
|
363
|
+
else
|
364
|
+
@device.cmd("no ip domain-name abc.com")
|
365
|
+
end
|
366
|
+
@device.cmd("end")
|
367
|
+
node.cache_flush
|
368
|
+
end
|
369
|
+
|
370
|
+
def test_node_get_system_uptime
|
371
|
+
node.cache_flush
|
372
|
+
pattern = /.*System uptime:\s+(\d+) days, (\d+) hours, (\d+) minutes, (\d+) seconds/
|
373
|
+
|
374
|
+
s = @device.cmd("show system uptime | no-more")
|
375
|
+
node_uptime = node.system_uptime
|
376
|
+
|
377
|
+
md = pattern.match(s)
|
378
|
+
assert(md, "Error, no match found for #{pattern}")
|
379
|
+
|
380
|
+
observed_system_uptime =
|
381
|
+
(md[1].to_i * 86400) + (md[2].to_i * 3600) + (md[3].to_i * 60) + (md[4].to_i)
|
382
|
+
delta = node_uptime - observed_system_uptime
|
383
|
+
assert(delta < 10,
|
384
|
+
"Error, System uptime delta is (#{delta}), expected (delta < 10)")
|
385
|
+
end
|
386
|
+
|
387
|
+
def test_node_get_last_reset_time
|
388
|
+
last_reset_time = node.last_reset_time
|
389
|
+
ref = cmd_ref.lookup("show_version", "last_reset_time")
|
390
|
+
assert(ref, "Error, reference not found")
|
391
|
+
s = @device.cmd("#{ref.test_config_get}")
|
392
|
+
pattern = ref.test_config_get_regex
|
393
|
+
md = pattern.match(s)
|
394
|
+
# N9k doesn't provide this info at present.
|
395
|
+
if !last_reset_time.empty?
|
396
|
+
assert(md, "Error, no match found for #{pattern}")
|
397
|
+
assert_equal(md[1], last_reset_time,
|
398
|
+
"Error, Last reset time does not match")
|
399
|
+
else
|
400
|
+
assert(!md, "Error, output found in ASCII '#{md}' but not in node")
|
401
|
+
end
|
402
|
+
end
|
403
|
+
|
404
|
+
def test_node_get_last_reset_reason
|
405
|
+
last_reset_reason = node.last_reset_reason
|
406
|
+
ref = cmd_ref.lookup("show_version", "last_reset_reason")
|
407
|
+
assert(ref, "Error, reference not found")
|
408
|
+
s = @device.cmd("#{ref.test_config_get}")
|
409
|
+
pattern = ref.test_config_get_regex
|
410
|
+
md = pattern.match(s)
|
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")
|
415
|
+
end
|
416
|
+
|
417
|
+
def test_node_get_system_cpu_utilization
|
418
|
+
cpu_utilization = node.system_cpu_utilization
|
419
|
+
ref = cmd_ref.lookup("system", "resources")
|
420
|
+
assert(ref, "Error, reference not found")
|
421
|
+
s = @device.cmd("#{ref.test_config_get}")
|
422
|
+
pattern = ref.test_config_get_regex
|
423
|
+
md = pattern.match(s)
|
424
|
+
assert(md, "Error, md not populated, #{s}")
|
425
|
+
observed_cpu_utilization = md[1].to_f + md[2].to_f
|
426
|
+
delta = cpu_utilization - observed_cpu_utilization
|
427
|
+
assert(delta > -15.0 && delta < 15.0,
|
428
|
+
"Error: delta #{delta}, not +- 15.0")
|
429
|
+
end
|
430
|
+
|
431
|
+
def test_node_get_boot
|
432
|
+
boot = node.boot
|
433
|
+
ref = cmd_ref.lookup("show_version", "boot_image")
|
434
|
+
assert(ref, "Error, reference not found")
|
435
|
+
s = @device.cmd("#{ref.test_config_get}")
|
436
|
+
s =~ ref.test_config_get_regex
|
437
|
+
assert_equal(Regexp.last_match(1), boot,
|
438
|
+
"Error, Kickstart Image does not match")
|
439
|
+
end
|
440
|
+
|
441
|
+
def test_node_get_system
|
442
|
+
system = node.system
|
443
|
+
ref = cmd_ref.lookup("show_version", "system_image")
|
444
|
+
assert(ref, "Error, reference not found")
|
445
|
+
s = @device.cmd("#{ref.test_config_get}")
|
446
|
+
s =~ ref.test_config_get_regex
|
447
|
+
assert_equal(Regexp.last_match(1), system,
|
448
|
+
"Error, System Image does not match")
|
449
|
+
end
|
450
|
+
end
|