Dennis Dmitriev | 2a49873 | 2018-12-21 18:30:23 +0200 | [diff] [blame] | 1 | # 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 Dmitriev | 8565c34 | 2019-02-11 23:45:03 +0200 | [diff] [blame] | 15 | import jenkins |
Dennis Dmitriev | 2a49873 | 2018-12-21 18:30:23 +0200 | [diff] [blame] | 16 | import pytest |
Dennis Dmitriev | 8565c34 | 2019-02-11 23:45:03 +0200 | [diff] [blame] | 17 | import os |
Dennis Dmitriev | 2a49873 | 2018-12-21 18:30:23 +0200 | [diff] [blame] | 18 | |
| 19 | from tcp_tests import logger |
| 20 | from tcp_tests import settings |
| 21 | from tcp_tests.utils import run_jenkins_job |
| 22 | from tcp_tests.utils import get_jenkins_job_stages |
Dennis Dmitriev | 8565c34 | 2019-02-11 23:45:03 +0200 | [diff] [blame] | 23 | from tcp_tests.utils import get_jenkins_job_artifact |
Dennis Dmitriev | 2a49873 | 2018-12-21 18:30:23 +0200 | [diff] [blame] | 24 | |
| 25 | LOG = logger.logger |
| 26 | |
| 27 | |
| 28 | class 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") |
obutenko | ca85840 | 2019-07-04 18:31:39 +0300 | [diff] [blame] | 56 | 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 Dmitriev | 2a49873 | 2018-12-21 18:30:23 +0200 | [diff] [blame] | 61 | 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 Arhipova | dab7ba3 | 2020-06-23 13:32:28 +0300 | [diff] [blame] | 102 | @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 |
| 123 | |
| 124 | show_step(1) |
| 125 | salt.sync_time() |
| 126 | |
| 127 | show_step(2) |
| 128 | tempest_actions.prepare(pipeline=True) |
| 129 | |
| 130 | show_step(3) |
| 131 | job_name = 'cvp-tempest' |
| 132 | job_parameters = { |
| 133 | 'TEMPEST_ENDPOINT_TYPE': 'internalURL', |
| 134 | 'TEMPEST_TEST_PATTERN': 'set=full', |
| 135 | } |
| 136 | cvp_tempest_result = dt.start_job_on_jenkins( |
| 137 | job_name, |
| 138 | jenkins_tgt='I@docker:client:stack:jenkins and I@salt:master', |
| 139 | start_timeout=jenkins_start_timeout, |
| 140 | build_timeout=jenkins_build_timeout, |
| 141 | verbose=True, |
| 142 | job_parameters=job_parameters, |
| 143 | job_output_prefix='[ {job_name}/{build_number}:platform {time} ] ') |
| 144 | LOG.info('Job {0} result: {1}'.format(job_name, cvp_tempest_result)) |
| 145 | |
| 146 | show_step(4) |
| 147 | tempest_actions.fetch_arficats( |
| 148 | username='root', report_dir="/root/test/") |
| 149 | |
| 150 | @pytest.mark.grab_versions |
| 151 | @pytest.mark.parametrize("_", [settings.ENV_NAME]) |
Dennis Dmitriev | 2a49873 | 2018-12-21 18:30:23 +0200 | [diff] [blame] | 152 | @pytest.mark.run_cvp_func_sanity |
| 153 | def test_run_cvp_func_sanity(self, salt_actions, show_step, _): |
| 154 | """Runner for Pipeline CVP - Functional tests |
| 155 | |
| 156 | Scenario: |
| 157 | 1. Get CICD Jenkins access credentials from salt |
| 158 | 2. Run job cvp-sanity |
| 159 | 3. Get passed stages from cvp-sanity |
Dennis Dmitriev | 8565c34 | 2019-02-11 23:45:03 +0200 | [diff] [blame] | 160 | 4. Download XML report from the job |
Dennis Dmitriev | 2a49873 | 2018-12-21 18:30:23 +0200 | [diff] [blame] | 161 | """ |
| 162 | salt = salt_actions |
| 163 | show_step(1) |
| 164 | |
| 165 | tgt = 'I@docker:client:stack:jenkins and cid01*' |
| 166 | jenkins_host = salt.get_single_pillar( |
| 167 | tgt=tgt, pillar="jenkins:client:master:host") |
| 168 | jenkins_port = salt.get_single_pillar( |
| 169 | tgt=tgt, pillar="jenkins:client:master:port") |
obutenko | ca85840 | 2019-07-04 18:31:39 +0300 | [diff] [blame] | 170 | jenkins_protocol = salt.get_single_pillar( |
| 171 | tgt=tgt, pillar="jenkins:client:master:proto") |
| 172 | jenkins_url = '{0}://{1}:{2}'.format(jenkins_protocol, |
| 173 | jenkins_host, |
| 174 | jenkins_port) |
Dennis Dmitriev | 2a49873 | 2018-12-21 18:30:23 +0200 | [diff] [blame] | 175 | jenkins_user = salt.get_single_pillar( |
| 176 | tgt=tgt, pillar="jenkins:client:master:username") |
| 177 | jenkins_pass = salt.get_single_pillar( |
| 178 | tgt=tgt, pillar="jenkins:client:master:password") |
| 179 | jenkins_start_timeout = 60 |
| 180 | jenkins_build_timeout = 1800 |
| 181 | |
Dennis Dmitriev | 85c5249 | 2019-03-12 15:26:56 +0200 | [diff] [blame] | 182 | try: |
| 183 | maas_minion_id = salt.get_single_pillar( |
| 184 | tgt='I@maas:cluster or I@maas:region', |
| 185 | pillar="__reclass__:nodename") |
Oleksii Zhurba | 04302d4 | 2019-05-30 09:56:21 -0500 | [diff] [blame] | 186 | ntp_skipped_nodes = '{0}'.format(maas_minion_id) |
Dennis Dmitriev | 85c5249 | 2019-03-12 15:26:56 +0200 | [diff] [blame] | 187 | except LookupError: |
| 188 | ntp_skipped_nodes = '' |
Dennis Dmitriev | a51b89d | 2019-03-05 21:49:07 +0200 | [diff] [blame] | 189 | |
Dennis Dmitriev | 2a49873 | 2018-12-21 18:30:23 +0200 | [diff] [blame] | 190 | job_name = 'cvp-sanity' |
Tatyana Leontovich | a090c5a | 2019-05-17 02:07:28 +0300 | [diff] [blame] | 191 | skipped_packages = ("python-setuptools," |
| 192 | "python-pkg-resources,xunitmerge," |
| 193 | "python-gnocchiclient, " |
| 194 | "python-ujson,python-octaviaclient") |
| 195 | |
Dennis Dmitriev | 2a49873 | 2018-12-21 18:30:23 +0200 | [diff] [blame] | 196 | job_parameters = { |
Tatyana Leontovich | a090c5a | 2019-05-17 02:07:28 +0300 | [diff] [blame] | 197 | 'EXTRA_PARAMS': ( |
| 198 | """ |
| 199 | envs: |
| 200 | - skipped_packages='{0}' |
| 201 | - skipped_modules='xunitmerge,setuptools' |
| 202 | - skipped_services='docker,containerd' |
Oleksii Zhurba | 04302d4 | 2019-05-30 09:56:21 -0500 | [diff] [blame] | 203 | - ntp_skipped_nodes='{1}'""" |
Tatyana Leontovich | a090c5a | 2019-05-17 02:07:28 +0300 | [diff] [blame] | 204 | .format(skipped_packages, ntp_skipped_nodes)), |
Dennis Dmitriev | 2a49873 | 2018-12-21 18:30:23 +0200 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | show_step(2) |
| 208 | cvp_func_sanity_result = run_jenkins_job.run_job( |
| 209 | host=jenkins_url, |
| 210 | username=jenkins_user, |
| 211 | password=jenkins_pass, |
| 212 | start_timeout=jenkins_start_timeout, |
| 213 | build_timeout=jenkins_build_timeout, |
| 214 | verbose=True, |
| 215 | job_name=job_name, |
| 216 | job_parameters=job_parameters, |
| 217 | job_output_prefix='[ cvp-func/{build_number}:platform {time} ] ') |
| 218 | |
| 219 | show_step(3) |
| 220 | (description, stages) = get_jenkins_job_stages.get_deployment_result( |
| 221 | host=jenkins_url, |
| 222 | username=jenkins_user, |
| 223 | password=jenkins_pass, |
| 224 | job_name=job_name, |
| 225 | build_number='lastBuild') |
| 226 | |
| 227 | LOG.info(description) |
| 228 | LOG.info('\n'.join(stages)) |
Dennis Dmitriev | 8565c34 | 2019-02-11 23:45:03 +0200 | [diff] [blame] | 229 | LOG.info('Job {0} result: {1}'.format(job_name, |
| 230 | cvp_func_sanity_result)) |
| 231 | # Download XML report |
| 232 | show_step(4) |
| 233 | destination_name = os.path.join(settings.LOGS_DIR, |
| 234 | "cvp_sanity_results.xml") |
| 235 | # Do not fail the test case when the job is failed, but |
| 236 | # artifact with the XML report is present in the job. |
| 237 | try: |
| 238 | get_jenkins_job_artifact.download_artifact( |
| 239 | host=jenkins_url, |
| 240 | username=jenkins_user, |
| 241 | password=jenkins_pass, |
| 242 | job_name=job_name, |
| 243 | build_number='lastBuild', |
| 244 | artifact_path='validation_artifacts/cvp-sanity_report.xml', |
| 245 | destination_name=destination_name) |
| 246 | except jenkins.NotFoundException: |
| 247 | raise jenkins.NotFoundException("{0}\n{1}".format( |
| 248 | description, '\n'.join(stages))) |
Dennis Dmitriev | 1566e3f | 2019-01-11 17:35:43 +0200 | [diff] [blame] | 249 | |
| 250 | @pytest.mark.grab_versions |
| 251 | @pytest.mark.parametrize("_", [settings.ENV_NAME]) |
| 252 | @pytest.mark.run_cvp_ha_smoke |
| 253 | def test_run_cvp_ha_smoke(self, underlay_actions, salt_actions, |
| 254 | show_step, _): |
| 255 | """Runner for Pipeline CVP - HA tests |
| 256 | |
| 257 | Scenario: |
| 258 | 1. Get CICD Jenkins access credentials from salt |
| 259 | 2. Run job cvp-ha with tempest set=smoke |
| 260 | 3. Get passed stages from cvp-ha |
| 261 | """ |
| 262 | salt = salt_actions |
| 263 | show_step(1) |
| 264 | |
| 265 | tgt = 'I@docker:client:stack:jenkins and cid01*' |
| 266 | jenkins_host = salt.get_single_pillar( |
| 267 | tgt=tgt, pillar="jenkins:client:master:host") |
| 268 | jenkins_port = salt.get_single_pillar( |
| 269 | tgt=tgt, pillar="jenkins:client:master:port") |
obutenko | ca85840 | 2019-07-04 18:31:39 +0300 | [diff] [blame] | 270 | jenkins_protocol = salt.get_single_pillar( |
| 271 | tgt=tgt, pillar="jenkins:client:master:proto") |
| 272 | jenkins_url = '{0}://{1}:{2}'.format(jenkins_protocol, |
| 273 | jenkins_host, |
| 274 | jenkins_port) |
Dennis Dmitriev | 1566e3f | 2019-01-11 17:35:43 +0200 | [diff] [blame] | 275 | jenkins_user = salt.get_single_pillar( |
| 276 | tgt=tgt, pillar="jenkins:client:master:username") |
| 277 | jenkins_pass = salt.get_single_pillar( |
| 278 | tgt=tgt, pillar="jenkins:client:master:password") |
| 279 | jenkins_start_timeout = 60 |
| 280 | jenkins_build_timeout = 1800 |
| 281 | |
| 282 | tempest_target_node = salt.get_single_pillar( |
| 283 | tgt='cfg01*', |
| 284 | pillar="runtest:tempest:test_target") |
| 285 | |
| 286 | job_name = 'cvp-ha' |
| 287 | job_parameters = { |
| 288 | 'TEMPEST_TARGET_NODE': tempest_target_node, |
| 289 | 'TEMPEST_TEST_PATTERN': 'set=smoke', |
| 290 | } |
| 291 | |
| 292 | show_step(2) |
| 293 | cvp_ha_smoke_result = run_jenkins_job.run_job( |
| 294 | host=jenkins_url, |
| 295 | username=jenkins_user, |
| 296 | password=jenkins_pass, |
| 297 | start_timeout=jenkins_start_timeout, |
| 298 | build_timeout=jenkins_build_timeout, |
| 299 | verbose=True, |
| 300 | job_name=job_name, |
| 301 | job_parameters=job_parameters, |
| 302 | job_output_prefix='[ cvp-ha/{build_number} {time} ] ') |
| 303 | |
| 304 | show_step(3) |
| 305 | (description, stages) = get_jenkins_job_stages.get_deployment_result( |
| 306 | host=jenkins_url, |
| 307 | username=jenkins_user, |
| 308 | password=jenkins_pass, |
| 309 | job_name=job_name, |
| 310 | build_number='lastBuild') |
| 311 | |
| 312 | LOG.info(description) |
| 313 | LOG.info('\n'.join(stages)) |
| 314 | |
| 315 | assert cvp_ha_smoke_result == 'SUCCESS', "{0}\n{1}".format( |
| 316 | description, '\n'.join(stages)) |
Oleksii Zhurba | 1d547c1 | 2019-05-13 17:42:42 -0500 | [diff] [blame] | 317 | |
| 318 | @pytest.mark.grab_versions |
| 319 | @pytest.mark.parametrize("_", [settings.ENV_NAME]) |
| 320 | @pytest.mark.run_stacklight |
| 321 | def test_run_cvp_stacklight(self, salt_actions, show_step, _): |
| 322 | """Runner for Pipeline CVP - Stacklight |
| 323 | |
| 324 | Scenario: |
| 325 | 1. Get CICD Jenkins access credentials from salt |
| 326 | 2. Run job cvp-stacklight |
| 327 | 3. Get passed stages from cvp-stacklight |
| 328 | 4. Download XML report from the job |
| 329 | """ |
| 330 | salt = salt_actions |
| 331 | show_step(1) |
| 332 | |
| 333 | tgt = 'I@docker:client:stack:jenkins and cid01*' |
| 334 | jenkins_host = salt.get_single_pillar( |
| 335 | tgt=tgt, pillar="jenkins:client:master:host") |
| 336 | jenkins_port = salt.get_single_pillar( |
| 337 | tgt=tgt, pillar="jenkins:client:master:port") |
obutenko | ca85840 | 2019-07-04 18:31:39 +0300 | [diff] [blame] | 338 | jenkins_protocol = salt.get_single_pillar( |
| 339 | tgt=tgt, pillar="jenkins:client:master:proto") |
| 340 | jenkins_url = '{0}://{1}:{2}'.format(jenkins_protocol, |
| 341 | jenkins_host, |
| 342 | jenkins_port) |
Oleksii Zhurba | 1d547c1 | 2019-05-13 17:42:42 -0500 | [diff] [blame] | 343 | jenkins_user = salt.get_single_pillar( |
| 344 | tgt=tgt, pillar="jenkins:client:master:username") |
| 345 | jenkins_pass = salt.get_single_pillar( |
| 346 | tgt=tgt, pillar="jenkins:client:master:password") |
Hanna Arhipova | 81af833 | 2019-10-28 14:33:06 +0200 | [diff] [blame] | 347 | cirros_image = salt.get_single_pillar( |
| 348 | tgt="I@salt:master", |
| 349 | pillar="_param:glance_image_cirros_location") |
Oleksii Zhurba | 1d547c1 | 2019-05-13 17:42:42 -0500 | [diff] [blame] | 350 | jenkins_start_timeout = 60 |
Hanna Arhipova | 81af833 | 2019-10-28 14:33:06 +0200 | [diff] [blame] | 351 | jenkins_build_timeout = 50 * 60 |
Oleksii Zhurba | 1d547c1 | 2019-05-13 17:42:42 -0500 | [diff] [blame] | 352 | |
| 353 | job_name = 'cvp-stacklight' |
Hanna Arhipova | 81af833 | 2019-10-28 14:33:06 +0200 | [diff] [blame] | 354 | job_parameters = { |
| 355 | "EXTRA_PARAMS": """ |
| 356 | envs: |
| 357 | - SL_AUTOCONF=True |
| 358 | - CIRROS_QCOW2_URL={image} |
| 359 | """.format(image=cirros_image) |
| 360 | } |
Oleksii Zhurba | 1d547c1 | 2019-05-13 17:42:42 -0500 | [diff] [blame] | 361 | |
| 362 | show_step(2) |
| 363 | cvp_stacklight_result = run_jenkins_job.run_job( |
| 364 | host=jenkins_url, |
| 365 | username=jenkins_user, |
| 366 | password=jenkins_pass, |
| 367 | start_timeout=jenkins_start_timeout, |
| 368 | build_timeout=jenkins_build_timeout, |
| 369 | verbose=True, |
| 370 | job_name=job_name, |
Hanna Arhipova | 81af833 | 2019-10-28 14:33:06 +0200 | [diff] [blame] | 371 | job_parameters=job_parameters, |
Oleksii Zhurba | 1d547c1 | 2019-05-13 17:42:42 -0500 | [diff] [blame] | 372 | job_output_prefix='[cvp-stacklight/{build_number}:platform {time}]' |
| 373 | ) |
| 374 | |
| 375 | show_step(3) |
| 376 | (description, stages) = get_jenkins_job_stages.get_deployment_result( |
| 377 | host=jenkins_url, |
| 378 | username=jenkins_user, |
| 379 | password=jenkins_pass, |
| 380 | job_name=job_name, |
| 381 | build_number='lastBuild') |
| 382 | |
| 383 | LOG.info(description) |
| 384 | LOG.info('\n'.join(stages)) |
| 385 | LOG.info('Job {0} result: {1}'.format(job_name, |
| 386 | cvp_stacklight_result)) |
| 387 | # Download XML report |
| 388 | show_step(4) |
| 389 | destination_name = os.path.join(settings.LOGS_DIR, |
| 390 | "stacklight_report.xml") |
| 391 | # Do not fail the test case when the job is failed, but |
| 392 | # artifact with the XML report is present in the job. |
| 393 | try: |
| 394 | get_jenkins_job_artifact.download_artifact( |
| 395 | host=jenkins_url, |
| 396 | username=jenkins_user, |
| 397 | password=jenkins_pass, |
| 398 | job_name=job_name, |
| 399 | build_number='lastBuild', |
| 400 | artifact_path='validation_artifacts/cvp-stacklight_report.xml', |
| 401 | destination_name=destination_name) |
| 402 | except jenkins.NotFoundException: |
| 403 | raise jenkins.NotFoundException("{0}\n{1}".format( |
| 404 | description, '\n'.join(stages))) |