|
13 | 13 | # See the License for the specific language governing permissions and
|
14 | 14 | # limitations under the License.
|
15 | 15 | ###############################################################################
|
16 |
| -# TestCase Name: |
17 |
| -# ------------- |
18 |
| -# test-cisco_vxlan_vtep.rb |
19 | 16 | #
|
20 |
| -# TestCase Prerequisites: |
21 |
| -# ----------------------- |
22 |
| -# This is a Puppet cisco_vxlan_vtep resource testcase for Puppet Agent on |
23 |
| -# Nexus devices. |
24 |
| -# The test case assumes the following prerequisites are already satisfied: |
25 |
| -# - Host configuration file contains agent and master information. |
26 |
| -# - SSH is enabled on the N9K Agent. |
27 |
| -# - Puppet master/server is started. |
28 |
| -# - Puppet agent certificate has been signed on the Puppet master/server. |
29 |
| -# |
30 |
| -# TestCase: |
31 |
| -# --------- |
32 |
| -# This cisco_vxlan_vtep resource test verifies default and non-default values |
33 |
| -# for all properties. |
34 |
| -# |
35 |
| -# The following exit_codes are validated for Puppet, Vegas shell and |
36 |
| -# Bash shell commands. |
37 |
| -# |
38 |
| -# Vegas and Bash Shell Commands: |
39 |
| -# 0 - successful command execution |
40 |
| -# > 0 - failed command execution. |
41 |
| -# |
42 |
| -# Puppet Commands: |
43 |
| -# 0 - no changes have occurred |
44 |
| -# 1 - errors have occurred, |
45 |
| -# 2 - changes have occurred |
46 |
| -# 4 - failures have occurred and |
47 |
| -# 6 - changes and failures have occurred. |
48 |
| -# |
49 |
| -# NOTE: 0 is the default exit_code checked in Beaker::DSL::Helpers::on() method. |
50 |
| -# |
51 |
| -# The test cases use RegExp pattern matching on stdout or output IO |
52 |
| -# instance attributes to verify resource properties. |
| 17 | +# See README-develop-beaker-scripts.md (Section: Test Script Variable Reference) |
| 18 | +# for information regarding: |
| 19 | +# - test script general prequisites |
| 20 | +# - command return codes |
| 21 | +# - A description of the 'tests' hash and its usage |
53 | 22 | #
|
54 | 23 | ###############################################################################
|
55 |
| - |
56 | 24 | require File.expand_path('../../lib/utilitylib.rb', __FILE__)
|
57 | 25 |
|
58 |
| -# ----------------------------- |
59 |
| -# Common settings and variables |
60 |
| -# ----------------------------- |
61 |
| -testheader = 'Resource cisco_vxlan_vtep' |
62 |
| - |
63 |
| -# The 'tests' hash is used to define all of the test data values and expected |
64 |
| -# results. It is also used to pass optional flags to the test methods when |
65 |
| -# necessary. |
66 |
| - |
67 |
| -# 'tests' hash |
68 |
| -# Top-level keys set by caller: |
69 |
| -# tests[:master] - the master object |
70 |
| -# tests[:agent] - the agent object |
71 |
| -# |
| 26 | +# Test hash top-level keys |
72 | 27 | tests = {
|
73 |
| - master: master, |
74 |
| - agent: agent, |
75 |
| - platform: 'n(5|6|7|8|9)k', |
76 |
| - resource_name: 'cisco_vxlan_vtep', |
77 |
| -} |
78 |
| - |
79 |
| -# tests[id] keys set by caller and used by test_harness_common: |
80 |
| -# |
81 |
| -# tests[id] keys set by caller: |
82 |
| -# tests[id][:desc] - a string to use with logs & debugs |
83 |
| -# tests[id][:manifest] - the complete manifest, as used by test_harness_common |
84 |
| -# tests[id][:resource] - a hash of expected states, used by test_resource |
85 |
| -# tests[id][:resource_cmd] - 'puppet resource' command to use with test_resource |
86 |
| -# tests[id][:ensure] - (Optional) set to :present or :absent before calling |
87 |
| -# tests[id][:code] - (Optional) override the default exit code in some tests. |
88 |
| -# |
89 |
| -# These keys are local use only and not used by test_harness_common: |
90 |
| -# |
91 |
| -# tests[id][:manifest_props] - This is essentially a master list of properties |
92 |
| -# that permits re-use of the properties for both :present and :absent testing |
93 |
| -# without destroying the list |
94 |
| -# tests[id][:resource_props] - This is essentially a master hash of properties |
95 |
| -# that permits re-use of the properties for both :present and :absent testing |
96 |
| -# without destroying the hash |
97 |
| -# tests[id][:title_pattern] - (Optional) defines the manifest title. |
98 |
| -# Can be used with :af for mixed title/af testing. If mixing, :af values will |
99 |
| -# be merged with title values and override any duplicates. If omitted, |
100 |
| -# :title_pattern will be set to 'id'. |
101 |
| -# tests[id][:af] - (Optional) defines the address-family values. |
102 |
| -# Must use :title_pattern if :af is not specified. Useful for testing mixed |
103 |
| -# title/af manifests |
104 |
| -# |
105 |
| -tests['default_properties'] = { |
106 |
| - title_pattern: 'nve1', |
107 |
| - manifest_props: " |
108 |
| - description => 'default', |
109 |
| - host_reachability => 'default', |
110 |
| - shutdown => 'default', |
111 |
| - source_interface => 'default', |
112 |
| - ", |
113 |
| - resource_props: { |
114 |
| - 'host_reachability' => 'flood', |
115 |
| - 'shutdown' => 'true', |
116 |
| - }, |
| 28 | + agent: agent, |
| 29 | + master: master, |
| 30 | + operating_system: 'nexus', |
| 31 | + platform: 'n(5|6|7|8|9)k', |
| 32 | + resource_name: 'cisco_vxlan_vtep', |
117 | 33 | }
|
118 | 34 |
|
119 |
| -tests['non_default_properties'] = { |
| 35 | +# Test hash test cases |
| 36 | +tests[:default] = { |
120 | 37 | title_pattern: 'nve1',
|
121 |
| - manifest_props: " |
122 |
| - description => 'Configured by Puppet', |
123 |
| - host_reachability => 'evpn', |
124 |
| - shutdown => 'false', |
125 |
| - source_interface => 'loopback55', |
126 |
| - ", |
127 |
| - resource_props: { |
128 |
| - 'description' => 'Configured by Puppet', |
129 |
| - 'host_reachability' => 'evpn', |
130 |
| - 'shutdown' => 'false', |
131 |
| - 'source_interface' => 'loopback55', |
| 38 | + preclean: 'cisco_vxlan_vtep', |
| 39 | + manifest_props: { |
| 40 | + description: 'default', |
| 41 | + host_reachability: 'default', |
| 42 | + shutdown: 'default', |
| 43 | + source_interface: 'default', |
| 44 | + source_interface_hold_down_time: 'default', |
132 | 45 | },
|
133 |
| -} |
134 |
| - |
135 |
| -# Source Interface Hold-down Time |
136 |
| -if platform[/n(8|9)k/] |
137 |
| - tests['default_properties'][:manifest_props][:source_interface_hold_down_time] = 'default' |
138 |
| - tests['non_default_properties'][:manifest_props][:source_interface_hold_down_time] = '100' |
139 |
| - tests['non_default_properties'][:resource_props][:source_interface_hold_down_time] = '100' |
140 |
| -end |
141 |
| - |
142 |
| -tests['change_parameters'] = { |
143 |
| - title_pattern: 'nve1', |
144 |
| - manifest_props: " |
145 |
| - host_reachability => 'flood', |
146 |
| - shutdown => 'true', |
147 |
| - source_interface => 'loopback1', |
148 |
| - ", |
149 |
| - resource_props: { |
150 |
| - 'description' => 'Configured by Puppet', |
| 46 | + resource: { |
151 | 47 | 'host_reachability' => 'flood',
|
152 | 48 | 'shutdown' => 'true',
|
153 |
| - 'source_interface' => 'loopback1', |
154 | 49 | },
|
155 | 50 | }
|
156 | 51 |
|
157 |
| -tests['change_source_int_when_shutdown'] = { |
| 52 | +tests[:non_default] = { |
158 | 53 | title_pattern: 'nve1',
|
159 |
| - manifest_props: " |
160 |
| - source_interface => 'loopback88', |
161 |
| - ", |
162 |
| - resource_props: { |
163 |
| - 'description' => 'Configured by Puppet', |
164 |
| - 'host_reachability' => 'flood', |
165 |
| - 'shutdown' => 'true', |
166 |
| - 'source_interface' => 'loopback88', |
| 54 | + manifest_props: { |
| 55 | + description: 'Puppet test', |
| 56 | + host_reachability: 'evpn', |
| 57 | + shutdown: 'false', |
| 58 | + source_interface: 'loopback55', |
| 59 | + source_interface_hold_down_time: '100', |
167 | 60 | },
|
168 | 61 | }
|
169 | 62 |
|
170 |
| -################################################################# |
171 |
| -# HELPER FUNCTIONS |
172 |
| -################################################################# |
173 |
| - |
174 |
| -# Full command string for puppet resource command |
175 |
| -def puppet_resource_cmd |
176 |
| - PUPPET_BINPATH + 'resource cisco_vxlan_vtep' |
| 63 | +def unsupported_properties(*) |
| 64 | + unprops = [] |
| 65 | + unprops << :source_interface_hold_down_time unless platform[/n(8|9)k/] |
| 66 | + unprops |
177 | 67 | end
|
178 | 68 |
|
179 |
| -def build_manifest_cisco_vxlan_vtep(tests, id) |
180 |
| - if tests[id][:ensure] == :absent |
181 |
| - state = 'ensure => absent,' |
182 |
| - tests[id][:resource] = {} |
183 |
| - else |
184 |
| - state = 'ensure => present,' |
185 |
| - manifest = tests[id][:manifest_props] |
186 |
| - tests[id][:resource] = tests[id][:resource_props] |
187 |
| - end |
188 |
| - |
189 |
| - tests[id][:title_pattern] = id if tests[id][:title_pattern].nil? |
190 |
| - logger.debug("build_manifest_cisco_vxlan_vtep :: title_pattern:\n" + |
191 |
| - tests[id][:title_pattern]) |
192 |
| - tests[id][:manifest] = "cat <<EOF >#{PUPPETMASTER_MANIFESTPATH} |
193 |
| - node 'default' { |
194 |
| - cisco_vxlan_vtep { '#{tests[id][:title_pattern]}': |
195 |
| - #{state} |
196 |
| - #{manifest} |
197 |
| - } |
198 |
| - } |
199 |
| -EOF" |
200 |
| -end |
201 |
| - |
202 |
| -def test_harness_cisco_vxlan_vtep(tests, id) |
203 |
| - return unless platform_supports_test(tests, id) |
204 |
| - |
205 |
| - tests[id][:ensure] = :present if tests[id][:ensure].nil? |
206 |
| - tests[id][:resource_cmd] = puppet_resource_cmd |
207 |
| - tests[id][:desc] += " [ensure => #{tests[id][:ensure]}]" |
208 |
| - |
209 |
| - # Build the manifest for this test |
210 |
| - build_manifest_cisco_vxlan_vtep(tests, id) |
211 |
| - |
212 |
| - test_manifest(tests, id) |
213 |
| - test_resource(tests, id) |
214 |
| - test_idempotence(tests, id) |
| 69 | +# Overridden to properly handle dependencies for this test file. |
| 70 | +def test_harness_dependencies(*) |
| 71 | + return unless platform[/n(5|6)k/] |
| 72 | + skip_if_nv_overlay_rejected(agent) |
215 | 73 |
|
216 |
| - tests[id][:ensure] = nil |
| 74 | + # Vxlan has a hard requirement to disable feature fabricpath on n5/6k |
| 75 | + cmd = 'no feature-set fabricpath' |
| 76 | + command_config(agent, cmd, cmd) |
217 | 77 | end
|
218 | 78 |
|
219 | 79 | #################################################################
|
220 | 80 | # TEST CASE EXECUTION
|
221 | 81 | #################################################################
|
222 |
| -test_name "TestCase :: #{testheader}" do |
| 82 | +test_name "TestCase :: #{tests[:resource_name]}" do |
223 | 83 | skip_unless_supported(tests)
|
224 | 84 |
|
225 |
| - # ------------------------------------------------------------------- |
226 |
| - logger.info("\n#{'-' * 60}\nSection 1. Default Property Testing") |
227 |
| - resource_absent_cleanup(agent, 'cisco_vxlan_vtep', |
228 |
| - 'Setup switch for cisco_vxlan_vtep provider test') |
229 |
| - |
230 | 85 | # -----------------------------------
|
231 |
| - id = 'default_properties' |
232 |
| - tests[id][:desc] = '1.1 Default Properties' |
233 |
| - test_harness_cisco_vxlan_vtep(tests, id) |
| 86 | + logger.info("\n#{'-' * 60}\nSection 1. Default Property Testing") |
| 87 | + id = :default |
| 88 | + test_harness_run(tests, id) |
234 | 89 |
|
235 |
| - tests[id][:desc] = '1.2 Default Properties' |
236 | 90 | tests[id][:ensure] = :absent
|
237 |
| - test_harness_cisco_vxlan_vtep(tests, id) |
| 91 | + tests[id].delete(:preclean) |
| 92 | + test_harness_run(tests, id) |
238 | 93 |
|
239 |
| - # ------------------------------------------------------------------- |
| 94 | + # ----------------------------------- |
240 | 95 | logger.info("\n#{'-' * 60}\nSection 2. Non Default Property Testing")
|
| 96 | + test_harness_run(tests, :non_default) |
241 | 97 |
|
242 |
| - id = 'non_default_properties' |
243 |
| - tests[id][:desc] = '2.1 Non-Default Properties' |
244 |
| - test_harness_cisco_vxlan_vtep(tests, id) |
245 |
| - |
246 |
| - tests[id][:desc] = '2.2 Non-Default Properties' |
247 |
| - tests[id][:ensure] = :absent |
248 |
| - test_harness_cisco_vxlan_vtep(tests, id) |
249 |
| - # ------------------------------------------------------------------- |
250 |
| - |
251 |
| - # ------------------------------------------------------------------- |
252 |
| - logger.info("\n#{'-' * 60}\nSection 3. Property Changes") |
253 |
| - |
254 |
| - id = 'non_default_properties' |
255 |
| - tests[id][:desc] = '3.1 Setup' |
256 |
| - test_harness_cisco_vxlan_vtep(tests, id) |
257 |
| - |
258 |
| - id = 'change_parameters' |
259 |
| - tests[id][:desc] = '3.1 Change host_reach, shutdown state, source int' |
260 |
| - test_harness_cisco_vxlan_vtep(tests, id) |
261 |
| - |
262 |
| - id = 'change_source_int_when_shutdown' |
263 |
| - tests[id][:desc] = '3.1 Change source_interface, shutdown state: true' |
264 |
| - test_harness_cisco_vxlan_vtep(tests, id) |
265 |
| - |
266 |
| - resource_absent_cleanup(agent, 'cisco_vxlan_vtep', |
267 |
| - 'Setup switch for cisco_vxlan_vtep provider test') |
| 98 | + resource_absent_cleanup(agent, 'cisco_vxlan_vtep') |
268 | 99 | end
|
269 |
| - |
270 |
| -logger.info('TestCase :: # {testheader} :: End') |
| 100 | +logger.info("TestCase :: #{tests[:resource_name]} :: End") |
0 commit comments