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" |
Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 36 | class_name = "runtest" |
| 37 | run_cmd = '/bin/bash -c "run-tempest"' |
| 38 | |
Dennis Dmitriev | b6bcc5c | 2018-09-26 11:07:53 +0000 | [diff] [blame] | 39 | def __init__(self, config, underlay, salt_api, cluster_name, |
Oleksii Butenko | 7456610 | 2018-09-11 11:55:13 +0300 | [diff] [blame] | 40 | domain_name, tempest_threads, |
Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 41 | tempest_pattern=settings.TEMPEST_PATTERN, |
Oleksii Butenko | 25a8f37 | 2019-03-22 17:25:47 +0200 | [diff] [blame] | 42 | tempest_extra_args=settings.TEMPEST_EXTRA_ARGS, |
obutenko | c431435 | 2018-12-26 16:14:24 +0200 | [diff] [blame] | 43 | run_cmd=None): |
Dennis Dmitriev | b6bcc5c | 2018-09-26 11:07:53 +0000 | [diff] [blame] | 44 | self.__config = config |
Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 45 | self.underlay = underlay |
| 46 | self.__salt_api = salt_api |
Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 47 | self.cluster_name = cluster_name |
| 48 | self.domain_name = domain_name |
| 49 | self.tempest_threads = tempest_threads |
Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 50 | self.tempest_pattern = tempest_pattern |
Oleksii Butenko | 25a8f37 | 2019-03-22 17:25:47 +0200 | [diff] [blame] | 51 | self.tempest_extra_args = tempest_extra_args |
Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 52 | self.run_cmd = run_cmd or self.run_cmd |
Dennis Dmitriev | b6bcc5c | 2018-09-26 11:07:53 +0000 | [diff] [blame] | 53 | self.master_name = self.underlay.get_target_node_names( |
| 54 | self.master_host)[0] |
Dennis Dmitriev | 1566e3f | 2019-01-11 17:35:43 +0200 | [diff] [blame] | 55 | self.master_minion = self.underlay.get_target_minion_ids( |
| 56 | self.master_host)[0] |
obutenko | c431435 | 2018-12-26 16:14:24 +0200 | [diff] [blame] | 57 | self.__target_name = None |
sgudz | 6571a5e | 2019-02-26 15:49:22 +0200 | [diff] [blame] | 58 | self.__target_minion = None |
Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 59 | |
| 60 | @property |
| 61 | def salt_api(self): |
| 62 | return self.__salt_api |
| 63 | |
Dennis Dmitriev | b6bcc5c | 2018-09-26 11:07:53 +0000 | [diff] [blame] | 64 | @property |
obutenko | c431435 | 2018-12-26 16:14:24 +0200 | [diff] [blame] | 65 | def target_name(self): |
| 66 | if not self.__target_name: |
obutenko | a1e3cea | 2019-01-12 21:11:55 +0200 | [diff] [blame] | 67 | target_host = self.__salt_api.get_single_pillar( |
Dennis Dmitriev | 1566e3f | 2019-01-11 17:35:43 +0200 | [diff] [blame] | 68 | tgt=self.master_minion, |
obutenko | c431435 | 2018-12-26 16:14:24 +0200 | [diff] [blame] | 69 | pillar="runtest:tempest:test_target") |
obutenko | c431435 | 2018-12-26 16:14:24 +0200 | [diff] [blame] | 70 | if target_host[-1] == "*": |
| 71 | target_host = target_host[:-1] |
| 72 | self.__target_name = self.underlay.get_target_node_names( |
| 73 | target_host)[0] |
| 74 | return self.__target_name |
obutenko | 3e44b60 | 2018-11-13 12:50:22 +0200 | [diff] [blame] | 75 | |
sgudz | 6571a5e | 2019-02-26 15:49:22 +0200 | [diff] [blame] | 76 | @property |
| 77 | def target_minion(self): |
| 78 | if not self.__target_minion: |
| 79 | target_host = self.__salt_api.get_single_pillar( |
| 80 | tgt=self.master_minion, |
| 81 | pillar="runtest:tempest:test_target") |
| 82 | if target_host[-1] == "*": |
| 83 | target_host = target_host[:-1] |
| 84 | self.__target_minion = self.underlay.get_target_minion_ids( |
| 85 | target_host)[0] |
| 86 | return self.__target_minion |
| 87 | |
Hanna Arhipova | a85bfa6 | 2020-01-03 18:49:15 +0200 | [diff] [blame] | 88 | def fetch_arficats( |
| 89 | self, |
| 90 | username=None, |
| 91 | file_format='xml', |
| 92 | report_pattern="report_*", |
| 93 | report_dir=TEMPEST_CFG_DIR): |
Dennis Dmitriev | b6bcc5c | 2018-09-26 11:07:53 +0000 | [diff] [blame] | 94 | with self.underlay.remote(node_name=self.target_name, |
| 95 | username=None) as tgt: |
Hanna Arhipova | a85bfa6 | 2020-01-03 18:49:15 +0200 | [diff] [blame] | 96 | result = tgt.execute('find {} -name "{}.{}"'.format( |
| 97 | report_dir, report_pattern, file_format)) |
Oleksii Butenko | 71d76f3 | 2018-06-05 17:46:34 +0300 | [diff] [blame] | 98 | LOG.debug("Find result {0}".format(result)) |
| 99 | assert len(result['stdout']) > 0, ('No report found, please check' |
| 100 | ' if test run was successful.') |
| 101 | report = result['stdout'][0].rstrip() |
| 102 | LOG.debug("Found files {0}".format(report)) |
Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 103 | tgt.download( |
Oleksii Butenko | 71d76f3 | 2018-06-05 17:46:34 +0300 | [diff] [blame] | 104 | destination=report, # noqa |
| 105 | target=os.getcwd()) |
Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 106 | |
Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 107 | def save_runtime_logs(self, logs=None, inspect=None): |
| 108 | if logs: |
| 109 | with open("{path}/{target}_tempest_run.log".format( |
Dennis Dmitriev | b6bcc5c | 2018-09-26 11:07:53 +0000 | [diff] [blame] | 110 | path=settings.LOGS_DIR, |
| 111 | target=self.target_name), 'w') as f: |
Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 112 | LOG.info("Save tempest console log") |
| 113 | container_log = logs |
Oleksii Butenko | 71d76f3 | 2018-06-05 17:46:34 +0300 | [diff] [blame] | 114 | f.write(container_log.encode('ascii', 'ignore')) |
Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 115 | |
| 116 | if inspect: |
Oleksii Butenko | 71d76f3 | 2018-06-05 17:46:34 +0300 | [diff] [blame] | 117 | with open("{path}/{target}_tempest_container_info.json.log".format( |
Dennis Dmitriev | b6bcc5c | 2018-09-26 11:07:53 +0000 | [diff] [blame] | 118 | path=settings.LOGS_DIR, |
| 119 | target=self.target_name), 'w') as f: |
Oleksii Butenko | 71d76f3 | 2018-06-05 17:46:34 +0300 | [diff] [blame] | 120 | LOG.info("Save tempest container inspect data") |
Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 121 | |
| 122 | container_inspect = json.dumps(inspect, |
| 123 | indent=4, sort_keys=True) |
| 124 | f.write(container_inspect) |
| 125 | |
Hanna Arhipova | a85bfa6 | 2020-01-03 18:49:15 +0200 | [diff] [blame] | 126 | def prepare(self, pipeline=False): |
Dennis Dmitriev | b6bcc5c | 2018-09-26 11:07:53 +0000 | [diff] [blame] | 127 | salt_call_cmd = "salt-call -l info --hard-crash --state-output=mixed " |
obutenko | a1e3cea | 2019-01-12 21:11:55 +0200 | [diff] [blame] | 128 | barbican_integration = self.__salt_api.get_single_pillar( |
Tatyana Leontovich | 8b1fda0 | 2019-01-23 13:14:33 +0200 | [diff] [blame] | 129 | tgt="ctl01*", |
obutenko | a1e3cea | 2019-01-12 21:11:55 +0200 | [diff] [blame] | 130 | pillar="_param:barbican_integration_enabled") |
Oleksii Butenko | d4b3dff | 2019-05-10 14:38:14 +0300 | [diff] [blame] | 131 | if self.__salt_api.local('I@opencontrail:compute:enabled:true', |
| 132 | 'match.pillar', |
| 133 | 'opencontrail:compute:enabled:true' |
| 134 | ).get('return', [{}]) != [{}]: |
| 135 | contrail_integration = True |
| 136 | else: |
| 137 | contrail_integration = False |
Tatyana Leontovich | 8b1fda0 | 2019-01-23 13:14:33 +0200 | [diff] [blame] | 138 | |
obutenko | c48f435 | 2019-01-24 17:03:06 +0200 | [diff] [blame] | 139 | LOG.info("Barbican integration {0}".format(barbican_integration)) |
Oleksii Butenko | d4b3dff | 2019-05-10 14:38:14 +0300 | [diff] [blame] | 140 | LOG.info("Opencontrail integration {0}".format(contrail_integration)) |
| 141 | |
Dennis Dmitriev | b6bcc5c | 2018-09-26 11:07:53 +0000 | [diff] [blame] | 142 | commands = [ |
| 143 | { |
Tatyana Leontovich | eea03e9 | 2018-11-20 12:51:50 +0200 | [diff] [blame] | 144 | 'description': ("Install docker-ce package and " |
Dennis Dmitriev | b6bcc5c | 2018-09-26 11:07:53 +0000 | [diff] [blame] | 145 | "enable packets forwarding"), |
| 146 | 'node_name': self.target_name, |
| 147 | 'cmd': ("set -ex;" + |
Tatyana Leontovich | eea03e9 | 2018-11-20 12:51:50 +0200 | [diff] [blame] | 148 | salt_call_cmd + " pkg.install docker-ce && " + |
Dennis Dmitriev | b6bcc5c | 2018-09-26 11:07:53 +0000 | [diff] [blame] | 149 | " iptables --policy FORWARD ACCEPT")}, |
| 150 | { |
| 151 | 'description': "Install PyPI docker package", |
| 152 | 'node_name': self.target_name, |
| 153 | 'cmd': ("set -ex;" + |
| 154 | salt_call_cmd + " pip.install setuptools && " + |
Hanna Arhipova | a85bfa6 | 2020-01-03 18:49:15 +0200 | [diff] [blame] | 155 | salt_call_cmd + " pip.install docker")} |
Dennis Dmitriev | b6bcc5c | 2018-09-26 11:07:53 +0000 | [diff] [blame] | 156 | ] |
Hanna Arhipova | a85bfa6 | 2020-01-03 18:49:15 +0200 | [diff] [blame] | 157 | if not pipeline: |
| 158 | commands.append( |
| 159 | { |
| 160 | 'description': "Generate config for Tempest", |
| 161 | 'node_name': self.master_name, |
| 162 | 'cmd': ("set -ex;" + |
| 163 | "salt-run state.orchestrate " + |
| 164 | "runtest.orchestrate.tempest") |
| 165 | } |
| 166 | ) |
obutenko | a1e3cea | 2019-01-12 21:11:55 +0200 | [diff] [blame] | 167 | |
Oleksii Butenko | d4b3dff | 2019-05-10 14:38:14 +0300 | [diff] [blame] | 168 | if contrail_integration: |
| 169 | vsrx_router = self.__salt_api.get_single_pillar( |
| 170 | tgt="I@opencontrail:control:role:primary", |
Andrew Baraniuk | 6361cfc | 2019-06-04 12:58:14 +0300 | [diff] [blame] | 171 | pillar="_param:opencontrail_router02_address") |
Oleksii Butenko | 125dcf4 | 2019-07-23 16:34:40 +0300 | [diff] [blame] | 172 | target_asn = '["target:64512:10000"]' |
Oleksii Butenko | d4b3dff | 2019-05-10 14:38:14 +0300 | [diff] [blame] | 173 | public_network = "192.168.200.0" |
| 174 | contrail_commands = [ |
| 175 | { |
| 176 | 'description': "Iproute to vsrx router", |
| 177 | 'node_name': self.target_name, |
| 178 | 'cmd': ("set -ex; ip route replace " + |
| 179 | public_network + "/24 via " + vsrx_router)}, |
| 180 | { |
Andrew Baraniuk | 6361cfc | 2019-06-04 12:58:14 +0300 | [diff] [blame] | 181 | 'description': "Iptables for public", |
| 182 | 'node_name': self.target_name, |
| 183 | 'cmd': ("set -ex; iptables -t nat -A POSTROUTING -s " + |
| 184 | public_network + "/24 ! -d " + public_network + |
| 185 | "/24 -j MASQUERADE")}, |
| 186 | { |
Oleksii Butenko | d4b3dff | 2019-05-10 14:38:14 +0300 | [diff] [blame] | 187 | 'description': "Align security group: remove all rules", |
| 188 | 'node_name': self.target_name, |
| 189 | 'cmd': ("set -ex;" + |
| 190 | "salt 'ctl01*' cmd.run '. /root/keystonercv3; " + |
| 191 | "openstack security group rule list --column ID " + |
| 192 | "-f value | xargs " + |
| 193 | "openstack security group rule delete|true';")}, |
| 194 | { |
| 195 | 'description': "Align security group: remove all default", |
| 196 | 'node_name': self.target_name, |
| 197 | 'cmd': ("set -ex;" + |
| 198 | " salt ctl01* cmd.run '. /root/keystonercv3; " + |
| 199 | "openstack security group " + |
| 200 | "list --column ID --column Name -f value|" + |
| 201 | "grep default|cut -d \" \" -f 1|" + |
| 202 | "xargs openstack security group delete|true'")}, |
| 203 | { |
| 204 | 'description': "Align security group: add rules", |
| 205 | 'node_name': self.target_name, |
| 206 | 'cmd': ("set -ex;" + |
| 207 | "salt 'ctl01*' cmd.run '. /root/keystonercv3; " + |
| 208 | "openstack security group rule create default " + |
| 209 | "--egress --protocol tcp'; " + |
| 210 | "salt 'ctl01*' cmd.run '. /root/keystonercv3; " + |
| 211 | "openstack security group rule create default " + |
| 212 | "--ingress --protocol tcp'; " + |
| 213 | "salt 'ctl01*' cmd.run '. /root/keystonercv3; " + |
| 214 | "openstack security group rule create default " + |
| 215 | "--egress --protocol icmp'; " + |
| 216 | "salt 'ctl01*' cmd.run '. /root/keystonercv3; " + |
| 217 | "openstack security group rule create default " + |
| 218 | "--ingress --protocol icmp'; ")}, |
| 219 | { |
Oleksii Butenko | 125dcf4 | 2019-07-23 16:34:40 +0300 | [diff] [blame] | 220 | 'description': "Run skipped in pipelines neutron.client", |
| 221 | 'node_name': self.target_name, |
| 222 | 'cmd': ("set -ex;" + |
| 223 | "salt -C 'I@neutron:client and cfg*' " + |
| 224 | "state.sls neutron.client|true")}, |
| 225 | { |
Oleksii Butenko | d4b3dff | 2019-05-10 14:38:14 +0300 | [diff] [blame] | 226 | 'description': "Create public network with target", |
| 227 | 'node_name': self.target_name, |
| 228 | 'cmd': ("set -ex;" + |
| 229 | "salt -C 'I@opencontrail:control:role:primary' " + |
| 230 | "contrail.virtual_network_create public " + |
Oleksii Butenko | 125dcf4 | 2019-07-23 16:34:40 +0300 | [diff] [blame] | 231 | "route_target_list='" + target_asn + "'")} |
Oleksii Butenko | d4b3dff | 2019-05-10 14:38:14 +0300 | [diff] [blame] | 232 | ] |
Oleksii Butenko | 125dcf4 | 2019-07-23 16:34:40 +0300 | [diff] [blame] | 233 | commands = contrail_commands + commands |
Oleksii Butenko | d4b3dff | 2019-05-10 14:38:14 +0300 | [diff] [blame] | 234 | |
obutenko | c48f435 | 2019-01-24 17:03:06 +0200 | [diff] [blame] | 235 | if barbican_integration: |
obutenko | a1e3cea | 2019-01-12 21:11:55 +0200 | [diff] [blame] | 236 | commands.append({ |
| 237 | 'description': "Configure barbican", |
| 238 | 'node_name': self.master_name, |
| 239 | 'cmd': ("set -ex;" + |
| 240 | salt_call_cmd + |
| 241 | " state.sls barbican.client && " + |
| 242 | salt_call_cmd + |
obutenko | c48f435 | 2019-01-24 17:03:06 +0200 | [diff] [blame] | 243 | " state.sls runtest.test_accounts" + |
obutenko | a1e3cea | 2019-01-12 21:11:55 +0200 | [diff] [blame] | 244 | salt_call_cmd + |
| 245 | " state.sls runtest.barbican_sign_image")}, |
| 246 | ) |
| 247 | |
Dennis Dmitriev | b6bcc5c | 2018-09-26 11:07:53 +0000 | [diff] [blame] | 248 | self.__salt_api.execute_commands(commands=commands, |
| 249 | label="Prepare for Tempest") |
Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 250 | |
| 251 | def run_tempest(self, timeout=600): |
sgudz | 6571a5e | 2019-02-26 15:49:22 +0200 | [diff] [blame] | 252 | tgt = self.target_minion |
Dennis Dmitriev | b6bcc5c | 2018-09-26 11:07:53 +0000 | [diff] [blame] | 253 | image_nameversion = "{}:{}".format(self.image_name, self.image_version) |
Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 254 | |
Dennis Dmitriev | b6bcc5c | 2018-09-26 11:07:53 +0000 | [diff] [blame] | 255 | docker_args = ( |
Oleksii Butenko | 25a8f37 | 2019-03-22 17:25:47 +0200 | [diff] [blame] | 256 | " -t" |
| 257 | " --net host" |
| 258 | " --name {container_name}" |
| 259 | " -e ARGS=\"-r {tempest_pattern}" |
| 260 | " -w {tempest_threads} {tempest_extra_args}\"" |
Dennis Dmitriev | b6bcc5c | 2018-09-26 11:07:53 +0000 | [diff] [blame] | 261 | " -v {cfg_dir}/tempest.conf:/etc/tempest/tempest.conf" |
| 262 | " -v /tmp/:/tmp/" |
| 263 | " -v {cfg_dir}:/root/tempest" |
| 264 | " -v /etc/ssl/certs/:/etc/ssl/certs/" |
Oleksii Butenko | 25a8f37 | 2019-03-22 17:25:47 +0200 | [diff] [blame] | 265 | " -d" |
Dennis Dmitriev | b6bcc5c | 2018-09-26 11:07:53 +0000 | [diff] [blame] | 266 | " {image_nameversion} {run_cmd}" |
| 267 | .format( |
| 268 | container_name=self.container_name, |
| 269 | image_nameversion=image_nameversion, |
| 270 | tempest_pattern=self.tempest_pattern, |
| 271 | tempest_threads=self.tempest_threads, |
Oleksii Butenko | 25a8f37 | 2019-03-22 17:25:47 +0200 | [diff] [blame] | 272 | tempest_extra_args=self.tempest_extra_args, |
Dennis Dmitriev | b6bcc5c | 2018-09-26 11:07:53 +0000 | [diff] [blame] | 273 | cfg_dir=TEMPEST_CFG_DIR, |
| 274 | run_cmd=self.run_cmd, |
| 275 | )) |
Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 276 | |
Dennis Dmitriev | b6bcc5c | 2018-09-26 11:07:53 +0000 | [diff] [blame] | 277 | commands = [ |
| 278 | { |
| 279 | 'description': "Run Tempest tests {0}".format( |
| 280 | image_nameversion), |
| 281 | 'node_name': self.target_name, |
| 282 | 'cmd': ("set -ex;" + |
| 283 | " docker rm --force {container_name} || true;" |
| 284 | " docker run {docker_args}" |
| 285 | .format(container_name=self.container_name, |
| 286 | docker_args=docker_args)), |
| 287 | 'timeout': timeout}, |
| 288 | ] |
Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 289 | |
Dennis Dmitriev | b6bcc5c | 2018-09-26 11:07:53 +0000 | [diff] [blame] | 290 | self.__salt_api.execute_commands(commands=commands, |
| 291 | label="Run Tempest tests") |
Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 292 | |
sgudz | 6571a5e | 2019-02-26 15:49:22 +0200 | [diff] [blame] | 293 | def simplify_salt_api_return(api_return, only_first_match=True): |
| 294 | """ |
| 295 | Salt API always returns a dict with one key as 'return' |
| 296 | and value as a list with dict. For example: |
| 297 | For single node: |
| 298 | api.local('cfg01*', 'test.ping', expr_form='compound') |
| 299 | {u'return':[{u'cfg01.cookied-cicd-queens-dvr-sl.local':True}]} |
| 300 | For multinode: |
| 301 | api.local('ctl*', 'test.ping', expr_form='compound') |
| 302 | {u'return': [{u'ctl01.cookied-cicd-queens-dvr-sl.local': True, |
| 303 | u'ctl02.cookied-cicd-queens-dvr-sl.local': True, |
| 304 | u'ctl03.cookied-cicd-queens-dvr-sl.local': True}]} |
| 305 | When wrong function is given: |
| 306 | api.local('ctl01*', 'wrong_func', expr_form='compound') |
| 307 | {u'return': [{u'ctl01.cookied-cicd-queens-dvr-sl.local': |
| 308 | u"'wrong_func' is not available."}]} |
| 309 | Empty return: |
| 310 | api.local('wrong_target', 'test.ping', expr_form='compound') |
| 311 | {u'return': [{}]} |
| 312 | """ |
| 313 | if api_return.get('return', [{}]) != [{}]: |
| 314 | api_return = api_return['return'][0] |
| 315 | if only_first_match: |
| 316 | api_return = next(api_return.iteritems())[1] |
sgudz | 6571a5e | 2019-02-26 15:49:22 +0200 | [diff] [blame] | 317 | return api_return |
| 318 | else: |
| 319 | LOG.info('''Salt api returns empty result: [{}]''') |
| 320 | return False |
| 321 | |
Oleksii Butenko | b0ca4cc | 2018-10-22 16:29:54 +0300 | [diff] [blame] | 322 | def wait_status(s): |
sgudz | 6571a5e | 2019-02-26 15:49:22 +0200 | [diff] [blame] | 323 | inspect_res = self.salt_api.local(tgt, 'dockerng.inspect', |
Oleksii Butenko | b0ca4cc | 2018-10-22 16:29:54 +0300 | [diff] [blame] | 324 | self.container_name) |
sgudz | 6571a5e | 2019-02-26 15:49:22 +0200 | [diff] [blame] | 325 | inspect = simplify_salt_api_return(inspect_res) |
| 326 | if inspect: |
Oleksii Butenko | b0ca4cc | 2018-10-22 16:29:54 +0300 | [diff] [blame] | 327 | status = inspect['State']['Status'] |
Oleksii Butenko | b0ca4cc | 2018-10-22 16:29:54 +0300 | [diff] [blame] | 328 | return status.lower() == s.lower() |
Oleksii Butenko | b0ca4cc | 2018-10-22 16:29:54 +0300 | [diff] [blame] | 329 | return False |
| 330 | |
sgudz | 6571a5e | 2019-02-26 15:49:22 +0200 | [diff] [blame] | 331 | if wait_status('running'): |
| 332 | helpers.wait(lambda: wait_status('exited'), |
| 333 | timeout=timeout, |
| 334 | timeout_msg=('Tempest run didnt finished ' |
| 335 | 'in {}'.format(timeout))) |
Oleksii Butenko | b0ca4cc | 2018-10-22 16:29:54 +0300 | [diff] [blame] | 336 | |
sgudz | 6571a5e | 2019-02-26 15:49:22 +0200 | [diff] [blame] | 337 | inspect_res = self.salt_api.local(tgt, 'dockerng.inspect', |
| 338 | self.container_name) |
| 339 | inspect = simplify_salt_api_return(inspect_res) |
Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 340 | |
sgudz | 6571a5e | 2019-02-26 15:49:22 +0200 | [diff] [blame] | 341 | logs_res = self.salt_api.local(tgt, 'dockerng.logs', |
| 342 | self.container_name) |
| 343 | logs = simplify_salt_api_return(logs_res) |
sgudz | 2457db8 | 2019-03-01 16:06:36 +0200 | [diff] [blame] | 344 | rm_res = self.salt_api.local(tgt, 'dockerng.rm', |
| 345 | self.container_name) |
| 346 | LOG.info("Tempest container was removed: {}".format( |
| 347 | json.dumps(rm_res, indent=4))) |
sgudz | 6571a5e | 2019-02-26 15:49:22 +0200 | [diff] [blame] | 348 | else: |
| 349 | inspect_res = self.salt_api.local(tgt, 'dockerng.inspect', |
| 350 | self.container_name) |
| 351 | inspect = simplify_salt_api_return(inspect_res) |
| 352 | if inspect: |
| 353 | status = inspect['State']['Status'] |
| 354 | LOG.info("Container is not in RUNNING state. " |
| 355 | "Current container status is {}".format(status)) |
| 356 | logs_res = self.salt_api.local(tgt, |
| 357 | 'dockerng.logs', |
| 358 | self.container_name) |
| 359 | logs = simplify_salt_api_return(logs_res) |
| 360 | else: |
| 361 | LOG.info("dockerng returns unexpected" |
| 362 | " result: {}".format(inspect_res)) |
| 363 | logs = None |
| 364 | inspect = None |
Dmitry Tyzhnenko | c56b77e | 2018-05-21 11:01:43 +0300 | [diff] [blame] | 365 | |
| 366 | return {'inspect': inspect, |
| 367 | 'logs': logs} |
Oleksii Butenko | e82441d | 2018-06-12 16:01:33 +0300 | [diff] [blame] | 368 | |
obutenko | c431435 | 2018-12-26 16:14:24 +0200 | [diff] [blame] | 369 | def prepare_and_run_tempest(self, username='root'): |
Oleksii Butenko | e82441d | 2018-06-12 16:01:33 +0300 | [diff] [blame] | 370 | """ |
| 371 | Run tempest tests |
| 372 | """ |
| 373 | tempest_timeout = settings.TEMPEST_TIMEOUT |
obutenko | c431435 | 2018-12-26 16:14:24 +0200 | [diff] [blame] | 374 | self.prepare() |
Oleksii Butenko | e82441d | 2018-06-12 16:01:33 +0300 | [diff] [blame] | 375 | test_res = self.run_tempest(tempest_timeout) |
| 376 | self.fetch_arficats(username=username) |
| 377 | self.save_runtime_logs(**test_res) |