blob: 1523c48e30dcf6f977c3270176f74900aec98fe7 [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
Hanna Arhipova7cd2c2c2020-09-10 08:20:50 +0300124 tempest_pattern = settings.TEMPEST_PATTERN
Hanna Arhipova653d5562020-08-03 15:32:09 +0300125 skiplist_file = "tcp_tests/templates/{}/tempest_skip.list".\
126 format(cluster_name)
Hanna Arhipovadab7ba32020-06-23 13:32:28 +0300127
128 show_step(1)
129 salt.sync_time()
130
131 show_step(2)
132 tempest_actions.prepare(pipeline=True)
Hanna Arhipova653d5562020-08-03 15:32:09 +0300133 # Copy skip list to cfg node
134 skiplist = open(skiplist_file, 'r').read() or ""
135 salt.file_makedirs(tgt="I@salt:master", path="/usr/share/tempest")
136 salt.file_write(tgt="I@salt:master",
137 filename="/usr/share/tempest/skip.list",
138 content=skiplist)
Hanna Arhipovadab7ba32020-06-23 13:32:28 +0300139
140 show_step(3)
141 job_name = 'cvp-tempest'
142 job_parameters = {
Hanna Arhipova653d5562020-08-03 15:32:09 +0300143 'EXTRA_PARAMS': """
144---
145 DEBUG_MODE: false
146 GENERATE_CONFIG: true
147 SKIP_LIST_PATH: /usr/share/tempest/skip.list
148 report_prefix: "cvp_"
Hanna Arhipova4ce82fb2020-11-11 16:35:55 +0200149 concurrency: {concurrency}
150 """.format(concurrency=settings.TEMPEST_THREADS),
151
Hanna Arhipovadab7ba32020-06-23 13:32:28 +0300152 'TEMPEST_ENDPOINT_TYPE': 'internalURL',
Hanna Arhipova7cd2c2c2020-09-10 08:20:50 +0300153 'TEMPEST_TEST_PATTERN': tempest_pattern,
Hanna Arhipovadab7ba32020-06-23 13:32:28 +0300154 }
155 cvp_tempest_result = dt.start_job_on_jenkins(
156 job_name,
157 jenkins_tgt='I@docker:client:stack:jenkins and I@salt:master',
158 start_timeout=jenkins_start_timeout,
159 build_timeout=jenkins_build_timeout,
160 verbose=True,
161 job_parameters=job_parameters,
162 job_output_prefix='[ {job_name}/{build_number}:platform {time} ] ')
163 LOG.info('Job {0} result: {1}'.format(job_name, cvp_tempest_result))
164
165 show_step(4)
166 tempest_actions.fetch_arficats(
167 username='root', report_dir="/root/test/")
168
169 @pytest.mark.grab_versions
170 @pytest.mark.parametrize("_", [settings.ENV_NAME])
Dennis Dmitriev2a498732018-12-21 18:30:23 +0200171 @pytest.mark.run_cvp_func_sanity
172 def test_run_cvp_func_sanity(self, salt_actions, show_step, _):
173 """Runner for Pipeline CVP - Functional tests
174
175 Scenario:
176 1. Get CICD Jenkins access credentials from salt
177 2. Run job cvp-sanity
178 3. Get passed stages from cvp-sanity
Dennis Dmitriev8565c342019-02-11 23:45:03 +0200179 4. Download XML report from the job
Dennis Dmitriev2a498732018-12-21 18:30:23 +0200180 """
181 salt = salt_actions
182 show_step(1)
183
184 tgt = 'I@docker:client:stack:jenkins and cid01*'
185 jenkins_host = salt.get_single_pillar(
186 tgt=tgt, pillar="jenkins:client:master:host")
187 jenkins_port = salt.get_single_pillar(
188 tgt=tgt, pillar="jenkins:client:master:port")
obutenkoca858402019-07-04 18:31:39 +0300189 jenkins_protocol = salt.get_single_pillar(
190 tgt=tgt, pillar="jenkins:client:master:proto")
191 jenkins_url = '{0}://{1}:{2}'.format(jenkins_protocol,
192 jenkins_host,
193 jenkins_port)
Dennis Dmitriev2a498732018-12-21 18:30:23 +0200194 jenkins_user = salt.get_single_pillar(
195 tgt=tgt, pillar="jenkins:client:master:username")
196 jenkins_pass = salt.get_single_pillar(
197 tgt=tgt, pillar="jenkins:client:master:password")
198 jenkins_start_timeout = 60
199 jenkins_build_timeout = 1800
200
Dennis Dmitriev85c52492019-03-12 15:26:56 +0200201 try:
202 maas_minion_id = salt.get_single_pillar(
203 tgt='I@maas:cluster or I@maas:region',
204 pillar="__reclass__:nodename")
Oleksii Zhurba04302d42019-05-30 09:56:21 -0500205 ntp_skipped_nodes = '{0}'.format(maas_minion_id)
Dennis Dmitriev85c52492019-03-12 15:26:56 +0200206 except LookupError:
207 ntp_skipped_nodes = ''
Dennis Dmitrieva51b89d2019-03-05 21:49:07 +0200208
Dennis Dmitriev2a498732018-12-21 18:30:23 +0200209 job_name = 'cvp-sanity'
Tatyana Leontovicha090c5a2019-05-17 02:07:28 +0300210 skipped_packages = ("python-setuptools,"
211 "python-pkg-resources,xunitmerge,"
212 "python-gnocchiclient, "
213 "python-ujson,python-octaviaclient")
214
Dennis Dmitriev2a498732018-12-21 18:30:23 +0200215 job_parameters = {
Tatyana Leontovicha090c5a2019-05-17 02:07:28 +0300216 'EXTRA_PARAMS': (
217 """
218 envs:
219 - skipped_packages='{0}'
220 - skipped_modules='xunitmerge,setuptools'
221 - skipped_services='docker,containerd'
Oleksii Zhurba04302d42019-05-30 09:56:21 -0500222 - ntp_skipped_nodes='{1}'"""
Tatyana Leontovicha090c5a2019-05-17 02:07:28 +0300223 .format(skipped_packages, ntp_skipped_nodes)),
Dennis Dmitriev2a498732018-12-21 18:30:23 +0200224 }
225
226 show_step(2)
227 cvp_func_sanity_result = run_jenkins_job.run_job(
228 host=jenkins_url,
229 username=jenkins_user,
230 password=jenkins_pass,
231 start_timeout=jenkins_start_timeout,
232 build_timeout=jenkins_build_timeout,
233 verbose=True,
234 job_name=job_name,
235 job_parameters=job_parameters,
236 job_output_prefix='[ cvp-func/{build_number}:platform {time} ] ')
237
238 show_step(3)
239 (description, stages) = get_jenkins_job_stages.get_deployment_result(
240 host=jenkins_url,
241 username=jenkins_user,
242 password=jenkins_pass,
243 job_name=job_name,
244 build_number='lastBuild')
245
246 LOG.info(description)
247 LOG.info('\n'.join(stages))
Dennis Dmitriev8565c342019-02-11 23:45:03 +0200248 LOG.info('Job {0} result: {1}'.format(job_name,
249 cvp_func_sanity_result))
250 # Download XML report
251 show_step(4)
252 destination_name = os.path.join(settings.LOGS_DIR,
253 "cvp_sanity_results.xml")
254 # Do not fail the test case when the job is failed, but
255 # artifact with the XML report is present in the job.
256 try:
257 get_jenkins_job_artifact.download_artifact(
258 host=jenkins_url,
259 username=jenkins_user,
260 password=jenkins_pass,
261 job_name=job_name,
262 build_number='lastBuild',
263 artifact_path='validation_artifacts/cvp-sanity_report.xml',
264 destination_name=destination_name)
265 except jenkins.NotFoundException:
266 raise jenkins.NotFoundException("{0}\n{1}".format(
267 description, '\n'.join(stages)))
Dennis Dmitriev1566e3f2019-01-11 17:35:43 +0200268
269 @pytest.mark.grab_versions
270 @pytest.mark.parametrize("_", [settings.ENV_NAME])
271 @pytest.mark.run_cvp_ha_smoke
272 def test_run_cvp_ha_smoke(self, underlay_actions, salt_actions,
273 show_step, _):
274 """Runner for Pipeline CVP - HA tests
275
276 Scenario:
277 1. Get CICD Jenkins access credentials from salt
278 2. Run job cvp-ha with tempest set=smoke
279 3. Get passed stages from cvp-ha
280 """
281 salt = salt_actions
282 show_step(1)
283
284 tgt = 'I@docker:client:stack:jenkins and cid01*'
285 jenkins_host = salt.get_single_pillar(
286 tgt=tgt, pillar="jenkins:client:master:host")
287 jenkins_port = salt.get_single_pillar(
288 tgt=tgt, pillar="jenkins:client:master:port")
obutenkoca858402019-07-04 18:31:39 +0300289 jenkins_protocol = salt.get_single_pillar(
290 tgt=tgt, pillar="jenkins:client:master:proto")
291 jenkins_url = '{0}://{1}:{2}'.format(jenkins_protocol,
292 jenkins_host,
293 jenkins_port)
Dennis Dmitriev1566e3f2019-01-11 17:35:43 +0200294 jenkins_user = salt.get_single_pillar(
295 tgt=tgt, pillar="jenkins:client:master:username")
296 jenkins_pass = salt.get_single_pillar(
297 tgt=tgt, pillar="jenkins:client:master:password")
298 jenkins_start_timeout = 60
299 jenkins_build_timeout = 1800
300
301 tempest_target_node = salt.get_single_pillar(
302 tgt='cfg01*',
303 pillar="runtest:tempest:test_target")
304
305 job_name = 'cvp-ha'
306 job_parameters = {
307 'TEMPEST_TARGET_NODE': tempest_target_node,
308 'TEMPEST_TEST_PATTERN': 'set=smoke',
309 }
310
311 show_step(2)
312 cvp_ha_smoke_result = run_jenkins_job.run_job(
313 host=jenkins_url,
314 username=jenkins_user,
315 password=jenkins_pass,
316 start_timeout=jenkins_start_timeout,
317 build_timeout=jenkins_build_timeout,
318 verbose=True,
319 job_name=job_name,
320 job_parameters=job_parameters,
321 job_output_prefix='[ cvp-ha/{build_number} {time} ] ')
322
323 show_step(3)
324 (description, stages) = get_jenkins_job_stages.get_deployment_result(
325 host=jenkins_url,
326 username=jenkins_user,
327 password=jenkins_pass,
328 job_name=job_name,
329 build_number='lastBuild')
330
331 LOG.info(description)
332 LOG.info('\n'.join(stages))
333
334 assert cvp_ha_smoke_result == 'SUCCESS', "{0}\n{1}".format(
335 description, '\n'.join(stages))
Oleksii Zhurba1d547c12019-05-13 17:42:42 -0500336
337 @pytest.mark.grab_versions
338 @pytest.mark.parametrize("_", [settings.ENV_NAME])
339 @pytest.mark.run_stacklight
340 def test_run_cvp_stacklight(self, salt_actions, show_step, _):
341 """Runner for Pipeline CVP - Stacklight
342
343 Scenario:
344 1. Get CICD Jenkins access credentials from salt
345 2. Run job cvp-stacklight
346 3. Get passed stages from cvp-stacklight
347 4. Download XML report from the job
348 """
349 salt = salt_actions
350 show_step(1)
351
352 tgt = 'I@docker:client:stack:jenkins and cid01*'
353 jenkins_host = salt.get_single_pillar(
354 tgt=tgt, pillar="jenkins:client:master:host")
355 jenkins_port = salt.get_single_pillar(
356 tgt=tgt, pillar="jenkins:client:master:port")
obutenkoca858402019-07-04 18:31:39 +0300357 jenkins_protocol = salt.get_single_pillar(
358 tgt=tgt, pillar="jenkins:client:master:proto")
359 jenkins_url = '{0}://{1}:{2}'.format(jenkins_protocol,
360 jenkins_host,
361 jenkins_port)
Oleksii Zhurba1d547c12019-05-13 17:42:42 -0500362 jenkins_user = salt.get_single_pillar(
363 tgt=tgt, pillar="jenkins:client:master:username")
364 jenkins_pass = salt.get_single_pillar(
365 tgt=tgt, pillar="jenkins:client:master:password")
Hanna Arhipova81af8332019-10-28 14:33:06 +0200366 cirros_image = salt.get_single_pillar(
367 tgt="I@salt:master",
368 pillar="_param:glance_image_cirros_location")
Oleksii Zhurba1d547c12019-05-13 17:42:42 -0500369 jenkins_start_timeout = 60
Hanna Arhipova81af8332019-10-28 14:33:06 +0200370 jenkins_build_timeout = 50 * 60
Oleksii Zhurba1d547c12019-05-13 17:42:42 -0500371
372 job_name = 'cvp-stacklight'
Hanna Arhipova81af8332019-10-28 14:33:06 +0200373 job_parameters = {
374 "EXTRA_PARAMS": """
375 envs:
376 - SL_AUTOCONF=True
377 - CIRROS_QCOW2_URL={image}
378 """.format(image=cirros_image)
379 }
Oleksii Zhurba1d547c12019-05-13 17:42:42 -0500380
381 show_step(2)
382 cvp_stacklight_result = run_jenkins_job.run_job(
383 host=jenkins_url,
384 username=jenkins_user,
385 password=jenkins_pass,
386 start_timeout=jenkins_start_timeout,
387 build_timeout=jenkins_build_timeout,
388 verbose=True,
389 job_name=job_name,
Hanna Arhipova81af8332019-10-28 14:33:06 +0200390 job_parameters=job_parameters,
Oleksii Zhurba1d547c12019-05-13 17:42:42 -0500391 job_output_prefix='[cvp-stacklight/{build_number}:platform {time}]'
392 )
393
394 show_step(3)
395 (description, stages) = get_jenkins_job_stages.get_deployment_result(
396 host=jenkins_url,
397 username=jenkins_user,
398 password=jenkins_pass,
399 job_name=job_name,
400 build_number='lastBuild')
401
402 LOG.info(description)
403 LOG.info('\n'.join(stages))
404 LOG.info('Job {0} result: {1}'.format(job_name,
405 cvp_stacklight_result))
406 # Download XML report
407 show_step(4)
408 destination_name = os.path.join(settings.LOGS_DIR,
409 "stacklight_report.xml")
410 # Do not fail the test case when the job is failed, but
411 # artifact with the XML report is present in the job.
412 try:
413 get_jenkins_job_artifact.download_artifact(
414 host=jenkins_url,
415 username=jenkins_user,
416 password=jenkins_pass,
417 job_name=job_name,
418 build_number='lastBuild',
419 artifact_path='validation_artifacts/cvp-stacklight_report.xml',
420 destination_name=destination_name)
421 except jenkins.NotFoundException:
422 raise jenkins.NotFoundException("{0}\n{1}".format(
423 description, '\n'.join(stages)))