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