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") |
| 56 | jenkins_url = 'http://{0}:{1}'.format(jenkins_host, jenkins_port) |
| 57 | jenkins_user = salt.get_single_pillar( |
| 58 | tgt=tgt, pillar="jenkins:client:master:username") |
| 59 | jenkins_pass = salt.get_single_pillar( |
| 60 | tgt=tgt, pillar="jenkins:client:master:password") |
| 61 | jenkins_start_timeout = 60 |
| 62 | jenkins_build_timeout = 1800 |
| 63 | |
| 64 | job_name = 'cvp-func' |
| 65 | job_parameters = { |
| 66 | 'TARGET_NODE': 'gtw01*', |
| 67 | 'TEMPEST_ENDPOINT_TYPE': 'internalURL', |
| 68 | 'TEMPEST_TEST_PATTERN': 'set=smoke', |
| 69 | } |
| 70 | show_step(2) |
| 71 | cvp_func_smoke_result = run_jenkins_job.run_job( |
| 72 | host=jenkins_url, |
| 73 | username=jenkins_user, |
| 74 | password=jenkins_pass, |
| 75 | start_timeout=jenkins_start_timeout, |
| 76 | build_timeout=jenkins_build_timeout, |
| 77 | verbose=True, |
| 78 | job_name=job_name, |
| 79 | job_parameters=job_parameters, |
| 80 | job_output_prefix='[ cvp-func/{build_number}:platform {time} ] ') |
| 81 | |
| 82 | show_step(3) |
| 83 | (description, stages) = get_jenkins_job_stages.get_deployment_result( |
| 84 | host=jenkins_url, |
| 85 | username=jenkins_user, |
| 86 | password=jenkins_pass, |
| 87 | job_name=job_name, |
| 88 | build_number='lastBuild') |
| 89 | |
| 90 | LOG.info(description) |
| 91 | LOG.info('\n'.join(stages)) |
| 92 | |
| 93 | assert cvp_func_smoke_result == 'SUCCESS', "{0}\n{1}".format( |
| 94 | description, '\n'.join(stages)) |
| 95 | |
| 96 | @pytest.mark.grab_versions |
| 97 | @pytest.mark.parametrize("_", [settings.ENV_NAME]) |
| 98 | @pytest.mark.run_cvp_func_sanity |
| 99 | def test_run_cvp_func_sanity(self, salt_actions, show_step, _): |
| 100 | """Runner for Pipeline CVP - Functional tests |
| 101 | |
| 102 | Scenario: |
| 103 | 1. Get CICD Jenkins access credentials from salt |
| 104 | 2. Run job cvp-sanity |
| 105 | 3. Get passed stages from cvp-sanity |
Dennis Dmitriev | 8565c34 | 2019-02-11 23:45:03 +0200 | [diff] [blame] | 106 | 4. Download XML report from the job |
Dennis Dmitriev | 2a49873 | 2018-12-21 18:30:23 +0200 | [diff] [blame] | 107 | """ |
| 108 | salt = salt_actions |
| 109 | show_step(1) |
| 110 | |
| 111 | tgt = 'I@docker:client:stack:jenkins and cid01*' |
| 112 | jenkins_host = salt.get_single_pillar( |
| 113 | tgt=tgt, pillar="jenkins:client:master:host") |
| 114 | jenkins_port = salt.get_single_pillar( |
| 115 | tgt=tgt, pillar="jenkins:client:master:port") |
| 116 | jenkins_url = 'http://{0}:{1}'.format(jenkins_host, jenkins_port) |
| 117 | jenkins_user = salt.get_single_pillar( |
| 118 | tgt=tgt, pillar="jenkins:client:master:username") |
| 119 | jenkins_pass = salt.get_single_pillar( |
| 120 | tgt=tgt, pillar="jenkins:client:master:password") |
| 121 | jenkins_start_timeout = 60 |
| 122 | jenkins_build_timeout = 1800 |
| 123 | |
Dennis Dmitriev | 85c5249 | 2019-03-12 15:26:56 +0200 | [diff] [blame] | 124 | try: |
| 125 | maas_minion_id = salt.get_single_pillar( |
| 126 | tgt='I@maas:cluster or I@maas:region', |
| 127 | pillar="__reclass__:nodename") |
Oleksii Zhurba | 04302d4 | 2019-05-30 09:56:21 -0500 | [diff] [blame^] | 128 | ntp_skipped_nodes = '{0}'.format(maas_minion_id) |
Dennis Dmitriev | 85c5249 | 2019-03-12 15:26:56 +0200 | [diff] [blame] | 129 | except LookupError: |
| 130 | ntp_skipped_nodes = '' |
Dennis Dmitriev | a51b89d | 2019-03-05 21:49:07 +0200 | [diff] [blame] | 131 | |
Dennis Dmitriev | 2a49873 | 2018-12-21 18:30:23 +0200 | [diff] [blame] | 132 | job_name = 'cvp-sanity' |
Tatyana Leontovich | a090c5a | 2019-05-17 02:07:28 +0300 | [diff] [blame] | 133 | skipped_packages = ("python-setuptools," |
| 134 | "python-pkg-resources,xunitmerge," |
| 135 | "python-gnocchiclient, " |
| 136 | "python-ujson,python-octaviaclient") |
| 137 | |
Dennis Dmitriev | 2a49873 | 2018-12-21 18:30:23 +0200 | [diff] [blame] | 138 | job_parameters = { |
Tatyana Leontovich | a090c5a | 2019-05-17 02:07:28 +0300 | [diff] [blame] | 139 | 'EXTRA_PARAMS': ( |
| 140 | """ |
| 141 | envs: |
| 142 | - skipped_packages='{0}' |
| 143 | - skipped_modules='xunitmerge,setuptools' |
| 144 | - skipped_services='docker,containerd' |
Oleksii Zhurba | 04302d4 | 2019-05-30 09:56:21 -0500 | [diff] [blame^] | 145 | - ntp_skipped_nodes='{1}'""" |
Tatyana Leontovich | a090c5a | 2019-05-17 02:07:28 +0300 | [diff] [blame] | 146 | .format(skipped_packages, ntp_skipped_nodes)), |
Dennis Dmitriev | 2a49873 | 2018-12-21 18:30:23 +0200 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | show_step(2) |
| 150 | cvp_func_sanity_result = run_jenkins_job.run_job( |
| 151 | host=jenkins_url, |
| 152 | username=jenkins_user, |
| 153 | password=jenkins_pass, |
| 154 | start_timeout=jenkins_start_timeout, |
| 155 | build_timeout=jenkins_build_timeout, |
| 156 | verbose=True, |
| 157 | job_name=job_name, |
| 158 | job_parameters=job_parameters, |
| 159 | job_output_prefix='[ cvp-func/{build_number}:platform {time} ] ') |
| 160 | |
| 161 | show_step(3) |
| 162 | (description, stages) = get_jenkins_job_stages.get_deployment_result( |
| 163 | host=jenkins_url, |
| 164 | username=jenkins_user, |
| 165 | password=jenkins_pass, |
| 166 | job_name=job_name, |
| 167 | build_number='lastBuild') |
| 168 | |
| 169 | LOG.info(description) |
| 170 | LOG.info('\n'.join(stages)) |
Dennis Dmitriev | 8565c34 | 2019-02-11 23:45:03 +0200 | [diff] [blame] | 171 | LOG.info('Job {0} result: {1}'.format(job_name, |
| 172 | cvp_func_sanity_result)) |
| 173 | # Download XML report |
| 174 | show_step(4) |
| 175 | destination_name = os.path.join(settings.LOGS_DIR, |
| 176 | "cvp_sanity_results.xml") |
| 177 | # Do not fail the test case when the job is failed, but |
| 178 | # artifact with the XML report is present in the job. |
| 179 | try: |
| 180 | get_jenkins_job_artifact.download_artifact( |
| 181 | host=jenkins_url, |
| 182 | username=jenkins_user, |
| 183 | password=jenkins_pass, |
| 184 | job_name=job_name, |
| 185 | build_number='lastBuild', |
| 186 | artifact_path='validation_artifacts/cvp-sanity_report.xml', |
| 187 | destination_name=destination_name) |
| 188 | except jenkins.NotFoundException: |
| 189 | raise jenkins.NotFoundException("{0}\n{1}".format( |
| 190 | description, '\n'.join(stages))) |
Dennis Dmitriev | 1566e3f | 2019-01-11 17:35:43 +0200 | [diff] [blame] | 191 | |
| 192 | @pytest.mark.grab_versions |
| 193 | @pytest.mark.parametrize("_", [settings.ENV_NAME]) |
| 194 | @pytest.mark.run_cvp_ha_smoke |
| 195 | def test_run_cvp_ha_smoke(self, underlay_actions, salt_actions, |
| 196 | show_step, _): |
| 197 | """Runner for Pipeline CVP - HA tests |
| 198 | |
| 199 | Scenario: |
| 200 | 1. Get CICD Jenkins access credentials from salt |
| 201 | 2. Run job cvp-ha with tempest set=smoke |
| 202 | 3. Get passed stages from cvp-ha |
| 203 | """ |
| 204 | salt = salt_actions |
| 205 | show_step(1) |
| 206 | |
| 207 | tgt = 'I@docker:client:stack:jenkins and cid01*' |
| 208 | jenkins_host = salt.get_single_pillar( |
| 209 | tgt=tgt, pillar="jenkins:client:master:host") |
| 210 | jenkins_port = salt.get_single_pillar( |
| 211 | tgt=tgt, pillar="jenkins:client:master:port") |
| 212 | jenkins_url = 'http://{0}:{1}'.format(jenkins_host, jenkins_port) |
| 213 | jenkins_user = salt.get_single_pillar( |
| 214 | tgt=tgt, pillar="jenkins:client:master:username") |
| 215 | jenkins_pass = salt.get_single_pillar( |
| 216 | tgt=tgt, pillar="jenkins:client:master:password") |
| 217 | jenkins_start_timeout = 60 |
| 218 | jenkins_build_timeout = 1800 |
| 219 | |
| 220 | tempest_target_node = salt.get_single_pillar( |
| 221 | tgt='cfg01*', |
| 222 | pillar="runtest:tempest:test_target") |
| 223 | |
| 224 | job_name = 'cvp-ha' |
| 225 | job_parameters = { |
| 226 | 'TEMPEST_TARGET_NODE': tempest_target_node, |
| 227 | 'TEMPEST_TEST_PATTERN': 'set=smoke', |
| 228 | } |
| 229 | |
| 230 | show_step(2) |
| 231 | cvp_ha_smoke_result = run_jenkins_job.run_job( |
| 232 | host=jenkins_url, |
| 233 | username=jenkins_user, |
| 234 | password=jenkins_pass, |
| 235 | start_timeout=jenkins_start_timeout, |
| 236 | build_timeout=jenkins_build_timeout, |
| 237 | verbose=True, |
| 238 | job_name=job_name, |
| 239 | job_parameters=job_parameters, |
| 240 | job_output_prefix='[ cvp-ha/{build_number} {time} ] ') |
| 241 | |
| 242 | show_step(3) |
| 243 | (description, stages) = get_jenkins_job_stages.get_deployment_result( |
| 244 | host=jenkins_url, |
| 245 | username=jenkins_user, |
| 246 | password=jenkins_pass, |
| 247 | job_name=job_name, |
| 248 | build_number='lastBuild') |
| 249 | |
| 250 | LOG.info(description) |
| 251 | LOG.info('\n'.join(stages)) |
| 252 | |
| 253 | assert cvp_ha_smoke_result == 'SUCCESS', "{0}\n{1}".format( |
| 254 | description, '\n'.join(stages)) |
Oleksii Zhurba | 1d547c1 | 2019-05-13 17:42:42 -0500 | [diff] [blame] | 255 | |
| 256 | @pytest.mark.grab_versions |
| 257 | @pytest.mark.parametrize("_", [settings.ENV_NAME]) |
| 258 | @pytest.mark.run_stacklight |
| 259 | def test_run_cvp_stacklight(self, salt_actions, show_step, _): |
| 260 | """Runner for Pipeline CVP - Stacklight |
| 261 | |
| 262 | Scenario: |
| 263 | 1. Get CICD Jenkins access credentials from salt |
| 264 | 2. Run job cvp-stacklight |
| 265 | 3. Get passed stages from cvp-stacklight |
| 266 | 4. Download XML report from the job |
| 267 | """ |
| 268 | salt = salt_actions |
| 269 | show_step(1) |
| 270 | |
| 271 | tgt = 'I@docker:client:stack:jenkins and cid01*' |
| 272 | jenkins_host = salt.get_single_pillar( |
| 273 | tgt=tgt, pillar="jenkins:client:master:host") |
| 274 | jenkins_port = salt.get_single_pillar( |
| 275 | tgt=tgt, pillar="jenkins:client:master:port") |
| 276 | jenkins_url = 'http://{0}:{1}'.format(jenkins_host, jenkins_port) |
| 277 | jenkins_user = salt.get_single_pillar( |
| 278 | tgt=tgt, pillar="jenkins:client:master:username") |
| 279 | jenkins_pass = salt.get_single_pillar( |
| 280 | tgt=tgt, pillar="jenkins:client:master:password") |
| 281 | jenkins_start_timeout = 60 |
| 282 | jenkins_build_timeout = 1800 |
| 283 | |
| 284 | job_name = 'cvp-stacklight' |
| 285 | |
| 286 | show_step(2) |
| 287 | cvp_stacklight_result = run_jenkins_job.run_job( |
| 288 | host=jenkins_url, |
| 289 | username=jenkins_user, |
| 290 | password=jenkins_pass, |
| 291 | start_timeout=jenkins_start_timeout, |
| 292 | build_timeout=jenkins_build_timeout, |
| 293 | verbose=True, |
| 294 | job_name=job_name, |
| 295 | job_parameters={}, |
| 296 | job_output_prefix='[cvp-stacklight/{build_number}:platform {time}]' |
| 297 | ) |
| 298 | |
| 299 | show_step(3) |
| 300 | (description, stages) = get_jenkins_job_stages.get_deployment_result( |
| 301 | host=jenkins_url, |
| 302 | username=jenkins_user, |
| 303 | password=jenkins_pass, |
| 304 | job_name=job_name, |
| 305 | build_number='lastBuild') |
| 306 | |
| 307 | LOG.info(description) |
| 308 | LOG.info('\n'.join(stages)) |
| 309 | LOG.info('Job {0} result: {1}'.format(job_name, |
| 310 | cvp_stacklight_result)) |
| 311 | # Download XML report |
| 312 | show_step(4) |
| 313 | destination_name = os.path.join(settings.LOGS_DIR, |
| 314 | "stacklight_report.xml") |
| 315 | # Do not fail the test case when the job is failed, but |
| 316 | # artifact with the XML report is present in the job. |
| 317 | try: |
| 318 | get_jenkins_job_artifact.download_artifact( |
| 319 | host=jenkins_url, |
| 320 | username=jenkins_user, |
| 321 | password=jenkins_pass, |
| 322 | job_name=job_name, |
| 323 | build_number='lastBuild', |
| 324 | artifact_path='validation_artifacts/cvp-stacklight_report.xml', |
| 325 | destination_name=destination_name) |
| 326 | except jenkins.NotFoundException: |
| 327 | raise jenkins.NotFoundException("{0}\n{1}".format( |
| 328 | description, '\n'.join(stages))) |