Skip to content

Commit 95dfdc1

Browse files
Merge pull request #313 from cisco/release_1.3.0
Convert test_vxlan_vtep to use new syntax
2 parents e31961a + 8068713 commit 95dfdc1

File tree

3 files changed

+62
-221
lines changed

3 files changed

+62
-221
lines changed

lib/puppet/provider/cisco_vxlan_vtep/cisco.rb

+1-2
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ def puts_config
148148
VXLAN_VTEP_ALL_PROPS.each do |prop|
149149
current.concat(sprintf("\n%30s: %s", prop, @vtep_interface.send(prop)))
150150
end
151-
# debug current
152-
puts current
151+
debug current
153152
end # puts_config
154153
end

tests/beaker_tests/cisco_vxlan_vtep/test_vxlan_vtep.rb

+49-219
Original file line numberDiff line numberDiff line change
@@ -13,258 +13,88 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
###############################################################################
16-
# TestCase Name:
17-
# -------------
18-
# test-cisco_vxlan_vtep.rb
1916
#
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
5322
#
5423
###############################################################################
55-
5624
require File.expand_path('../../lib/utilitylib.rb', __FILE__)
5725

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
7227
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',
11733
}
11834

119-
tests['non_default_properties'] = {
35+
# Test hash test cases
36+
tests[:default] = {
12037
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',
13245
},
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: {
15147
'host_reachability' => 'flood',
15248
'shutdown' => 'true',
153-
'source_interface' => 'loopback1',
15449
},
15550
}
15651

157-
tests['change_source_int_when_shutdown'] = {
52+
tests[:non_default] = {
15853
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',
16760
},
16861
}
16962

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
17767
end
17868

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)
21573

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)
21777
end
21878

21979
#################################################################
22080
# TEST CASE EXECUTION
22181
#################################################################
222-
test_name "TestCase :: #{testheader}" do
82+
test_name "TestCase :: #{tests[:resource_name]}" do
22383
skip_unless_supported(tests)
22484

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-
23085
# -----------------------------------
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)
23489

235-
tests[id][:desc] = '1.2 Default Properties'
23690
tests[id][:ensure] = :absent
237-
test_harness_cisco_vxlan_vtep(tests, id)
91+
tests[id].delete(:preclean)
92+
test_harness_run(tests, id)
23893

239-
# -------------------------------------------------------------------
94+
# -----------------------------------
24095
logger.info("\n#{'-' * 60}\nSection 2. Non Default Property Testing")
96+
test_harness_run(tests, :non_default)
24197

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')
26899
end
269-
270-
logger.info('TestCase :: # {testheader} :: End')
100+
logger.info("TestCase :: #{tests[:resource_name]} :: End")

tests/beaker_tests/lib/utilitylib.rb

+12
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,18 @@ def prereq_skip(testheader, testcase, message)
810810
raise_skip_exception(testheader, testcase)
811811
end
812812

813+
# Some specific platform models do not support nv_overlay
814+
def skip_if_nv_overlay_rejected(agent)
815+
logger.info('Check for nv overlay support')
816+
cmd = get_vshell_cmd('config t ; feature nv overlay')
817+
on(agent, cmd, pty: true)
818+
# Failure message taken from 6001
819+
msg = 'NVE Feature NOT supported on this Platform'
820+
banner = '#' * msg.length
821+
raise_skip_exception("\n#{banner}\n#{msg}\n#{banner}\n", self) if
822+
stdout.match(msg)
823+
end
824+
813825
# Return an interface name from the first MT-full compatible line module found
814826
def mt_full_interface
815827
# Search for F3 card on device, create an interface name if found

0 commit comments

Comments
 (0)