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 |
Hanna Arhipova | 653d556 | 2020-08-03 15:32:09 +0300 | [diff] [blame] | 123 | cluster_name = settings.ENV_NAME |
Hanna Arhipova | 7cd2c2c | 2020-09-10 08:20:50 +0300 | [diff] [blame] | 124 | tempest_pattern = settings.TEMPEST_PATTERN |
Hanna Arhipova | 653d556 | 2020-08-03 15:32:09 +0300 | [diff] [blame] | 125 | skiplist_file = "tcp_tests/templates/{}/tempest_skip.list".\ |
| 126 | format(cluster_name) |
Hanna Arhipova | dab7ba3 | 2020-06-23 13:32:28 +0300 | [diff] [blame] | 127 | |
| 128 | show_step(1) |
| 129 | salt.sync_time() |
| 130 | |
| 131 | show_step(2) |
| 132 | tempest_actions.prepare(pipeline=True) |
Hanna Arhipova | 653d556 | 2020-08-03 15:32:09 +0300 | [diff] [blame] | 133 | # 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 Arhipova | dab7ba3 | 2020-06-23 13:32:28 +0300 | [diff] [blame] | 139 | |
| 140 | show_step(3) |
| 141 | job_name = 'cvp-tempest' |
| 142 | job_parameters = { |
Hanna Arhipova | 653d556 | 2020-08-03 15:32:09 +0300 | [diff] [blame] | 143 | '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 Arhipova | 4ce82fb | 2020-11-11 16:35:55 +0200 | [diff] [blame] | 149 | concurrency: {concurrency} |
| 150 | """.format(concurrency=settings.TEMPEST_THREADS), |
| 151 | |
Hanna Arhipova | dab7ba3 | 2020-06-23 13:32:28 +0300 | [diff] [blame] | 152 | 'TEMPEST_ENDPOINT_TYPE': 'internalURL', |
Hanna Arhipova | 7cd2c2c | 2020-09-10 08:20:50 +0300 | [diff] [blame] | 153 | 'TEMPEST_TEST_PATTERN': tempest_pattern, |
Hanna Arhipova | dab7ba3 | 2020-06-23 13:32:28 +0300 | [diff] [blame] | 154 | } |
Hanna Arhipova | 508f653 | 2021-01-27 15:52:45 +0200 | [diff] [blame] | 155 | job_result, job_description = dt.start_job_on_jenkins( |
Hanna Arhipova | dab7ba3 | 2020-06-23 13:32:28 +0300 | [diff] [blame] | 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} ] ') |
Hanna Arhipova | 508f653 | 2021-01-27 15:52:45 +0200 | [diff] [blame] | 163 | LOG.info('Job {0} result: {1}'.format(job_name, job_result)) |
Hanna Arhipova | dab7ba3 | 2020-06-23 13:32:28 +0300 | [diff] [blame] | 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 Dmitriev | 2a49873 | 2018-12-21 18:30:23 +0200 | [diff] [blame] | 171 | @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 Dmitriev | 8565c34 | 2019-02-11 23:45:03 +0200 | [diff] [blame] | 179 | 4. Download XML report from the job |
Dennis Dmitriev | 2a49873 | 2018-12-21 18:30:23 +0200 | [diff] [blame] | 180 | """ |
| 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") |
obutenko | ca85840 | 2019-07-04 18:31:39 +0300 | [diff] [blame] | 189 | 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 Dmitriev | 2a49873 | 2018-12-21 18:30:23 +0200 | [diff] [blame] | 194 | 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 Dmitriev | 85c5249 | 2019-03-12 15:26:56 +0200 | [diff] [blame] | 201 | try: |
| 202 | maas_minion_id = salt.get_single_pillar( |
| 203 | tgt='I@maas:cluster or I@maas:region', |
| 204 | pillar="__reclass__:nodename") |
Oleksii Zhurba | 04302d4 | 2019-05-30 09:56:21 -0500 | [diff] [blame] | 205 | ntp_skipped_nodes = '{0}'.format(maas_minion_id) |
Dennis Dmitriev | 85c5249 | 2019-03-12 15:26:56 +0200 | [diff] [blame] | 206 | except LookupError: |
| 207 | ntp_skipped_nodes = '' |
Dennis Dmitriev | a51b89d | 2019-03-05 21:49:07 +0200 | [diff] [blame] | 208 | |
Dennis Dmitriev | 2a49873 | 2018-12-21 18:30:23 +0200 | [diff] [blame] | 209 | job_name = 'cvp-sanity' |
dtsapikov | 269f519 | 2021-08-12 13:35:43 +0400 | [diff] [blame^] | 210 | server = jenkins.Jenkins(jenkins_url, jenkins_user, jenkins_pass) |
| 211 | build_number = server.get_job_info(job_name)['nextBuildNumber'] |
| 212 | |
Tatyana Leontovich | a090c5a | 2019-05-17 02:07:28 +0300 | [diff] [blame] | 213 | skipped_packages = ("python-setuptools," |
| 214 | "python-pkg-resources,xunitmerge," |
| 215 | "python-gnocchiclient, " |
| 216 | "python-ujson,python-octaviaclient") |
| 217 | |
Dennis Dmitriev | 2a49873 | 2018-12-21 18:30:23 +0200 | [diff] [blame] | 218 | job_parameters = { |
Tatyana Leontovich | a090c5a | 2019-05-17 02:07:28 +0300 | [diff] [blame] | 219 | 'EXTRA_PARAMS': ( |
| 220 | """ |
| 221 | envs: |
| 222 | - skipped_packages='{0}' |
| 223 | - skipped_modules='xunitmerge,setuptools' |
| 224 | - skipped_services='docker,containerd' |
Oleksii Zhurba | 04302d4 | 2019-05-30 09:56:21 -0500 | [diff] [blame] | 225 | - ntp_skipped_nodes='{1}'""" |
Tatyana Leontovich | a090c5a | 2019-05-17 02:07:28 +0300 | [diff] [blame] | 226 | .format(skipped_packages, ntp_skipped_nodes)), |
Dennis Dmitriev | 2a49873 | 2018-12-21 18:30:23 +0200 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | show_step(2) |
| 230 | cvp_func_sanity_result = run_jenkins_job.run_job( |
| 231 | host=jenkins_url, |
| 232 | username=jenkins_user, |
| 233 | password=jenkins_pass, |
| 234 | start_timeout=jenkins_start_timeout, |
| 235 | build_timeout=jenkins_build_timeout, |
| 236 | verbose=True, |
| 237 | job_name=job_name, |
| 238 | job_parameters=job_parameters, |
| 239 | job_output_prefix='[ cvp-func/{build_number}:platform {time} ] ') |
| 240 | |
| 241 | show_step(3) |
| 242 | (description, stages) = get_jenkins_job_stages.get_deployment_result( |
| 243 | host=jenkins_url, |
| 244 | username=jenkins_user, |
| 245 | password=jenkins_pass, |
| 246 | job_name=job_name, |
| 247 | build_number='lastBuild') |
| 248 | |
| 249 | LOG.info(description) |
| 250 | LOG.info('\n'.join(stages)) |
Dennis Dmitriev | 8565c34 | 2019-02-11 23:45:03 +0200 | [diff] [blame] | 251 | LOG.info('Job {0} result: {1}'.format(job_name, |
| 252 | cvp_func_sanity_result)) |
| 253 | # Download XML report |
| 254 | show_step(4) |
| 255 | destination_name = os.path.join(settings.LOGS_DIR, |
dtsapikov | 269f519 | 2021-08-12 13:35:43 +0400 | [diff] [blame^] | 256 | "tmp/" + job_name + "_" |
| 257 | + str(build_number) + "_results.xml") |
Dennis Dmitriev | 8565c34 | 2019-02-11 23:45:03 +0200 | [diff] [blame] | 258 | # Do not fail the test case when the job is failed, but |
| 259 | # artifact with the XML report is present in the job. |
| 260 | try: |
| 261 | get_jenkins_job_artifact.download_artifact( |
| 262 | host=jenkins_url, |
| 263 | username=jenkins_user, |
| 264 | password=jenkins_pass, |
| 265 | job_name=job_name, |
dtsapikov | 269f519 | 2021-08-12 13:35:43 +0400 | [diff] [blame^] | 266 | build_number=build_number, |
| 267 | artifact_path='validation_artifacts/' + job_name |
| 268 | + '_report.xml', |
| 269 | destination_name=destination_name) |
| 270 | except jenkins.NotFoundException: |
| 271 | raise jenkins.NotFoundException("{0}\n{1}".format( |
| 272 | description, '\n'.join(stages))) |
| 273 | |
| 274 | destination_name = os.path.join(settings.LOGS_DIR, |
| 275 | "tmp/" + job_name + "_" |
| 276 | + str(build_number) + "_full.log") |
| 277 | |
| 278 | try: |
| 279 | get_jenkins_job_artifact.download_artifact( |
| 280 | host=jenkins_url, |
| 281 | username=jenkins_user, |
| 282 | password=jenkins_pass, |
| 283 | job_name=job_name, |
| 284 | build_number=build_number, |
| 285 | artifact_path='validation_artifacts/full.log', |
Dennis Dmitriev | 8565c34 | 2019-02-11 23:45:03 +0200 | [diff] [blame] | 286 | destination_name=destination_name) |
| 287 | except jenkins.NotFoundException: |
| 288 | raise jenkins.NotFoundException("{0}\n{1}".format( |
| 289 | description, '\n'.join(stages))) |
Dennis Dmitriev | 1566e3f | 2019-01-11 17:35:43 +0200 | [diff] [blame] | 290 | |
| 291 | @pytest.mark.grab_versions |
| 292 | @pytest.mark.parametrize("_", [settings.ENV_NAME]) |
| 293 | @pytest.mark.run_cvp_ha_smoke |
| 294 | def test_run_cvp_ha_smoke(self, underlay_actions, salt_actions, |
| 295 | show_step, _): |
| 296 | """Runner for Pipeline CVP - HA tests |
| 297 | |
| 298 | Scenario: |
| 299 | 1. Get CICD Jenkins access credentials from salt |
| 300 | 2. Run job cvp-ha with tempest set=smoke |
| 301 | 3. Get passed stages from cvp-ha |
| 302 | """ |
| 303 | salt = salt_actions |
| 304 | show_step(1) |
| 305 | |
| 306 | tgt = 'I@docker:client:stack:jenkins and cid01*' |
| 307 | jenkins_host = salt.get_single_pillar( |
| 308 | tgt=tgt, pillar="jenkins:client:master:host") |
| 309 | jenkins_port = salt.get_single_pillar( |
| 310 | tgt=tgt, pillar="jenkins:client:master:port") |
obutenko | ca85840 | 2019-07-04 18:31:39 +0300 | [diff] [blame] | 311 | jenkins_protocol = salt.get_single_pillar( |
| 312 | tgt=tgt, pillar="jenkins:client:master:proto") |
| 313 | jenkins_url = '{0}://{1}:{2}'.format(jenkins_protocol, |
| 314 | jenkins_host, |
| 315 | jenkins_port) |
Dennis Dmitriev | 1566e3f | 2019-01-11 17:35:43 +0200 | [diff] [blame] | 316 | jenkins_user = salt.get_single_pillar( |
| 317 | tgt=tgt, pillar="jenkins:client:master:username") |
| 318 | jenkins_pass = salt.get_single_pillar( |
| 319 | tgt=tgt, pillar="jenkins:client:master:password") |
| 320 | jenkins_start_timeout = 60 |
| 321 | jenkins_build_timeout = 1800 |
| 322 | |
| 323 | tempest_target_node = salt.get_single_pillar( |
| 324 | tgt='cfg01*', |
| 325 | pillar="runtest:tempest:test_target") |
| 326 | |
| 327 | job_name = 'cvp-ha' |
| 328 | job_parameters = { |
| 329 | 'TEMPEST_TARGET_NODE': tempest_target_node, |
| 330 | 'TEMPEST_TEST_PATTERN': 'set=smoke', |
| 331 | } |
| 332 | |
| 333 | show_step(2) |
| 334 | cvp_ha_smoke_result = run_jenkins_job.run_job( |
| 335 | host=jenkins_url, |
| 336 | username=jenkins_user, |
| 337 | password=jenkins_pass, |
| 338 | start_timeout=jenkins_start_timeout, |
| 339 | build_timeout=jenkins_build_timeout, |
| 340 | verbose=True, |
| 341 | job_name=job_name, |
| 342 | job_parameters=job_parameters, |
| 343 | job_output_prefix='[ cvp-ha/{build_number} {time} ] ') |
| 344 | |
| 345 | show_step(3) |
| 346 | (description, stages) = get_jenkins_job_stages.get_deployment_result( |
| 347 | host=jenkins_url, |
| 348 | username=jenkins_user, |
| 349 | password=jenkins_pass, |
| 350 | job_name=job_name, |
| 351 | build_number='lastBuild') |
| 352 | |
| 353 | LOG.info(description) |
| 354 | LOG.info('\n'.join(stages)) |
| 355 | |
| 356 | assert cvp_ha_smoke_result == 'SUCCESS', "{0}\n{1}".format( |
| 357 | description, '\n'.join(stages)) |
Oleksii Zhurba | 1d547c1 | 2019-05-13 17:42:42 -0500 | [diff] [blame] | 358 | |
| 359 | @pytest.mark.grab_versions |
| 360 | @pytest.mark.parametrize("_", [settings.ENV_NAME]) |
| 361 | @pytest.mark.run_stacklight |
| 362 | def test_run_cvp_stacklight(self, salt_actions, show_step, _): |
| 363 | """Runner for Pipeline CVP - Stacklight |
| 364 | |
| 365 | Scenario: |
| 366 | 1. Get CICD Jenkins access credentials from salt |
| 367 | 2. Run job cvp-stacklight |
| 368 | 3. Get passed stages from cvp-stacklight |
| 369 | 4. Download XML report from the job |
| 370 | """ |
| 371 | salt = salt_actions |
| 372 | show_step(1) |
| 373 | |
| 374 | tgt = 'I@docker:client:stack:jenkins and cid01*' |
| 375 | jenkins_host = salt.get_single_pillar( |
| 376 | tgt=tgt, pillar="jenkins:client:master:host") |
| 377 | jenkins_port = salt.get_single_pillar( |
| 378 | tgt=tgt, pillar="jenkins:client:master:port") |
obutenko | ca85840 | 2019-07-04 18:31:39 +0300 | [diff] [blame] | 379 | jenkins_protocol = salt.get_single_pillar( |
| 380 | tgt=tgt, pillar="jenkins:client:master:proto") |
| 381 | jenkins_url = '{0}://{1}:{2}'.format(jenkins_protocol, |
| 382 | jenkins_host, |
| 383 | jenkins_port) |
Oleksii Zhurba | 1d547c1 | 2019-05-13 17:42:42 -0500 | [diff] [blame] | 384 | jenkins_user = salt.get_single_pillar( |
| 385 | tgt=tgt, pillar="jenkins:client:master:username") |
| 386 | jenkins_pass = salt.get_single_pillar( |
| 387 | tgt=tgt, pillar="jenkins:client:master:password") |
Hanna Arhipova | 81af833 | 2019-10-28 14:33:06 +0200 | [diff] [blame] | 388 | cirros_image = salt.get_single_pillar( |
| 389 | tgt="I@salt:master", |
| 390 | pillar="_param:glance_image_cirros_location") |
Oleksii Zhurba | 1d547c1 | 2019-05-13 17:42:42 -0500 | [diff] [blame] | 391 | jenkins_start_timeout = 60 |
Hanna Arhipova | 81af833 | 2019-10-28 14:33:06 +0200 | [diff] [blame] | 392 | jenkins_build_timeout = 50 * 60 |
Oleksii Zhurba | 1d547c1 | 2019-05-13 17:42:42 -0500 | [diff] [blame] | 393 | |
| 394 | job_name = 'cvp-stacklight' |
dtsapikov | 269f519 | 2021-08-12 13:35:43 +0400 | [diff] [blame^] | 395 | server = jenkins.Jenkins(jenkins_url, jenkins_user, jenkins_pass) |
| 396 | build_number = server.get_job_info(job_name)['nextBuildNumber'] |
| 397 | |
Hanna Arhipova | 81af833 | 2019-10-28 14:33:06 +0200 | [diff] [blame] | 398 | job_parameters = { |
| 399 | "EXTRA_PARAMS": """ |
| 400 | envs: |
| 401 | - SL_AUTOCONF=True |
| 402 | - CIRROS_QCOW2_URL={image} |
| 403 | """.format(image=cirros_image) |
| 404 | } |
Oleksii Zhurba | 1d547c1 | 2019-05-13 17:42:42 -0500 | [diff] [blame] | 405 | |
| 406 | show_step(2) |
| 407 | cvp_stacklight_result = run_jenkins_job.run_job( |
| 408 | host=jenkins_url, |
| 409 | username=jenkins_user, |
| 410 | password=jenkins_pass, |
| 411 | start_timeout=jenkins_start_timeout, |
| 412 | build_timeout=jenkins_build_timeout, |
| 413 | verbose=True, |
| 414 | job_name=job_name, |
Hanna Arhipova | 81af833 | 2019-10-28 14:33:06 +0200 | [diff] [blame] | 415 | job_parameters=job_parameters, |
Oleksii Zhurba | 1d547c1 | 2019-05-13 17:42:42 -0500 | [diff] [blame] | 416 | job_output_prefix='[cvp-stacklight/{build_number}:platform {time}]' |
| 417 | ) |
| 418 | |
| 419 | show_step(3) |
| 420 | (description, stages) = get_jenkins_job_stages.get_deployment_result( |
| 421 | host=jenkins_url, |
| 422 | username=jenkins_user, |
| 423 | password=jenkins_pass, |
| 424 | job_name=job_name, |
| 425 | build_number='lastBuild') |
| 426 | |
| 427 | LOG.info(description) |
| 428 | LOG.info('\n'.join(stages)) |
| 429 | LOG.info('Job {0} result: {1}'.format(job_name, |
| 430 | cvp_stacklight_result)) |
| 431 | # Download XML report |
| 432 | show_step(4) |
| 433 | destination_name = os.path.join(settings.LOGS_DIR, |
dtsapikov | 269f519 | 2021-08-12 13:35:43 +0400 | [diff] [blame^] | 434 | "tmp/" + job_name + "_" |
| 435 | + str(build_number) + "_results.xml") |
Oleksii Zhurba | 1d547c1 | 2019-05-13 17:42:42 -0500 | [diff] [blame] | 436 | # Do not fail the test case when the job is failed, but |
| 437 | # artifact with the XML report is present in the job. |
| 438 | try: |
| 439 | get_jenkins_job_artifact.download_artifact( |
| 440 | host=jenkins_url, |
| 441 | username=jenkins_user, |
| 442 | password=jenkins_pass, |
| 443 | job_name=job_name, |
| 444 | build_number='lastBuild', |
| 445 | artifact_path='validation_artifacts/cvp-stacklight_report.xml', |
| 446 | destination_name=destination_name) |
| 447 | except jenkins.NotFoundException: |
| 448 | raise jenkins.NotFoundException("{0}\n{1}".format( |
| 449 | description, '\n'.join(stages))) |
Hanna Arhipova | e97c66c | 2021-01-18 12:27:31 +0200 | [diff] [blame] | 450 | |
| 451 | @pytest.mark.grab_versions |
| 452 | @pytest.mark.parametrize("_", [settings.ENV_NAME]) |
| 453 | @pytest.mark.run_cvp_spt |
| 454 | def test_run_cvp_spt(self, salt_actions, show_step, _): |
| 455 | """Runner for Pipeline CVP - Functional tests |
| 456 | |
| 457 | Scenario: |
| 458 | 1. Get CICD Jenkins access credentials from salt |
| 459 | 2. Run job cvp-spt |
| 460 | 3. Get passed stages from cvp-spt |
| 461 | """ |
| 462 | salt = salt_actions |
| 463 | show_step(1) |
| 464 | |
| 465 | tgt = 'I@docker:client:stack:jenkins and cid01*' |
| 466 | jenkins_host = salt.get_single_pillar( |
| 467 | tgt=tgt, pillar="jenkins:client:master:host") |
| 468 | jenkins_port = salt.get_single_pillar( |
| 469 | tgt=tgt, pillar="jenkins:client:master:port") |
| 470 | jenkins_protocol = salt.get_single_pillar( |
| 471 | tgt=tgt, pillar="jenkins:client:master:proto") |
| 472 | jenkins_url = '{0}://{1}:{2}'.format(jenkins_protocol, |
| 473 | jenkins_host, |
| 474 | jenkins_port) |
| 475 | jenkins_user = salt.get_single_pillar( |
| 476 | tgt=tgt, pillar="jenkins:client:master:username") |
| 477 | jenkins_pass = salt.get_single_pillar( |
| 478 | tgt=tgt, pillar="jenkins:client:master:password") |
| 479 | jenkins_start_timeout = 60 |
| 480 | jenkins_build_timeout = 1800 |
| 481 | |
| 482 | job_name = 'cvp-spt' |
| 483 | |
| 484 | job_parameters = { |
| 485 | 'EXTRA_PARAMS': ( |
| 486 | """ |
| 487 | envs: |
| 488 | - tests_set='' |
| 489 | - image_name=TestCirros-0.4.0 |
| 490 | - networks=10.6.0.0/24 |
| 491 | """), |
| 492 | } |
| 493 | |
| 494 | show_step(2) |
| 495 | cvp_spt_result = run_jenkins_job.run_job( |
| 496 | host=jenkins_url, |
| 497 | username=jenkins_user, |
| 498 | password=jenkins_pass, |
| 499 | start_timeout=jenkins_start_timeout, |
| 500 | build_timeout=jenkins_build_timeout, |
| 501 | verbose=True, |
| 502 | job_name=job_name, |
| 503 | job_parameters=job_parameters, |
| 504 | job_output_prefix='[ cvp-func/{build_number}:platform {time} ] ') |
| 505 | |
| 506 | show_step(3) |
| 507 | (description, stages) = get_jenkins_job_stages.get_deployment_result( |
| 508 | host=jenkins_url, |
| 509 | username=jenkins_user, |
| 510 | password=jenkins_pass, |
| 511 | job_name=job_name, |
| 512 | build_number='lastBuild') |
| 513 | |
| 514 | LOG.info(description) |
| 515 | LOG.info('\n'.join(stages)) |
| 516 | LOG.info('Job {0} result: {1}'.format(job_name, |
| 517 | cvp_spt_result)) |
| 518 | assert cvp_spt_result == 'SUCCESS', "{0}\n{1}".format( |
| 519 | description, '\n'.join(stages)) |