blob: 4597e54f367113efaededad1e65d6cdfa42e53a2 [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_"
149 """,
Hanna Arhipovadab7ba32020-06-23 13:32:28 +0300150 'TEMPEST_ENDPOINT_TYPE': 'internalURL',
Hanna Arhipova7cd2c2c2020-09-10 08:20:50 +0300151 'TEMPEST_TEST_PATTERN': tempest_pattern,
Hanna Arhipovadab7ba32020-06-23 13:32:28 +0300152 }
153 cvp_tempest_result = dt.start_job_on_jenkins(
154 job_name,
155 jenkins_tgt='I@docker:client:stack:jenkins and I@salt:master',
156 start_timeout=jenkins_start_timeout,
157 build_timeout=jenkins_build_timeout,
158 verbose=True,
159 job_parameters=job_parameters,
160 job_output_prefix='[ {job_name}/{build_number}:platform {time} ] ')
161 LOG.info('Job {0} result: {1}'.format(job_name, cvp_tempest_result))
162
163 show_step(4)
164 tempest_actions.fetch_arficats(
165 username='root', report_dir="/root/test/")
166
167 @pytest.mark.grab_versions
168 @pytest.mark.parametrize("_", [settings.ENV_NAME])
Dennis Dmitriev2a498732018-12-21 18:30:23 +0200169 @pytest.mark.run_cvp_func_sanity
170 def test_run_cvp_func_sanity(self, salt_actions, show_step, _):
171 """Runner for Pipeline CVP - Functional tests
172
173 Scenario:
174 1. Get CICD Jenkins access credentials from salt
175 2. Run job cvp-sanity
176 3. Get passed stages from cvp-sanity
Dennis Dmitriev8565c342019-02-11 23:45:03 +0200177 4. Download XML report from the job
Dennis Dmitriev2a498732018-12-21 18:30:23 +0200178 """
179 salt = salt_actions
180 show_step(1)
181
182 tgt = 'I@docker:client:stack:jenkins and cid01*'
183 jenkins_host = salt.get_single_pillar(
184 tgt=tgt, pillar="jenkins:client:master:host")
185 jenkins_port = salt.get_single_pillar(
186 tgt=tgt, pillar="jenkins:client:master:port")
obutenkoca858402019-07-04 18:31:39 +0300187 jenkins_protocol = salt.get_single_pillar(
188 tgt=tgt, pillar="jenkins:client:master:proto")
189 jenkins_url = '{0}://{1}:{2}'.format(jenkins_protocol,
190 jenkins_host,
191 jenkins_port)
Dennis Dmitriev2a498732018-12-21 18:30:23 +0200192 jenkins_user = salt.get_single_pillar(
193 tgt=tgt, pillar="jenkins:client:master:username")
194 jenkins_pass = salt.get_single_pillar(
195 tgt=tgt, pillar="jenkins:client:master:password")
196 jenkins_start_timeout = 60
197 jenkins_build_timeout = 1800
198
Dennis Dmitriev85c52492019-03-12 15:26:56 +0200199 try:
200 maas_minion_id = salt.get_single_pillar(
201 tgt='I@maas:cluster or I@maas:region',
202 pillar="__reclass__:nodename")
Oleksii Zhurba04302d42019-05-30 09:56:21 -0500203 ntp_skipped_nodes = '{0}'.format(maas_minion_id)
Dennis Dmitriev85c52492019-03-12 15:26:56 +0200204 except LookupError:
205 ntp_skipped_nodes = ''
Dennis Dmitrieva51b89d2019-03-05 21:49:07 +0200206
Dennis Dmitriev2a498732018-12-21 18:30:23 +0200207 job_name = 'cvp-sanity'
Tatyana Leontovicha090c5a2019-05-17 02:07:28 +0300208 skipped_packages = ("python-setuptools,"
209 "python-pkg-resources,xunitmerge,"
210 "python-gnocchiclient, "
211 "python-ujson,python-octaviaclient")
212
Dennis Dmitriev2a498732018-12-21 18:30:23 +0200213 job_parameters = {
Tatyana Leontovicha090c5a2019-05-17 02:07:28 +0300214 'EXTRA_PARAMS': (
215 """
216 envs:
217 - skipped_packages='{0}'
218 - skipped_modules='xunitmerge,setuptools'
219 - skipped_services='docker,containerd'
Oleksii Zhurba04302d42019-05-30 09:56:21 -0500220 - ntp_skipped_nodes='{1}'"""
Tatyana Leontovicha090c5a2019-05-17 02:07:28 +0300221 .format(skipped_packages, ntp_skipped_nodes)),
Dennis Dmitriev2a498732018-12-21 18:30:23 +0200222 }
223
224 show_step(2)
225 cvp_func_sanity_result = run_jenkins_job.run_job(
226 host=jenkins_url,
227 username=jenkins_user,
228 password=jenkins_pass,
229 start_timeout=jenkins_start_timeout,
230 build_timeout=jenkins_build_timeout,
231 verbose=True,
232 job_name=job_name,
233 job_parameters=job_parameters,
234 job_output_prefix='[ cvp-func/{build_number}:platform {time} ] ')
235
236 show_step(3)
237 (description, stages) = get_jenkins_job_stages.get_deployment_result(
238 host=jenkins_url,
239 username=jenkins_user,
240 password=jenkins_pass,
241 job_name=job_name,
242 build_number='lastBuild')
243
244 LOG.info(description)
245 LOG.info('\n'.join(stages))
Dennis Dmitriev8565c342019-02-11 23:45:03 +0200246 LOG.info('Job {0} result: {1}'.format(job_name,
247 cvp_func_sanity_result))
248 # Download XML report
249 show_step(4)
250 destination_name = os.path.join(settings.LOGS_DIR,
251 "cvp_sanity_results.xml")
252 # Do not fail the test case when the job is failed, but
253 # artifact with the XML report is present in the job.
254 try:
255 get_jenkins_job_artifact.download_artifact(
256 host=jenkins_url,
257 username=jenkins_user,
258 password=jenkins_pass,
259 job_name=job_name,
260 build_number='lastBuild',
261 artifact_path='validation_artifacts/cvp-sanity_report.xml',
262 destination_name=destination_name)
263 except jenkins.NotFoundException:
264 raise jenkins.NotFoundException("{0}\n{1}".format(
265 description, '\n'.join(stages)))
Dennis Dmitriev1566e3f2019-01-11 17:35:43 +0200266
267 @pytest.mark.grab_versions
268 @pytest.mark.parametrize("_", [settings.ENV_NAME])
269 @pytest.mark.run_cvp_ha_smoke
270 def test_run_cvp_ha_smoke(self, underlay_actions, salt_actions,
271 show_step, _):
272 """Runner for Pipeline CVP - HA tests
273
274 Scenario:
275 1. Get CICD Jenkins access credentials from salt
276 2. Run job cvp-ha with tempest set=smoke
277 3. Get passed stages from cvp-ha
278 """
279 salt = salt_actions
280 show_step(1)
281
282 tgt = 'I@docker:client:stack:jenkins and cid01*'
283 jenkins_host = salt.get_single_pillar(
284 tgt=tgt, pillar="jenkins:client:master:host")
285 jenkins_port = salt.get_single_pillar(
286 tgt=tgt, pillar="jenkins:client:master:port")
obutenkoca858402019-07-04 18:31:39 +0300287 jenkins_protocol = salt.get_single_pillar(
288 tgt=tgt, pillar="jenkins:client:master:proto")
289 jenkins_url = '{0}://{1}:{2}'.format(jenkins_protocol,
290 jenkins_host,
291 jenkins_port)
Dennis Dmitriev1566e3f2019-01-11 17:35:43 +0200292 jenkins_user = salt.get_single_pillar(
293 tgt=tgt, pillar="jenkins:client:master:username")
294 jenkins_pass = salt.get_single_pillar(
295 tgt=tgt, pillar="jenkins:client:master:password")
296 jenkins_start_timeout = 60
297 jenkins_build_timeout = 1800
298
299 tempest_target_node = salt.get_single_pillar(
300 tgt='cfg01*',
301 pillar="runtest:tempest:test_target")
302
303 job_name = 'cvp-ha'
304 job_parameters = {
305 'TEMPEST_TARGET_NODE': tempest_target_node,
306 'TEMPEST_TEST_PATTERN': 'set=smoke',
307 }
308
309 show_step(2)
310 cvp_ha_smoke_result = run_jenkins_job.run_job(
311 host=jenkins_url,
312 username=jenkins_user,
313 password=jenkins_pass,
314 start_timeout=jenkins_start_timeout,
315 build_timeout=jenkins_build_timeout,
316 verbose=True,
317 job_name=job_name,
318 job_parameters=job_parameters,
319 job_output_prefix='[ cvp-ha/{build_number} {time} ] ')
320
321 show_step(3)
322 (description, stages) = get_jenkins_job_stages.get_deployment_result(
323 host=jenkins_url,
324 username=jenkins_user,
325 password=jenkins_pass,
326 job_name=job_name,
327 build_number='lastBuild')
328
329 LOG.info(description)
330 LOG.info('\n'.join(stages))
331
332 assert cvp_ha_smoke_result == 'SUCCESS', "{0}\n{1}".format(
333 description, '\n'.join(stages))
Oleksii Zhurba1d547c12019-05-13 17:42:42 -0500334
335 @pytest.mark.grab_versions
336 @pytest.mark.parametrize("_", [settings.ENV_NAME])
337 @pytest.mark.run_stacklight
338 def test_run_cvp_stacklight(self, salt_actions, show_step, _):
339 """Runner for Pipeline CVP - Stacklight
340
341 Scenario:
342 1. Get CICD Jenkins access credentials from salt
343 2. Run job cvp-stacklight
344 3. Get passed stages from cvp-stacklight
345 4. Download XML report from the job
346 """
347 salt = salt_actions
348 show_step(1)
349
350 tgt = 'I@docker:client:stack:jenkins and cid01*'
351 jenkins_host = salt.get_single_pillar(
352 tgt=tgt, pillar="jenkins:client:master:host")
353 jenkins_port = salt.get_single_pillar(
354 tgt=tgt, pillar="jenkins:client:master:port")
obutenkoca858402019-07-04 18:31:39 +0300355 jenkins_protocol = salt.get_single_pillar(
356 tgt=tgt, pillar="jenkins:client:master:proto")
357 jenkins_url = '{0}://{1}:{2}'.format(jenkins_protocol,
358 jenkins_host,
359 jenkins_port)
Oleksii Zhurba1d547c12019-05-13 17:42:42 -0500360 jenkins_user = salt.get_single_pillar(
361 tgt=tgt, pillar="jenkins:client:master:username")
362 jenkins_pass = salt.get_single_pillar(
363 tgt=tgt, pillar="jenkins:client:master:password")
Hanna Arhipova81af8332019-10-28 14:33:06 +0200364 cirros_image = salt.get_single_pillar(
365 tgt="I@salt:master",
366 pillar="_param:glance_image_cirros_location")
Oleksii Zhurba1d547c12019-05-13 17:42:42 -0500367 jenkins_start_timeout = 60
Hanna Arhipova81af8332019-10-28 14:33:06 +0200368 jenkins_build_timeout = 50 * 60
Oleksii Zhurba1d547c12019-05-13 17:42:42 -0500369
370 job_name = 'cvp-stacklight'
Hanna Arhipova81af8332019-10-28 14:33:06 +0200371 job_parameters = {
372 "EXTRA_PARAMS": """
373 envs:
374 - SL_AUTOCONF=True
375 - CIRROS_QCOW2_URL={image}
376 """.format(image=cirros_image)
377 }
Oleksii Zhurba1d547c12019-05-13 17:42:42 -0500378
379 show_step(2)
380 cvp_stacklight_result = run_jenkins_job.run_job(
381 host=jenkins_url,
382 username=jenkins_user,
383 password=jenkins_pass,
384 start_timeout=jenkins_start_timeout,
385 build_timeout=jenkins_build_timeout,
386 verbose=True,
387 job_name=job_name,
Hanna Arhipova81af8332019-10-28 14:33:06 +0200388 job_parameters=job_parameters,
Oleksii Zhurba1d547c12019-05-13 17:42:42 -0500389 job_output_prefix='[cvp-stacklight/{build_number}:platform {time}]'
390 )
391
392 show_step(3)
393 (description, stages) = get_jenkins_job_stages.get_deployment_result(
394 host=jenkins_url,
395 username=jenkins_user,
396 password=jenkins_pass,
397 job_name=job_name,
398 build_number='lastBuild')
399
400 LOG.info(description)
401 LOG.info('\n'.join(stages))
402 LOG.info('Job {0} result: {1}'.format(job_name,
403 cvp_stacklight_result))
404 # Download XML report
405 show_step(4)
406 destination_name = os.path.join(settings.LOGS_DIR,
407 "stacklight_report.xml")
408 # Do not fail the test case when the job is failed, but
409 # artifact with the XML report is present in the job.
410 try:
411 get_jenkins_job_artifact.download_artifact(
412 host=jenkins_url,
413 username=jenkins_user,
414 password=jenkins_pass,
415 job_name=job_name,
416 build_number='lastBuild',
417 artifact_path='validation_artifacts/cvp-stacklight_report.xml',
418 destination_name=destination_name)
419 except jenkins.NotFoundException:
420 raise jenkins.NotFoundException("{0}\n{1}".format(
421 description, '\n'.join(stages)))