cisco_node_utils 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/CHANGELOG.md +126 -1
- data/README.md +19 -12
- data/Rakefile +1 -0
- data/bin/git/hooks/commit-msg/enforce_style +8 -0
- data/cisco_node_utils.gemspec +4 -3
- data/docs/README-develop-best-practices.md +127 -109
- data/docs/README-develop-node-utils-APIs.md +47 -39
- data/docs/template-router.rb +3 -7
- data/lib/.rubocop.yml +4 -4
- data/lib/cisco_node_utils.rb +1 -1
- data/lib/cisco_node_utils/aaa_authentication_login.rb +96 -0
- data/lib/cisco_node_utils/aaa_authentication_login_service.rb +133 -0
- data/lib/cisco_node_utils/aaa_authorization_service.rb +150 -0
- data/lib/cisco_node_utils/ace.rb +196 -0
- data/lib/cisco_node_utils/acl.rb +100 -0
- data/lib/cisco_node_utils/bgp.rb +301 -163
- data/lib/cisco_node_utils/bgp_af.rb +187 -19
- data/lib/cisco_node_utils/bgp_neighbor.rb +18 -33
- data/lib/cisco_node_utils/bgp_neighbor_af.rb +25 -48
- data/lib/cisco_node_utils/cisco_cmn_utils.rb +23 -4
- data/lib/cisco_node_utils/cmd_ref/README_YAML.md +593 -0
- data/lib/cisco_node_utils/cmd_ref/aaa_auth_login_service.yaml +22 -0
- data/lib/cisco_node_utils/cmd_ref/aaa_authentication_login.yaml +31 -0
- data/lib/cisco_node_utils/cmd_ref/aaa_authorization_service.yaml +22 -0
- data/lib/cisco_node_utils/cmd_ref/acl.yaml +43 -0
- data/lib/cisco_node_utils/cmd_ref/bgp.yaml +242 -0
- data/lib/cisco_node_utils/cmd_ref/bgp_af.yaml +164 -0
- data/lib/cisco_node_utils/cmd_ref/bgp_neighbor.yaml +131 -0
- data/lib/cisco_node_utils/cmd_ref/bgp_neighbor_af.yaml +179 -0
- data/lib/cisco_node_utils/cmd_ref/dnsclient.yaml +34 -0
- data/lib/cisco_node_utils/cmd_ref/evpn_vni.yaml +42 -0
- data/lib/cisco_node_utils/cmd_ref/fabricpath.yaml +172 -0
- data/lib/cisco_node_utils/cmd_ref/fabricpath_topology.yaml +35 -0
- data/lib/cisco_node_utils/cmd_ref/feature.yaml +42 -0
- data/lib/cisco_node_utils/cmd_ref/fex.yaml +9 -0
- data/lib/cisco_node_utils/cmd_ref/images.yaml +7 -0
- data/lib/cisco_node_utils/cmd_ref/interface.yaml +339 -0
- data/lib/cisco_node_utils/cmd_ref/interface_channel_group.yaml +28 -0
- data/lib/cisco_node_utils/cmd_ref/interface_ospf.yaml +61 -0
- data/lib/cisco_node_utils/cmd_ref/interface_portchannel.yaml +54 -0
- data/lib/cisco_node_utils/cmd_ref/interface_service_vni.yaml +32 -0
- data/lib/cisco_node_utils/cmd_ref/inventory.yaml +45 -0
- data/lib/cisco_node_utils/cmd_ref/memory.yaml +13 -0
- data/lib/cisco_node_utils/cmd_ref/ntp_config.yaml +7 -0
- data/lib/cisco_node_utils/cmd_ref/ntp_server.yaml +14 -0
- data/lib/cisco_node_utils/cmd_ref/ospf.yaml +74 -0
- data/lib/cisco_node_utils/cmd_ref/overlay_global.yaml +33 -0
- data/lib/cisco_node_utils/cmd_ref/pim.yaml +40 -0
- data/lib/cisco_node_utils/cmd_ref/portchannel_global.yaml +69 -0
- data/lib/cisco_node_utils/cmd_ref/radius_global.yaml +25 -0
- data/lib/cisco_node_utils/cmd_ref/radius_server.yaml +64 -0
- data/lib/cisco_node_utils/cmd_ref/radius_server_group.yaml +14 -0
- data/lib/cisco_node_utils/cmd_ref/show_system.yaml +5 -0
- data/lib/cisco_node_utils/cmd_ref/show_version.yaml +72 -0
- data/lib/cisco_node_utils/cmd_ref/snmp_community.yaml +23 -0
- data/lib/cisco_node_utils/cmd_ref/snmp_group.yaml +7 -0
- data/lib/cisco_node_utils/cmd_ref/snmp_notification_receiver.yaml +50 -0
- data/lib/cisco_node_utils/cmd_ref/snmp_server.yaml +51 -0
- data/lib/cisco_node_utils/cmd_ref/snmp_user.yaml +55 -0
- data/lib/cisco_node_utils/cmd_ref/snmpnotification.yaml +11 -0
- data/lib/cisco_node_utils/cmd_ref/syslog_server.yaml +18 -0
- data/lib/cisco_node_utils/cmd_ref/syslog_settings.yaml +7 -0
- data/lib/cisco_node_utils/cmd_ref/system.yaml +6 -0
- data/lib/cisco_node_utils/cmd_ref/tacacs_server.yaml +49 -0
- data/lib/cisco_node_utils/cmd_ref/tacacs_server_group.yaml +33 -0
- data/lib/cisco_node_utils/cmd_ref/tacacs_server_host.yaml +35 -0
- data/lib/cisco_node_utils/cmd_ref/vdc.yaml +38 -0
- data/lib/cisco_node_utils/cmd_ref/virtual_service.yaml +6 -0
- data/lib/cisco_node_utils/cmd_ref/vlan.yaml +56 -0
- data/lib/cisco_node_utils/cmd_ref/vni.yaml +76 -0
- data/lib/cisco_node_utils/cmd_ref/vpc.yaml +197 -0
- data/lib/cisco_node_utils/cmd_ref/vrf.yaml +88 -0
- data/lib/cisco_node_utils/cmd_ref/vtp.yaml +38 -0
- data/lib/cisco_node_utils/cmd_ref/vxlan_vtep.yaml +60 -0
- data/lib/cisco_node_utils/cmd_ref/vxlan_vtep_vni.yaml +39 -0
- data/lib/cisco_node_utils/cmd_ref/yum.yaml +13 -0
- data/lib/cisco_node_utils/command_reference.rb +359 -187
- data/lib/cisco_node_utils/configparser_lib.rb +1 -1
- data/lib/cisco_node_utils/dns_domain.rb +19 -5
- data/lib/cisco_node_utils/domain_name.rb +4 -8
- data/lib/cisco_node_utils/evpn_vni.rb +157 -0
- data/lib/cisco_node_utils/fabricpath_global.rb +388 -0
- data/lib/cisco_node_utils/fabricpath_topology.rb +150 -0
- data/lib/cisco_node_utils/feature.rb +111 -0
- data/lib/cisco_node_utils/interface.rb +390 -97
- data/lib/cisco_node_utils/interface_channel_group.rb +124 -0
- data/lib/cisco_node_utils/interface_ospf.rb +11 -34
- data/lib/cisco_node_utils/interface_portchannel.rb +157 -0
- data/lib/cisco_node_utils/interface_service_vni.rb +132 -0
- data/lib/cisco_node_utils/name_server.rb +1 -1
- data/lib/cisco_node_utils/node.rb +55 -249
- data/lib/cisco_node_utils/node_util.rb +5 -1
- data/lib/cisco_node_utils/ntp_config.rb +2 -2
- data/lib/cisco_node_utils/ntp_server.rb +14 -5
- data/lib/cisco_node_utils/overlay_global.rb +153 -0
- data/lib/cisco_node_utils/pim.rb +124 -0
- data/lib/cisco_node_utils/pim_group_list.rb +108 -0
- data/lib/cisco_node_utils/pim_rp_address.rb +102 -0
- data/lib/cisco_node_utils/platform.rb +8 -9
- data/lib/cisco_node_utils/portchannel_global.rb +277 -0
- data/lib/cisco_node_utils/radius_global.rb +9 -19
- data/lib/cisco_node_utils/radius_server.rb +31 -41
- data/lib/cisco_node_utils/radius_server_group.rb +117 -0
- data/lib/cisco_node_utils/router_ospf.rb +1 -1
- data/lib/cisco_node_utils/router_ospf_vrf.rb +14 -19
- data/lib/cisco_node_utils/snmp_notification_receiver.rb +158 -0
- data/lib/cisco_node_utils/snmpcommunity.rb +3 -5
- data/lib/cisco_node_utils/snmpgroup.rb +1 -1
- data/lib/cisco_node_utils/snmpnotification.rb +57 -0
- data/lib/cisco_node_utils/snmpserver.rb +8 -17
- data/lib/cisco_node_utils/snmpuser.rb +67 -28
- data/lib/cisco_node_utils/syslog_server.rb +3 -9
- data/lib/cisco_node_utils/syslog_settings.rb +2 -10
- data/lib/cisco_node_utils/tacacs_server.rb +9 -14
- data/lib/cisco_node_utils/tacacs_server_group.rb +145 -0
- data/lib/cisco_node_utils/tacacs_server_host.rb +5 -9
- data/lib/cisco_node_utils/vdc.rb +88 -0
- data/lib/cisco_node_utils/version.rb +5 -2
- data/lib/cisco_node_utils/vlan.rb +71 -8
- data/lib/cisco_node_utils/vni.rb +227 -0
- data/lib/cisco_node_utils/vpc.rb +377 -0
- data/lib/cisco_node_utils/vrf.rb +60 -9
- data/lib/cisco_node_utils/vrf_af.rb +191 -0
- data/lib/cisco_node_utils/vtp.rb +8 -6
- data/lib/cisco_node_utils/vxlan_vtep.rb +151 -0
- data/lib/cisco_node_utils/vxlan_vtep_vni.rb +234 -0
- data/lib/cisco_node_utils/yum.rb +1 -1
- data/tests/.rubocop.yml +1 -1
- data/tests/basetest.rb +16 -7
- data/tests/ciscotest.rb +55 -13
- data/tests/cmd_config.yaml +2 -2
- data/tests/platform_info.rb +3 -2
- data/tests/test_aaa_authentication_login.rb +219 -0
- data/tests/test_aaa_authentication_login_service.rb +759 -0
- data/tests/test_aaa_authorization_service.rb +1041 -0
- data/tests/test_ace.rb +160 -0
- data/tests/test_acl.rb +176 -0
- data/tests/test_bgp_af.rb +269 -13
- data/tests/test_bgp_neighbor.rb +38 -40
- data/tests/test_bgp_neighbor_af.rb +92 -32
- data/tests/test_command_config.rb +5 -5
- data/tests/test_command_reference.rb +284 -101
- data/tests/test_dns_domain.rb +1 -1
- data/tests/test_domain_name.rb +1 -1
- data/tests/test_evpn_vni.rb +106 -0
- data/tests/test_fabricpath_global.rb +243 -0
- data/tests/test_fabricpath_topology.rb +98 -0
- data/tests/test_interface.rb +292 -74
- data/tests/test_interface_channel_group.rb +74 -0
- data/tests/test_interface_ospf.rb +9 -4
- data/tests/test_interface_portchannel.rb +105 -0
- data/tests/test_interface_service_vni.rb +232 -0
- data/tests/test_interface_svi.rb +77 -62
- data/tests/test_interface_switchport.rb +17 -5
- data/tests/test_name_server.rb +1 -1
- data/tests/test_node.rb +1 -1
- data/tests/test_node_ext.rb +10 -20
- data/tests/test_ntp_config.rb +1 -1
- data/tests/test_ntp_server.rb +18 -6
- data/tests/test_overlay_global.rb +102 -0
- data/tests/test_pim.rb +177 -0
- data/tests/test_pim_group_list.rb +181 -0
- data/tests/test_pim_rp_address.rb +153 -0
- data/tests/test_platform.rb +3 -3
- data/tests/test_portchannel_global.rb +202 -0
- data/tests/test_radius_global.rb +1 -1
- data/tests/test_radius_server.rb +92 -57
- data/tests/test_radius_server_group.rb +149 -0
- data/tests/test_router_bgp.rb +283 -112
- data/tests/test_router_ospf.rb +2 -2
- data/tests/test_router_ospf_vrf.rb +4 -4
- data/tests/test_snmp_notification_receiver.rb +167 -0
- data/tests/test_snmpcommunity.rb +1 -1
- data/tests/test_snmpgroup.rb +1 -1
- data/tests/test_snmpnotification.rb +72 -0
- data/tests/test_snmpserver.rb +29 -105
- data/tests/test_snmpuser.rb +32 -30
- data/tests/test_syslog_server.rb +36 -10
- data/tests/test_syslog_settings.rb +1 -1
- data/tests/test_tacacs_server.rb +1 -1
- data/tests/test_tacacs_server_group.rb +405 -0
- data/tests/test_tacacs_server_host.rb +1 -1
- data/tests/test_vdc.rb +78 -0
- data/tests/test_vlan.rb +74 -19
- data/tests/test_vlan_mt_full.rb +95 -0
- data/tests/test_vni.rb +106 -0
- data/tests/test_vpc.rb +361 -0
- data/tests/test_vrf.rb +172 -29
- data/tests/test_vtp.rb +1 -1
- data/tests/test_vxlan_vtep.rb +214 -0
- data/tests/test_vxlan_vtep_vni.rb +201 -0
- data/tests/test_yum.rb +1 -1
- metadata +120 -11
- data/lib/cisco_node_utils/README_YAML.md +0 -325
- data/lib/cisco_node_utils/command_reference_common.yaml +0 -1051
- data/lib/cisco_node_utils/command_reference_common_bgp.yaml +0 -535
- data/lib/cisco_node_utils/command_reference_n3064.yaml +0 -13
- data/lib/cisco_node_utils/command_reference_n7k.yaml +0 -52
- data/lib/cisco_node_utils/command_reference_n9k.yaml +0 -26
- data/tests/platform_info.yaml +0 -10
@@ -2,7 +2,7 @@
|
|
2
2
|
#
|
3
3
|
# Michael Wiebe, December 2014
|
4
4
|
#
|
5
|
-
# Copyright (c) 2014-
|
5
|
+
# Copyright (c) 2014-2016 Cisco and/or its affiliates.
|
6
6
|
#
|
7
7
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
8
|
# you may not use this file except in compliance with the License.
|
@@ -67,7 +67,7 @@ class TestCommandConfig < CiscoTestCase
|
|
67
67
|
config_cmd_hash.each do |k, v|
|
68
68
|
v.each_value do |v1|
|
69
69
|
# Send commands
|
70
|
-
cfg_cmd_str = "
|
70
|
+
cfg_cmd_str = "#{v1.gsub(/^/, ' ')}"
|
71
71
|
cfg_string = remove_whitespace(cfg_cmd_str)
|
72
72
|
# puts "cfg_string: \n||\n#{cfg_string}||\n"
|
73
73
|
begin
|
@@ -120,7 +120,7 @@ class TestCommandConfig < CiscoTestCase
|
|
120
120
|
sleep 30 # long-running command
|
121
121
|
curr = @device.cmd('show int brief | count')[/^(\d+)$/]
|
122
122
|
flunk('Timeout while creating 1024 loopback interfaces' \
|
123
|
-
"(pre:#{pre} curr:#{curr}") unless
|
123
|
+
"(pre:#{pre} curr:#{curr}") unless pre == curr - 1024
|
124
124
|
end
|
125
125
|
|
126
126
|
# Remove 1024 loopback interfaces
|
@@ -134,7 +134,7 @@ class TestCommandConfig < CiscoTestCase
|
|
134
134
|
sleep 30 # long-running: n95 can take 70+ sec to remove all of these
|
135
135
|
curr = @device.cmd(show_int_count)[/^(\d+)$/]
|
136
136
|
flunk('Timeout while deleting 1024 loopback interfaces ' \
|
137
|
-
"(pre:#{pre} curr:#{curr}") unless
|
137
|
+
"(pre:#{pre} curr:#{curr}") unless pre == curr
|
138
138
|
end
|
139
139
|
end
|
140
140
|
|
@@ -142,7 +142,7 @@ class TestCommandConfig < CiscoTestCase
|
|
142
142
|
cfg_hash = load_yaml(:negative)
|
143
143
|
cfg_hash.each_value do |v|
|
144
144
|
v.each_value do |v1|
|
145
|
-
cfg_cmd_str = "
|
145
|
+
cfg_cmd_str = "#{v1.gsub(/^/, ' ')}\n"
|
146
146
|
cfg_string = remove_whitespace(cfg_cmd_str)
|
147
147
|
assert_raises(CliError) { node.config(cfg_string) }
|
148
148
|
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
#
|
3
3
|
# November 2014, Glenn F. Matthews
|
4
4
|
#
|
5
|
-
# Copyright (c) 2014-
|
5
|
+
# Copyright (c) 2014-2016 Cisco and/or its affiliates.
|
6
6
|
#
|
7
7
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
8
|
# you may not use this file except in compliance with the License.
|
@@ -17,13 +17,14 @@
|
|
17
17
|
# limitations under the License.
|
18
18
|
#
|
19
19
|
|
20
|
-
|
20
|
+
require_relative 'basetest'
|
21
|
+
|
21
22
|
require 'tempfile'
|
22
23
|
require_relative '../lib/cisco_node_utils/command_reference'
|
23
24
|
|
24
25
|
# TestCmdRef - Minitest for CommandReference and CmdRef classes.
|
25
|
-
class TestCmdRef <
|
26
|
-
include
|
26
|
+
class TestCmdRef < Minitest::Test
|
27
|
+
include Cisco
|
27
28
|
|
28
29
|
def setup
|
29
30
|
@input_file = Tempfile.new('test.yaml')
|
@@ -33,8 +34,19 @@ class TestCmdRef < MiniTest::Test
|
|
33
34
|
@input_file.close!
|
34
35
|
end
|
35
36
|
|
36
|
-
|
37
|
-
|
37
|
+
# Extend standard Minitest error handling to report UnsupportedError as skip
|
38
|
+
def capture_exceptions
|
39
|
+
super do
|
40
|
+
begin
|
41
|
+
yield
|
42
|
+
rescue Cisco::UnsupportedError => e
|
43
|
+
skip(e.to_s)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def load_file(**args)
|
49
|
+
CommandReference.new(**args, :files => [@input_file.path])
|
38
50
|
end
|
39
51
|
|
40
52
|
def write(string)
|
@@ -42,44 +54,39 @@ class TestCmdRef < MiniTest::Test
|
|
42
54
|
@input_file.flush
|
43
55
|
end
|
44
56
|
|
57
|
+
def test_data_sanity
|
58
|
+
# Make sure the actual YAML in our library loads for various platforms
|
59
|
+
CommandReference.new
|
60
|
+
CommandReference.new(platform: :nexus, cli: true)
|
61
|
+
CommandReference.new(platform: :nexus, product: 'N9K-C9396PX', cli: true)
|
62
|
+
CommandReference.new(platform: :nexus, product: 'N7K-C7010', cli: true)
|
63
|
+
CommandReference.new(platform: :nexus, product: 'N3K-C3064PQ-10GE',
|
64
|
+
cli: true)
|
65
|
+
end
|
66
|
+
|
45
67
|
def test_load_empty_file
|
46
68
|
# should load successfully but yield an empty hash
|
47
69
|
reference = load_file
|
48
|
-
|
70
|
+
assert_empty(reference)
|
49
71
|
end
|
50
72
|
|
51
73
|
def test_load_whitespace_only
|
52
74
|
write(' ')
|
53
75
|
reference = load_file
|
54
|
-
|
76
|
+
assert_empty(reference)
|
55
77
|
end
|
56
78
|
|
57
79
|
def test_load_not_valid_yaml
|
58
80
|
# The control characters embedded below are not permitted in YAML.
|
59
|
-
# Syck (in older Ruby versions) will incorrectly accept these
|
60
|
-
# while parsing the file, but our CmdRef constructor will eventually
|
61
|
-
# reject the data.
|
62
|
-
# Psych (in newer Ruby versions) will correctly reject
|
63
|
-
# this data at parse time.
|
64
81
|
write("
|
65
|
-
|
66
|
-
|
67
|
-
default_value:\vtrue")
|
82
|
+
name\a\e\b\f:
|
83
|
+
default_value:\vtrue")
|
68
84
|
assert_raises(RuntimeError) { load_file }
|
69
85
|
end
|
70
86
|
|
71
|
-
def test_load_feature_no_name
|
72
|
-
# should error out
|
73
|
-
write('feature:')
|
74
|
-
assert_raises(RuntimeError) do
|
75
|
-
load_file
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
87
|
def test_load_feature_name_no_data
|
80
88
|
write("
|
81
|
-
|
82
|
-
name:")
|
89
|
+
name:")
|
83
90
|
assert_raises(RuntimeError) do
|
84
91
|
load_file
|
85
92
|
end
|
@@ -87,122 +94,298 @@ feature:
|
|
87
94
|
|
88
95
|
def test_load_feature_name_default
|
89
96
|
write("
|
90
|
-
|
91
|
-
|
92
|
-
default_value: true")
|
97
|
+
name:
|
98
|
+
default_value: true")
|
93
99
|
reference = load_file
|
94
100
|
assert(!reference.empty?)
|
95
|
-
ref = reference.lookup('
|
101
|
+
ref = reference.lookup('test', 'name')
|
96
102
|
assert_equal(true, ref.default_value)
|
97
103
|
end
|
98
104
|
|
99
|
-
def test_load_duplicate_feature
|
100
|
-
write("
|
101
|
-
feature:
|
102
|
-
name:
|
103
|
-
default_value: false
|
104
|
-
feature:
|
105
|
-
name:
|
106
|
-
config_get: 'show feature'
|
107
|
-
")
|
108
|
-
assert_raises(RuntimeError) { load_file }
|
109
|
-
end
|
110
|
-
|
111
105
|
def test_load_duplicate_name
|
112
106
|
write("
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
config_get: 'show feature'")
|
107
|
+
name:
|
108
|
+
default_value: false
|
109
|
+
name:
|
110
|
+
config_get: 'show feature'")
|
118
111
|
assert_raises(RuntimeError) { load_file }
|
119
112
|
end
|
120
113
|
|
121
114
|
def test_load_duplicate_param
|
122
115
|
write("
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
default_value: true")
|
116
|
+
name:
|
117
|
+
default_value: false
|
118
|
+
default_value: true")
|
127
119
|
assert_raises(RuntimeError) { load_file }
|
128
120
|
end
|
129
121
|
|
130
122
|
def test_load_unsupported_key
|
131
123
|
write("
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
what_is_this: \"I don't even\"")
|
124
|
+
name:
|
125
|
+
config_get: 'show feature'
|
126
|
+
what_is_this: \"I don't even\"")
|
136
127
|
assert_raises(RuntimeError) { load_file }
|
137
128
|
end
|
138
129
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
# default_value: false")
|
148
|
-
# self.assert_raises(RuntimeError) { load_file }
|
149
|
-
# end
|
130
|
+
def test_load_unalphabetized
|
131
|
+
write("
|
132
|
+
name_b:
|
133
|
+
default_value: true
|
134
|
+
name_a:
|
135
|
+
default_value: false")
|
136
|
+
assert_raises(RuntimeError) { load_file }
|
137
|
+
end
|
150
138
|
|
151
139
|
def type_check(obj, cls)
|
152
140
|
assert(obj.is_a?(cls), "#{obj} should be #{cls} but is #{obj.class}")
|
153
141
|
end
|
154
142
|
|
155
143
|
def test_load_types
|
156
|
-
write(
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
144
|
+
write(%q(
|
145
|
+
name:
|
146
|
+
default_value: true
|
147
|
+
config_get: show hello
|
148
|
+
config_get_token: '/hello world/'
|
149
|
+
config_set: [ \"hello\", \"world\" ]
|
150
|
+
test_config_get_regex: '/hello world/'
|
151
|
+
test_config_result:
|
152
|
+
false: RuntimeError
|
153
|
+
32: "Long VLAN name knob is not enabled"
|
154
|
+
nil: ~
|
155
|
+
))
|
165
156
|
reference = load_file
|
166
|
-
ref = reference.lookup('
|
157
|
+
ref = reference.lookup('test', 'name')
|
167
158
|
type_check(ref.default_value, TrueClass)
|
168
159
|
type_check(ref.config_get, String)
|
169
|
-
type_check(ref.config_get_token,
|
160
|
+
type_check(ref.config_get_token, Array)
|
161
|
+
type_check(ref.config_get_token[0], Regexp)
|
170
162
|
type_check(ref.config_set, Array)
|
171
163
|
type_check(ref.test_config_get_regex, Regexp)
|
164
|
+
assert_raises(IndexError) { ref.test_config_get }
|
165
|
+
type_check(ref.test_config_result(false), RuntimeError.class)
|
166
|
+
type_check(ref.test_config_result(32), String)
|
167
|
+
type_check(ref.test_config_result('nil'), NilClass)
|
168
|
+
|
169
|
+
assert(ref.default_value?)
|
170
|
+
assert(ref.config_get?)
|
171
|
+
assert(ref.config_get_token?)
|
172
|
+
assert(ref.config_set?)
|
172
173
|
end
|
173
174
|
|
174
|
-
def
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
175
|
+
def write_variants
|
176
|
+
write("
|
177
|
+
name:
|
178
|
+
default_value: 'generic'
|
179
|
+
cli_nexus:
|
180
|
+
default_value: 'NXAPI base'
|
181
|
+
/N7K/:
|
182
|
+
default_value: ~
|
183
|
+
/N9K/:
|
184
|
+
default_value: 'NXAPI N9K'
|
185
|
+
")
|
186
|
+
end
|
187
|
+
|
188
|
+
def test_load_generic
|
189
|
+
write_variants
|
190
|
+
reference = load_file
|
191
|
+
assert_equal('generic', reference.lookup('test', 'name').default_value)
|
183
192
|
end
|
184
193
|
|
185
194
|
def test_load_n9k
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
refute(reference.files.any? { |filename| /n7k.yaml/ =~ filename })
|
190
|
-
refute(reference.files.any? { |filename| /n3064.yaml/ =~ filename })
|
195
|
+
write_variants
|
196
|
+
reference = load_file(platform: :nexus, product: 'N9K-C9396PX', cli: true)
|
197
|
+
assert_equal('NXAPI N9K', reference.lookup('test', 'name').default_value)
|
191
198
|
end
|
192
199
|
|
193
200
|
def test_load_n7k
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
assert(reference.files.any? { |filename| /n7k.yaml/ =~ filename })
|
198
|
-
refute(reference.files.any? { |filename| /n3064.yaml/ =~ filename })
|
201
|
+
write_variants
|
202
|
+
reference = load_file(platform: :nexus, product: 'N7K-C7010', cli: true)
|
203
|
+
assert_equal(nil, reference.lookup('test', 'name').default_value)
|
199
204
|
end
|
200
205
|
|
201
206
|
def test_load_n3k_3064
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
+
write_variants
|
208
|
+
reference = load_file(platform: :nexus, product: 'N3K-C3064PQ-10GE',
|
209
|
+
cli: true)
|
210
|
+
assert_equal('NXAPI base', reference.lookup('test', 'name').default_value)
|
211
|
+
end
|
212
|
+
|
213
|
+
def write_exclusions
|
214
|
+
write("
|
215
|
+
_exclude:
|
216
|
+
- /N9K/
|
217
|
+
|
218
|
+
name:
|
219
|
+
_exclude: [/C30../, /C31../]
|
220
|
+
default_value: hello
|
221
|
+
|
222
|
+
rank:
|
223
|
+
default_value: 27
|
224
|
+
")
|
225
|
+
end
|
226
|
+
|
227
|
+
def test_exclude_whole_file
|
228
|
+
write_exclusions
|
229
|
+
reference = load_file(product: 'N9K-C9396PX')
|
230
|
+
|
231
|
+
ref = reference.lookup('test', 'name')
|
232
|
+
# default_value is nil for an unsupported property
|
233
|
+
assert(ref.default_value?, 'default_value? returned false')
|
234
|
+
assert_nil(ref.default_value)
|
235
|
+
refute(ref.config_get?)
|
236
|
+
assert_raises(Cisco::UnsupportedError) { ref.config_get }
|
237
|
+
|
238
|
+
# Because the whole file is excluded, we don't know which
|
239
|
+
# attributes are 'valid' - so any attribute name is permitted:
|
240
|
+
ref = reference.lookup('test', 'foobar')
|
241
|
+
assert(ref.default_value?)
|
242
|
+
assert_nil(ref.default_value)
|
243
|
+
refute(ref.config_get?)
|
244
|
+
assert_raises(Cisco::UnsupportedError) { ref.config_get }
|
245
|
+
end
|
246
|
+
|
247
|
+
def test_exclude_whole_item
|
248
|
+
write_exclusions
|
249
|
+
reference = load_file(product: 'N3K-C3172PQ')
|
250
|
+
assert_equal(27, reference.lookup('test', 'rank').default_value)
|
251
|
+
|
252
|
+
ref = reference.lookup('test', 'name')
|
253
|
+
assert(ref.default_value?)
|
254
|
+
assert_nil(ref.default_value)
|
255
|
+
refute(ref.config_get?)
|
256
|
+
assert_raises(Cisco::UnsupportedError) { ref.config_get }
|
257
|
+
end
|
258
|
+
|
259
|
+
def test_exclude_no_exclusion
|
260
|
+
write_exclusions
|
261
|
+
reference = load_file(product: 'N7K-C7010')
|
262
|
+
assert_equal('hello', reference.lookup('test', 'name').default_value)
|
263
|
+
assert_equal(27, reference.lookup('test', 'rank').default_value)
|
264
|
+
end
|
265
|
+
|
266
|
+
def test_exclude_implicit
|
267
|
+
write("
|
268
|
+
name:
|
269
|
+
cli_nexus:
|
270
|
+
default_value: 1
|
271
|
+
")
|
272
|
+
reference = load_file(platform: 'nexus', cli: false)
|
273
|
+
ref = reference.lookup('test', 'name')
|
274
|
+
assert(ref.default_value?)
|
275
|
+
assert_nil(ref.default_value)
|
276
|
+
end
|
277
|
+
|
278
|
+
def test_default_only
|
279
|
+
write("
|
280
|
+
name:
|
281
|
+
default_only: 'x'
|
282
|
+
")
|
283
|
+
reference = load_file
|
284
|
+
ref = reference.lookup('test', 'name')
|
285
|
+
assert(ref.default_only?)
|
286
|
+
assert(ref.default_value?)
|
287
|
+
assert_equal('x', ref.default_value)
|
288
|
+
refute(ref.config_set?)
|
289
|
+
assert_raises(Cisco::UnsupportedError) { ref.config_set }
|
290
|
+
end
|
291
|
+
|
292
|
+
def test_default_only_cleanup
|
293
|
+
write("
|
294
|
+
name:
|
295
|
+
default_only: 'x'
|
296
|
+
config_set: 'foo'
|
297
|
+
")
|
298
|
+
reference = load_file
|
299
|
+
ref = reference.lookup('test', 'name')
|
300
|
+
assert(ref.default_only?)
|
301
|
+
assert(ref.default_value?)
|
302
|
+
assert_equal('x', ref.default_value)
|
303
|
+
refute(ref.config_set?)
|
304
|
+
assert_raises(Cisco::UnsupportedError) { ref.config_set }
|
305
|
+
|
306
|
+
write("
|
307
|
+
name2:
|
308
|
+
config_set: 'foo'
|
309
|
+
default_only: 'x'
|
310
|
+
")
|
311
|
+
reference = load_file
|
312
|
+
ref = reference.lookup('test', 'name2')
|
313
|
+
assert(ref.default_only?)
|
314
|
+
assert(ref.default_value?)
|
315
|
+
assert_equal('x', ref.default_value)
|
316
|
+
refute(ref.config_set?)
|
317
|
+
assert_raises(Cisco::UnsupportedError) { ref.config_set }
|
318
|
+
end
|
319
|
+
|
320
|
+
def test_default_only_default_value
|
321
|
+
write("
|
322
|
+
name:
|
323
|
+
kind: int
|
324
|
+
cli_nexus:
|
325
|
+
default_value: 10
|
326
|
+
config_set: 'hello'
|
327
|
+
default_only: 0
|
328
|
+
")
|
329
|
+
reference = load_file
|
330
|
+
ref = reference.lookup('test', 'name')
|
331
|
+
assert(ref.default_only?)
|
332
|
+
assert(ref.default_value?)
|
333
|
+
assert_equal(0, ref.default_value)
|
334
|
+
refute(ref.config_set?)
|
335
|
+
assert_raises(Cisco::UnsupportedError) { ref.config_set }
|
336
|
+
|
337
|
+
reference = load_file(cli: true, platform: 'nexus')
|
338
|
+
ref = reference.lookup('test', 'name')
|
339
|
+
refute(ref.default_only?)
|
340
|
+
assert(ref.default_value?)
|
341
|
+
assert_equal(10, ref.default_value)
|
342
|
+
assert(ref.config_set?)
|
343
|
+
assert_raises(IndexError) { ref.config_get }
|
344
|
+
end
|
345
|
+
|
346
|
+
def test_config_get_token_hash_substitution
|
347
|
+
write(%q(
|
348
|
+
name:
|
349
|
+
config_get_token:
|
350
|
+
['/^router ospf <name>$/',
|
351
|
+
'/^vrf <vrf>$/',
|
352
|
+
'/^router-id (\S+)$/']
|
353
|
+
test2:
|
354
|
+
config_get_token:
|
355
|
+
['abc <val1> def',
|
356
|
+
'xyz <val2>']
|
357
|
+
))
|
358
|
+
reference = load_file
|
359
|
+
ref = reference.lookup('test', 'name')
|
360
|
+
token = ref.config_get_token(name: 'red')
|
361
|
+
assert_equal([/^router ospf red$/, /^router-id (\S+)$/],
|
362
|
+
token)
|
363
|
+
token = ref.config_get_token(name: 'blue', vrf: 'green')
|
364
|
+
assert_equal([/^router ospf blue$/, /^vrf green$/, /^router-id (\S+)$/],
|
365
|
+
token)
|
366
|
+
ref = reference.lookup('test', 'test2')
|
367
|
+
token = ref.config_get_token(val1: '1', val2: '2')
|
368
|
+
assert_equal(['abc 1 def', 'xyz 2'], token)
|
369
|
+
token = ref.config_get_token(val1: '1', extra_val: 'asdf')
|
370
|
+
assert_equal(['abc 1 def'], token)
|
371
|
+
token = ref.config_get_token(val2: '2')
|
372
|
+
assert_equal(['xyz 2'], token)
|
373
|
+
assert_raises(ArgumentError) { token = ref.config_get_token }
|
374
|
+
assert_raises(ArgumentError) { token = ref.config_get_token(extra: 'x') }
|
375
|
+
end
|
376
|
+
|
377
|
+
def test_config_get_token_printf_substitution
|
378
|
+
write("
|
379
|
+
name:
|
380
|
+
config_get_token: ['/^interface %s$/i', '/^description (.*)/']
|
381
|
+
")
|
382
|
+
reference = load_file
|
383
|
+
ref = reference.lookup('test', 'name')
|
384
|
+
token = ref.config_get_token('Ethernet1/1')
|
385
|
+
assert_equal([%r{^interface Ethernet1/1$}i, /^description (.*)/],
|
386
|
+
token)
|
387
|
+
# Negative tests - wrong # of args
|
388
|
+
assert_raises(ArgumentError) { ref.config_get_token }
|
389
|
+
assert_raises(ArgumentError) { ref.config_get_token('eth1/1', 'foo') }
|
207
390
|
end
|
208
391
|
end
|