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 |
Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 17 | |
Oleksii Butenko | b0ca4cc | 2018-10-22 16:29:54 +0300 | [diff] [blame] | 18 | from devops.helpers import helpers |
| 19 | |
Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 20 | from tcp_tests import logger |
| 21 | from tcp_tests import settings |
| 22 | |
Oleksii Butenko | b0ca4cc | 2018-10-22 16:29:54 +0300 | [diff] [blame] | 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 | |
Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 28 | |
| 29 | class RuntestManager(object): |
| 30 | """Helper manager for execution tempest via runtest-formula""" |
| 31 | |
| 32 | image_name = settings.TEMPEST_IMAGE |
| 33 | image_version = settings.TEMPEST_IMAGE_VERSION |
| 34 | container_name = 'run-tempest-ci' |
| 35 | master_host = "cfg01" |
Dennis Dmitriev | b6bcc5c | 2018-09-26 11:07:53 +0000 | [diff] [blame] | 36 | control_host = "ctl01" |
sgudz | a5c901d | 2018-10-29 15:08:33 +0200 | [diff] [blame] | 37 | compute_host = "cmp" |
Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 38 | class_name = "runtest" |
| 39 | run_cmd = '/bin/bash -c "run-tempest"' |
| 40 | |
Dennis Dmitriev | b6bcc5c | 2018-09-26 11:07:53 +0000 | [diff] [blame] | 41 | def __init__(self, config, underlay, salt_api, cluster_name, |
Oleksii Butenko | 7456610 | 2018-09-11 11:55:13 +0300 | [diff] [blame] | 42 | domain_name, tempest_threads, |
Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 43 | tempest_pattern=settings.TEMPEST_PATTERN, |
| 44 | run_cmd=None, target='gtw01'): |
Dennis Dmitriev | b6bcc5c | 2018-09-26 11:07:53 +0000 | [diff] [blame] | 45 | self.__config = config |
Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 46 | self.underlay = underlay |
| 47 | self.__salt_api = salt_api |
Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 48 | self.cluster_name = cluster_name |
| 49 | self.domain_name = domain_name |
| 50 | self.tempest_threads = tempest_threads |
Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 51 | self.tempest_pattern = tempest_pattern |
| 52 | self.run_cmd = run_cmd or self.run_cmd |
Dennis Dmitriev | b6bcc5c | 2018-09-26 11:07:53 +0000 | [diff] [blame] | 53 | self.target_name = self.underlay.get_target_node_names(target)[0] |
| 54 | self.master_name = self.underlay.get_target_node_names( |
| 55 | self.master_host)[0] |
| 56 | self.control_name = self.underlay.get_target_node_names( |
| 57 | self.control_host)[0] |
sgudz | a5c901d | 2018-10-29 15:08:33 +0200 | [diff] [blame] | 58 | self.compute_name = self.underlay.get_target_node_names( |
| 59 | self.compute_host)[0] |
obutenko | 3e44b60 | 2018-11-13 12:50:22 +0200 | [diff] [blame] | 60 | self.barbican = False |
Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 61 | |
| 62 | @property |
| 63 | def salt_api(self): |
| 64 | return self.__salt_api |
| 65 | |
Dennis Dmitriev | b6bcc5c | 2018-09-26 11:07:53 +0000 | [diff] [blame] | 66 | @property |
| 67 | def runtest_pillar(self): |
| 68 | public_net = self.__config.underlay.dhcp_ranges[ |
| 69 | settings.EXTERNAL_ADDRESS_POOL_NAME] |
| 70 | public_gateway = public_net["gateway"].encode("ascii") |
| 71 | public_cidr = public_net["cidr"].encode("ascii") |
| 72 | public_allocation_start = public_net["start"].encode("ascii") |
| 73 | public_allocation_end = public_net["end"].encode("ascii") |
Dennis Dmitriev | cf52b8e | 2018-11-06 17:28:38 +0200 | [diff] [blame] | 74 | tempest_test_target = self.target_name.encode("ascii") + "*" |
Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 75 | |
obutenko | 3e44b60 | 2018-11-13 12:50:22 +0200 | [diff] [blame] | 76 | pillar = { |
Dennis Dmitriev | b6bcc5c | 2018-09-26 11:07:53 +0000 | [diff] [blame] | 77 | 'classes': ['service.runtest.tempest', |
| 78 | 'service.runtest.tempest.public_net', |
| 79 | 'service.runtest.tempest.services.manila.glance'], |
| 80 | 'parameters': { |
| 81 | '_param': { |
| 82 | 'runtest_tempest_cfg_dir': TEMPEST_CFG_DIR, |
| 83 | 'runtest_tempest_cfg_name': 'tempest.conf', |
| 84 | 'runtest_tempest_public_net': 'public', |
| 85 | 'openstack_public_neutron_subnet_gateway': public_gateway, |
| 86 | 'openstack_public_neutron_subnet_cidr': public_cidr, |
| 87 | 'openstack_public_neutron_subnet_allocation_start': |
| 88 | public_allocation_start, |
| 89 | 'openstack_public_neutron_subnet_allocation_end': |
| 90 | public_allocation_end, |
Dennis Dmitriev | cf52b8e | 2018-11-06 17:28:38 +0200 | [diff] [blame] | 91 | 'tempest_test_target': tempest_test_target, |
sgudz | 2f5aaf6 | 2018-10-30 13:20:04 +0200 | [diff] [blame] | 92 | 'glance_image_cirros_location': |
| 93 | 'http://cz8133.bud.mirantis.net:8099' |
| 94 | '/cirros-0.3.5-x86_64-disk.img', |
| 95 | 'glance_image_fedora_location': |
| 96 | 'http://cz8133.bud.mirantis.net:8099' |
| 97 | '/Fedora-Cloud-Base-27-1.6.x86_64.qcow2', |
| 98 | 'glance_image_manila_location': |
| 99 | 'http://cz8133.bud.mirantis.net:8099' |
| 100 | '/manila-service-image-master.qcow2', |
Dennis Dmitriev | b6bcc5c | 2018-09-26 11:07:53 +0000 | [diff] [blame] | 101 | }, |
| 102 | 'neutron': { |
| 103 | 'client': { |
| 104 | 'enabled': True |
| 105 | } |
| 106 | }, |
| 107 | 'runtest': { |
| 108 | 'enabled': True, |
| 109 | 'keystonerc_node': 'ctl01*', |
| 110 | 'tempest': { |
| 111 | 'enabled': True, |
| 112 | 'cfg_dir': '${_param:runtest_tempest_cfg_dir}', |
| 113 | 'cfg_name': '${_param:runtest_tempest_cfg_name}', |
Oleksii Butenko | 09cc0cd | 2018-10-16 14:31:57 +0300 | [diff] [blame] | 114 | 'put_keystone_rc_enabled': True, |
| 115 | 'put_local_image_file_enabled': False, |
Dennis Dmitriev | b6bcc5c | 2018-09-26 11:07:53 +0000 | [diff] [blame] | 116 | 'DEFAULT': { |
| 117 | 'log_file': 'tempest.log' |
| 118 | }, |
| 119 | 'compute': { |
Dennis Dmitriev | b6bcc5c | 2018-09-26 11:07:53 +0000 | [diff] [blame] | 120 | 'min_compute_nodes': 2, |
Dennis Dmitriev | b6bcc5c | 2018-09-26 11:07:53 +0000 | [diff] [blame] | 121 | }, |
| 122 | 'convert_to_uuid': { |
| 123 | 'network': { |
| 124 | 'public_network_id': |
| 125 | '${_param:runtest_tempest_public_net}' |
| 126 | } |
| 127 | }, |
Oleksii Butenko | 173e770 | 2018-10-24 18:31:12 +0300 | [diff] [blame] | 128 | 'heat_plugin': { |
| 129 | 'build_timeout': '600' |
| 130 | }, |
Dennis Dmitriev | b6bcc5c | 2018-09-26 11:07:53 +0000 | [diff] [blame] | 131 | 'share': { |
| 132 | 'capability_snapshot_support': True, |
| 133 | 'run_driver_assisted_migration_tests': False, |
| 134 | 'run_manage_unmanage_snapshot_tests': False, |
| 135 | 'run_manage_unmanage_tests': False, |
| 136 | 'run_migration_with_preserve_snapshots_tests': |
| 137 | False, |
| 138 | 'run_quota_tests': True, |
| 139 | 'run_replication_tests': False, |
| 140 | 'run_snapshot_tests': True, |
| 141 | }}}}} |
Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 142 | |
obutenko | 3e44b60 | 2018-11-13 12:50:22 +0200 | [diff] [blame] | 143 | if self.barbican: |
| 144 | pillar['classes'].append('service.runtest.tempest.barbican') |
| 145 | |
| 146 | return pillar |
| 147 | |
Oleksii Butenko | 71d76f3 | 2018-06-05 17:46:34 +0300 | [diff] [blame] | 148 | def fetch_arficats(self, username=None, file_format='xml'): |
Dennis Dmitriev | b6bcc5c | 2018-09-26 11:07:53 +0000 | [diff] [blame] | 149 | with self.underlay.remote(node_name=self.target_name, |
| 150 | username=None) as tgt: |
Oleksii Butenko | 71d76f3 | 2018-06-05 17:46:34 +0300 | [diff] [blame] | 151 | result = tgt.execute('find {} -name "report_*.{}"'.format( |
| 152 | TEMPEST_CFG_DIR, file_format)) |
| 153 | LOG.debug("Find result {0}".format(result)) |
| 154 | assert len(result['stdout']) > 0, ('No report found, please check' |
| 155 | ' if test run was successful.') |
| 156 | report = result['stdout'][0].rstrip() |
| 157 | LOG.debug("Found files {0}".format(report)) |
Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 158 | tgt.download( |
Oleksii Butenko | 71d76f3 | 2018-06-05 17:46:34 +0300 | [diff] [blame] | 159 | destination=report, # noqa |
| 160 | target=os.getcwd()) |
Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 161 | |
Dennis Dmitriev | b6bcc5c | 2018-09-26 11:07:53 +0000 | [diff] [blame] | 162 | def store_runtest_model(self, runtest_pillar=None): |
Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 163 | with self.underlay.yaml_editor( |
| 164 | file_path="/srv/salt/reclass/classes/cluster/" |
| 165 | "{cluster_name}/infra/" |
| 166 | "{class_name}.yml".format( |
| 167 | cluster_name=self.cluster_name, |
| 168 | class_name=self.class_name), |
Dennis Dmitriev | b6bcc5c | 2018-09-26 11:07:53 +0000 | [diff] [blame] | 169 | node_name=self.master_name) as editor: |
| 170 | editor.content = runtest_pillar or self.runtest_pillar |
Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 171 | with self.underlay.yaml_editor( |
| 172 | file_path="/srv/salt/reclass/nodes/_generated/" |
| 173 | "cfg01.{domain_name}.yml".format( |
| 174 | domain_name=self.domain_name), |
Dennis Dmitriev | b6bcc5c | 2018-09-26 11:07:53 +0000 | [diff] [blame] | 175 | node_name=self.master_name) as editor: |
Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 176 | editor.content['classes'].append( |
| 177 | 'cluster.{cluster_name}.infra.{class_name}'.format( |
| 178 | cluster_name=self.cluster_name, |
| 179 | class_name=self.class_name)) |
| 180 | |
Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 181 | def save_runtime_logs(self, logs=None, inspect=None): |
| 182 | if logs: |
| 183 | with open("{path}/{target}_tempest_run.log".format( |
Dennis Dmitriev | b6bcc5c | 2018-09-26 11:07:53 +0000 | [diff] [blame] | 184 | path=settings.LOGS_DIR, |
| 185 | target=self.target_name), 'w') as f: |
Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 186 | LOG.info("Save tempest console log") |
| 187 | container_log = logs |
Oleksii Butenko | 71d76f3 | 2018-06-05 17:46:34 +0300 | [diff] [blame] | 188 | f.write(container_log.encode('ascii', 'ignore')) |
Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 189 | |
| 190 | if inspect: |
Oleksii Butenko | 71d76f3 | 2018-06-05 17:46:34 +0300 | [diff] [blame] | 191 | with open("{path}/{target}_tempest_container_info.json.log".format( |
Dennis Dmitriev | b6bcc5c | 2018-09-26 11:07:53 +0000 | [diff] [blame] | 192 | path=settings.LOGS_DIR, |
| 193 | target=self.target_name), 'w') as f: |
Oleksii Butenko | 71d76f3 | 2018-06-05 17:46:34 +0300 | [diff] [blame] | 194 | LOG.info("Save tempest container inspect data") |
Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 195 | |
| 196 | container_inspect = json.dumps(inspect, |
| 197 | indent=4, sort_keys=True) |
| 198 | f.write(container_inspect) |
| 199 | |
sgudz | a5c901d | 2018-10-29 15:08:33 +0200 | [diff] [blame] | 200 | def prepare(self): |
obutenko | 3e44b60 | 2018-11-13 12:50:22 +0200 | [diff] [blame] | 201 | barbican_pillar = "nova:controller:barbican:enabled" |
| 202 | result = self.__salt_api.get_pillar(tgt=self.control_name, |
| 203 | pillar=barbican_pillar) |
| 204 | self.barbican = result[0].get(self.control_name, False) |
Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 205 | self.store_runtest_model() |
Oleksii Butenko | 09cc0cd | 2018-10-16 14:31:57 +0300 | [diff] [blame] | 206 | cirros_pillar = ("salt-call --out=newline_values_only " |
| 207 | "pillar.get " |
| 208 | "glance:client:identity:" |
| 209 | "admin_identity:image:cirros:location") |
sgudz | a5c901d | 2018-10-29 15:08:33 +0200 | [diff] [blame] | 210 | dpdk_pillar = "linux:network:dpdk:enabled" |
Dennis Dmitriev | b6bcc5c | 2018-09-26 11:07:53 +0000 | [diff] [blame] | 211 | salt_cmd = "salt -l info --hard-crash --state-output=mixed " |
| 212 | salt_call_cmd = "salt-call -l info --hard-crash --state-output=mixed " |
sgudz | a5c901d | 2018-10-29 15:08:33 +0200 | [diff] [blame] | 213 | |
| 214 | result = self.__salt_api.get_pillar(tgt=self.compute_name, |
| 215 | pillar=dpdk_pillar) |
| 216 | |
| 217 | dpdk = result[0].get(self.compute_name, False) |
| 218 | LOG.info("DPDK enabled: {}".format(bool(dpdk))) |
| 219 | |
Dennis Dmitriev | b6bcc5c | 2018-09-26 11:07:53 +0000 | [diff] [blame] | 220 | commands = [ |
| 221 | { |
| 222 | 'description': "Sync salt objects for runtest model", |
| 223 | 'node_name': self.master_name, |
| 224 | 'cmd': ("set -ex;" + |
| 225 | salt_cmd + "'*' saltutil.refresh_pillar && " + |
| 226 | salt_cmd + "'*' saltutil.sync_all")}, |
| 227 | { |
Tatyana Leontovich | eea03e9 | 2018-11-20 12:51:50 +0200 | [diff] [blame] | 228 | 'description': ("Install docker-ce package and " |
Dennis Dmitriev | b6bcc5c | 2018-09-26 11:07:53 +0000 | [diff] [blame] | 229 | "enable packets forwarding"), |
| 230 | 'node_name': self.target_name, |
| 231 | 'cmd': ("set -ex;" + |
Tatyana Leontovich | eea03e9 | 2018-11-20 12:51:50 +0200 | [diff] [blame] | 232 | salt_call_cmd + " pkg.install docker-ce && " + |
Dennis Dmitriev | b6bcc5c | 2018-09-26 11:07:53 +0000 | [diff] [blame] | 233 | " iptables --policy FORWARD ACCEPT")}, |
| 234 | { |
| 235 | 'description': "Install PyPI docker package", |
| 236 | 'node_name': self.target_name, |
| 237 | 'cmd': ("set -ex;" + |
| 238 | salt_call_cmd + " pip.install setuptools && " + |
| 239 | salt_call_cmd + " pip.install docker")}, |
| 240 | { |
| 241 | 'description': "Run salt.minion state for runtest formula", |
| 242 | 'node_name': self.master_name, |
| 243 | 'cmd': ("set -ex;" + |
| 244 | salt_call_cmd + " state.sls salt.minion && " |
| 245 | " sleep 20")}, |
| 246 | { |
| 247 | 'description': "Enforce keystone state for neutronv2", |
| 248 | 'node_name': self.master_name, |
| 249 | 'cmd': ("set -ex;" + |
| 250 | salt_call_cmd + " state.sls keystone.client")}, |
| 251 | { |
| 252 | 'description': "Create networks for Tempest tests", |
| 253 | 'node_name': self.master_name, |
| 254 | 'cmd': ("set -ex;" + |
| 255 | salt_call_cmd + " state.sls neutron.client")}, |
| 256 | { |
| 257 | 'description': "Create flavors for Tempest tests", |
| 258 | 'node_name': self.master_name, |
| 259 | 'cmd': ("set -ex;" + |
| 260 | salt_call_cmd + " state.sls nova.client")}, |
| 261 | { |
Oleksii Butenko | 09cc0cd | 2018-10-16 14:31:57 +0300 | [diff] [blame] | 262 | 'description': "Upload images for Tempest", |
Dennis Dmitriev | b6bcc5c | 2018-09-26 11:07:53 +0000 | [diff] [blame] | 263 | 'node_name': self.master_name, |
| 264 | 'cmd': ("set -ex;" + |
| 265 | salt_call_cmd + " state.sls glance.client")}, |
| 266 | { |
| 267 | 'description': "Generate config for Tempest", |
| 268 | 'node_name': self.master_name, |
| 269 | 'cmd': ("set -ex;" + |
| 270 | salt_call_cmd + " state.sls runtest")}, |
Oleksii Butenko | 09cc0cd | 2018-10-16 14:31:57 +0300 | [diff] [blame] | 271 | { |
| 272 | 'description': "Upload cirros image", |
| 273 | 'node_name': self.master_name, |
| 274 | 'cmd': ("set -ex;" |
| 275 | "cirros_url=$({}) && {} '{}' cmd.run " |
| 276 | "\"wget $cirros_url -O /tmp/TestCirros-0.3.5.img\"" |
| 277 | .format(cirros_pillar, salt_cmd, self.target_name))}, |
Dennis Dmitriev | b6bcc5c | 2018-09-26 11:07:53 +0000 | [diff] [blame] | 278 | ] |
Oleksii Butenko | 5cd0a16 | 2018-06-14 18:18:10 +0300 | [diff] [blame] | 279 | |
Tatyana Leontovich | 61a821d | 2018-08-21 12:30:51 +0300 | [diff] [blame] | 280 | if dpdk: |
Dennis Dmitriev | b6bcc5c | 2018-09-26 11:07:53 +0000 | [diff] [blame] | 281 | commands.append({ |
| 282 | 'description': "Configure flavor for DPDK", |
| 283 | 'node_name': self.control_name, |
| 284 | 'cmd': ("set -ex;" + |
| 285 | salt_call_cmd + " cmd.run " |
| 286 | " '. /root/keystonercv3;" |
sgudz | 905ec69 | 2018-10-16 15:30:39 +0300 | [diff] [blame] | 287 | " openstack flavor set m1.extra_tiny_test" |
| 288 | " --property hw:mem_page_size=any;" |
Dennis Dmitriev | b6bcc5c | 2018-09-26 11:07:53 +0000 | [diff] [blame] | 289 | " openstack flavor set m1.tiny_test" |
sgudz | 905ec69 | 2018-10-16 15:30:39 +0300 | [diff] [blame] | 290 | " --property hw:mem_page_size=any'")}, |
Dennis Dmitriev | b6bcc5c | 2018-09-26 11:07:53 +0000 | [diff] [blame] | 291 | ) |
Oleksii Butenko | 5cd0a16 | 2018-06-14 18:18:10 +0300 | [diff] [blame] | 292 | |
obutenko | 3e44b60 | 2018-11-13 12:50:22 +0200 | [diff] [blame] | 293 | if self.barbican: |
| 294 | commands.append({ |
| 295 | 'description': "Configure barbican", |
| 296 | 'node_name': self.master_name, |
| 297 | 'cmd': ("set -ex;" + |
| 298 | salt_call_cmd + |
| 299 | " state.sls barbican.client && " + |
| 300 | salt_call_cmd + |
| 301 | " state.sls runtest.test_accounts && " + |
| 302 | salt_call_cmd + |
| 303 | " state.sls runtest.barbican_sign_image")}, |
| 304 | ) |
| 305 | |
Dennis Dmitriev | b6bcc5c | 2018-09-26 11:07:53 +0000 | [diff] [blame] | 306 | self.__salt_api.execute_commands(commands=commands, |
| 307 | label="Prepare for Tempest") |
Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 308 | |
| 309 | def run_tempest(self, timeout=600): |
Dennis Dmitriev | b6bcc5c | 2018-09-26 11:07:53 +0000 | [diff] [blame] | 310 | tgt = self.target_name |
| 311 | image_nameversion = "{}:{}".format(self.image_name, self.image_version) |
Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 312 | |
Dennis Dmitriev | b6bcc5c | 2018-09-26 11:07:53 +0000 | [diff] [blame] | 313 | docker_args = ( |
Oleksii Butenko | b0ca4cc | 2018-10-22 16:29:54 +0300 | [diff] [blame] | 314 | " -t " |
Dennis Dmitriev | b6bcc5c | 2018-09-26 11:07:53 +0000 | [diff] [blame] | 315 | " --name {container_name} " |
| 316 | " -e ARGS=\"-r {tempest_pattern} -w {tempest_threads}\"" |
| 317 | " -v {cfg_dir}/tempest.conf:/etc/tempest/tempest.conf" |
| 318 | " -v /tmp/:/tmp/" |
| 319 | " -v {cfg_dir}:/root/tempest" |
| 320 | " -v /etc/ssl/certs/:/etc/ssl/certs/" |
Oleksii Butenko | b0ca4cc | 2018-10-22 16:29:54 +0300 | [diff] [blame] | 321 | " -d " |
Dennis Dmitriev | b6bcc5c | 2018-09-26 11:07:53 +0000 | [diff] [blame] | 322 | " {image_nameversion} {run_cmd}" |
| 323 | .format( |
| 324 | container_name=self.container_name, |
| 325 | image_nameversion=image_nameversion, |
| 326 | tempest_pattern=self.tempest_pattern, |
| 327 | tempest_threads=self.tempest_threads, |
| 328 | cfg_dir=TEMPEST_CFG_DIR, |
| 329 | run_cmd=self.run_cmd, |
| 330 | )) |
Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 331 | |
Dennis Dmitriev | b6bcc5c | 2018-09-26 11:07:53 +0000 | [diff] [blame] | 332 | commands = [ |
| 333 | { |
| 334 | 'description': "Run Tempest tests {0}".format( |
| 335 | image_nameversion), |
| 336 | 'node_name': self.target_name, |
| 337 | 'cmd': ("set -ex;" + |
| 338 | " docker rm --force {container_name} || true;" |
| 339 | " docker run {docker_args}" |
| 340 | .format(container_name=self.container_name, |
| 341 | docker_args=docker_args)), |
| 342 | 'timeout': timeout}, |
| 343 | ] |
Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 344 | |
Dennis Dmitriev | b6bcc5c | 2018-09-26 11:07:53 +0000 | [diff] [blame] | 345 | self.__salt_api.execute_commands(commands=commands, |
| 346 | label="Run Tempest tests") |
Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 347 | |
Oleksii Butenko | b0ca4cc | 2018-10-22 16:29:54 +0300 | [diff] [blame] | 348 | def wait_status(s): |
| 349 | inspect_res = self.salt_api.local(tgt, |
| 350 | 'dockerng.inspect', |
| 351 | self.container_name) |
| 352 | if 'return' in inspect_res: |
| 353 | inspect = inspect_res['return'] |
| 354 | inspect = inspect[0] |
| 355 | inspect = next(inspect.iteritems())[1] |
| 356 | status = inspect['State']['Status'] |
| 357 | |
| 358 | return status.lower() == s.lower() |
| 359 | |
| 360 | return False |
| 361 | |
| 362 | helpers.wait(lambda: wait_status('exited'), |
| 363 | timeout=timeout, |
| 364 | timeout_msg=('Tempest run didnt finished ' |
| 365 | 'in {}'.format(timeout))) |
| 366 | |
Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 367 | inspect_res = self.salt_api.local(tgt, |
| 368 | 'dockerng.inspect', |
| 369 | self.container_name) |
| 370 | inspect = inspect_res['return'][0] |
| 371 | inspect = next(inspect.iteritems())[1] |
Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 372 | logs_res = self.salt_api.local(tgt, |
| 373 | 'dockerng.logs', |
| 374 | self.container_name) |
| 375 | logs = logs_res['return'][0] |
| 376 | logs = next(logs.iteritems())[1] |
Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 377 | |
| 378 | res = self.salt_api.local(tgt, 'dockerng.rm', self.container_name) |
| 379 | LOG.info("Tempest container was removed".format( |
| 380 | json.dumps(res, indent=4))) |
| 381 | |
| 382 | return {'inspect': inspect, |
| 383 | 'logs': logs} |
Oleksii Butenko | e82441d | 2018-06-12 16:01:33 +0300 | [diff] [blame] | 384 | |
sgudz | a5c901d | 2018-10-29 15:08:33 +0200 | [diff] [blame] | 385 | def prepare_and_run_tempest(self, username='root'): |
Oleksii Butenko | e82441d | 2018-06-12 16:01:33 +0300 | [diff] [blame] | 386 | """ |
| 387 | Run tempest tests |
| 388 | """ |
| 389 | tempest_timeout = settings.TEMPEST_TIMEOUT |
sgudz | a5c901d | 2018-10-29 15:08:33 +0200 | [diff] [blame] | 390 | self.prepare() |
Oleksii Butenko | e82441d | 2018-06-12 16:01:33 +0300 | [diff] [blame] | 391 | test_res = self.run_tempest(tempest_timeout) |
| 392 | self.fetch_arficats(username=username) |
| 393 | self.save_runtime_logs(**test_res) |