Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 1 | # Copyright 2018 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 | |
Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 15 | import json |
Oleksii Butenko | 71d76f3 | 2018-06-05 17:46:34 +0300 | [diff] [blame] | 16 | import os |
Dennis Dmitriev | 6d52a45 | 2018-09-26 11:06:32 +0000 | [diff] [blame^] | 17 | import time |
| 18 | |
| 19 | from devops.helpers import helpers |
Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 20 | |
| 21 | from tcp_tests import logger |
| 22 | from tcp_tests import settings |
| 23 | |
Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 24 | LOG = logger.logger |
| 25 | |
| 26 | TEMPEST_CFG_DIR = '/tmp/test' |
| 27 | |
Dennis Dmitriev | 6d52a45 | 2018-09-26 11:06:32 +0000 | [diff] [blame^] | 28 | CONFIG = { |
| 29 | 'classes': ['service.runtest.tempest', |
| 30 | 'service.runtest.tempest.services.manila.glance'], |
| 31 | 'parameters': { |
| 32 | '_param': { |
| 33 | 'runtest_tempest_cfg_dir': TEMPEST_CFG_DIR, |
| 34 | 'runtest_tempest_cfg_name': 'tempest.conf', |
| 35 | 'runtest_tempest_public_net': 'net04_ext', |
| 36 | 'tempest_test_target': 'gtw01*' |
| 37 | }, |
| 38 | 'neutron': { |
| 39 | 'client': { |
| 40 | 'enabled': True |
| 41 | } |
| 42 | }, |
| 43 | 'runtest': { |
| 44 | 'enabled': True, |
| 45 | 'keystonerc_node': 'ctl01*', |
| 46 | 'tempest': { |
| 47 | 'enabled': True, |
| 48 | 'cfg_dir': '${_param:runtest_tempest_cfg_dir}', |
| 49 | 'cfg_name': '${_param:runtest_tempest_cfg_name}', |
| 50 | 'DEFAULT': { |
| 51 | 'log_file': 'tempest.log' |
| 52 | }, |
| 53 | 'compute': { |
| 54 | 'build_timeout': 600, |
| 55 | 'max_microversion': 2.53, |
| 56 | 'min_compute_nodes': 2, |
| 57 | 'min_microversion': 2.1, |
| 58 | 'volume_device_name': 'vdc' |
| 59 | }, |
| 60 | 'convert_to_uuid': { |
| 61 | 'network': { |
| 62 | 'public_network_id': |
| 63 | '${_param:runtest_tempest_public_net}' |
| 64 | } |
| 65 | }, |
| 66 | 'dns_feature_enabled': { |
| 67 | 'api_admin': False, |
| 68 | 'api_v1': False, |
| 69 | 'api_v2': True, |
| 70 | 'api_v2_quotas': True, |
| 71 | 'api_v2_root_recordsets': True, |
| 72 | 'bug_1573141_fixed': True |
| 73 | }, |
| 74 | 'heat_plugin': { |
| 75 | 'floating_network_name': |
| 76 | '${_param:runtest_tempest_public_net}' |
| 77 | }, |
| 78 | 'network': { |
| 79 | 'floating_network_name': |
| 80 | '${_param:runtest_tempest_public_net}' |
| 81 | }, |
| 82 | 'share': { |
| 83 | 'capability_snapshot_support': True, |
| 84 | 'run_driver_assisted_migration_tests': False, |
| 85 | 'run_manage_unmanage_snapshot_tests': False, |
| 86 | 'run_manage_unmanage_tests': False, |
| 87 | 'run_migration_with_preserve_snapshots_tests': False, |
| 88 | 'run_quota_tests': True, |
| 89 | 'run_replication_tests': False, |
| 90 | 'run_snapshot_tests': True, |
| 91 | }}}}} |
| 92 | |
Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 93 | |
| 94 | class RuntestManager(object): |
| 95 | """Helper manager for execution tempest via runtest-formula""" |
| 96 | |
| 97 | image_name = settings.TEMPEST_IMAGE |
| 98 | image_version = settings.TEMPEST_IMAGE_VERSION |
| 99 | container_name = 'run-tempest-ci' |
| 100 | master_host = "cfg01" |
Dennis Dmitriev | 6d52a45 | 2018-09-26 11:06:32 +0000 | [diff] [blame^] | 101 | master_tgt = "{}*".format(master_host) |
Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 102 | class_name = "runtest" |
| 103 | run_cmd = '/bin/bash -c "run-tempest"' |
| 104 | |
Dennis Dmitriev | 6d52a45 | 2018-09-26 11:06:32 +0000 | [diff] [blame^] | 105 | def __init__(self, underlay, salt_api, cluster_name, |
Oleksii Butenko | 7456610 | 2018-09-11 11:55:13 +0300 | [diff] [blame] | 106 | domain_name, tempest_threads, |
Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 107 | tempest_pattern=settings.TEMPEST_PATTERN, |
| 108 | run_cmd=None, target='gtw01'): |
| 109 | self.underlay = underlay |
| 110 | self.__salt_api = salt_api |
Dennis Dmitriev | 6d52a45 | 2018-09-26 11:06:32 +0000 | [diff] [blame^] | 111 | self.target = target |
Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 112 | self.cluster_name = cluster_name |
| 113 | self.domain_name = domain_name |
| 114 | self.tempest_threads = tempest_threads |
Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 115 | self.tempest_pattern = tempest_pattern |
| 116 | self.run_cmd = run_cmd or self.run_cmd |
| 117 | |
| 118 | @property |
| 119 | def salt_api(self): |
| 120 | return self.__salt_api |
| 121 | |
Dennis Dmitriev | 6d52a45 | 2018-09-26 11:06:32 +0000 | [diff] [blame^] | 122 | def install_python_lib(self): |
| 123 | return self.salt_api.local( |
| 124 | "{}*".format(self.target), |
| 125 | 'pip.install', 'docker'), None |
Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 126 | |
Dennis Dmitriev | 6d52a45 | 2018-09-26 11:06:32 +0000 | [diff] [blame^] | 127 | def run_salt_minion_state(self): |
| 128 | return self.salt_api.local('cfg01*', 'state.sls', 'salt.minion') |
| 129 | |
| 130 | def create_networks(self): |
| 131 | return self.salt_api.local('cfg01*', 'state.sls', 'neutron.client') |
| 132 | |
| 133 | def create_flavors(self): |
| 134 | return self.salt_api.local('cfg01*', 'state.sls', 'nova.client') |
| 135 | |
| 136 | def set_property(self): |
| 137 | return self.salt_api.local( |
| 138 | tgt='ctl01*', |
| 139 | fun='cmd.run', |
| 140 | args='. /root/keystonercv3; openstack ' |
| 141 | 'flavor set m1.tiny_test ' |
| 142 | '--property hw:mem_page_size=small') |
| 143 | |
| 144 | def create_cirros(self): |
| 145 | return self.salt_api.local('cfg01*', 'state.sls', 'glance.client') |
| 146 | |
| 147 | def generate_config(self): |
| 148 | return self.salt_api.local('cfg01*', 'state.sls', 'runtest') |
Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 149 | |
Oleksii Butenko | 71d76f3 | 2018-06-05 17:46:34 +0300 | [diff] [blame] | 150 | def fetch_arficats(self, username=None, file_format='xml'): |
Dennis Dmitriev | 6d52a45 | 2018-09-26 11:06:32 +0000 | [diff] [blame^] | 151 | target_name = next(node_name for node_name |
| 152 | in self.underlay.node_names() if |
| 153 | self.target in node_name) |
| 154 | with self.underlay.remote(node_name=target_name, username=None) as tgt: |
Oleksii Butenko | 71d76f3 | 2018-06-05 17:46:34 +0300 | [diff] [blame] | 155 | result = tgt.execute('find {} -name "report_*.{}"'.format( |
| 156 | TEMPEST_CFG_DIR, file_format)) |
| 157 | LOG.debug("Find result {0}".format(result)) |
| 158 | assert len(result['stdout']) > 0, ('No report found, please check' |
| 159 | ' if test run was successful.') |
| 160 | report = result['stdout'][0].rstrip() |
| 161 | LOG.debug("Found files {0}".format(report)) |
Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 162 | tgt.download( |
Oleksii Butenko | 71d76f3 | 2018-06-05 17:46:34 +0300 | [diff] [blame] | 163 | destination=report, # noqa |
| 164 | target=os.getcwd()) |
Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 165 | |
Dennis Dmitriev | 6d52a45 | 2018-09-26 11:06:32 +0000 | [diff] [blame^] | 166 | def store_runtest_model(self, config=CONFIG): |
| 167 | master_name = next(node_name for node_name |
| 168 | in self.underlay.node_names() if |
| 169 | self.master_host in node_name) |
Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 170 | with self.underlay.yaml_editor( |
| 171 | file_path="/srv/salt/reclass/classes/cluster/" |
| 172 | "{cluster_name}/infra/" |
| 173 | "{class_name}.yml".format( |
| 174 | cluster_name=self.cluster_name, |
| 175 | class_name=self.class_name), |
Dennis Dmitriev | 6d52a45 | 2018-09-26 11:06:32 +0000 | [diff] [blame^] | 176 | node_name=master_name) as editor: |
| 177 | editor.content = config |
Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 178 | with self.underlay.yaml_editor( |
| 179 | file_path="/srv/salt/reclass/nodes/_generated/" |
| 180 | "cfg01.{domain_name}.yml".format( |
| 181 | domain_name=self.domain_name), |
Dennis Dmitriev | 6d52a45 | 2018-09-26 11:06:32 +0000 | [diff] [blame^] | 182 | node_name=master_name) as editor: |
Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 183 | editor.content['classes'].append( |
| 184 | 'cluster.{cluster_name}.infra.{class_name}'.format( |
| 185 | cluster_name=self.cluster_name, |
| 186 | class_name=self.class_name)) |
| 187 | |
Dennis Dmitriev | 6d52a45 | 2018-09-26 11:06:32 +0000 | [diff] [blame^] | 188 | self.salt_api.local('*', 'saltutil.refresh_pillar') |
| 189 | self.salt_api.local('*', 'saltutil.sync_all') |
| 190 | |
Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 191 | def save_runtime_logs(self, logs=None, inspect=None): |
| 192 | if logs: |
| 193 | with open("{path}/{target}_tempest_run.log".format( |
Dennis Dmitriev | 6d52a45 | 2018-09-26 11:06:32 +0000 | [diff] [blame^] | 194 | path=settings.LOGS_DIR, target=self.target), 'w') as f: |
Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 195 | LOG.info("Save tempest console log") |
| 196 | container_log = logs |
Oleksii Butenko | 71d76f3 | 2018-06-05 17:46:34 +0300 | [diff] [blame] | 197 | f.write(container_log.encode('ascii', 'ignore')) |
Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 198 | |
| 199 | if inspect: |
Oleksii Butenko | 71d76f3 | 2018-06-05 17:46:34 +0300 | [diff] [blame] | 200 | with open("{path}/{target}_tempest_container_info.json.log".format( |
Dennis Dmitriev | 6d52a45 | 2018-09-26 11:06:32 +0000 | [diff] [blame^] | 201 | path=settings.LOGS_DIR, target=self.target), 'w') as f: |
Oleksii Butenko | 71d76f3 | 2018-06-05 17:46:34 +0300 | [diff] [blame] | 202 | LOG.info("Save tempest container inspect data") |
Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 203 | |
| 204 | container_inspect = json.dumps(inspect, |
| 205 | indent=4, sort_keys=True) |
| 206 | f.write(container_inspect) |
| 207 | |
Tatyana Leontovich | 61a821d | 2018-08-21 12:30:51 +0300 | [diff] [blame] | 208 | def prepare(self, dpdk=None): |
Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 209 | self.store_runtest_model() |
Oleksii Butenko | 5cd0a16 | 2018-06-14 18:18:10 +0300 | [diff] [blame] | 210 | |
Dennis Dmitriev | 6d52a45 | 2018-09-26 11:06:32 +0000 | [diff] [blame^] | 211 | res = self.install_python_lib() |
| 212 | LOG.info(json.dumps(res, indent=4)) |
Oleksii Butenko | 5cd0a16 | 2018-06-14 18:18:10 +0300 | [diff] [blame] | 213 | |
Dennis Dmitriev | 6d52a45 | 2018-09-26 11:06:32 +0000 | [diff] [blame^] | 214 | res = self.run_salt_minion_state() |
| 215 | LOG.info(json.dumps(res, indent=4)) |
| 216 | time.sleep(20) |
| 217 | |
| 218 | res = self.create_networks() |
| 219 | LOG.info(json.dumps(res, indent=4)) |
| 220 | time.sleep(20) |
| 221 | |
| 222 | res = self.create_flavors() |
| 223 | LOG.info(json.dumps(res, indent=4)) |
| 224 | time.sleep(20) |
Tatyana Leontovich | 61a821d | 2018-08-21 12:30:51 +0300 | [diff] [blame] | 225 | if dpdk: |
Dennis Dmitriev | 6d52a45 | 2018-09-26 11:06:32 +0000 | [diff] [blame^] | 226 | res = self.set_property() |
| 227 | LOG.info('Update flavor property') |
| 228 | LOG.info(json.dumps(res, indent=4)) |
| 229 | time.sleep(20) |
Oleksii Butenko | 5cd0a16 | 2018-06-14 18:18:10 +0300 | [diff] [blame] | 230 | |
Dennis Dmitriev | 6d52a45 | 2018-09-26 11:06:32 +0000 | [diff] [blame^] | 231 | res = self.create_cirros() |
| 232 | LOG.info(json.dumps(res, indent=4)) |
| 233 | time.sleep(20) |
| 234 | |
| 235 | res = self.generate_config() |
| 236 | LOG.info(json.dumps(res, indent=4)) |
| 237 | time.sleep(20) |
Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 238 | |
| 239 | def run_tempest(self, timeout=600): |
Dennis Dmitriev | 6d52a45 | 2018-09-26 11:06:32 +0000 | [diff] [blame^] | 240 | tgt = "{}*".format(self.target) |
| 241 | params = { |
| 242 | "name": self.container_name, |
| 243 | "image": "{}:{}".format(self.image_name, self.image_version), |
| 244 | "environment": { |
| 245 | "ARGS": "-r {tempest_pattern} -w " |
| 246 | "{tempest_threads} ".format( |
| 247 | tempest_pattern=self.tempest_pattern, |
| 248 | tempest_threads=self.tempest_threads) # noqa |
| 249 | }, |
| 250 | "binds": [ |
| 251 | "{cfg_dir}/tempest.conf:/etc/tempest/tempest.conf".format(cfg_dir=TEMPEST_CFG_DIR), # noqa |
| 252 | "/tmp/:/tmp/", |
| 253 | "{cfg_dir}:/root/tempest".format(cfg_dir=TEMPEST_CFG_DIR), |
| 254 | "/etc/ssl/certs/:/etc/ssl/certs/" |
| 255 | ], |
| 256 | "auto_remove": False, |
| 257 | "cmd": self.run_cmd |
| 258 | } |
Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 259 | |
Dennis Dmitriev | 6d52a45 | 2018-09-26 11:06:32 +0000 | [diff] [blame^] | 260 | res = self.salt_api.local(tgt, 'dockerng.pull', "{}:{}".format( |
| 261 | self.image_name, self.image_version)) |
| 262 | LOG.info("Tempest image has beed pulled- \n{}".format( |
| 263 | json.dumps(res, indent=4))) |
Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 264 | |
Dennis Dmitriev | 6d52a45 | 2018-09-26 11:06:32 +0000 | [diff] [blame^] | 265 | res = self.salt_api.local(tgt, 'dockerng.create', kwargs=params) |
| 266 | LOG.info("Tempest container has been created - \n{}".format( |
| 267 | json.dumps(res, indent=4))) |
Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 268 | |
Dennis Dmitriev | 6d52a45 | 2018-09-26 11:06:32 +0000 | [diff] [blame^] | 269 | res = self.salt_api.local(tgt, 'dockerng.start', self.container_name) |
| 270 | LOG.info("Tempest container has been started - \n{}".format( |
| 271 | json.dumps(res, indent=4))) |
| 272 | |
| 273 | def wait_status(s): |
| 274 | inspect_res = self.salt_api.local(tgt, |
| 275 | 'dockerng.inspect', |
| 276 | self.container_name) |
| 277 | if 'return' in inspect_res: |
| 278 | inspect = inspect_res['return'] |
| 279 | inspect = inspect[0] |
| 280 | inspect = next(inspect.iteritems())[1] |
| 281 | status = inspect['State']['Status'] |
| 282 | |
| 283 | return status.lower() == s.lower() |
| 284 | |
| 285 | return False |
| 286 | |
| 287 | helpers.wait(lambda: wait_status('exited'), |
| 288 | timeout=timeout, |
| 289 | timeout_msg=('Tempest run didnt finished ' |
| 290 | 'in {}'.format(timeout))) |
Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 291 | |
| 292 | inspect_res = self.salt_api.local(tgt, |
| 293 | 'dockerng.inspect', |
| 294 | self.container_name) |
| 295 | inspect = inspect_res['return'][0] |
| 296 | inspect = next(inspect.iteritems())[1] |
Dennis Dmitriev | 6d52a45 | 2018-09-26 11:06:32 +0000 | [diff] [blame^] | 297 | if inspect['State']['ExitCode'] != 0: |
| 298 | LOG.error("Tempest running failed") |
| 299 | LOG.info("Tempest tests have been finished - \n{}".format( |
| 300 | json.dumps(res, indent=4))) |
| 301 | |
Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 302 | logs_res = self.salt_api.local(tgt, |
| 303 | 'dockerng.logs', |
| 304 | self.container_name) |
| 305 | logs = logs_res['return'][0] |
| 306 | logs = next(logs.iteritems())[1] |
Dennis Dmitriev | 6d52a45 | 2018-09-26 11:06:32 +0000 | [diff] [blame^] | 307 | LOG.info("Tempest result - \n{}".format( |
| 308 | logs.encode('ascii', 'ignore'))) |
Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 309 | |
| 310 | res = self.salt_api.local(tgt, 'dockerng.rm', self.container_name) |
| 311 | LOG.info("Tempest container was removed".format( |
| 312 | json.dumps(res, indent=4))) |
| 313 | |
| 314 | return {'inspect': inspect, |
| 315 | 'logs': logs} |
Oleksii Butenko | e82441d | 2018-06-12 16:01:33 +0300 | [diff] [blame] | 316 | |
Tatyana Leontovich | 61a821d | 2018-08-21 12:30:51 +0300 | [diff] [blame] | 317 | def prepare_and_run_tempest(self, username='root', dpdk=None): |
Oleksii Butenko | e82441d | 2018-06-12 16:01:33 +0300 | [diff] [blame] | 318 | """ |
| 319 | Run tempest tests |
| 320 | """ |
| 321 | tempest_timeout = settings.TEMPEST_TIMEOUT |
Tatyana Leontovich | 61a821d | 2018-08-21 12:30:51 +0300 | [diff] [blame] | 322 | self.prepare(dpdk=dpdk) |
Oleksii Butenko | e82441d | 2018-06-12 16:01:33 +0300 | [diff] [blame] | 323 | test_res = self.run_tempest(tempest_timeout) |
| 324 | self.fetch_arficats(username=username) |
| 325 | self.save_runtime_logs(**test_res) |