blob: 3d5fbc7ad0aca4861c9e23402f5deea959edd057 [file] [log] [blame]
Dennis Dmitriev2a498732018-12-21 18:30:23 +02001# Copyright 2016 Mirantis, Inc.
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13# under the License.
14
Dennis Dmitriev8565c342019-02-11 23:45:03 +020015import jenkins
Dennis Dmitriev2a498732018-12-21 18:30:23 +020016import pytest
Dennis Dmitriev8565c342019-02-11 23:45:03 +020017import os
Dennis Dmitriev2a498732018-12-21 18:30:23 +020018
19from tcp_tests import logger
20from tcp_tests import settings
21from tcp_tests.utils import run_jenkins_job
22from tcp_tests.utils import get_jenkins_job_stages
Dennis Dmitriev8565c342019-02-11 23:45:03 +020023from tcp_tests.utils import get_jenkins_job_artifact
Dennis Dmitriev2a498732018-12-21 18:30:23 +020024
25LOG = logger.logger
26
27
28class TestCvpPipelines(object):
29 """Test class for running Cloud Validation Pipelines
30
31 Requires environment variables:
32 ENV_NAME
33 LAB_CONFIG_NAME
34 TESTS_CONFIGS
35 """
36
37 @pytest.mark.grab_versions
38 @pytest.mark.parametrize("_", [settings.ENV_NAME])
39 @pytest.mark.run_cvp_func_smoke
40 def test_run_cvp_func_smoke(self, salt_actions, show_step, _):
41 """Runner for Pipeline CVP - Functional tests
42
43 Scenario:
44 1. Get CICD Jenkins access credentials from salt
45 2. Run job cvp-func
46 3. Get passed stages from cvp-func
47 """
48 salt = salt_actions
49 show_step(1)
50
51 tgt = 'I@docker:client:stack:jenkins and cid01*'
52 jenkins_host = salt.get_single_pillar(
53 tgt=tgt, pillar="jenkins:client:master:host")
54 jenkins_port = salt.get_single_pillar(
55 tgt=tgt, pillar="jenkins:client:master:port")
obutenkoca858402019-07-04 18:31:39 +030056 jenkins_protocol = salt.get_single_pillar(
57 tgt=tgt, pillar="jenkins:client:master:proto")
58 jenkins_url = '{0}://{1}:{2}'.format(jenkins_protocol,
59 jenkins_host,
60 jenkins_port)
Dennis Dmitriev2a498732018-12-21 18:30:23 +020061 jenkins_user = salt.get_single_pillar(
62 tgt=tgt, pillar="jenkins:client:master:username")
63 jenkins_pass = salt.get_single_pillar(
64 tgt=tgt, pillar="jenkins:client:master:password")
65 jenkins_start_timeout = 60
66 jenkins_build_timeout = 1800
67
68 job_name = 'cvp-func'
69 job_parameters = {
70 'TARGET_NODE': 'gtw01*',
71 'TEMPEST_ENDPOINT_TYPE': 'internalURL',
72 'TEMPEST_TEST_PATTERN': 'set=smoke',
73 }
74 show_step(2)
75 cvp_func_smoke_result = run_jenkins_job.run_job(
76 host=jenkins_url,
77 username=jenkins_user,
78 password=jenkins_pass,
79 start_timeout=jenkins_start_timeout,
80 build_timeout=jenkins_build_timeout,
81 verbose=True,
82 job_name=job_name,
83 job_parameters=job_parameters,
84 job_output_prefix='[ cvp-func/{build_number}:platform {time} ] ')
85
86 show_step(3)
87 (description, stages) = get_jenkins_job_stages.get_deployment_result(
88 host=jenkins_url,
89 username=jenkins_user,
90 password=jenkins_pass,
91 job_name=job_name,
92 build_number='lastBuild')
93
94 LOG.info(description)
95 LOG.info('\n'.join(stages))
96
97 assert cvp_func_smoke_result == 'SUCCESS', "{0}\n{1}".format(
98 description, '\n'.join(stages))
99
100 @pytest.mark.grab_versions
101 @pytest.mark.parametrize("_", [settings.ENV_NAME])
Hanna Arhipovadab7ba32020-06-23 13:32:28 +0300102 @pytest.mark.run_cvp_tempest
103 def test_run_cvp_tempest(
104 self,
105 salt_actions,
106 show_step,
107 drivetrain_actions,
108 tempest_actions, _):
109 """Runner for Pipeline CVP - Tempest tests
110
111 Scenario:
112 1. Sync time on the environment nodes
113 2. Execute pre-requites for Tempest
114 3. Run cvp-tempest Jenkins job and get results
115 4. Download Tempest xml report from Jenkins node to foundation
116 node
117
118 """
119 salt = salt_actions
120 dt = drivetrain_actions
121 jenkins_start_timeout = 60
122 jenkins_build_timeout = 6 * 60 * 60
Hanna Arhipova653d5562020-08-03 15:32:09 +0300123 cluster_name = settings.ENV_NAME
124 skiplist_file = "tcp_tests/templates/{}/tempest_skip.list".\
125 format(cluster_name)
Hanna Arhipovadab7ba32020-06-23 13:32:28 +0300126
127 show_step(1)
128 salt.sync_time()
129
130 show_step(2)
131 tempest_actions.prepare(pipeline=True)
Hanna Arhipova653d5562020-08-03 15:32:09 +0300132 # Copy skip list to cfg node
133 skiplist = open(skiplist_file, 'r').read() or ""
134 salt.file_makedirs(tgt="I@salt:master", path="/usr/share/tempest")
135 salt.file_write(tgt="I@salt:master",
136 filename="/usr/share/tempest/skip.list",
137 content=skiplist)
Hanna Arhipovadab7ba32020-06-23 13:32:28 +0300138
139 show_step(3)
140 job_name = 'cvp-tempest'
141 job_parameters = {
Hanna Arhipova653d5562020-08-03 15:32:09 +0300142 'EXTRA_PARAMS': """
143---
144 DEBUG_MODE: false
145 GENERATE_CONFIG: true
146 SKIP_LIST_PATH: /usr/share/tempest/skip.list
147 report_prefix: "cvp_"
148 """,
Hanna Arhipovadab7ba32020-06-23 13:32:28 +0300149 'TEMPEST_ENDPOINT_TYPE': 'internalURL',
150 'TEMPEST_TEST_PATTERN': 'set=full',
151 }
152 cvp_tempest_result = dt.start_job_on_jenkins(
153 job_name,
154 jenkins_tgt='I@docker:client:stack:jenkins and I@salt:master',
155 start_timeout=jenkins_start_timeout,
156 build_timeout=jenkins_build_timeout,
157 verbose=True,
158 job_parameters=job_parameters,
159 job_output_prefix='[ {job_name}/{build_number}:platform {time} ] ')
160 LOG.info('Job {0} result: {1}'.format(job_name, cvp_tempest_result))
161
162 show_step(4)
163 tempest_actions.fetch_arficats(
164 username='root', report_dir="/root/test/")
165
166 @pytest.mark.grab_versions
167 @pytest.mark.parametrize("_", [settings.ENV_NAME])
Dennis Dmitriev2a498732018-12-21 18:30:23 +0200168 @pytest.mark.run_cvp_func_sanity
169 def test_run_cvp_func_sanity(self, salt_actions, show_step, _):
170 """Runner for Pipeline CVP - Functional tests
171
172 Scenario:
173 1. Get CICD Jenkins access credentials from salt
174 2. Run job cvp-sanity
175 3. Get passed stages from cvp-sanity
Dennis Dmitriev8565c342019-02-11 23:45:03 +0200176 4. Download XML report from the job
Dennis Dmitriev2a498732018-12-21 18:30:23 +0200177 """
178 salt = salt_actions
179 show_step(1)
180
181 tgt = 'I@docker:client:stack:jenkins and cid01*'
182 jenkins_host = salt.get_single_pillar(
183 tgt=tgt, pillar="jenkins:client:master:host")
184 jenkins_port = salt.get_single_pillar(
185 tgt=tgt, pillar="jenkins:client:master:port")
obutenkoca858402019-07-04 18:31:39 +0300186 jenkins_protocol = salt.get_single_pillar(
187 tgt=tgt, pillar="jenkins:client:master:proto")
188 jenkins_url = '{0}://{1}:{2}'.format(jenkins_protocol,
189 jenkins_host,
190 jenkins_port)
Dennis Dmitriev2a498732018-12-21 18:30:23 +0200191 jenkins_user = salt.get_single_pillar(
192 tgt=tgt, pillar="jenkins:client:master:username")
193 jenkins_pass = salt.get_single_pillar(
194 tgt=tgt, pillar="jenkins:client:master:password")
195 jenkins_start_timeout = 60
196 jenkins_build_timeout = 1800
197
Dennis Dmitriev85c52492019-03-12 15:26:56 +0200198 try:
199 maas_minion_id = salt.get_single_pillar(
200 tgt='I@maas:cluster or I@maas:region',
201 pillar="__reclass__:nodename")
Oleksii Zhurba04302d42019-05-30 09:56:21 -0500202 ntp_skipped_nodes = '{0}'.format(maas_minion_id)
Dennis Dmitriev85c52492019-03-12 15:26:56 +0200203 except LookupError:
204 ntp_skipped_nodes = ''
Dennis Dmitrieva51b89d2019-03-05 21:49:07 +0200205
Dennis Dmitriev2a498732018-12-21 18:30:23 +0200206 job_name = 'cvp-sanity'
Tatyana Leontovicha090c5a2019-05-17 02:07:28 +0300207 skipped_packages = ("python-setuptools,"
208 "python-pkg-resources,xunitmerge,"
209 "python-gnocchiclient, "
210 "python-ujson,python-octaviaclient")
211
Dennis Dmitriev2a498732018-12-21 18:30:23 +0200212 job_parameters = {
Tatyana Leontovicha090c5a2019-05-17 02:07:28 +0300213 'EXTRA_PARAMS': (
214 """
215 envs:
216 - skipped_packages='{0}'
217 - skipped_modules='xunitmerge,setuptools'
218 - skipped_services='docker,containerd'
Oleksii Zhurba04302d42019-05-30 09:56:21 -0500219 - ntp_skipped_nodes='{1}'"""
Tatyana Leontovicha090c5a2019-05-17 02:07:28 +0300220 .format(skipped_packages, ntp_skipped_nodes)),
Dennis Dmitriev2a498732018-12-21 18:30:23 +0200221 }
222
223 show_step(2)
224 cvp_func_sanity_result = run_jenkins_job.run_job(
225 host=jenkins_url,
226 username=jenkins_user,
227 password=jenkins_pass,
228 start_timeout=jenkins_start_timeout,
229 build_timeout=jenkins_build_timeout,
230 verbose=True,
231 job_name=job_name,
232 job_parameters=job_parameters,
233 job_output_prefix='[ cvp-func/{build_number}:platform {time} ] ')
234
235 show_step(3)
236 (description, stages) = get_jenkins_job_stages.get_deployment_result(
237 host=jenkins_url,
238 username=jenkins_user,
239 password=jenkins_pass,
240 job_name=job_name,
241 build_number='lastBuild')
242
243 LOG.info(description)
244 LOG.info('\n'.join(stages))
Dennis Dmitriev8565c342019-02-11 23:45:03 +0200245 LOG.info('Job {0} result: {1}'.format(job_name,
246 cvp_func_sanity_result))
247 # Download XML report
248 show_step(4)
249 destination_name = os.path.join(settings.LOGS_DIR,
250 "cvp_sanity_results.xml")
251 # Do not fail the test case when the job is failed, but
252 # artifact with the XML report is present in the job.
253 try:
254 get_jenkins_job_artifact.download_artifact(
255 host=jenkins_url,
256 username=jenkins_user,
257 password=jenkins_pass,
258 job_name=job_name,
259 build_number='lastBuild',
260 artifact_path='validation_artifacts/cvp-sanity_report.xml',
261 destination_name=destination_name)
262 except jenkins.NotFoundException:
263 raise jenkins.NotFoundException("{0}\n{1}".format(
264 description, '\n'.join(stages)))
Dennis Dmitriev1566e3f2019-01-11 17:35:43 +0200265
266 @pytest.mark.grab_versions
267 @pytest.mark.parametrize("_", [settings.ENV_NAME])
268 @pytest.mark.run_cvp_ha_smoke
269 def test_run_cvp_ha_smoke(self, underlay_actions, salt_actions,
270 show_step, _):
271 """Runner for Pipeline CVP - HA tests
272
273 Scenario:
274 1. Get CICD Jenkins access credentials from salt
275 2. Run job cvp-ha with tempest set=smoke
276 3. Get passed stages from cvp-ha
277 """
278 salt = salt_actions
279 show_step(1)
280
281 tgt = 'I@docker:client:stack:jenkins and cid01*'
282 jenkins_host = salt.get_single_pillar(
283 tgt=tgt, pillar="jenkins:client:master:host")
284 jenkins_port = salt.get_single_pillar(
285 tgt=tgt, pillar="jenkins:client:master:port")
obutenkoca858402019-07-04 18:31:39 +0300286 jenkins_protocol = salt.get_single_pillar(
287 tgt=tgt, pillar="jenkins:client:master:proto")
288 jenkins_url = '{0}://{1}:{2}'.format(jenkins_protocol,
289 jenkins_host,
290 jenkins_port)
Dennis Dmitriev1566e3f2019-01-11 17:35:43 +0200291 jenkins_user = salt.get_single_pillar(
292 tgt=tgt, pillar="jenkins:client:master:username")
293 jenkins_pass = salt.get_single_pillar(
294 tgt=tgt, pillar="jenkins:client:master:password")
295 jenkins_start_timeout = 60
296 jenkins_build_timeout = 1800
297
298 tempest_target_node = salt.get_single_pillar(
299 tgt='cfg01*',
300 pillar="runtest:tempest:test_target")
301
302 job_name = 'cvp-ha'
303 job_parameters = {
304 'TEMPEST_TARGET_NODE': tempest_target_node,
305 'TEMPEST_TEST_PATTERN': 'set=smoke',
306 }
307
308 show_step(2)
309 cvp_ha_smoke_result = run_jenkins_job.run_job(
310 host=jenkins_url,
311 username=jenkins_user,
312 password=jenkins_pass,
313 start_timeout=jenkins_start_timeout,
314 build_timeout=jenkins_build_timeout,
315 verbose=True,
316 job_name=job_name,
317 job_parameters=job_parameters,
318 job_output_prefix='[ cvp-ha/{build_number} {time} ] ')
319
320 show_step(3)
321 (description, stages) = get_jenkins_job_stages.get_deployment_result(
322 host=jenkins_url,
323 username=jenkins_user,
324 password=jenkins_pass,
325 job_name=job_name,
326 build_number='lastBuild')
327
328 LOG.info(description)
329 LOG.info('\n'.join(stages))
330
331 assert cvp_ha_smoke_result == 'SUCCESS', "{0}\n{1}".format(
332 description, '\n'.join(stages))
Oleksii Zhurba1d547c12019-05-13 17:42:42 -0500333
334 @pytest.mark.grab_versions
335 @pytest.mark.parametrize("_", [settings.ENV_NAME])
336 @pytest.mark.run_stacklight
337 def test_run_cvp_stacklight(self, salt_actions, show_step, _):
338 """Runner for Pipeline CVP - Stacklight
339
340 Scenario:
341 1. Get CICD Jenkins access credentials from salt
342 2. Run job cvp-stacklight
343 3. Get passed stages from cvp-stacklight
344 4. Download XML report from the job
345 """
346 salt = salt_actions
347 show_step(1)
348
349 tgt = 'I@docker:client:stack:jenkins and cid01*'
350 jenkins_host = salt.get_single_pillar(
351 tgt=tgt, pillar="jenkins:client:master:host")
352 jenkins_port = salt.get_single_pillar(
353 tgt=tgt, pillar="jenkins:client:master:port")
obutenkoca858402019-07-04 18:31:39 +0300354 jenkins_protocol = salt.get_single_pillar(
355 tgt=tgt, pillar="jenkins:client:master:proto")
356 jenkins_url = '{0}://{1}:{2}'.format(jenkins_protocol,
357 jenkins_host,
358 jenkins_port)
Oleksii Zhurba1d547c12019-05-13 17:42:42 -0500359 jenkins_user = salt.get_single_pillar(
360 tgt=tgt, pillar="jenkins:client:master:username")
361 jenkins_pass = salt.get_single_pillar(
362 tgt=tgt, pillar="jenkins:client:master:password")
Hanna Arhipova81af8332019-10-28 14:33:06 +0200363 cirros_image = salt.get_single_pillar(
364 tgt="I@salt:master",
365 pillar="_param:glance_image_cirros_location")
Oleksii Zhurba1d547c12019-05-13 17:42:42 -0500366 jenkins_start_timeout = 60
Hanna Arhipova81af8332019-10-28 14:33:06 +0200367 jenkins_build_timeout = 50 * 60
Oleksii Zhurba1d547c12019-05-13 17:42:42 -0500368
369 job_name = 'cvp-stacklight'
Hanna Arhipova81af8332019-10-28 14:33:06 +0200370 job_parameters = {
371 "EXTRA_PARAMS": """
372 envs:
373 - SL_AUTOCONF=True
374 - CIRROS_QCOW2_URL={image}
375 """.format(image=cirros_image)
376 }
Oleksii Zhurba1d547c12019-05-13 17:42:42 -0500377
378 show_step(2)
379 cvp_stacklight_result = run_jenkins_job.run_job(
380 host=jenkins_url,
381 username=jenkins_user,
382 password=jenkins_pass,
383 start_timeout=jenkins_start_timeout,
384 build_timeout=jenkins_build_timeout,
385 verbose=True,
386 job_name=job_name,
Hanna Arhipova81af8332019-10-28 14:33:06 +0200387 job_parameters=job_parameters,
Oleksii Zhurba1d547c12019-05-13 17:42:42 -0500388 job_output_prefix='[cvp-stacklight/{build_number}:platform {time}]'
389 )
390
391 show_step(3)
392 (description, stages) = get_jenkins_job_stages.get_deployment_result(
393 host=jenkins_url,
394 username=jenkins_user,
395 password=jenkins_pass,
396 job_name=job_name,
397 build_number='lastBuild')
398
399 LOG.info(description)
400 LOG.info('\n'.join(stages))
401 LOG.info('Job {0} result: {1}'.format(job_name,
402 cvp_stacklight_result))
403 # Download XML report
404 show_step(4)
405 destination_name = os.path.join(settings.LOGS_DIR,
406 "stacklight_report.xml")
407 # Do not fail the test case when the job is failed, but
408 # artifact with the XML report is present in the job.
409 try:
410 get_jenkins_job_artifact.download_artifact(
411 host=jenkins_url,
412 username=jenkins_user,
413 password=jenkins_pass,
414 job_name=job_name,
415 build_number='lastBuild',
416 artifact_path='validation_artifacts/cvp-stacklight_report.xml',
417 destination_name=destination_name)
418 except jenkins.NotFoundException:
419 raise jenkins.NotFoundException("{0}\n{1}".format(
420 description, '\n'.join(stages)))