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 | |
| 15 | import pytest |
| 16 | |
| 17 | from tcp_tests import logger |
| 18 | from tcp_tests import settings |
| 19 | from tcp_tests.utils import run_jenkins_job |
| 20 | from tcp_tests.utils import get_jenkins_job_stages |
| 21 | |
| 22 | LOG = logger.logger |
| 23 | |
| 24 | |
| 25 | class TestCvpPipelines(object): |
| 26 | """Test class for running Cloud Validation Pipelines |
| 27 | |
| 28 | Requires environment variables: |
| 29 | ENV_NAME |
| 30 | LAB_CONFIG_NAME |
| 31 | TESTS_CONFIGS |
| 32 | """ |
| 33 | |
| 34 | @pytest.mark.grab_versions |
| 35 | @pytest.mark.parametrize("_", [settings.ENV_NAME]) |
| 36 | @pytest.mark.run_cvp_func_smoke |
| 37 | def test_run_cvp_func_smoke(self, salt_actions, show_step, _): |
| 38 | """Runner for Pipeline CVP - Functional tests |
| 39 | |
| 40 | Scenario: |
| 41 | 1. Get CICD Jenkins access credentials from salt |
| 42 | 2. Run job cvp-func |
| 43 | 3. Get passed stages from cvp-func |
| 44 | """ |
| 45 | salt = salt_actions |
| 46 | show_step(1) |
| 47 | |
| 48 | tgt = 'I@docker:client:stack:jenkins and cid01*' |
| 49 | jenkins_host = salt.get_single_pillar( |
| 50 | tgt=tgt, pillar="jenkins:client:master:host") |
| 51 | jenkins_port = salt.get_single_pillar( |
| 52 | tgt=tgt, pillar="jenkins:client:master:port") |
| 53 | jenkins_url = 'http://{0}:{1}'.format(jenkins_host, jenkins_port) |
| 54 | jenkins_user = salt.get_single_pillar( |
| 55 | tgt=tgt, pillar="jenkins:client:master:username") |
| 56 | jenkins_pass = salt.get_single_pillar( |
| 57 | tgt=tgt, pillar="jenkins:client:master:password") |
| 58 | jenkins_start_timeout = 60 |
| 59 | jenkins_build_timeout = 1800 |
| 60 | |
| 61 | job_name = 'cvp-func' |
| 62 | job_parameters = { |
| 63 | 'TARGET_NODE': 'gtw01*', |
| 64 | 'TEMPEST_ENDPOINT_TYPE': 'internalURL', |
| 65 | 'TEMPEST_TEST_PATTERN': 'set=smoke', |
| 66 | } |
| 67 | show_step(2) |
| 68 | cvp_func_smoke_result = run_jenkins_job.run_job( |
| 69 | host=jenkins_url, |
| 70 | username=jenkins_user, |
| 71 | password=jenkins_pass, |
| 72 | start_timeout=jenkins_start_timeout, |
| 73 | build_timeout=jenkins_build_timeout, |
| 74 | verbose=True, |
| 75 | job_name=job_name, |
| 76 | job_parameters=job_parameters, |
| 77 | job_output_prefix='[ cvp-func/{build_number}:platform {time} ] ') |
| 78 | |
| 79 | show_step(3) |
| 80 | (description, stages) = get_jenkins_job_stages.get_deployment_result( |
| 81 | host=jenkins_url, |
| 82 | username=jenkins_user, |
| 83 | password=jenkins_pass, |
| 84 | job_name=job_name, |
| 85 | build_number='lastBuild') |
| 86 | |
| 87 | LOG.info(description) |
| 88 | LOG.info('\n'.join(stages)) |
| 89 | |
| 90 | assert cvp_func_smoke_result == 'SUCCESS', "{0}\n{1}".format( |
| 91 | description, '\n'.join(stages)) |
| 92 | |
| 93 | @pytest.mark.grab_versions |
| 94 | @pytest.mark.parametrize("_", [settings.ENV_NAME]) |
| 95 | @pytest.mark.run_cvp_func_sanity |
| 96 | def test_run_cvp_func_sanity(self, salt_actions, show_step, _): |
| 97 | """Runner for Pipeline CVP - Functional tests |
| 98 | |
| 99 | Scenario: |
| 100 | 1. Get CICD Jenkins access credentials from salt |
| 101 | 2. Run job cvp-sanity |
| 102 | 3. Get passed stages from cvp-sanity |
| 103 | """ |
| 104 | salt = salt_actions |
| 105 | show_step(1) |
| 106 | |
| 107 | tgt = 'I@docker:client:stack:jenkins and cid01*' |
| 108 | jenkins_host = salt.get_single_pillar( |
| 109 | tgt=tgt, pillar="jenkins:client:master:host") |
| 110 | jenkins_port = salt.get_single_pillar( |
| 111 | tgt=tgt, pillar="jenkins:client:master:port") |
| 112 | jenkins_url = 'http://{0}:{1}'.format(jenkins_host, jenkins_port) |
| 113 | jenkins_user = salt.get_single_pillar( |
| 114 | tgt=tgt, pillar="jenkins:client:master:username") |
| 115 | jenkins_pass = salt.get_single_pillar( |
| 116 | tgt=tgt, pillar="jenkins:client:master:password") |
| 117 | jenkins_start_timeout = 60 |
| 118 | jenkins_build_timeout = 1800 |
| 119 | |
| 120 | job_name = 'cvp-sanity' |
| 121 | job_parameters = { |
| 122 | 'TEST_SET': '/var/lib/cvp-sanity/cvp_checks/tests/', |
Dennis Dmitriev | 1566e3f | 2019-01-11 17:35:43 +0200 | [diff] [blame^] | 123 | 'TESTS_SETTINGS': 'drivetrain_version=proposed', |
Dennis Dmitriev | 2a49873 | 2018-12-21 18:30:23 +0200 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | show_step(2) |
| 127 | cvp_func_sanity_result = run_jenkins_job.run_job( |
| 128 | host=jenkins_url, |
| 129 | username=jenkins_user, |
| 130 | password=jenkins_pass, |
| 131 | start_timeout=jenkins_start_timeout, |
| 132 | build_timeout=jenkins_build_timeout, |
| 133 | verbose=True, |
| 134 | job_name=job_name, |
| 135 | job_parameters=job_parameters, |
| 136 | job_output_prefix='[ cvp-func/{build_number}:platform {time} ] ') |
| 137 | |
| 138 | show_step(3) |
| 139 | (description, stages) = get_jenkins_job_stages.get_deployment_result( |
| 140 | host=jenkins_url, |
| 141 | username=jenkins_user, |
| 142 | password=jenkins_pass, |
| 143 | job_name=job_name, |
| 144 | build_number='lastBuild') |
| 145 | |
| 146 | LOG.info(description) |
| 147 | LOG.info('\n'.join(stages)) |
| 148 | |
| 149 | assert cvp_func_sanity_result == 'SUCCESS', "{0}\n{1}".format( |
| 150 | description, '\n'.join(stages)) |
Dennis Dmitriev | 1566e3f | 2019-01-11 17:35:43 +0200 | [diff] [blame^] | 151 | |
| 152 | @pytest.mark.grab_versions |
| 153 | @pytest.mark.parametrize("_", [settings.ENV_NAME]) |
| 154 | @pytest.mark.run_cvp_ha_smoke |
| 155 | def test_run_cvp_ha_smoke(self, underlay_actions, salt_actions, |
| 156 | show_step, _): |
| 157 | """Runner for Pipeline CVP - HA tests |
| 158 | |
| 159 | Scenario: |
| 160 | 1. Get CICD Jenkins access credentials from salt |
| 161 | 2. Run job cvp-ha with tempest set=smoke |
| 162 | 3. Get passed stages from cvp-ha |
| 163 | """ |
| 164 | salt = salt_actions |
| 165 | show_step(1) |
| 166 | |
| 167 | tgt = 'I@docker:client:stack:jenkins and cid01*' |
| 168 | jenkins_host = salt.get_single_pillar( |
| 169 | tgt=tgt, pillar="jenkins:client:master:host") |
| 170 | jenkins_port = salt.get_single_pillar( |
| 171 | tgt=tgt, pillar="jenkins:client:master:port") |
| 172 | jenkins_url = 'http://{0}:{1}'.format(jenkins_host, jenkins_port) |
| 173 | jenkins_user = salt.get_single_pillar( |
| 174 | tgt=tgt, pillar="jenkins:client:master:username") |
| 175 | jenkins_pass = salt.get_single_pillar( |
| 176 | tgt=tgt, pillar="jenkins:client:master:password") |
| 177 | jenkins_start_timeout = 60 |
| 178 | jenkins_build_timeout = 1800 |
| 179 | |
| 180 | tempest_target_node = salt.get_single_pillar( |
| 181 | tgt='cfg01*', |
| 182 | pillar="runtest:tempest:test_target") |
| 183 | |
| 184 | job_name = 'cvp-ha' |
| 185 | job_parameters = { |
| 186 | 'TEMPEST_TARGET_NODE': tempest_target_node, |
| 187 | 'TEMPEST_TEST_PATTERN': 'set=smoke', |
| 188 | } |
| 189 | |
| 190 | show_step(2) |
| 191 | cvp_ha_smoke_result = run_jenkins_job.run_job( |
| 192 | host=jenkins_url, |
| 193 | username=jenkins_user, |
| 194 | password=jenkins_pass, |
| 195 | start_timeout=jenkins_start_timeout, |
| 196 | build_timeout=jenkins_build_timeout, |
| 197 | verbose=True, |
| 198 | job_name=job_name, |
| 199 | job_parameters=job_parameters, |
| 200 | job_output_prefix='[ cvp-ha/{build_number} {time} ] ') |
| 201 | |
| 202 | show_step(3) |
| 203 | (description, stages) = get_jenkins_job_stages.get_deployment_result( |
| 204 | host=jenkins_url, |
| 205 | username=jenkins_user, |
| 206 | password=jenkins_pass, |
| 207 | job_name=job_name, |
| 208 | build_number='lastBuild') |
| 209 | |
| 210 | LOG.info(description) |
| 211 | LOG.info('\n'.join(stages)) |
| 212 | |
| 213 | assert cvp_ha_smoke_result == 'SUCCESS', "{0}\n{1}".format( |
| 214 | description, '\n'.join(stages)) |