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/', |
| 123 | } |
| 124 | |
| 125 | show_step(2) |
| 126 | cvp_func_sanity_result = run_jenkins_job.run_job( |
| 127 | host=jenkins_url, |
| 128 | username=jenkins_user, |
| 129 | password=jenkins_pass, |
| 130 | start_timeout=jenkins_start_timeout, |
| 131 | build_timeout=jenkins_build_timeout, |
| 132 | verbose=True, |
| 133 | job_name=job_name, |
| 134 | job_parameters=job_parameters, |
| 135 | job_output_prefix='[ cvp-func/{build_number}:platform {time} ] ') |
| 136 | |
| 137 | show_step(3) |
| 138 | (description, stages) = get_jenkins_job_stages.get_deployment_result( |
| 139 | host=jenkins_url, |
| 140 | username=jenkins_user, |
| 141 | password=jenkins_pass, |
| 142 | job_name=job_name, |
| 143 | build_number='lastBuild') |
| 144 | |
| 145 | LOG.info(description) |
| 146 | LOG.info('\n'.join(stages)) |
| 147 | |
| 148 | assert cvp_func_sanity_result == 'SUCCESS', "{0}\n{1}".format( |
| 149 | description, '\n'.join(stages)) |