cisco_node_utils 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -0,0 +1,1017 @@
|
|
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
|
+
require File.expand_path("../../lib/cisco_node_utils/interface", __FILE__)
|
17
|
+
|
18
|
+
include Cisco
|
19
|
+
|
20
|
+
class TestInterface < CiscoTestCase
|
21
|
+
# Global class variables for debugs
|
22
|
+
@@debug_group_ipv4_all_interfaces = "interface_ipv4_all_interfaces"
|
23
|
+
@@debug_validate_interfaces_not_empty = "validate_interfaces_not_empty"
|
24
|
+
@@debug_validate_interface_shutdown = "validate_interface_shutdown"
|
25
|
+
@@debug_validate_get_switchport = "validate_get_switchport"
|
26
|
+
@@debug_validate_description = "validate_description"
|
27
|
+
@@debug_validate_get_access_vlan = "validate_get_access_vlan"
|
28
|
+
@@debug_validate_ipv4_address = "validate_ipv4_address"
|
29
|
+
@@debug_validate_ipv4_proxy_arp = "validate_ipv4_proxy_arp"
|
30
|
+
@@debug_validate_ipv4_redirects = "validate_ipv4_redirects"
|
31
|
+
@@debug_test_interface_ipv4_all_interfaces = "test_interface_ipv4_all_interfaces"
|
32
|
+
|
33
|
+
# Debug flags, globally defined
|
34
|
+
#
|
35
|
+
# debug_flag - Flag to control if debugs are displayed, can take
|
36
|
+
# true/false as values.
|
37
|
+
# debug_detail - Flag to control if detailed debugs are displayed, can take
|
38
|
+
# true/false as values.
|
39
|
+
# debug_method - The method name to be displayed, can take any string
|
40
|
+
# or the string 'all' if all debugs should be turned
|
41
|
+
# on.
|
42
|
+
# debug_group - The method name to be displayed, can take any string
|
43
|
+
# or the string 'all' if all debugs should be turned on.
|
44
|
+
CiscoTestCase.debug_flag = false
|
45
|
+
CiscoTestCase.debug_detail = false
|
46
|
+
CiscoTestCase.debug_method = ""
|
47
|
+
CiscoTestCase.debug_group = @@debug_group_ipv4_all_interfaces
|
48
|
+
|
49
|
+
SWITCHPORT_SHUTDOWN_HASH = {
|
50
|
+
"shutdown_ethernet_switchport_shutdown" =>
|
51
|
+
["system default switchport", "system default switchport shutdown"],
|
52
|
+
"shutdown_ethernet_switchport_noshutdown" =>
|
53
|
+
["system default switchport", "no system default switchport shutdown"],
|
54
|
+
"shutdown_ethernet_noswitchport_shutdown" =>
|
55
|
+
["no system default switchport", "system default switchport shutdown"],
|
56
|
+
"shutdown_ethernet_noswitchport_noshutdown"=>
|
57
|
+
["no system default switchport", "no system default switchport shutdown"],
|
58
|
+
}
|
59
|
+
|
60
|
+
DEFAULT_IF_ACCESS_VLAN = 1
|
61
|
+
DEFAULT_IF_DESCRIPTION = ""
|
62
|
+
DEFAULT_IF_IP_ADDRESS = nil
|
63
|
+
DEFAULT_IF_IP_NETMASK_LEN = nil
|
64
|
+
DEFAULT_IF_IP_PROXY_ARP = false
|
65
|
+
DEFAULT_IF_IP_REDIRECTS = true
|
66
|
+
IF_DESCRIPTION_SIZE = 243 # SIZE = VSH Max 255 - "description " keyword
|
67
|
+
|
68
|
+
def interface_ipv4_config(ifname, address, length,
|
69
|
+
config = true, secip = false)
|
70
|
+
s = @device.cmd("configure terminal")
|
71
|
+
s = @device.cmd("interface #{ifname}")
|
72
|
+
if config == true
|
73
|
+
s = @device.cmd("no switchport")
|
74
|
+
s = @device.cmd("ip address #{address}/#{length}") if secip != true
|
75
|
+
s = @device.cmd("ip address #{address}/#{length} secondary") if secip == true
|
76
|
+
else
|
77
|
+
# this will both primary and secondary
|
78
|
+
s = @device.cmd("no ip address")
|
79
|
+
s = @device.cmd("switchport")
|
80
|
+
end
|
81
|
+
s = @device.cmd("end")
|
82
|
+
node.cache_flush
|
83
|
+
end
|
84
|
+
|
85
|
+
def get_interface_match_line(name, pattern)
|
86
|
+
s = @device.cmd("show run interface #{name} all | no-more")
|
87
|
+
line = pattern.match(s)
|
88
|
+
line
|
89
|
+
end
|
90
|
+
|
91
|
+
def get_interface_count
|
92
|
+
output = @device.cmd("show run interface all | inc interface | no-more")
|
93
|
+
# next line needs to be done because sh run interface all also shows
|
94
|
+
# ospf interface related config
|
95
|
+
arr = output.split("\n").select { |str| str.start_with?("interface") }
|
96
|
+
arr.count
|
97
|
+
end
|
98
|
+
|
99
|
+
def create_interface(ifname=interfaces[0])
|
100
|
+
interface = Interface.new(ifname)
|
101
|
+
end
|
102
|
+
|
103
|
+
def interface_ethernet_default(ethernet_id)
|
104
|
+
s = @device.cmd("configure terminal")
|
105
|
+
s = @device.cmd("default interface ethernet #{ethernet_id}")
|
106
|
+
s = @device.cmd("end")
|
107
|
+
node.cache_flush
|
108
|
+
end
|
109
|
+
|
110
|
+
def validate_interfaces_not_empty
|
111
|
+
CiscoTestCase.debug(@@debug_validate_interfaces_not_empty,
|
112
|
+
@@debug_group_ipv4_all_interfaces,
|
113
|
+
2, "Interface")
|
114
|
+
interfaces = Interface.interfaces
|
115
|
+
refute_empty(interfaces, "Error: interfaces collection empty")
|
116
|
+
|
117
|
+
# Get number of interfaces
|
118
|
+
int_size = get_interface_count()
|
119
|
+
assert_equal(int_size, interfaces.size(),
|
120
|
+
"Error: Interfaces collection size not correct")
|
121
|
+
end
|
122
|
+
|
123
|
+
def get_system_default_switchport_shutdown
|
124
|
+
state = []
|
125
|
+
s = @device.cmd("sh run all | in \"system default switchport\"")
|
126
|
+
|
127
|
+
s.split("\n")[1..-2].each { |line|
|
128
|
+
state << line unless line.include?("fabricpath")
|
129
|
+
}
|
130
|
+
state
|
131
|
+
end
|
132
|
+
|
133
|
+
def set_system_default_switchport_shutdown(state)
|
134
|
+
@device.cmd("configure terminal")
|
135
|
+
state.each { | config_line |
|
136
|
+
@device.cmd(config_line)
|
137
|
+
}
|
138
|
+
@device.cmd("end")
|
139
|
+
node.cache_flush
|
140
|
+
end
|
141
|
+
|
142
|
+
def validate_interface_shutdown(inttype_h)
|
143
|
+
state = get_system_default_switchport_shutdown
|
144
|
+
|
145
|
+
# Validate the collection
|
146
|
+
inttype_h.each do | k, v |
|
147
|
+
CiscoTestCase.debug(@@debug_validate_interface_shutdown,
|
148
|
+
@@debug_group_ipv4_all_interfaces,
|
149
|
+
2,
|
150
|
+
"Interface: #{k}")
|
151
|
+
|
152
|
+
interface = v[:interface]
|
153
|
+
|
154
|
+
SWITCHPORT_SHUTDOWN_HASH.each { | lookup_string, config_array |
|
155
|
+
# puts "lookup_string: #{lookup_string}"
|
156
|
+
|
157
|
+
# Configure the system default shwitchport and shutdown settings
|
158
|
+
set_system_default_switchport_shutdown(config_array)
|
159
|
+
|
160
|
+
interface.shutdown = false
|
161
|
+
refute(interface.shutdown, "Error: #{interface.name} shutdown is not false")
|
162
|
+
|
163
|
+
interface.shutdown = true
|
164
|
+
assert(interface.shutdown, "Error: #{interface.name} shutdown is not true")
|
165
|
+
|
166
|
+
# Test default shutdown state
|
167
|
+
if k.downcase.include?("ethernet") # Ethernet interfaces
|
168
|
+
|
169
|
+
ref = cmd_ref.lookup("interface", lookup_string)
|
170
|
+
assert(ref, "Error, reference not found for #{lookup_string}")
|
171
|
+
|
172
|
+
result = interface.default_shutdown
|
173
|
+
assert_equal(ref.default_value, result, "Error: #{interface.name}, " +
|
174
|
+
"(#{lookup_string}), shutdown is #{result}, incorrect")
|
175
|
+
ref = nil
|
176
|
+
else # port-channel and loopback interfaces
|
177
|
+
assert_equal(interface.default_shutdown, v[:default_shutdown],
|
178
|
+
"default shutdown state (#{lookup_string}), incorrect")
|
179
|
+
end
|
180
|
+
}
|
181
|
+
end
|
182
|
+
set_system_default_switchport_shutdown(state)
|
183
|
+
end
|
184
|
+
|
185
|
+
# set_switchport is handled else where since it changes the
|
186
|
+
# interface to L2 and that would affect the idea of this test.
|
187
|
+
def validate_get_switchport(inttype_h)
|
188
|
+
# Validate the collection
|
189
|
+
inttype_h.each do | k, v |
|
190
|
+
CiscoTestCase.debug(@@debug_validate_get_switchport,
|
191
|
+
@@debug_group_ipv4_all_interfaces,
|
192
|
+
2,
|
193
|
+
"Interface: #{k}")
|
194
|
+
interface = v[:interface]
|
195
|
+
|
196
|
+
# Adding a check for getting the switchport_mode on a interfaces
|
197
|
+
# that does not support switchport. This used to fail with
|
198
|
+
# exception and was first found in end-to-end testing due to how
|
199
|
+
# the provider, by default, invokes the getter methods for an
|
200
|
+
# interface.
|
201
|
+
assert_equal(v[:switchport],
|
202
|
+
interface.switchport_mode,
|
203
|
+
"Error: #{interface.name}, switchport mode not correct")
|
204
|
+
|
205
|
+
# get_default check
|
206
|
+
assert_equal(v[:default_switchport],
|
207
|
+
interface.default_switchport_mode,
|
208
|
+
"Error: #{interface.name}, switchport mode, default, not correct")
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
def validate_description(inttype_h)
|
213
|
+
# Validate the description
|
214
|
+
inttype_h.each do | k, v |
|
215
|
+
CiscoTestCase.debug(@@debug_validate_description,
|
216
|
+
@@debug_group_ipv4_all_interfaces,
|
217
|
+
2,
|
218
|
+
"Interface: #{k}")
|
219
|
+
interface = v[:interface]
|
220
|
+
|
221
|
+
CiscoTestCase.debug_detail(@@debug_validate_description,
|
222
|
+
@@debug_group_ipv4_all_interfaces,
|
223
|
+
4,
|
224
|
+
"Value - #{v[:description]}")
|
225
|
+
|
226
|
+
# check of description
|
227
|
+
assert_equal(v[:description], interface.description,
|
228
|
+
"Error: Description not configured")
|
229
|
+
|
230
|
+
# change description
|
231
|
+
interface.description = v[:description_new]
|
232
|
+
assert_equal(v[:description_new], interface.description,
|
233
|
+
"Error: Description not configured")
|
234
|
+
|
235
|
+
# get_default check
|
236
|
+
assert_equal(v[:default_description], interface.default_description,
|
237
|
+
"Error: Description, default, not configured")
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
def validate_get_access_vlan(inttype_h)
|
242
|
+
# Validate the collection
|
243
|
+
inttype_h.each do | k, v |
|
244
|
+
CiscoTestCase.debug(@@debug_validate_get_access_vlan,
|
245
|
+
@@debug_group_ipv4_all_interfaces,
|
246
|
+
2,
|
247
|
+
"Interface: #{k}")
|
248
|
+
interface = v[:interface]
|
249
|
+
|
250
|
+
assert_equal(v[:access_vlan], interface.access_vlan,
|
251
|
+
"Error: Access vlan value not correct")
|
252
|
+
|
253
|
+
# get_default check
|
254
|
+
assert_equal(v[:default_access_vlan], interface.default_access_vlan,
|
255
|
+
"Error: Access vlan, default, value not correct")
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
259
|
+
def validate_ipv4_address(inttype_h)
|
260
|
+
# Validate the collection
|
261
|
+
inttype_h.each do | k, v |
|
262
|
+
CiscoTestCase.debug(@@debug_validate_ipv4_address,
|
263
|
+
@@debug_group_ipv4_all_interfaces,
|
264
|
+
2,
|
265
|
+
"Interface: #{k}")
|
266
|
+
interface = v[:interface]
|
267
|
+
|
268
|
+
# verify existing value
|
269
|
+
address = v[:address_len].split("/").first
|
270
|
+
length = v[:address_len].split("/").last.to_i
|
271
|
+
|
272
|
+
CiscoTestCase.debug_detail(@@debug_validate_ipv4_address,
|
273
|
+
@@debug_group_ipv4_all_interfaces,
|
274
|
+
4,
|
275
|
+
"Address/Length: #{address}/#{length}")
|
276
|
+
pattern = (/^\s+ip address #{address}\/#{length}/)
|
277
|
+
line = get_interface_match_line(interface.name, pattern)
|
278
|
+
|
279
|
+
refute_nil(line, "Error: ipv4 address #{address}/#{length} " +
|
280
|
+
"missing in CLI for #{k}")
|
281
|
+
assert_equal(address, interface.ipv4_address,
|
282
|
+
"Error: ipv4 address get value mismatch for #{k}")
|
283
|
+
assert_equal(length, interface.ipv4_netmask_length,
|
284
|
+
"Error: ipv4 netmask length get value mismatch for #{k}")
|
285
|
+
|
286
|
+
# get default
|
287
|
+
assert_equal(DEFAULT_IF_IP_ADDRESS, interface.default_ipv4_address,
|
288
|
+
"Error: ipv4 address get default value mismatch for #{k}")
|
289
|
+
|
290
|
+
# get_default_netmask
|
291
|
+
assert_equal(DEFAULT_IF_IP_NETMASK_LEN,
|
292
|
+
interface.default_ipv4_netmask_length,
|
293
|
+
"Error: ipv4 netmask length default mismatch for #{k}")
|
294
|
+
|
295
|
+
# Unconfigure ipaddress
|
296
|
+
interface.ipv4_addr_mask_set(interface.default_ipv4_address,
|
297
|
+
interface.default_ipv4_netmask_length)
|
298
|
+
pattern = (/^\s+ip address #{address}\/#{length}/)
|
299
|
+
line = get_interface_match_line(interface.name, pattern)
|
300
|
+
|
301
|
+
assert_nil(line, "Error: ipv4 address still present in CLI for #{k}")
|
302
|
+
assert_equal(DEFAULT_IF_IP_ADDRESS, interface.ipv4_address,
|
303
|
+
"Error: ipv4 address value mismatch after unconfig for #{k}")
|
304
|
+
assert_equal(DEFAULT_IF_IP_NETMASK_LEN,
|
305
|
+
interface.ipv4_netmask_length,
|
306
|
+
"Error: ipv4 netmask length default mismatch for #{k}")
|
307
|
+
end
|
308
|
+
end
|
309
|
+
|
310
|
+
def validate_ipv4_proxy_arp(inttype_h)
|
311
|
+
# Validate the collection
|
312
|
+
inttype_h.each do | k, v |
|
313
|
+
# Skipping loopback, proxy arp not supported
|
314
|
+
next if (k == 'loopback0')
|
315
|
+
|
316
|
+
CiscoTestCase.debug(@@debug_validate_ipv4_proxy_arp,
|
317
|
+
@@debug_group_ipv4_all_interfaces,
|
318
|
+
2,
|
319
|
+
"Interface: #{k}")
|
320
|
+
interface = v[:interface]
|
321
|
+
|
322
|
+
# puts "value - #{v[:proxy_arp]}"
|
323
|
+
pattern = (/^\s+ip proxy-arp/)
|
324
|
+
line = get_interface_match_line(interface.name, pattern)
|
325
|
+
# puts line
|
326
|
+
assert_equal(!v[:proxy_arp], line.nil?,
|
327
|
+
"Error: ip proxy-arp enable missing in CLI")
|
328
|
+
assert_equal(v[:proxy_arp], interface.ipv4_proxy_arp,
|
329
|
+
"Error: ip proxy-arp get value 'true' mismatch")
|
330
|
+
|
331
|
+
# puts "value reverse- #{!v[:proxy_arp]}"
|
332
|
+
interface.ipv4_proxy_arp = !v[:proxy_arp]
|
333
|
+
line = get_interface_match_line(interface.name, pattern)
|
334
|
+
assert_equal(v[:proxy_arp], line.nil?,
|
335
|
+
"Error: ip proxy-arp disable missing in CLI")
|
336
|
+
assert_equal(!v[:proxy_arp], interface.ipv4_proxy_arp,
|
337
|
+
"Error: ip proxy-arp get value 'false' mismatch")
|
338
|
+
|
339
|
+
# get default
|
340
|
+
assert_equal(DEFAULT_IF_IP_PROXY_ARP,
|
341
|
+
interface.default_ipv4_proxy_arp,
|
342
|
+
"Error: ip proxy arp get default value mismatch")
|
343
|
+
|
344
|
+
# get default and set
|
345
|
+
interface.ipv4_proxy_arp = interface.default_ipv4_proxy_arp
|
346
|
+
line = get_interface_match_line(interface.name, pattern)
|
347
|
+
assert_nil(line, "Error: default ip proxy-arp set failed")
|
348
|
+
assert_equal(DEFAULT_IF_IP_PROXY_ARP,
|
349
|
+
interface.ipv4_proxy_arp,
|
350
|
+
"Error: ip proxy-arp default get value mismatch")
|
351
|
+
end
|
352
|
+
end
|
353
|
+
|
354
|
+
def validate_ipv4_redirects(inttype_h)
|
355
|
+
# Validate the collection
|
356
|
+
inttype_h.each do | k, v |
|
357
|
+
CiscoTestCase.debug(@@debug_validate_ipv4_redirects,
|
358
|
+
@@debug_group_ipv4_all_interfaces,
|
359
|
+
2,
|
360
|
+
"Interface: #{k}")
|
361
|
+
interface = v[:interface]
|
362
|
+
|
363
|
+
if k.include?("loopback")
|
364
|
+
lookup_name = "ipv4_redirects_loopback"
|
365
|
+
else
|
366
|
+
lookup_name = "ipv4_redirects_other_interfaces"
|
367
|
+
end
|
368
|
+
|
369
|
+
ref = cmd_ref.lookup("interface", lookup_name)
|
370
|
+
assert(ref, "Error, reference not found")
|
371
|
+
|
372
|
+
# Check default
|
373
|
+
assert_equal(ref.default_value, interface.default_ipv4_redirects,
|
374
|
+
"ipv4 redirects default incorrect for interface #{k}")
|
375
|
+
|
376
|
+
begin
|
377
|
+
config_set = ref.config_set
|
378
|
+
rescue IndexError
|
379
|
+
config_set = nil
|
380
|
+
end
|
381
|
+
|
382
|
+
if config_set
|
383
|
+
pattern = ref.test_config_get_regex[0]
|
384
|
+
|
385
|
+
if k.include?("loopback")
|
386
|
+
assert_raises(Cisco::CliError) {
|
387
|
+
interface.ipv4_redirects = true
|
388
|
+
}
|
389
|
+
else
|
390
|
+
interface.ipv4_redirects = true
|
391
|
+
assert(interface.ipv4_redirects, "Couldn't set redirects to true")
|
392
|
+
line = get_interface_match_line(interface.name, pattern)
|
393
|
+
assert_nil(line, "Error: #{k} ipv4_redirects cfg mismatch")
|
394
|
+
|
395
|
+
interface.ipv4_redirects = false
|
396
|
+
refute(interface.ipv4_redirects, "Couldn't set redirects to false")
|
397
|
+
line = get_interface_match_line(interface.name, pattern)
|
398
|
+
refute_nil(line, "Error: #{k} ipv4_redirects cfg mismatch")
|
399
|
+
end
|
400
|
+
else
|
401
|
+
# Getter should return same value as default if setter isn't supported
|
402
|
+
assert_equal(interface.ipv4_redirects, interface.default_ipv4_redirects,
|
403
|
+
"ipv4 redirects default incorrect")
|
404
|
+
|
405
|
+
# Make sure setter fails
|
406
|
+
assert_raises(ref.test_config_result(true)) {
|
407
|
+
interface.ipv4_redirects = true
|
408
|
+
}
|
409
|
+
assert_raises(ref.test_config_result(false)) {
|
410
|
+
interface.ipv4_redirects = false
|
411
|
+
}
|
412
|
+
end
|
413
|
+
end
|
414
|
+
end
|
415
|
+
|
416
|
+
def test_interface_create_name_nil
|
417
|
+
assert_raises(TypeError) do
|
418
|
+
Interface.new(nil)
|
419
|
+
end
|
420
|
+
end
|
421
|
+
|
422
|
+
def test_interface_create_name_invalid
|
423
|
+
assert_raises(TypeError) do
|
424
|
+
Interface.new(node)
|
425
|
+
end
|
426
|
+
end
|
427
|
+
|
428
|
+
def test_interface_create_does_not_exist
|
429
|
+
assert_raises(CliError) do
|
430
|
+
Interface.new("bogus")
|
431
|
+
end
|
432
|
+
end
|
433
|
+
|
434
|
+
def test_interface_create_valid
|
435
|
+
interface = Interface.new(interfaces[0])
|
436
|
+
assert_equal(interfaces[0].downcase, interface.name)
|
437
|
+
end
|
438
|
+
|
439
|
+
def test_interface_description_nil
|
440
|
+
interface = Interface.new(interfaces[0])
|
441
|
+
assert_raises(TypeError) do
|
442
|
+
interface.description = nil
|
443
|
+
end
|
444
|
+
end
|
445
|
+
|
446
|
+
def test_interface_description_zero_length
|
447
|
+
interface = Interface.new(interfaces[0])
|
448
|
+
interface.description = ""
|
449
|
+
assert_equal("", interface.description)
|
450
|
+
end
|
451
|
+
|
452
|
+
def test_interface_description_too_long
|
453
|
+
interface = Interface.new(interfaces[0])
|
454
|
+
description = "a" * (IF_DESCRIPTION_SIZE + 1)
|
455
|
+
assert_raises(RuntimeError) {
|
456
|
+
interface.description = description
|
457
|
+
}
|
458
|
+
interface_ethernet_default(interfaces_id[0])
|
459
|
+
end
|
460
|
+
|
461
|
+
def test_interface_description_valid
|
462
|
+
interface = Interface.new(interfaces[0])
|
463
|
+
alphabet = "abcdefghijklmnopqrstuvwxyz 0123456789"
|
464
|
+
description = ""
|
465
|
+
1.upto(IF_DESCRIPTION_SIZE) { | i |
|
466
|
+
description += alphabet[i % alphabet.size, 1]
|
467
|
+
if i == IF_DESCRIPTION_SIZE
|
468
|
+
# puts("description (#{i}): #{description}")
|
469
|
+
interface.description = description
|
470
|
+
assert_equal(description.rstrip, interface.description)
|
471
|
+
end
|
472
|
+
}
|
473
|
+
interface_ethernet_default(interfaces_id[0])
|
474
|
+
end
|
475
|
+
|
476
|
+
def test_interface_shutdown_valid
|
477
|
+
interface = Interface.new(interfaces[0])
|
478
|
+
interface.shutdown = true
|
479
|
+
assert(interface.shutdown, "Error: shutdown state is not true")
|
480
|
+
|
481
|
+
interface.shutdown = false
|
482
|
+
refute(interface.shutdown, "Error: shutdown state is not false")
|
483
|
+
interface_ethernet_default(interfaces_id[0])
|
484
|
+
end
|
485
|
+
|
486
|
+
def test_interface_get_access_vlan
|
487
|
+
interface = Interface.new(interfaces[0])
|
488
|
+
interface.switchport_mode = :disabled
|
489
|
+
interface.switchport_mode = :access
|
490
|
+
assert_equal(DEFAULT_IF_ACCESS_VLAN, interface.access_vlan)
|
491
|
+
interface_ethernet_default(interfaces_id[0])
|
492
|
+
end
|
493
|
+
|
494
|
+
def test_interface_get_access_vlan_switchport_disabled
|
495
|
+
interface = Interface.new(interfaces[0])
|
496
|
+
interface.switchport_mode = :disabled
|
497
|
+
assert_equal(DEFAULT_IF_ACCESS_VLAN, interface.access_vlan)
|
498
|
+
interface_ethernet_default(interfaces_id[0])
|
499
|
+
end
|
500
|
+
|
501
|
+
def test_interface_get_access_vlan_switchport_trunk
|
502
|
+
interface = Interface.new(interfaces[0])
|
503
|
+
interface.switchport_mode = :disabled
|
504
|
+
interface.switchport_mode = :trunk
|
505
|
+
assert_equal(DEFAULT_IF_ACCESS_VLAN, interface.access_vlan)
|
506
|
+
interface_ethernet_default(interfaces_id[0])
|
507
|
+
end
|
508
|
+
|
509
|
+
=begin
|
510
|
+
def test_interface_get_prefix_list_when_switchport
|
511
|
+
interface = Interface.new(interfaces[0])
|
512
|
+
interface.switchport_mode = :access
|
513
|
+
addresses = interface.prefixes
|
514
|
+
assert_empty(addresses)
|
515
|
+
interface_ethernet_default(interfaces_id[0])
|
516
|
+
end
|
517
|
+
|
518
|
+
def test_interface_get_prefix_list_with_ipv4_address_assignment
|
519
|
+
interface = Interface.new(interfaces[0])
|
520
|
+
interface.switchport_mode = :access
|
521
|
+
interface.switchport_mode = :disabled
|
522
|
+
s = @device.cmd("configure terminal")
|
523
|
+
s = @device.cmd("interface #{interfaces[0]}")
|
524
|
+
s = @device.cmd("ip address 192.168.1.100 255.255.255.0")
|
525
|
+
s = @device.cmd("end")
|
526
|
+
node.cache_flush
|
527
|
+
prefixes = interface.prefixes
|
528
|
+
assert_equal(1, prefixes.size)
|
529
|
+
assert(prefixes.has_key?("192.168.1.100"))
|
530
|
+
interface.switchport_mode = :access
|
531
|
+
prefixes = nil
|
532
|
+
interface_ethernet_default(interfaces_id[0])
|
533
|
+
end
|
534
|
+
|
535
|
+
def test_interface_get_prefix_list_with_ipv6_address_assignment
|
536
|
+
interface = Interface.new(interfaces[0] )
|
537
|
+
interface.switchport_mode = :access
|
538
|
+
interface.switchport_mode = :disabled
|
539
|
+
s = @device.cmd("configure terminal")
|
540
|
+
s = @device.cmd("interface #{interfaces[0]}")
|
541
|
+
s = @device.cmd("ipv6 address fd56:31f7:e4ad:5585::1/64")
|
542
|
+
s = @device.cmd("end")
|
543
|
+
node.cache_flush
|
544
|
+
prefixes = interface.prefixes
|
545
|
+
assert_equal(2, prefixes.size)
|
546
|
+
assert(prefixes.has_key?("fd56:31f7:e4ad:5585::1"))
|
547
|
+
interface.switchport_mode = :access
|
548
|
+
prefixes = nil
|
549
|
+
interface_ethernet_default(interfaces_id[0])
|
550
|
+
end
|
551
|
+
|
552
|
+
def test_interface_get_prefix_list_with_both_ip4_and_ipv6_address_assignments
|
553
|
+
interface = Interface.new(interfaces[0])
|
554
|
+
interface.switchport_mode = :access
|
555
|
+
interface.switchport_mode = :disabled
|
556
|
+
s = @device.cmd("configure terminal")
|
557
|
+
s = @device.cmd("interface #{interfaces[0]}")
|
558
|
+
s = @device.cmd("ip address 192.168.1.100 255.255.255.0")
|
559
|
+
s = @device.cmd("ipv6 address fd56:31f7:e4ad:5585::1/64")
|
560
|
+
s = @device.cmd("end")
|
561
|
+
node.cache_flush
|
562
|
+
prefixes = interface.prefixes
|
563
|
+
assert_equal(3, prefixes.size)
|
564
|
+
assert(prefixes.has_key?("192.168.1.100"))
|
565
|
+
assert(prefixes.has_key?("fd56:31f7:e4ad:5585::1"))
|
566
|
+
interface.switchport_mode = :access
|
567
|
+
prefixes = nil
|
568
|
+
interface_ethernet_default(interfaces_id[0])
|
569
|
+
end
|
570
|
+
=end
|
571
|
+
def negotiate_auto_helper(interface, default, cmd_ref)
|
572
|
+
inf_name = interface.name
|
573
|
+
|
574
|
+
# Test default
|
575
|
+
assert_equal(default, interface.default_negotiate_auto,
|
576
|
+
"Error: #{inf_name} negotiate auto default value mismatch")
|
577
|
+
|
578
|
+
begin
|
579
|
+
config_set = cmd_ref.config_set
|
580
|
+
rescue IndexError
|
581
|
+
config_set = nil
|
582
|
+
end
|
583
|
+
|
584
|
+
if config_set
|
585
|
+
# skip test if cli not supported on interface
|
586
|
+
s = @device.cmd("conf t; interface #{interface}")
|
587
|
+
s = @device.cmd("negotiate auto")
|
588
|
+
unless s[/% Invalid command/]
|
589
|
+
|
590
|
+
interface.negotiate_auto = true
|
591
|
+
assert_equal(interface.negotiate_auto, true,
|
592
|
+
"Error: #{inf_name} negotiate auto value not true")
|
593
|
+
|
594
|
+
pattern = cmd_ref.test_config_get_regex[0]
|
595
|
+
line = get_interface_match_line(interface.name, pattern)
|
596
|
+
# TBD needs to get the result from cmd_ref.test_config_get_result[0]
|
597
|
+
assert_nil(line, "Error: #{inf_name} no negotiate auto cfg mismatch")
|
598
|
+
|
599
|
+
pattern = cmd_ref.test_config_get_regex[1]
|
600
|
+
line = get_interface_match_line(interface.name, pattern)
|
601
|
+
refute_nil(line, "Error: #{inf_name} negotiate auto cfg mismatch")
|
602
|
+
|
603
|
+
interface.negotiate_auto = false
|
604
|
+
refute(interface.negotiate_auto,
|
605
|
+
"Error: #{inf_name} negotiate auto value not false")
|
606
|
+
|
607
|
+
pattern = cmd_ref.test_config_get_regex[0]
|
608
|
+
line = get_interface_match_line(interface.name, pattern)
|
609
|
+
refute_nil(line, "Error: #{inf_name} no negotiate auto cfg mismatch")
|
610
|
+
end
|
611
|
+
else
|
612
|
+
# check the get
|
613
|
+
assert_equal(interface.negotiate_auto, default,
|
614
|
+
"Error: #{inf_name} negotiate auto value should be same as default")
|
615
|
+
|
616
|
+
# check the set for unsupported platforms
|
617
|
+
assert_raises(RuntimeError) do
|
618
|
+
interface.negotiate_auto = true
|
619
|
+
end
|
620
|
+
end
|
621
|
+
end
|
622
|
+
|
623
|
+
def test_negotiate_auto_portchannel
|
624
|
+
ref = cmd_ref.lookup("interface",
|
625
|
+
"negotiate_auto_portchannel")
|
626
|
+
assert(ref, "Error, reference not found")
|
627
|
+
|
628
|
+
inf_name = "port-channel10"
|
629
|
+
s = @device.cmd("configure terminal")
|
630
|
+
s = @device.cmd("interface port-channel 10")
|
631
|
+
s = @device.cmd("end")
|
632
|
+
node.cache_flush()
|
633
|
+
interface = Interface.new(inf_name)
|
634
|
+
default = ref.default_value
|
635
|
+
|
636
|
+
# Test with switchport
|
637
|
+
negotiate_auto_helper(interface, default, ref)
|
638
|
+
|
639
|
+
# Test with no switchport
|
640
|
+
s = @device.cmd("configure terminal")
|
641
|
+
s = @device.cmd("interface port-channel 10")
|
642
|
+
s = @device.cmd("no switchport")
|
643
|
+
s = @device.cmd("end")
|
644
|
+
node.cache_flush()
|
645
|
+
negotiate_auto_helper(interface, default, ref)
|
646
|
+
|
647
|
+
# Cleanup
|
648
|
+
s = @device.cmd("configure terminal")
|
649
|
+
s = @device.cmd("no interface port-channel 10")
|
650
|
+
s = @device.cmd("end")
|
651
|
+
node.cache_flush()
|
652
|
+
end
|
653
|
+
|
654
|
+
def test_negotiate_auto_ethernet
|
655
|
+
ref = cmd_ref.lookup("interface",
|
656
|
+
"negotiate_auto_ethernet")
|
657
|
+
assert(ref, "Error, reference not found")
|
658
|
+
|
659
|
+
# Some platforms does not support negotiate auto
|
660
|
+
# if so then we abort the test.
|
661
|
+
|
662
|
+
inf_name = interfaces[0]
|
663
|
+
interface = Interface.new(inf_name)
|
664
|
+
default = ref.default_value
|
665
|
+
|
666
|
+
# Test with switchport
|
667
|
+
negotiate_auto_helper(interface, default, ref)
|
668
|
+
|
669
|
+
# Test with no switchport
|
670
|
+
s = @device.cmd("configure terminal")
|
671
|
+
s = @device.cmd("interface #{interfaces[0]}")
|
672
|
+
s = @device.cmd("no switchport")
|
673
|
+
s = @device.cmd("end")
|
674
|
+
node.cache_flush()
|
675
|
+
negotiate_auto_helper(interface, default, ref)
|
676
|
+
|
677
|
+
# Cleanup
|
678
|
+
interface_ethernet_default(interfaces_id[0])
|
679
|
+
node.cache_flush()
|
680
|
+
end
|
681
|
+
|
682
|
+
def test_negotiate_auto_loopback
|
683
|
+
ref = cmd_ref.lookup("interface",
|
684
|
+
"negotiate_auto_other_interfaces")
|
685
|
+
assert(ref, "Error, reference not found")
|
686
|
+
|
687
|
+
inf_name = "loopback2"
|
688
|
+
s = @device.cmd("configure terminal")
|
689
|
+
s = @device.cmd("interface loopback 2")
|
690
|
+
s = @device.cmd("end")
|
691
|
+
node.cache_flush()
|
692
|
+
interface = Interface.new(inf_name)
|
693
|
+
|
694
|
+
assert_equal(interface.negotiate_auto, ref.default_value,
|
695
|
+
"Error: #{inf_name} negotiate auto value mismatch")
|
696
|
+
|
697
|
+
assert_raises(ref.test_config_result(true)) {
|
698
|
+
interface.negotiate_auto = true
|
699
|
+
}
|
700
|
+
assert_raises(ref.test_config_result(false)) {
|
701
|
+
interface.negotiate_auto = false
|
702
|
+
}
|
703
|
+
|
704
|
+
# Cleanup
|
705
|
+
s = @device.cmd("configure terminal")
|
706
|
+
s = @device.cmd("no interface loopback 2")
|
707
|
+
s = @device.cmd("end")
|
708
|
+
node.cache_flush()
|
709
|
+
end
|
710
|
+
|
711
|
+
def test_interfaces_not_empty
|
712
|
+
interfaces = Interface.interfaces
|
713
|
+
refute_empty(interfaces, "Error: interfaces collection empty")
|
714
|
+
interfaces = nil
|
715
|
+
end
|
716
|
+
|
717
|
+
def test_interface_ipv4_addr_mask_set_address_invalid
|
718
|
+
interface = create_interface
|
719
|
+
interface.switchport_mode = :disabled
|
720
|
+
assert_raises(RuntimeError) do
|
721
|
+
interface.ipv4_addr_mask_set("", 14)
|
722
|
+
end
|
723
|
+
interface.switchport_mode = :access
|
724
|
+
interface_ethernet_default(interfaces_id[0])
|
725
|
+
end
|
726
|
+
|
727
|
+
def test_interface_ipv4_addr_mask_set_netmask_invalid
|
728
|
+
interface = create_interface
|
729
|
+
interface.switchport_mode = :disabled
|
730
|
+
assert_raises(RuntimeError) do
|
731
|
+
interface.ipv4_addr_mask_set("8.1.1.2", DEFAULT_IF_IP_NETMASK_LEN)
|
732
|
+
end
|
733
|
+
interface.switchport_mode = :access
|
734
|
+
interface_ethernet_default(interfaces_id[0])
|
735
|
+
end
|
736
|
+
|
737
|
+
def test_interface_ipv4_address
|
738
|
+
interface = create_interface
|
739
|
+
interface.switchport_mode = :disabled
|
740
|
+
address = "8.7.1.1"
|
741
|
+
length = 15
|
742
|
+
|
743
|
+
# setter, getter
|
744
|
+
interface.ipv4_addr_mask_set(address, length)
|
745
|
+
pattern = (/^\s+ip address #{address}\/#{length}/)
|
746
|
+
line = get_interface_match_line(interface.name, pattern)
|
747
|
+
refute_nil(line, "Error: ipv4 address missing in CLI")
|
748
|
+
assert_equal(address, interface.ipv4_address,
|
749
|
+
"Error: ipv4 address get value mismatch")
|
750
|
+
assert_equal(length, interface.ipv4_netmask_length,
|
751
|
+
"Error: ipv4 netmask length get value mismatch")
|
752
|
+
# get default
|
753
|
+
assert_equal(DEFAULT_IF_IP_ADDRESS, interface.default_ipv4_address,
|
754
|
+
"Error: ipv4 address get default value mismatch")
|
755
|
+
|
756
|
+
# get_default_netmask
|
757
|
+
assert_equal(DEFAULT_IF_IP_NETMASK_LEN,
|
758
|
+
interface.default_ipv4_netmask_length,
|
759
|
+
"Error: ipv4 netmask length get default value mismatch")
|
760
|
+
|
761
|
+
# unconfigure ipaddress
|
762
|
+
interface.ipv4_addr_mask_set(interface.default_ipv4_address, length)
|
763
|
+
pattern = (/^\s+ip address (.*)/)
|
764
|
+
line = get_interface_match_line(interface.name, pattern)
|
765
|
+
assert_nil(line, "Error: ipv4 address still present in CLI")
|
766
|
+
assert_equal(DEFAULT_IF_IP_ADDRESS, interface.ipv4_address,
|
767
|
+
"Error: ipv4 address value mismatch after unconfig")
|
768
|
+
assert_equal(DEFAULT_IF_IP_NETMASK_LEN,
|
769
|
+
interface.ipv4_netmask_length,
|
770
|
+
"Error: ipv4 netmask length default get value mismatch")
|
771
|
+
|
772
|
+
interface.switchport_mode = :access
|
773
|
+
interface_ethernet_default(interfaces_id[0])
|
774
|
+
end
|
775
|
+
|
776
|
+
def test_interface_ipv4_address_getter_with_preconfig
|
777
|
+
address = "8.7.1.1"
|
778
|
+
length = 15
|
779
|
+
ifname = interfaces[0]
|
780
|
+
# preconfigure
|
781
|
+
interface_ipv4_config(ifname, address, length)
|
782
|
+
# create interface
|
783
|
+
interface = create_interface(ifname)
|
784
|
+
# getter
|
785
|
+
assert_equal(address, interface.ipv4_address,
|
786
|
+
"Error: ipv4 address get value mismatch")
|
787
|
+
assert_equal(length, interface.ipv4_netmask_length,
|
788
|
+
"Error: ipv4 netmask length get value mismatch")
|
789
|
+
# unconfigure ipaddress
|
790
|
+
interface_ipv4_config(ifname, address, length, false)
|
791
|
+
interface_ethernet_default(interfaces_id[0])
|
792
|
+
end
|
793
|
+
|
794
|
+
def test_interface_ipv4_address_getter_with_preconfig_secondary
|
795
|
+
address = "8.7.1.1"
|
796
|
+
length = 15
|
797
|
+
sec_address = "1.1.2.5"
|
798
|
+
sec_length = 10
|
799
|
+
ifname = interfaces[0]
|
800
|
+
# preconfigure primary and secondary
|
801
|
+
interface_ipv4_config(ifname, address, length)
|
802
|
+
interface_ipv4_config(ifname, sec_address, sec_length, true, true)
|
803
|
+
|
804
|
+
# create interface
|
805
|
+
interface = create_interface(ifname)
|
806
|
+
# getter
|
807
|
+
assert_equal(address, interface.ipv4_address,
|
808
|
+
"Error: ipv4 address get value mismatch")
|
809
|
+
assert_equal(length, interface.ipv4_netmask_length,
|
810
|
+
"Error: ipv4 netmask length get value mismatch")
|
811
|
+
# unconfigure ipaddress includign secondary
|
812
|
+
interface_ipv4_config(ifname, address, length, false, false)
|
813
|
+
interface_ethernet_default(interfaces_id[0])
|
814
|
+
end
|
815
|
+
|
816
|
+
def test_interface_ipv4_proxy_arp
|
817
|
+
interface = create_interface
|
818
|
+
interface.switchport_mode = :disabled
|
819
|
+
|
820
|
+
# set with value true
|
821
|
+
interface.ipv4_proxy_arp = true
|
822
|
+
pattern = (/^\s+ip proxy-arp/)
|
823
|
+
line = get_interface_match_line(interface.name, pattern)
|
824
|
+
refute_nil(line, "Error: ip proxy-arp enable missing in CLI")
|
825
|
+
assert(interface.ipv4_proxy_arp,
|
826
|
+
"Error: ip proxy-arp get value 'true' mismatch")
|
827
|
+
|
828
|
+
# set with value false
|
829
|
+
interface.ipv4_proxy_arp = false
|
830
|
+
line = get_interface_match_line(interface.name, pattern)
|
831
|
+
assert_nil(line, "Error: ip proxy-arp disable missing in CLI")
|
832
|
+
refute(interface.ipv4_proxy_arp,
|
833
|
+
"Error: ip proxy-arp get value 'false' mismatch")
|
834
|
+
|
835
|
+
# get default
|
836
|
+
assert_equal(DEFAULT_IF_IP_PROXY_ARP,
|
837
|
+
interface.default_ipv4_proxy_arp,
|
838
|
+
"Error: ip proxy arp get default value mismatch")
|
839
|
+
|
840
|
+
# get default and set
|
841
|
+
interface.ipv4_proxy_arp = interface.default_ipv4_proxy_arp
|
842
|
+
line = get_interface_match_line(interface.name, pattern)
|
843
|
+
assert_nil(line, "Error: default ip proxy-arp set failed")
|
844
|
+
assert_equal(DEFAULT_IF_IP_PROXY_ARP,
|
845
|
+
interface.ipv4_proxy_arp,
|
846
|
+
"Error: ip proxy-arp default get value mismatch")
|
847
|
+
|
848
|
+
interface.switchport_mode = :access
|
849
|
+
interface_ethernet_default(interfaces_id[0])
|
850
|
+
end
|
851
|
+
|
852
|
+
def test_interface_ipv4_redirects
|
853
|
+
interface = create_interface
|
854
|
+
interface.switchport_mode = :disabled
|
855
|
+
|
856
|
+
# set with value false
|
857
|
+
interface.ipv4_redirects = false
|
858
|
+
pattern = (/^\s+no ip redirects/)
|
859
|
+
line = get_interface_match_line(interface.name, pattern)
|
860
|
+
refute_nil(line, "Error: ip redirects disable missing in CLI")
|
861
|
+
refute(interface.ipv4_redirects,
|
862
|
+
"Error: ip redirects get value 'false' mismatch")
|
863
|
+
|
864
|
+
# set with value true
|
865
|
+
interface.ipv4_redirects = true
|
866
|
+
line = get_interface_match_line(interface.name, pattern)
|
867
|
+
assert_nil(line, "Error: ip redirects enable missing in CLI")
|
868
|
+
assert(interface.ipv4_redirects,
|
869
|
+
"Error: ip redirects get value 'true' mismatch")
|
870
|
+
|
871
|
+
# get default
|
872
|
+
assert_equal(DEFAULT_IF_IP_REDIRECTS,
|
873
|
+
interface.default_ipv4_redirects,
|
874
|
+
"Error: ip redirects get default value mismatch")
|
875
|
+
|
876
|
+
# get default and set
|
877
|
+
interface.ipv4_redirects = interface.default_ipv4_redirects
|
878
|
+
line = get_interface_match_line(interface.name, pattern)
|
879
|
+
assert_nil(line, "Error: default ip redirects set failed")
|
880
|
+
assert_equal(DEFAULT_IF_IP_REDIRECTS, interface.ipv4_redirects,
|
881
|
+
"Error: ip redirects default get value mismatch")
|
882
|
+
|
883
|
+
interface.switchport_mode = :access
|
884
|
+
interface_ethernet_default(interfaces_id[0])
|
885
|
+
end
|
886
|
+
|
887
|
+
# NOTE - Changes to this method may require new validation methods
|
888
|
+
# to be created or existing ones to be modified.
|
889
|
+
def test_interface_ipv4_all_interfaces
|
890
|
+
CiscoTestCase.debug(@@debug_test_interface_ipv4_all_interfaces,
|
891
|
+
@@debug_group_ipv4_all_interfaces,
|
892
|
+
0,
|
893
|
+
"test_interface_ipv4_all_interfaces")
|
894
|
+
|
895
|
+
inttype_h = {}
|
896
|
+
inttype_h[interfaces[0]] = {
|
897
|
+
:address_len => "8.7.1.1/15",
|
898
|
+
:proxy_arp => true,
|
899
|
+
:redirects => false,
|
900
|
+
:description => "This is a test",
|
901
|
+
:description_new => "Testing Testing",
|
902
|
+
:default_description => DEFAULT_IF_DESCRIPTION,
|
903
|
+
:shutdown => false,
|
904
|
+
:change_shutdown => true,
|
905
|
+
:default_shutdown => false,
|
906
|
+
:switchport => :disabled,
|
907
|
+
:default_switchport => :disabled,
|
908
|
+
:access_vlan => DEFAULT_IF_ACCESS_VLAN,
|
909
|
+
:default_access_vlan => DEFAULT_IF_ACCESS_VLAN
|
910
|
+
}
|
911
|
+
inttype_h["Vlan45"] = {
|
912
|
+
:address_len => "9.7.1.1/15",
|
913
|
+
:proxy_arp => true,
|
914
|
+
:redirects => false,
|
915
|
+
:description => "Company A",
|
916
|
+
:description_new => "Mini Me",
|
917
|
+
:default_description => DEFAULT_IF_DESCRIPTION,
|
918
|
+
:shutdown => true,
|
919
|
+
:change_shutdown => false,
|
920
|
+
:default_shutdown => true,
|
921
|
+
:switchport => :disabled,
|
922
|
+
:default_switchport => :disabled,
|
923
|
+
:access_vlan => DEFAULT_IF_ACCESS_VLAN,
|
924
|
+
:default_access_vlan => DEFAULT_IF_ACCESS_VLAN
|
925
|
+
}
|
926
|
+
inttype_h["port-channel48"] = {
|
927
|
+
:address_len => "10.7.1.1/15",
|
928
|
+
:proxy_arp => false,
|
929
|
+
:redirects => false,
|
930
|
+
:description => "Company B",
|
931
|
+
:description_new => "Dr. Bond",
|
932
|
+
:default_description => DEFAULT_IF_DESCRIPTION,
|
933
|
+
:shutdown => false,
|
934
|
+
:change_shutdown => true,
|
935
|
+
:default_shutdown => false,
|
936
|
+
:switchport => :disabled,
|
937
|
+
:default_switchport => :disabled,
|
938
|
+
:access_vlan => DEFAULT_IF_ACCESS_VLAN,
|
939
|
+
:default_access_vlan => DEFAULT_IF_ACCESS_VLAN
|
940
|
+
}
|
941
|
+
inttype_h["loopback0"] = {
|
942
|
+
:address_len => "11.7.1.1/15",
|
943
|
+
:redirects => false, # (not supported on loopback)
|
944
|
+
:description => "233KLDK",
|
945
|
+
:description_new => "Back to the Future",
|
946
|
+
:default_description => DEFAULT_IF_DESCRIPTION,
|
947
|
+
:shutdown => false,
|
948
|
+
:change_shutdown => true,
|
949
|
+
:default_shutdown => false,
|
950
|
+
:switchport => :disabled,
|
951
|
+
:default_switchport => :disabled,
|
952
|
+
:access_vlan => DEFAULT_IF_ACCESS_VLAN,
|
953
|
+
:default_access_vlan => DEFAULT_IF_ACCESS_VLAN
|
954
|
+
}
|
955
|
+
# Skipping mgmt0 interface since that interface is our 'path' to
|
956
|
+
# master should revisit this later
|
957
|
+
|
958
|
+
# Set system defaults to "factory" values prior to initial test.
|
959
|
+
set_system_default_switchport_shutdown(
|
960
|
+
SWITCHPORT_SHUTDOWN_HASH["shutdown_ethernet_noswitchport_shutdown"])
|
961
|
+
|
962
|
+
# pre-configure
|
963
|
+
inttype_h.each do | k, v |
|
964
|
+
# puts "TEST: pre-config hash key : #{k}"
|
965
|
+
if !(/^Vlan\d./).match(k.to_s).nil? ||
|
966
|
+
s = @device.cmd("configure terminal")
|
967
|
+
s = @device.cmd("feature interface-vlan")
|
968
|
+
s = @device.cmd("end")
|
969
|
+
node.cache_flush
|
970
|
+
end
|
971
|
+
|
972
|
+
# puts "TEST: pre-config k: v '#{k} : #{v}'"
|
973
|
+
s = @device.cmd("configure terminal")
|
974
|
+
s = @device.cmd("interface #{k}")
|
975
|
+
if !(/^Ethernet\d.\d/).match(k.to_s).nil? ||
|
976
|
+
!(/^port-channel\d/).match(k.to_s).nil?
|
977
|
+
s = @device.cmd("no switchport")
|
978
|
+
end
|
979
|
+
# puts "k: #{k}, k1: #{k1}, address #{v1[:address_len]}"
|
980
|
+
s = @device.cmd("ip address #{v[:address_len]}") unless v[:address_len].nil?
|
981
|
+
s = @device.cmd("ip proxy-arp") if !v[:proxy_arp].nil? && v[:proxy_arp] == true
|
982
|
+
s = @device.cmd("ip redirects") if !v[:redirects].nil? && v[:redirects] == true
|
983
|
+
s = @device.cmd("description #{v[:description]}") unless v[:description].nil?
|
984
|
+
s = @device.cmd("exit")
|
985
|
+
s = @device.cmd("end")
|
986
|
+
|
987
|
+
# Create an Interface instance and associate it
|
988
|
+
v[:interface] = Interface.new(k, false)
|
989
|
+
end
|
990
|
+
# Flush the cache since we've modified the device
|
991
|
+
node.cache_flush
|
992
|
+
|
993
|
+
# Validate the collection
|
994
|
+
validate_interfaces_not_empty()
|
995
|
+
validate_get_switchport(inttype_h)
|
996
|
+
validate_description(inttype_h)
|
997
|
+
validate_get_access_vlan(inttype_h)
|
998
|
+
validate_ipv4_address(inttype_h)
|
999
|
+
validate_ipv4_proxy_arp(inttype_h)
|
1000
|
+
validate_ipv4_redirects(inttype_h)
|
1001
|
+
validate_interface_shutdown(inttype_h)
|
1002
|
+
|
1003
|
+
# Cleanup the preload configuration
|
1004
|
+
s = @device.cmd("configure terminal")
|
1005
|
+
inttype_h.each do | k, v |
|
1006
|
+
if !(/^Ethernet\d.\d/).match(k.to_s).nil?
|
1007
|
+
s = @device.cmd("default interface #{k}")
|
1008
|
+
else
|
1009
|
+
s = @device.cmd("no interface #{k}")
|
1010
|
+
end
|
1011
|
+
end
|
1012
|
+
s = @device.cmd("no feature interface-vlan")
|
1013
|
+
s = @device.cmd("exit")
|
1014
|
+
s = @device.cmd("end")
|
1015
|
+
node.cache_flush
|
1016
|
+
end
|
1017
|
+
end
|