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
|
@@ -16,22 +16,23 @@
|
|
|
16
16
|
# See the License for the specific language governing permissions and
|
|
17
17
|
# limitations under the License.
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
require_relative 'ciscotest'
|
|
20
|
+
require_relative '../lib/cisco_node_utils/configparser_lib'
|
|
21
21
|
require 'timeout'
|
|
22
22
|
require 'yaml'
|
|
23
23
|
|
|
24
24
|
def load_yaml(test_type=:positive)
|
|
25
25
|
if test_type == :positive
|
|
26
|
-
path = File.expand_path(
|
|
26
|
+
path = File.expand_path('../cmd_config.yaml', __FILE__)
|
|
27
27
|
elsif test_type == :negative
|
|
28
|
-
path = File.expand_path(
|
|
28
|
+
path = File.expand_path('../cmd_config_invalid.yaml', __FILE__)
|
|
29
29
|
else
|
|
30
|
-
|
|
30
|
+
fail TypeError
|
|
31
31
|
end
|
|
32
|
-
|
|
32
|
+
YAML.load(File.read(path))
|
|
33
33
|
end
|
|
34
34
|
|
|
35
|
+
# TestCommandConfig - Minitest for ConfigParser module
|
|
35
36
|
class TestCommandConfig < CiscoTestCase
|
|
36
37
|
include ConfigParser
|
|
37
38
|
|
|
@@ -44,7 +45,7 @@ class TestCommandConfig < CiscoTestCase
|
|
|
44
45
|
end # remove_whitespace
|
|
45
46
|
|
|
46
47
|
def compare_with_results(desired_config_str, current_key)
|
|
47
|
-
retrieve_command =
|
|
48
|
+
retrieve_command = 'show running all'
|
|
48
49
|
running_config_str = node.show(retrieve_command)
|
|
49
50
|
|
|
50
51
|
begin
|
|
@@ -58,36 +59,35 @@ class TestCommandConfig < CiscoTestCase
|
|
|
58
59
|
end
|
|
59
60
|
# puts "Existing command block:\n#{existing}"
|
|
60
61
|
assert_equal(existing.empty?, false,
|
|
61
|
-
"Error: Expected configuration \n'#{desired_config_str}'\n
|
|
62
|
-
|
|
62
|
+
"Error: Expected configuration \n'#{desired_config_str}'\n " \
|
|
63
|
+
"does not exist.\nHash Key: #{current_key}")
|
|
63
64
|
end
|
|
64
65
|
|
|
65
66
|
def send_device_config(config_cmd_hash)
|
|
66
67
|
config_cmd_hash.each do |k, v|
|
|
67
|
-
v.
|
|
68
|
+
v.each_value do |v1|
|
|
68
69
|
# Send commands
|
|
69
|
-
cfg_cmd_str = "configure terminal\n#{v1.gsub(/^/,
|
|
70
|
+
cfg_cmd_str = "configure terminal\n#{v1.gsub(/^/, ' ')}\n end\n"
|
|
70
71
|
cfg_string = remove_whitespace(cfg_cmd_str)
|
|
71
72
|
# puts "cfg_string: \n||\n#{cfg_string}||\n"
|
|
72
73
|
begin
|
|
73
|
-
|
|
74
|
-
# puts "output : #{output}"
|
|
74
|
+
node.config(cfg_string)
|
|
75
75
|
# make sure config is present in success case
|
|
76
76
|
compare_with_results(v1, k)
|
|
77
77
|
rescue CliError => e
|
|
78
78
|
known_failure = e.message[/ERROR:.*port channel not present/]
|
|
79
|
-
refute(known_failure,
|
|
79
|
+
refute(known_failure, 'ERROR: port channel not present')
|
|
80
80
|
raise
|
|
81
81
|
end
|
|
82
|
-
end
|
|
82
|
+
end
|
|
83
83
|
end
|
|
84
84
|
end
|
|
85
85
|
|
|
86
86
|
def build_int_scale_config(add=true)
|
|
87
|
-
add ? s =
|
|
87
|
+
add ? s = '' : s = 'no '
|
|
88
88
|
current_interface = 0
|
|
89
89
|
num_interfaces = 1024
|
|
90
|
-
command_list =
|
|
90
|
+
command_list = ''
|
|
91
91
|
while current_interface < num_interfaces
|
|
92
92
|
command_list += "#{s}interface loopback#{current_interface}\n"
|
|
93
93
|
current_interface += 1
|
|
@@ -112,81 +112,84 @@ class TestCommandConfig < CiscoTestCase
|
|
|
112
112
|
|
|
113
113
|
# Add 1024 loopback interfaces
|
|
114
114
|
cfg_hash_add = Hash.new { |h, k| h[k] = Hash.new(&h.default_proc) }
|
|
115
|
-
cfg_hash_add [
|
|
115
|
+
cfg_hash_add ['loopback-int-add']['command'] = "#{build_int_scale_config}"
|
|
116
116
|
begin
|
|
117
117
|
send_device_config(cfg_hash_add)
|
|
118
118
|
rescue Timeout::Error
|
|
119
119
|
puts "\n -- Long-running command, extending timeout +30 sec"
|
|
120
120
|
sleep 30 # long-running command
|
|
121
|
-
curr = @device.cmd(
|
|
122
|
-
flunk(
|
|
121
|
+
curr = @device.cmd('show int brief | count')[/^(\d+)$/]
|
|
122
|
+
flunk('Timeout while creating 1024 loopback interfaces' \
|
|
123
123
|
"(pre:#{pre} curr:#{curr}") unless (pre == curr - 1024)
|
|
124
124
|
end
|
|
125
125
|
|
|
126
126
|
# Remove 1024 loopback interfaces
|
|
127
127
|
cfg_hash_remove = Hash.new { |h, k| h[k] = Hash.new(&h.default_proc) }
|
|
128
|
-
cfg_hash_remove
|
|
128
|
+
cfg_hash_remove['loopback-int-add']['command'] = \
|
|
129
|
+
"#{build_int_scale_config(false)}"
|
|
129
130
|
begin
|
|
130
131
|
send_device_config(cfg_hash_remove)
|
|
131
132
|
rescue Timeout::Error
|
|
132
133
|
puts "\n -- Long-running command, extending timeout +30 sec"
|
|
133
|
-
sleep 30
|
|
134
|
+
sleep 30 # long-running: n95 can take 70+ sec to remove all of these
|
|
134
135
|
curr = @device.cmd(show_int_count)[/^(\d+)$/]
|
|
135
|
-
flunk(
|
|
136
|
+
flunk('Timeout while deleting 1024 loopback interfaces ' \
|
|
136
137
|
"(pre:#{pre} curr:#{curr}") unless (pre == curr)
|
|
137
138
|
end
|
|
138
139
|
end
|
|
139
140
|
|
|
140
141
|
def test_invalid_config
|
|
141
|
-
cfg_hash = load_yaml(
|
|
142
|
-
cfg_hash.
|
|
143
|
-
v.
|
|
144
|
-
cfg_cmd_str = "configure terminal\n#{v1.gsub(/^/,
|
|
142
|
+
cfg_hash = load_yaml(:negative)
|
|
143
|
+
cfg_hash.each_value do |v|
|
|
144
|
+
v.each_value do |v1|
|
|
145
|
+
cfg_cmd_str = "configure terminal\n#{v1.gsub(/^/, ' ')}\n end\n"
|
|
145
146
|
cfg_string = remove_whitespace(cfg_cmd_str)
|
|
146
|
-
assert_raises(CliError)
|
|
147
|
-
|
|
148
|
-
end
|
|
149
|
-
end # k1, v1
|
|
147
|
+
assert_raises(CliError) { node.config(cfg_string) }
|
|
148
|
+
end
|
|
150
149
|
end
|
|
151
150
|
end
|
|
152
151
|
|
|
153
152
|
def test_indent_with_tab
|
|
154
153
|
assert_raises(RuntimeError,
|
|
155
|
-
|
|
154
|
+
'Should have caught TAB char in indent area') do
|
|
156
155
|
Configuration.new(" \t interface loopback10")
|
|
157
156
|
end
|
|
158
157
|
end
|
|
159
158
|
|
|
160
159
|
def test_build_min_config_hash
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
160
|
+
# 1. Get superset of running-config and agent-config
|
|
161
|
+
# 2. From superset derive minimum needed for parity with running
|
|
162
|
+
runn_str = "
|
|
163
|
+
\ninterface loopback10
|
|
164
|
+
\n description foo
|
|
165
|
+
\ninterface loopback11
|
|
166
|
+
\ninterface loopback12
|
|
167
|
+
\ninterface loopback13"
|
|
168
|
+
runn_hash = Configuration.new(runn_str)
|
|
169
|
+
|
|
170
|
+
agent_str = "
|
|
171
|
+
\ninterface loopback10
|
|
172
|
+
\n description 10
|
|
173
|
+
\ninterface loopback11
|
|
174
|
+
\nno interface loopback12
|
|
175
|
+
\ninterface loopback13"
|
|
176
|
+
agent_hash = Configuration.new(agent_str)
|
|
177
|
+
|
|
178
|
+
min_expected = ['interface loopback10',
|
|
179
|
+
'description 10',
|
|
180
|
+
'no interface loopback12',
|
|
181
|
+
].join("\n")
|
|
182
|
+
|
|
183
|
+
superset_str = agent_hash.compare_with(runn_hash)
|
|
184
|
+
superset_hash = Configuration.new(superset_str)
|
|
185
|
+
|
|
186
|
+
min_config_hash =
|
|
187
|
+
Configuration.build_min_config_hash(superset_hash.configuration,
|
|
188
|
+
agent_hash.configuration)
|
|
189
|
+
min_config_str = Configuration.config_hash_to_str(min_config_hash)
|
|
190
|
+
|
|
191
|
+
assert_equal(min_config_str.include?(min_expected), true,
|
|
192
|
+
"Error:\nExpected:\n#{min_expected}\n" \
|
|
193
|
+
"\nFound:\n#{min_config_str}")
|
|
191
194
|
end
|
|
192
195
|
end
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
2
|
#
|
|
3
|
-
# Unit testing for CommandReference and CmdRef classes.
|
|
4
3
|
# November 2014, Glenn F. Matthews
|
|
5
4
|
#
|
|
6
5
|
# Copyright (c) 2014-2015 Cisco and/or its affiliates.
|
|
@@ -20,9 +19,10 @@
|
|
|
20
19
|
|
|
21
20
|
require 'minitest/autorun'
|
|
22
21
|
require 'tempfile'
|
|
23
|
-
|
|
22
|
+
require_relative '../lib/cisco_node_utils/command_reference'
|
|
24
23
|
|
|
25
|
-
|
|
24
|
+
# TestCmdRef - Minitest for CommandReference and CmdRef classes.
|
|
25
|
+
class TestCmdRef < MiniTest::Test
|
|
26
26
|
include CommandReference
|
|
27
27
|
|
|
28
28
|
def setup
|
|
@@ -34,7 +34,7 @@ class TestCmdRef < MiniTest::Unit::TestCase
|
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
def load_file
|
|
37
|
-
CommandReference.new(
|
|
37
|
+
CommandReference.new('', [@input_file.path])
|
|
38
38
|
end
|
|
39
39
|
|
|
40
40
|
def write(string)
|
|
@@ -49,7 +49,7 @@ class TestCmdRef < MiniTest::Unit::TestCase
|
|
|
49
49
|
end
|
|
50
50
|
|
|
51
51
|
def test_load_whitespace_only
|
|
52
|
-
write(
|
|
52
|
+
write(' ')
|
|
53
53
|
reference = load_file
|
|
54
54
|
assert(reference.empty?)
|
|
55
55
|
end
|
|
@@ -65,14 +65,12 @@ class TestCmdRef < MiniTest::Unit::TestCase
|
|
|
65
65
|
feature\a\e:
|
|
66
66
|
name\b\f:
|
|
67
67
|
default_value:\vtrue")
|
|
68
|
-
assert_raises(RuntimeError)
|
|
69
|
-
load_file
|
|
70
|
-
end
|
|
68
|
+
assert_raises(RuntimeError) { load_file }
|
|
71
69
|
end
|
|
72
70
|
|
|
73
71
|
def test_load_feature_no_name
|
|
74
72
|
# should error out
|
|
75
|
-
write(
|
|
73
|
+
write('feature:')
|
|
76
74
|
assert_raises(RuntimeError) do
|
|
77
75
|
load_file
|
|
78
76
|
end
|
|
@@ -83,7 +81,7 @@ feature\a\e:
|
|
|
83
81
|
feature:
|
|
84
82
|
name:")
|
|
85
83
|
assert_raises(RuntimeError) do
|
|
86
|
-
|
|
84
|
+
load_file
|
|
87
85
|
end
|
|
88
86
|
end
|
|
89
87
|
|
|
@@ -94,7 +92,7 @@ feature:
|
|
|
94
92
|
default_value: true")
|
|
95
93
|
reference = load_file
|
|
96
94
|
assert(!reference.empty?)
|
|
97
|
-
ref = reference.lookup(
|
|
95
|
+
ref = reference.lookup('feature', 'name')
|
|
98
96
|
assert_equal(true, ref.default_value)
|
|
99
97
|
end
|
|
100
98
|
|
|
@@ -107,9 +105,7 @@ feature:
|
|
|
107
105
|
name:
|
|
108
106
|
config_get: 'show feature'
|
|
109
107
|
")
|
|
110
|
-
assert_raises(RuntimeError)
|
|
111
|
-
reference = load_file
|
|
112
|
-
end
|
|
108
|
+
assert_raises(RuntimeError) { load_file }
|
|
113
109
|
end
|
|
114
110
|
|
|
115
111
|
def test_load_duplicate_name
|
|
@@ -119,9 +115,7 @@ feature:
|
|
|
119
115
|
default_value: false
|
|
120
116
|
name:
|
|
121
117
|
config_get: 'show feature'")
|
|
122
|
-
assert_raises(RuntimeError)
|
|
123
|
-
reference = load_file
|
|
124
|
-
end
|
|
118
|
+
assert_raises(RuntimeError) { load_file }
|
|
125
119
|
end
|
|
126
120
|
|
|
127
121
|
def test_load_duplicate_param
|
|
@@ -130,9 +124,7 @@ feature:
|
|
|
130
124
|
name:
|
|
131
125
|
default_value: false
|
|
132
126
|
default_value: true")
|
|
133
|
-
assert_raises(RuntimeError)
|
|
134
|
-
reference = load_file
|
|
135
|
-
end
|
|
127
|
+
assert_raises(RuntimeError) { load_file }
|
|
136
128
|
end
|
|
137
129
|
|
|
138
130
|
def test_load_unsupported_key
|
|
@@ -141,26 +133,20 @@ feature:
|
|
|
141
133
|
name:
|
|
142
134
|
config_get: 'show feature'
|
|
143
135
|
what_is_this: \"I don't even\"")
|
|
144
|
-
assert_raises(RuntimeError)
|
|
145
|
-
reference = load_file
|
|
146
|
-
end
|
|
136
|
+
assert_raises(RuntimeError) { load_file }
|
|
147
137
|
end
|
|
148
138
|
|
|
149
|
-
|
|
150
|
-
#
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
reference = load_file
|
|
161
|
-
end
|
|
162
|
-
end
|
|
163
|
-
=end
|
|
139
|
+
# # Alphabetization of features is not enforced at this time.
|
|
140
|
+
# def test_load_features_unalphabetized
|
|
141
|
+
# write("
|
|
142
|
+
# zzz:
|
|
143
|
+
# name:
|
|
144
|
+
# default_value: true
|
|
145
|
+
# zzy:
|
|
146
|
+
# name:
|
|
147
|
+
# default_value: false")
|
|
148
|
+
# self.assert_raises(RuntimeError) { load_file }
|
|
149
|
+
# end
|
|
164
150
|
|
|
165
151
|
def type_check(obj, cls)
|
|
166
152
|
assert(obj.is_a?(cls), "#{obj} should be #{cls} but is #{obj.class}")
|
|
@@ -177,7 +163,7 @@ feature:
|
|
|
177
163
|
test_config_get_regex: !ruby/regexp '/hello world/'
|
|
178
164
|
")
|
|
179
165
|
reference = load_file
|
|
180
|
-
ref = reference.lookup(
|
|
166
|
+
ref = reference.lookup('feature', 'name')
|
|
181
167
|
type_check(ref.default_value, TrueClass)
|
|
182
168
|
type_check(ref.config_get, String)
|
|
183
169
|
type_check(ref.config_get_token, Regexp)
|
|
@@ -186,18 +172,18 @@ feature:
|
|
|
186
172
|
end
|
|
187
173
|
|
|
188
174
|
def test_load_common
|
|
189
|
-
reference = CommandReference.new(
|
|
175
|
+
reference = CommandReference.new('')
|
|
190
176
|
assert(reference.files.any? { |filename| /common.yaml/ =~ filename })
|
|
191
177
|
refute(reference.files.any? { |filename| /n9k.yaml/ =~ filename })
|
|
192
178
|
refute(reference.files.any? { |filename| /n7k.yaml/ =~ filename })
|
|
193
179
|
refute(reference.files.any? { |filename| /n3064.yaml/ =~ filename })
|
|
194
180
|
# Some spot checks
|
|
195
|
-
type_check(reference.lookup(
|
|
196
|
-
type_check(reference.lookup(
|
|
181
|
+
type_check(reference.lookup('vtp', 'feature').config_get_token, String)
|
|
182
|
+
type_check(reference.lookup('vtp', 'version').default_value, Integer)
|
|
197
183
|
end
|
|
198
184
|
|
|
199
185
|
def test_load_n9k
|
|
200
|
-
reference = CommandReference.new(
|
|
186
|
+
reference = CommandReference.new('N9K-C9396PX')
|
|
201
187
|
assert(reference.files.any? { |filename| /common.yaml/ =~ filename })
|
|
202
188
|
assert(reference.files.any? { |filename| /n9k.yaml/ =~ filename })
|
|
203
189
|
refute(reference.files.any? { |filename| /n7k.yaml/ =~ filename })
|
|
@@ -205,7 +191,7 @@ feature:
|
|
|
205
191
|
end
|
|
206
192
|
|
|
207
193
|
def test_load_n7k
|
|
208
|
-
reference = CommandReference.new(
|
|
194
|
+
reference = CommandReference.new('N7K-C7010')
|
|
209
195
|
assert(reference.files.any? { |filename| /common.yaml/ =~ filename })
|
|
210
196
|
refute(reference.files.any? { |filename| /n9k.yaml/ =~ filename })
|
|
211
197
|
assert(reference.files.any? { |filename| /n7k.yaml/ =~ filename })
|
|
@@ -213,7 +199,7 @@ feature:
|
|
|
213
199
|
end
|
|
214
200
|
|
|
215
201
|
def test_load_n3k_3064
|
|
216
|
-
reference = CommandReference.new(
|
|
202
|
+
reference = CommandReference.new('N3K-C3064PQ-10GE')
|
|
217
203
|
assert(reference.files.any? { |filename| /common.yaml/ =~ filename })
|
|
218
204
|
refute(reference.files.any? { |filename| /n9k.yaml/ =~ filename })
|
|
219
205
|
refute(reference.files.any? { |filename| /n7k.yaml/ =~ filename })
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Minitest for DnsDomain 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/dns_domain'
|
|
20
|
+
|
|
21
|
+
# TestDnsDomain - Minitest for DnsDomain node utility.
|
|
22
|
+
class TestDnsDomain < CiscoTestCase
|
|
23
|
+
def setup
|
|
24
|
+
# setup runs at the beginning of each test
|
|
25
|
+
super
|
|
26
|
+
no_dnsdomain_tests
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def teardown
|
|
30
|
+
# teardown runs at the end of each test
|
|
31
|
+
no_dnsdomain_tests
|
|
32
|
+
super
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def no_dnsdomain_tests
|
|
36
|
+
# Turn the feature off for a clean test.
|
|
37
|
+
config('no ip domain-list aoeu.com',
|
|
38
|
+
'no ip domain-list asdf.com',
|
|
39
|
+
'no vrf context test')
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# TESTS
|
|
43
|
+
|
|
44
|
+
def test_dnsdomain_create_destroy_single
|
|
45
|
+
id = 'aoeu.com'
|
|
46
|
+
refute_includes(Cisco::DnsDomain.dnsdomains, id)
|
|
47
|
+
|
|
48
|
+
ns = Cisco::DnsDomain.new(id)
|
|
49
|
+
assert_includes(Cisco::DnsDomain.dnsdomains, id)
|
|
50
|
+
assert_equal(Cisco::DnsDomain.dnsdomains[id], ns)
|
|
51
|
+
|
|
52
|
+
ns.destroy
|
|
53
|
+
refute_includes(Cisco::DnsDomain.dnsdomains, id)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def test_dnsdomain_create_destroy_multiple
|
|
57
|
+
id1 = 'aoeu.com'
|
|
58
|
+
id2 = 'asdf.com'
|
|
59
|
+
refute_includes(Cisco::DnsDomain.dnsdomains, id1)
|
|
60
|
+
refute_includes(Cisco::DnsDomain.dnsdomains, id2)
|
|
61
|
+
|
|
62
|
+
ns1 = Cisco::DnsDomain.new(id1)
|
|
63
|
+
ns2 = Cisco::DnsDomain.new(id2)
|
|
64
|
+
assert_includes(Cisco::DnsDomain.dnsdomains, id1)
|
|
65
|
+
assert_includes(Cisco::DnsDomain.dnsdomains, id2)
|
|
66
|
+
assert_equal(Cisco::DnsDomain.dnsdomains[id1], ns1)
|
|
67
|
+
assert_equal(Cisco::DnsDomain.dnsdomains[id2], ns2)
|
|
68
|
+
|
|
69
|
+
ns1.destroy
|
|
70
|
+
refute_includes(Cisco::DnsDomain.dnsdomains, id1)
|
|
71
|
+
assert_includes(Cisco::DnsDomain.dnsdomains, id2)
|
|
72
|
+
ns2.destroy
|
|
73
|
+
refute_includes(Cisco::DnsDomain.dnsdomains, id2)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def test_dnsdomain_create_destroy_single_vrf
|
|
77
|
+
id = 'aoeu.com'
|
|
78
|
+
vrf = 'test'
|
|
79
|
+
non_vrf = Cisco::DnsDomain.new(id)
|
|
80
|
+
assert_includes(Cisco::DnsDomain.dnsdomains, id)
|
|
81
|
+
refute_includes(Cisco::DnsDomain.dnsdomains(vrf), id)
|
|
82
|
+
|
|
83
|
+
ns = Cisco::DnsDomain.new(id, vrf)
|
|
84
|
+
assert_includes(Cisco::DnsDomain.dnsdomains(vrf), id)
|
|
85
|
+
assert_equal(Cisco::DnsDomain.dnsdomains(vrf)[id], ns)
|
|
86
|
+
|
|
87
|
+
ns.destroy
|
|
88
|
+
refute_includes(Cisco::DnsDomain.dnsdomains(vrf), id)
|
|
89
|
+
assert_includes(Cisco::DnsDomain.dnsdomains, id)
|
|
90
|
+
non_vrf.destroy
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def test_dnsdomain_create_destroy_multiple_vrf
|
|
94
|
+
id1 = 'aoeu.com'
|
|
95
|
+
id2 = 'asdf.com'
|
|
96
|
+
vrf = 'test'
|
|
97
|
+
refute_includes(Cisco::DnsDomain.dnsdomains(vrf), id1)
|
|
98
|
+
refute_includes(Cisco::DnsDomain.dnsdomains(vrf), id2)
|
|
99
|
+
|
|
100
|
+
ns1 = Cisco::DnsDomain.new(id1, vrf)
|
|
101
|
+
ns2 = Cisco::DnsDomain.new(id2, vrf)
|
|
102
|
+
assert_includes(Cisco::DnsDomain.dnsdomains(vrf), id1)
|
|
103
|
+
assert_includes(Cisco::DnsDomain.dnsdomains(vrf), id2)
|
|
104
|
+
assert_equal(Cisco::DnsDomain.dnsdomains(vrf)[id1], ns1)
|
|
105
|
+
assert_equal(Cisco::DnsDomain.dnsdomains(vrf)[id2], ns2)
|
|
106
|
+
|
|
107
|
+
ns1.destroy
|
|
108
|
+
refute_includes(Cisco::DnsDomain.dnsdomains(vrf), id1)
|
|
109
|
+
assert_includes(Cisco::DnsDomain.dnsdomains(vrf), id2)
|
|
110
|
+
ns2.destroy
|
|
111
|
+
refute_includes(Cisco::DnsDomain.dnsdomains(vrf), id2)
|
|
112
|
+
end
|
|
113
|
+
end
|