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