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 | a51b89d | 2019-03-05 21:49:07 +0200 | [diff] [blame^] | 124 | maas_minion_id = salt.get_single_pillar( |
| 125 | tgt='I@maas:cluster:enabled:True or I@maas:region:enabled:True', |
| 126 | pillar="__reclass__:nodename") |
| 127 | |
Dennis Dmitriev | 2a49873 | 2018-12-21 18:30:23 +0200 | [diff] [blame] | 128 | job_name = 'cvp-sanity' |
| 129 | job_parameters = { |
| 130 | 'TEST_SET': '/var/lib/cvp-sanity/cvp_checks/tests/', |
Dennis Dmitriev | a51b89d | 2019-03-05 21:49:07 +0200 | [diff] [blame^] | 131 | 'TESTS_SETTINGS': ( |
| 132 | 'drivetrain_version={0};ntp_skipped_nodes={1}' |
| 133 | .format(settings.MCP_VERSION, maas_minion_id)), |
Dennis Dmitriev | 2a49873 | 2018-12-21 18:30:23 +0200 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | show_step(2) |
| 137 | cvp_func_sanity_result = run_jenkins_job.run_job( |
| 138 | host=jenkins_url, |
| 139 | username=jenkins_user, |
| 140 | password=jenkins_pass, |
| 141 | start_timeout=jenkins_start_timeout, |
| 142 | build_timeout=jenkins_build_timeout, |
| 143 | verbose=True, |
| 144 | job_name=job_name, |
| 145 | job_parameters=job_parameters, |
| 146 | job_output_prefix='[ cvp-func/{build_number}:platform {time} ] ') |
| 147 | |
| 148 | show_step(3) |
| 149 | (description, stages) = get_jenkins_job_stages.get_deployment_result( |
| 150 | host=jenkins_url, |
| 151 | username=jenkins_user, |
| 152 | password=jenkins_pass, |
| 153 | job_name=job_name, |
| 154 | build_number='lastBuild') |
| 155 | |
| 156 | LOG.info(description) |
| 157 | LOG.info('\n'.join(stages)) |
Dennis Dmitriev | 8565c34 | 2019-02-11 23:45:03 +0200 | [diff] [blame] | 158 | LOG.info('Job {0} result: {1}'.format(job_name, |
| 159 | cvp_func_sanity_result)) |
| 160 | # Download XML report |
| 161 | show_step(4) |
| 162 | destination_name = os.path.join(settings.LOGS_DIR, |
| 163 | "cvp_sanity_results.xml") |
| 164 | # Do not fail the test case when the job is failed, but |
| 165 | # artifact with the XML report is present in the job. |
| 166 | try: |
| 167 | get_jenkins_job_artifact.download_artifact( |
| 168 | host=jenkins_url, |
| 169 | username=jenkins_user, |
| 170 | password=jenkins_pass, |
| 171 | job_name=job_name, |
| 172 | build_number='lastBuild', |
| 173 | artifact_path='validation_artifacts/cvp-sanity_report.xml', |
| 174 | destination_name=destination_name) |
| 175 | except jenkins.NotFoundException: |
| 176 | raise jenkins.NotFoundException("{0}\n{1}".format( |
| 177 | description, '\n'.join(stages))) |
Dennis Dmitriev | 1566e3f | 2019-01-11 17:35:43 +0200 | [diff] [blame] | 178 | |
| 179 | @pytest.mark.grab_versions |
| 180 | @pytest.mark.parametrize("_", [settings.ENV_NAME]) |
| 181 | @pytest.mark.run_cvp_ha_smoke |
| 182 | def test_run_cvp_ha_smoke(self, underlay_actions, salt_actions, |
| 183 | show_step, _): |
| 184 | """Runner for Pipeline CVP - HA tests |
| 185 | |
| 186 | Scenario: |
| 187 | 1. Get CICD Jenkins access credentials from salt |
| 188 | 2. Run job cvp-ha with tempest set=smoke |
| 189 | 3. Get passed stages from cvp-ha |
| 190 | """ |
| 191 | salt = salt_actions |
| 192 | show_step(1) |
| 193 | |
| 194 | tgt = 'I@docker:client:stack:jenkins and cid01*' |
| 195 | jenkins_host = salt.get_single_pillar( |
| 196 | tgt=tgt, pillar="jenkins:client:master:host") |
| 197 | jenkins_port = salt.get_single_pillar( |
| 198 | tgt=tgt, pillar="jenkins:client:master:port") |
| 199 | jenkins_url = 'http://{0}:{1}'.format(jenkins_host, jenkins_port) |
| 200 | jenkins_user = salt.get_single_pillar( |
| 201 | tgt=tgt, pillar="jenkins:client:master:username") |
| 202 | jenkins_pass = salt.get_single_pillar( |
| 203 | tgt=tgt, pillar="jenkins:client:master:password") |
| 204 | jenkins_start_timeout = 60 |
| 205 | jenkins_build_timeout = 1800 |
| 206 | |
| 207 | tempest_target_node = salt.get_single_pillar( |
| 208 | tgt='cfg01*', |
| 209 | pillar="runtest:tempest:test_target") |
| 210 | |
| 211 | job_name = 'cvp-ha' |
| 212 | job_parameters = { |
| 213 | 'TEMPEST_TARGET_NODE': tempest_target_node, |
| 214 | 'TEMPEST_TEST_PATTERN': 'set=smoke', |
| 215 | } |
| 216 | |
| 217 | show_step(2) |
| 218 | cvp_ha_smoke_result = run_jenkins_job.run_job( |
| 219 | host=jenkins_url, |
| 220 | username=jenkins_user, |
| 221 | password=jenkins_pass, |
| 222 | start_timeout=jenkins_start_timeout, |
| 223 | build_timeout=jenkins_build_timeout, |
| 224 | verbose=True, |
| 225 | job_name=job_name, |
| 226 | job_parameters=job_parameters, |
| 227 | job_output_prefix='[ cvp-ha/{build_number} {time} ] ') |
| 228 | |
| 229 | show_step(3) |
| 230 | (description, stages) = get_jenkins_job_stages.get_deployment_result( |
| 231 | host=jenkins_url, |
| 232 | username=jenkins_user, |
| 233 | password=jenkins_pass, |
| 234 | job_name=job_name, |
| 235 | build_number='lastBuild') |
| 236 | |
| 237 | LOG.info(description) |
| 238 | LOG.info('\n'.join(stages)) |
| 239 | |
| 240 | assert cvp_ha_smoke_result == 'SUCCESS', "{0}\n{1}".format( |
| 241 | description, '\n'.join(stages)) |