blob: c73bb88d062ec48215915ffd086631187b385420 [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])
102 @pytest.mark.run_cvp_func_sanity
103 def test_run_cvp_func_sanity(self, salt_actions, show_step, _):
104 """Runner for Pipeline CVP - Functional tests
105
106 Scenario:
107 1. Get CICD Jenkins access credentials from salt
108 2. Run job cvp-sanity
109 3. Get passed stages from cvp-sanity
Dennis Dmitriev8565c342019-02-11 23:45:03 +0200110 4. Download XML report from the job
Dennis Dmitriev2a498732018-12-21 18:30:23 +0200111 """
112 salt = salt_actions
113 show_step(1)
114
115 tgt = 'I@docker:client:stack:jenkins and cid01*'
116 jenkins_host = salt.get_single_pillar(
117 tgt=tgt, pillar="jenkins:client:master:host")
118 jenkins_port = salt.get_single_pillar(
119 tgt=tgt, pillar="jenkins:client:master:port")
obutenkoca858402019-07-04 18:31:39 +0300120 jenkins_protocol = salt.get_single_pillar(
121 tgt=tgt, pillar="jenkins:client:master:proto")
122 jenkins_url = '{0}://{1}:{2}'.format(jenkins_protocol,
123 jenkins_host,
124 jenkins_port)
Dennis Dmitriev2a498732018-12-21 18:30:23 +0200125 jenkins_user = salt.get_single_pillar(
126 tgt=tgt, pillar="jenkins:client:master:username")
127 jenkins_pass = salt.get_single_pillar(
128 tgt=tgt, pillar="jenkins:client:master:password")
129 jenkins_start_timeout = 60
130 jenkins_build_timeout = 1800
131
Dennis Dmitriev85c52492019-03-12 15:26:56 +0200132 try:
133 maas_minion_id = salt.get_single_pillar(
134 tgt='I@maas:cluster or I@maas:region',
135 pillar="__reclass__:nodename")
Oleksii Zhurba04302d42019-05-30 09:56:21 -0500136 ntp_skipped_nodes = '{0}'.format(maas_minion_id)
Dennis Dmitriev85c52492019-03-12 15:26:56 +0200137 except LookupError:
138 ntp_skipped_nodes = ''
Dennis Dmitrieva51b89d2019-03-05 21:49:07 +0200139
Dennis Dmitriev2a498732018-12-21 18:30:23 +0200140 job_name = 'cvp-sanity'
Tatyana Leontovicha090c5a2019-05-17 02:07:28 +0300141 skipped_packages = ("python-setuptools,"
142 "python-pkg-resources,xunitmerge,"
143 "python-gnocchiclient, "
144 "python-ujson,python-octaviaclient")
145
Dennis Dmitriev2a498732018-12-21 18:30:23 +0200146 job_parameters = {
Tatyana Leontovicha090c5a2019-05-17 02:07:28 +0300147 'EXTRA_PARAMS': (
148 """
149 envs:
150 - skipped_packages='{0}'
151 - skipped_modules='xunitmerge,setuptools'
152 - skipped_services='docker,containerd'
Oleksii Zhurba04302d42019-05-30 09:56:21 -0500153 - ntp_skipped_nodes='{1}'"""
Tatyana Leontovicha090c5a2019-05-17 02:07:28 +0300154 .format(skipped_packages, ntp_skipped_nodes)),
Dennis Dmitriev2a498732018-12-21 18:30:23 +0200155 }
156
157 show_step(2)
158 cvp_func_sanity_result = run_jenkins_job.run_job(
159 host=jenkins_url,
160 username=jenkins_user,
161 password=jenkins_pass,
162 start_timeout=jenkins_start_timeout,
163 build_timeout=jenkins_build_timeout,
164 verbose=True,
165 job_name=job_name,
166 job_parameters=job_parameters,
167 job_output_prefix='[ cvp-func/{build_number}:platform {time} ] ')
168
169 show_step(3)
170 (description, stages) = get_jenkins_job_stages.get_deployment_result(
171 host=jenkins_url,
172 username=jenkins_user,
173 password=jenkins_pass,
174 job_name=job_name,
175 build_number='lastBuild')
176
177 LOG.info(description)
178 LOG.info('\n'.join(stages))
Dennis Dmitriev8565c342019-02-11 23:45:03 +0200179 LOG.info('Job {0} result: {1}'.format(job_name,
180 cvp_func_sanity_result))
181 # Download XML report
182 show_step(4)
183 destination_name = os.path.join(settings.LOGS_DIR,
184 "cvp_sanity_results.xml")
185 # Do not fail the test case when the job is failed, but
186 # artifact with the XML report is present in the job.
187 try:
188 get_jenkins_job_artifact.download_artifact(
189 host=jenkins_url,
190 username=jenkins_user,
191 password=jenkins_pass,
192 job_name=job_name,
193 build_number='lastBuild',
194 artifact_path='validation_artifacts/cvp-sanity_report.xml',
195 destination_name=destination_name)
196 except jenkins.NotFoundException:
197 raise jenkins.NotFoundException("{0}\n{1}".format(
198 description, '\n'.join(stages)))
Dennis Dmitriev1566e3f2019-01-11 17:35:43 +0200199
200 @pytest.mark.grab_versions
201 @pytest.mark.parametrize("_", [settings.ENV_NAME])
202 @pytest.mark.run_cvp_ha_smoke
203 def test_run_cvp_ha_smoke(self, underlay_actions, salt_actions,
204 show_step, _):
205 """Runner for Pipeline CVP - HA tests
206
207 Scenario:
208 1. Get CICD Jenkins access credentials from salt
209 2. Run job cvp-ha with tempest set=smoke
210 3. Get passed stages from cvp-ha
211 """
212 salt = salt_actions
213 show_step(1)
214
215 tgt = 'I@docker:client:stack:jenkins and cid01*'
216 jenkins_host = salt.get_single_pillar(
217 tgt=tgt, pillar="jenkins:client:master:host")
218 jenkins_port = salt.get_single_pillar(
219 tgt=tgt, pillar="jenkins:client:master:port")
obutenkoca858402019-07-04 18:31:39 +0300220 jenkins_protocol = salt.get_single_pillar(
221 tgt=tgt, pillar="jenkins:client:master:proto")
222 jenkins_url = '{0}://{1}:{2}'.format(jenkins_protocol,
223 jenkins_host,
224 jenkins_port)
Dennis Dmitriev1566e3f2019-01-11 17:35:43 +0200225 jenkins_user = salt.get_single_pillar(
226 tgt=tgt, pillar="jenkins:client:master:username")
227 jenkins_pass = salt.get_single_pillar(
228 tgt=tgt, pillar="jenkins:client:master:password")
229 jenkins_start_timeout = 60
230 jenkins_build_timeout = 1800
231
232 tempest_target_node = salt.get_single_pillar(
233 tgt='cfg01*',
234 pillar="runtest:tempest:test_target")
235
236 job_name = 'cvp-ha'
237 job_parameters = {
238 'TEMPEST_TARGET_NODE': tempest_target_node,
239 'TEMPEST_TEST_PATTERN': 'set=smoke',
240 }
241
242 show_step(2)
243 cvp_ha_smoke_result = run_jenkins_job.run_job(
244 host=jenkins_url,
245 username=jenkins_user,
246 password=jenkins_pass,
247 start_timeout=jenkins_start_timeout,
248 build_timeout=jenkins_build_timeout,
249 verbose=True,
250 job_name=job_name,
251 job_parameters=job_parameters,
252 job_output_prefix='[ cvp-ha/{build_number} {time} ] ')
253
254 show_step(3)
255 (description, stages) = get_jenkins_job_stages.get_deployment_result(
256 host=jenkins_url,
257 username=jenkins_user,
258 password=jenkins_pass,
259 job_name=job_name,
260 build_number='lastBuild')
261
262 LOG.info(description)
263 LOG.info('\n'.join(stages))
264
265 assert cvp_ha_smoke_result == 'SUCCESS', "{0}\n{1}".format(
266 description, '\n'.join(stages))
Oleksii Zhurba1d547c12019-05-13 17:42:42 -0500267
268 @pytest.mark.grab_versions
269 @pytest.mark.parametrize("_", [settings.ENV_NAME])
270 @pytest.mark.run_stacklight
271 def test_run_cvp_stacklight(self, salt_actions, show_step, _):
272 """Runner for Pipeline CVP - Stacklight
273
274 Scenario:
275 1. Get CICD Jenkins access credentials from salt
276 2. Run job cvp-stacklight
277 3. Get passed stages from cvp-stacklight
278 4. Download XML report from the job
279 """
280 salt = salt_actions
281 show_step(1)
282
283 tgt = 'I@docker:client:stack:jenkins and cid01*'
284 jenkins_host = salt.get_single_pillar(
285 tgt=tgt, pillar="jenkins:client:master:host")
286 jenkins_port = salt.get_single_pillar(
287 tgt=tgt, pillar="jenkins:client:master:port")
obutenkoca858402019-07-04 18:31:39 +0300288 jenkins_protocol = salt.get_single_pillar(
289 tgt=tgt, pillar="jenkins:client:master:proto")
290 jenkins_url = '{0}://{1}:{2}'.format(jenkins_protocol,
291 jenkins_host,
292 jenkins_port)
Oleksii Zhurba1d547c12019-05-13 17:42:42 -0500293 jenkins_user = salt.get_single_pillar(
294 tgt=tgt, pillar="jenkins:client:master:username")
295 jenkins_pass = salt.get_single_pillar(
296 tgt=tgt, pillar="jenkins:client:master:password")
297 jenkins_start_timeout = 60
298 jenkins_build_timeout = 1800
299
300 job_name = 'cvp-stacklight'
301
302 show_step(2)
303 cvp_stacklight_result = run_jenkins_job.run_job(
304 host=jenkins_url,
305 username=jenkins_user,
306 password=jenkins_pass,
307 start_timeout=jenkins_start_timeout,
308 build_timeout=jenkins_build_timeout,
309 verbose=True,
310 job_name=job_name,
311 job_parameters={},
312 job_output_prefix='[cvp-stacklight/{build_number}:platform {time}]'
313 )
314
315 show_step(3)
316 (description, stages) = get_jenkins_job_stages.get_deployment_result(
317 host=jenkins_url,
318 username=jenkins_user,
319 password=jenkins_pass,
320 job_name=job_name,
321 build_number='lastBuild')
322
323 LOG.info(description)
324 LOG.info('\n'.join(stages))
325 LOG.info('Job {0} result: {1}'.format(job_name,
326 cvp_stacklight_result))
327 # Download XML report
328 show_step(4)
329 destination_name = os.path.join(settings.LOGS_DIR,
330 "stacklight_report.xml")
331 # Do not fail the test case when the job is failed, but
332 # artifact with the XML report is present in the job.
333 try:
334 get_jenkins_job_artifact.download_artifact(
335 host=jenkins_url,
336 username=jenkins_user,
337 password=jenkins_pass,
338 job_name=job_name,
339 build_number='lastBuild',
340 artifact_path='validation_artifacts/cvp-stacklight_report.xml',
341 destination_name=destination_name)
342 except jenkins.NotFoundException:
343 raise jenkins.NotFoundException("{0}\n{1}".format(
344 description, '\n'.join(stages)))