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.
Files changed (114) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +4 -0
  3. data/.rubocop.yml +81 -1
  4. data/.travis.yml +9 -0
  5. data/CHANGELOG.md +72 -6
  6. data/CONTRIBUTING.md +32 -7
  7. data/README.md +70 -7
  8. data/Rakefile +17 -0
  9. data/bin/check_metric_limits.rb +109 -0
  10. data/bin/git/hooks/commit-msg/enforce_style +81 -0
  11. data/bin/git/hooks/hook_lib +108 -0
  12. data/bin/git/hooks/hooks-wrapper +38 -0
  13. data/bin/git/hooks/post-flow-hotfix-start/update-version +24 -0
  14. data/bin/git/hooks/post-flow-release-finish/update-version +29 -0
  15. data/bin/git/hooks/post-flow-release-start/update-version +19 -0
  16. data/bin/git/hooks/post-merge/update-hooks +6 -0
  17. data/bin/git/hooks/post-rewrite/update-hooks +6 -0
  18. data/bin/git/hooks/pre-commit/rubocop +20 -0
  19. data/bin/git/hooks/pre-commit/validate-diffs +31 -0
  20. data/bin/git/hooks/pre-push/check-changelog +24 -0
  21. data/bin/git/hooks/pre-push/rubocop +7 -0
  22. data/bin/git/update-hooks +65 -0
  23. data/cisco_node_utils.gemspec +9 -3
  24. data/docs/README-develop-best-practices.md +404 -0
  25. data/docs/README-develop-node-utils-APIs.md +215 -365
  26. data/docs/README-maintainers.md +33 -3
  27. data/docs/template-router.rb +89 -91
  28. data/docs/template-test_router.rb +52 -55
  29. data/lib/.rubocop.yml +18 -0
  30. data/lib/cisco_node_utils.rb +2 -19
  31. data/lib/cisco_node_utils/README_YAML.md +1 -9
  32. data/lib/cisco_node_utils/bgp.rb +664 -0
  33. data/lib/cisco_node_utils/bgp_af.rb +530 -0
  34. data/lib/cisco_node_utils/bgp_neighbor.rb +425 -0
  35. data/lib/cisco_node_utils/bgp_neighbor_af.rb +709 -0
  36. data/lib/cisco_node_utils/cisco_cmn_utils.rb +59 -25
  37. data/lib/cisco_node_utils/command_reference.rb +72 -74
  38. data/lib/cisco_node_utils/command_reference_common.yaml +174 -9
  39. data/lib/cisco_node_utils/command_reference_common_bgp.yaml +535 -0
  40. data/lib/cisco_node_utils/command_reference_n7k.yaml +4 -0
  41. data/lib/cisco_node_utils/command_reference_n9k.yaml +0 -9
  42. data/lib/cisco_node_utils/configparser_lib.rb +152 -147
  43. data/lib/cisco_node_utils/dns_domain.rb +79 -0
  44. data/lib/cisco_node_utils/domain_name.rb +71 -0
  45. data/lib/cisco_node_utils/interface.rb +167 -161
  46. data/lib/cisco_node_utils/interface_ospf.rb +78 -81
  47. data/lib/cisco_node_utils/name_server.rb +64 -0
  48. data/lib/cisco_node_utils/node.rb +154 -198
  49. data/lib/cisco_node_utils/node_util.rb +61 -0
  50. data/lib/cisco_node_utils/ntp_config.rb +65 -0
  51. data/lib/cisco_node_utils/ntp_server.rb +76 -0
  52. data/lib/cisco_node_utils/platform.rb +174 -165
  53. data/lib/cisco_node_utils/radius_global.rb +146 -0
  54. data/lib/cisco_node_utils/radius_server.rb +295 -0
  55. data/lib/cisco_node_utils/router_ospf.rb +59 -63
  56. data/lib/cisco_node_utils/router_ospf_vrf.rb +226 -210
  57. data/lib/cisco_node_utils/snmpcommunity.rb +52 -58
  58. data/lib/cisco_node_utils/snmpgroup.rb +22 -23
  59. data/lib/cisco_node_utils/snmpserver.rb +99 -103
  60. data/lib/cisco_node_utils/snmpuser.rb +294 -274
  61. data/lib/cisco_node_utils/syslog_server.rb +92 -0
  62. data/lib/cisco_node_utils/syslog_settings.rb +69 -0
  63. data/lib/cisco_node_utils/tacacs_server.rb +137 -133
  64. data/lib/cisco_node_utils/tacacs_server_host.rb +84 -87
  65. data/lib/cisco_node_utils/version.rb +2 -1
  66. data/lib/cisco_node_utils/vlan.rb +28 -31
  67. data/lib/cisco_node_utils/vrf.rb +80 -0
  68. data/lib/cisco_node_utils/vtp.rb +100 -97
  69. data/lib/cisco_node_utils/yum.rb +15 -17
  70. data/tests/.rubocop.yml +15 -0
  71. data/tests/basetest.rb +81 -36
  72. data/tests/ciscotest.rb +38 -78
  73. data/{lib/cisco_node_utils → tests}/platform_info.rb +12 -8
  74. data/{lib/cisco_node_utils → tests}/platform_info.yaml +1 -1
  75. data/tests/test_bgp_af.rb +920 -0
  76. data/tests/test_bgp_neighbor.rb +403 -0
  77. data/tests/test_bgp_neighbor_af.rb +589 -0
  78. data/tests/test_command_config.rb +65 -62
  79. data/tests/test_command_reference.rb +31 -45
  80. data/tests/test_dns_domain.rb +113 -0
  81. data/tests/test_domain_name.rb +86 -0
  82. data/tests/test_interface.rb +424 -548
  83. data/tests/test_interface_ospf.rb +248 -432
  84. data/tests/test_interface_svi.rb +56 -79
  85. data/tests/test_interface_switchport.rb +196 -272
  86. data/tests/test_name_server.rb +85 -0
  87. data/tests/test_node.rb +7 -6
  88. data/tests/test_node_ext.rb +133 -186
  89. data/tests/test_ntp_config.rb +49 -0
  90. data/tests/test_ntp_server.rb +74 -0
  91. data/tests/test_platform.rb +58 -37
  92. data/tests/test_radius_global.rb +78 -0
  93. data/tests/test_radius_server.rb +185 -0
  94. data/tests/test_router_bgp.rb +838 -0
  95. data/tests/test_router_ospf.rb +49 -80
  96. data/tests/test_router_ospf_vrf.rb +274 -392
  97. data/tests/test_snmpcommunity.rb +128 -172
  98. data/tests/test_snmpgroup.rb +12 -14
  99. data/tests/test_snmpserver.rb +160 -189
  100. data/tests/test_snmpuser.rb +568 -717
  101. data/tests/test_syslog_server.rb +88 -0
  102. data/tests/test_syslog_settings.rb +54 -0
  103. data/tests/test_tacacs_server.rb +113 -148
  104. data/tests/test_tacacs_server_host.rb +108 -161
  105. data/tests/test_vlan.rb +63 -79
  106. data/tests/test_vrf.rb +92 -0
  107. data/tests/test_vtp.rb +108 -126
  108. data/tests/test_yum.rb +47 -41
  109. metadata +92 -56
  110. data/.rubocop_todo.yml +0 -293
  111. data/docs/.rubocop.yml +0 -13
  112. data/docs/template-feature.rb +0 -45
  113. data/docs/template-test_feature.rb +0 -51
  114. 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
- require File.expand_path("../ciscotest", __FILE__)
20
- require File.expand_path("../../lib/cisco_node_utils/configparser_lib", __FILE__)
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("../cmd_config.yaml", __FILE__)
26
+ path = File.expand_path('../cmd_config.yaml', __FILE__)
27
27
  elsif test_type == :negative
28
- path = File.expand_path("../cmd_config_invalid.yaml", __FILE__)
28
+ path = File.expand_path('../cmd_config_invalid.yaml', __FILE__)
29
29
  else
30
- raise TypeError
30
+ fail TypeError
31
31
  end
32
- config_hash = YAML.load(File.read(path))
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 = "show running all"
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 does not exist.\
62
- \nHash Key: #{current_key}")
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.each do |k1, v1|
68
+ v.each_value do |v1|
68
69
  # Send commands
69
- cfg_cmd_str = "configure terminal\n#{v1.gsub(/^/, " ")}\n end\n"
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
- output = node.config(cfg_string)
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, "ERROR: port channel not present")
79
+ refute(known_failure, 'ERROR: port channel not present')
80
80
  raise
81
81
  end
82
- end # k1, v1
82
+ end
83
83
  end
84
84
  end
85
85
 
86
86
  def build_int_scale_config(add=true)
87
- add ? s = "" : s = "no "
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 ["loopback-int-add"]["command"] = "#{build_int_scale_config}"
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("show int brief | count")[/^(\d+)$/]
122
- flunk("Timeout while creating 1024 loopback interfaces" +
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 ["loopback-int-add"]["command"] = "#{build_int_scale_config(add=false)}"
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 # long-running: n95 can take 70+ sec to remove all of these
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("Timeout while deleting 1024 loopback interfaces " +
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(test_type=:negative)
142
- cfg_hash.each do |k, v|
143
- v.each do |k1, v1|
144
- cfg_cmd_str = "configure terminal\n#{v1.gsub(/^/, " ")}\n end\n"
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) do
147
- output = node.config(cfg_string)
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
- "Should have caught TAB char in indent area") do
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
- # 1. Get superset of running-config and agent-config
162
- # 2. From superset derive minimum needed for parity with running
163
- runn_str = "
164
- \ninterface loopback10
165
- \n description foo
166
- \ninterface loopback11
167
- \ninterface loopback12
168
- \ninterface loopback13"
169
- runn_hash = Configuration.new(runn_str)
170
-
171
- agent_str = "
172
- \ninterface loopback10
173
- \n description 10
174
- \ninterface loopback11
175
- \nno interface loopback12
176
- \ninterface loopback13"
177
- agent_hash = Configuration.new(agent_str)
178
-
179
- min_expected = "interface loopback10\ndescription 10\nno interface loopback12"
180
-
181
- superset_str = agent_hash.compare_with(runn_hash)
182
- superset_hash = Configuration.new(superset_str)
183
-
184
- min_config_hash =
185
- Configuration.build_min_config_hash(superset_hash.configuration,
186
- agent_hash.configuration)
187
- min_config_str = Configuration.config_hash_to_str(min_config_hash)
188
-
189
- assert_equal(min_config_str.include?(min_expected), true,
190
- "Error:\nExpected:\n#{min_expected}\n\nFound:\n#{min_config_str}")
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
- require File.expand_path("../../lib/cisco_node_utils/command_reference", __FILE__)
22
+ require_relative '../lib/cisco_node_utils/command_reference'
24
23
 
25
- class TestCmdRef < MiniTest::Unit::TestCase
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("", [@input_file.path])
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) do
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("feature:")
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
- reference = load_file
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("feature", "name")
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) do
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) do
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) do
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) do
145
- reference = load_file
146
- end
136
+ assert_raises(RuntimeError) { load_file }
147
137
  end
148
138
 
149
- =begin
150
- # Alphabetization of features is not enforced at this time.
151
- def test_load_features_unalphabetized
152
- write("
153
- zzz:
154
- name:
155
- default_value: true
156
- zzy:
157
- name:
158
- default_value: false")
159
- self.assert_raises(RuntimeError) do
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("feature", "name")
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("vtp", "feature").config_get_token, String)
196
- type_check(reference.lookup("vtp", "version").default_value, Integer)
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("N9K-C9396PX")
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("N7K-C7010")
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("N3K-C3064PQ-10GE")
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