blob: ce3380670e9b66b52b03f2ec4d62bed53a649bf3 [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,"
137 "python-pkg-resources,xunitmerge', "
138 "skipped_services='docker, "
139 "containerd'; drivetrain_version={0};{1}"
Dennis Dmitriev85c52492019-03-12 15:26:56 +0200140 .format(settings.MCP_VERSION, ntp_skipped_nodes)),
Dennis Dmitriev2a498732018-12-21 18:30:23 +0200141 }
142
143 show_step(2)
144 cvp_func_sanity_result = run_jenkins_job.run_job(
145 host=jenkins_url,
146 username=jenkins_user,
147 password=jenkins_pass,
148 start_timeout=jenkins_start_timeout,
149 build_timeout=jenkins_build_timeout,
150 verbose=True,
151 job_name=job_name,
152 job_parameters=job_parameters,
153 job_output_prefix='[ cvp-func/{build_number}:platform {time} ] ')
154
155 show_step(3)
156 (description, stages) = get_jenkins_job_stages.get_deployment_result(
157 host=jenkins_url,
158 username=jenkins_user,
159 password=jenkins_pass,
160 job_name=job_name,
161 build_number='lastBuild')
162
163 LOG.info(description)
164 LOG.info('\n'.join(stages))
Dennis Dmitriev8565c342019-02-11 23:45:03 +0200165 LOG.info('Job {0} result: {1}'.format(job_name,
166 cvp_func_sanity_result))
167 # Download XML report
168 show_step(4)
169 destination_name = os.path.join(settings.LOGS_DIR,
170 "cvp_sanity_results.xml")
171 # Do not fail the test case when the job is failed, but
172 # artifact with the XML report is present in the job.
173 try:
174 get_jenkins_job_artifact.download_artifact(
175 host=jenkins_url,
176 username=jenkins_user,
177 password=jenkins_pass,
178 job_name=job_name,
179 build_number='lastBuild',
180 artifact_path='validation_artifacts/cvp-sanity_report.xml',
181 destination_name=destination_name)
182 except jenkins.NotFoundException:
183 raise jenkins.NotFoundException("{0}\n{1}".format(
184 description, '\n'.join(stages)))
Dennis Dmitriev1566e3f2019-01-11 17:35:43 +0200185
186 @pytest.mark.grab_versions
187 @pytest.mark.parametrize("_", [settings.ENV_NAME])
188 @pytest.mark.run_cvp_ha_smoke
189 def test_run_cvp_ha_smoke(self, underlay_actions, salt_actions,
190 show_step, _):
191 """Runner for Pipeline CVP - HA tests
192
193 Scenario:
194 1. Get CICD Jenkins access credentials from salt
195 2. Run job cvp-ha with tempest set=smoke
196 3. Get passed stages from cvp-ha
197 """
198 salt = salt_actions
199 show_step(1)
200
201 tgt = 'I@docker:client:stack:jenkins and cid01*'
202 jenkins_host = salt.get_single_pillar(
203 tgt=tgt, pillar="jenkins:client:master:host")
204 jenkins_port = salt.get_single_pillar(
205 tgt=tgt, pillar="jenkins:client:master:port")
206 jenkins_url = 'http://{0}:{1}'.format(jenkins_host, jenkins_port)
207 jenkins_user = salt.get_single_pillar(
208 tgt=tgt, pillar="jenkins:client:master:username")
209 jenkins_pass = salt.get_single_pillar(
210 tgt=tgt, pillar="jenkins:client:master:password")
211 jenkins_start_timeout = 60
212 jenkins_build_timeout = 1800
213
214 tempest_target_node = salt.get_single_pillar(
215 tgt='cfg01*',
216 pillar="runtest:tempest:test_target")
217
218 job_name = 'cvp-ha'
219 job_parameters = {
220 'TEMPEST_TARGET_NODE': tempest_target_node,
221 'TEMPEST_TEST_PATTERN': 'set=smoke',
222 }
223
224 show_step(2)
225 cvp_ha_smoke_result = run_jenkins_job.run_job(
226 host=jenkins_url,
227 username=jenkins_user,
228 password=jenkins_pass,
229 start_timeout=jenkins_start_timeout,
230 build_timeout=jenkins_build_timeout,
231 verbose=True,
232 job_name=job_name,
233 job_parameters=job_parameters,
234 job_output_prefix='[ cvp-ha/{build_number} {time} ] ')
235
236 show_step(3)
237 (description, stages) = get_jenkins_job_stages.get_deployment_result(
238 host=jenkins_url,
239 username=jenkins_user,
240 password=jenkins_pass,
241 job_name=job_name,
242 build_number='lastBuild')
243
244 LOG.info(description)
245 LOG.info('\n'.join(stages))
246
247 assert cvp_ha_smoke_result == 'SUCCESS', "{0}\n{1}".format(
248 description, '\n'.join(stages))