blob: 001341d9e598ee9bc7653ebd00fd15f4c9d03369 [file] [log] [blame]
Dennis Dmitriev2a498732018-12-21 18:30:23 +02001# 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 Dmitriev8565c342019-02-11 23:45:03 +020015import jenkins
Dennis Dmitriev2a498732018-12-21 18:30:23 +020016import pytest
Dennis Dmitriev8565c342019-02-11 23:45:03 +020017import os
Dennis Dmitriev2a498732018-12-21 18:30:23 +020018
19from tcp_tests import logger
20from tcp_tests import settings
21from tcp_tests.utils import run_jenkins_job
22from tcp_tests.utils import get_jenkins_job_stages
Dennis Dmitriev8565c342019-02-11 23:45:03 +020023from tcp_tests.utils import get_jenkins_job_artifact
Dennis Dmitriev2a498732018-12-21 18:30:23 +020024
25LOG = logger.logger
26
27
28class 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 Dmitriev8565c342019-02-11 23:45:03 +0200106 4. Download XML report from the job
Dennis Dmitriev2a498732018-12-21 18:30:23 +0200107 """
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 Dmitriev85c52492019-03-12 15:26:56 +0200124 try:
125 maas_minion_id = salt.get_single_pillar(
126 tgt='I@maas:cluster or I@maas:region',
127 pillar="__reclass__:nodename")
128 ntp_skipped_nodes = 'ntp_skipped_nodes={0}'.format(maas_minion_id)
129 except LookupError:
130 ntp_skipped_nodes = ''
Dennis Dmitrieva51b89d2019-03-05 21:49:07 +0200131
Dennis Dmitriev2a498732018-12-21 18:30:23 +0200132 job_name = 'cvp-sanity'
133 job_parameters = {
134 'TEST_SET': '/var/lib/cvp-sanity/cvp_checks/tests/',
Dennis Dmitrieva51b89d2019-03-05 21:49:07 +0200135 'TESTS_SETTINGS': (
Tatyana Leontovich6a96fec2019-04-03 14:06:29 +0300136 "skipped_packages='python-setuptools,"
Tatyana Leontovichb5da3602019-04-18 12:15:50 +0300137 "python-pkg-resources,xunitmerge,python-gnocchiclient,"
138 "python-ujson,python-octaviaclient', "
sgudza25bfe62019-05-06 14:48:29 +0300139 "skipped_modules='xunitmerge,setuptools', "
Tatyana Leontovich6a96fec2019-04-03 14:06:29 +0300140 "skipped_services='docker, "
141 "containerd'; drivetrain_version={0};{1}"
Dennis Dmitriev85c52492019-03-12 15:26:56 +0200142 .format(settings.MCP_VERSION, ntp_skipped_nodes)),
Dennis Dmitriev2a498732018-12-21 18:30:23 +0200143 }
144
145 show_step(2)
146 cvp_func_sanity_result = run_jenkins_job.run_job(
147 host=jenkins_url,
148 username=jenkins_user,
149 password=jenkins_pass,
150 start_timeout=jenkins_start_timeout,
151 build_timeout=jenkins_build_timeout,
152 verbose=True,
153 job_name=job_name,
154 job_parameters=job_parameters,
155 job_output_prefix='[ cvp-func/{build_number}:platform {time} ] ')
156
157 show_step(3)
158 (description, stages) = get_jenkins_job_stages.get_deployment_result(
159 host=jenkins_url,
160 username=jenkins_user,
161 password=jenkins_pass,
162 job_name=job_name,
163 build_number='lastBuild')
164
165 LOG.info(description)
166 LOG.info('\n'.join(stages))
Dennis Dmitriev8565c342019-02-11 23:45:03 +0200167 LOG.info('Job {0} result: {1}'.format(job_name,
168 cvp_func_sanity_result))
169 # Download XML report
170 show_step(4)
171 destination_name = os.path.join(settings.LOGS_DIR,
172 "cvp_sanity_results.xml")
173 # Do not fail the test case when the job is failed, but
174 # artifact with the XML report is present in the job.
175 try:
176 get_jenkins_job_artifact.download_artifact(
177 host=jenkins_url,
178 username=jenkins_user,
179 password=jenkins_pass,
180 job_name=job_name,
181 build_number='lastBuild',
182 artifact_path='validation_artifacts/cvp-sanity_report.xml',
183 destination_name=destination_name)
184 except jenkins.NotFoundException:
185 raise jenkins.NotFoundException("{0}\n{1}".format(
186 description, '\n'.join(stages)))
Dennis Dmitriev1566e3f2019-01-11 17:35:43 +0200187
188 @pytest.mark.grab_versions
189 @pytest.mark.parametrize("_", [settings.ENV_NAME])
190 @pytest.mark.run_cvp_ha_smoke
191 def test_run_cvp_ha_smoke(self, underlay_actions, salt_actions,
192 show_step, _):
193 """Runner for Pipeline CVP - HA tests
194
195 Scenario:
196 1. Get CICD Jenkins access credentials from salt
197 2. Run job cvp-ha with tempest set=smoke
198 3. Get passed stages from cvp-ha
199 """
200 salt = salt_actions
201 show_step(1)
202
203 tgt = 'I@docker:client:stack:jenkins and cid01*'
204 jenkins_host = salt.get_single_pillar(
205 tgt=tgt, pillar="jenkins:client:master:host")
206 jenkins_port = salt.get_single_pillar(
207 tgt=tgt, pillar="jenkins:client:master:port")
208 jenkins_url = 'http://{0}:{1}'.format(jenkins_host, jenkins_port)
209 jenkins_user = salt.get_single_pillar(
210 tgt=tgt, pillar="jenkins:client:master:username")
211 jenkins_pass = salt.get_single_pillar(
212 tgt=tgt, pillar="jenkins:client:master:password")
213 jenkins_start_timeout = 60
214 jenkins_build_timeout = 1800
215
216 tempest_target_node = salt.get_single_pillar(
217 tgt='cfg01*',
218 pillar="runtest:tempest:test_target")
219
220 job_name = 'cvp-ha'
221 job_parameters = {
222 'TEMPEST_TARGET_NODE': tempest_target_node,
223 'TEMPEST_TEST_PATTERN': 'set=smoke',
224 }
225
226 show_step(2)
227 cvp_ha_smoke_result = run_jenkins_job.run_job(
228 host=jenkins_url,
229 username=jenkins_user,
230 password=jenkins_pass,
231 start_timeout=jenkins_start_timeout,
232 build_timeout=jenkins_build_timeout,
233 verbose=True,
234 job_name=job_name,
235 job_parameters=job_parameters,
236 job_output_prefix='[ cvp-ha/{build_number} {time} ] ')
237
238 show_step(3)
239 (description, stages) = get_jenkins_job_stages.get_deployment_result(
240 host=jenkins_url,
241 username=jenkins_user,
242 password=jenkins_pass,
243 job_name=job_name,
244 build_number='lastBuild')
245
246 LOG.info(description)
247 LOG.info('\n'.join(stages))
248
249 assert cvp_ha_smoke_result == 'SUCCESS', "{0}\n{1}".format(
250 description, '\n'.join(stages))