Dennis Dmitriev | 010f4cd | 2016-11-01 20:43:51 +0200 | [diff] [blame] | 1 | # 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. |
Tatyana Leontovich | 53bd1f9 | 2017-09-08 13:04:42 +0300 | [diff] [blame] | 14 | import os |
Dennis Dmitriev | 010f4cd | 2016-11-01 20:43:51 +0200 | [diff] [blame] | 15 | |
Dmitry Tyzhnenko | 2b730a0 | 2017-04-07 19:31:32 +0300 | [diff] [blame] | 16 | from tcp_tests.managers.execute_commands import ExecuteCommandsMixin |
Tatyana Leontovich | 53bd1f9 | 2017-09-08 13:04:42 +0300 | [diff] [blame] | 17 | from tcp_tests import logger |
Tatyana Leontovich | 8b70b90 | 2017-11-10 20:44:08 +0200 | [diff] [blame] | 18 | from tcp_tests import settings |
Tatyana Leontovich | 53bd1f9 | 2017-09-08 13:04:42 +0300 | [diff] [blame] | 19 | |
| 20 | LOG = logger.logger |
Dmitry Tyzhnenko | 2b730a0 | 2017-04-07 19:31:32 +0300 | [diff] [blame] | 21 | |
| 22 | |
| 23 | class OpenstackManager(ExecuteCommandsMixin): |
Dennis Dmitriev | 010f4cd | 2016-11-01 20:43:51 +0200 | [diff] [blame] | 24 | """docstring for OpenstackManager""" |
| 25 | |
Dmitry Tyzhnenko | bc0f826 | 2017-04-28 15:39:26 +0300 | [diff] [blame] | 26 | __config = None |
| 27 | __underlay = None |
Tatyana Leontovich | e5ccdb3 | 2017-10-09 20:10:43 +0300 | [diff] [blame] | 28 | __hardware = None |
Dennis Dmitriev | 010f4cd | 2016-11-01 20:43:51 +0200 | [diff] [blame] | 29 | |
Tatyana Leontovich | e5ccdb3 | 2017-10-09 20:10:43 +0300 | [diff] [blame] | 30 | def __init__(self, config, underlay, hardware, salt): |
Dmitry Tyzhnenko | bc0f826 | 2017-04-28 15:39:26 +0300 | [diff] [blame] | 31 | self.__config = config |
| 32 | self.__underlay = underlay |
Tatyana Leontovich | e5ccdb3 | 2017-10-09 20:10:43 +0300 | [diff] [blame] | 33 | self.__hardware = hardware |
Dmitry Tyzhnenko | 2b730a0 | 2017-04-07 19:31:32 +0300 | [diff] [blame] | 34 | self._salt = salt |
Dmitry Tyzhnenko | bc0f826 | 2017-04-28 15:39:26 +0300 | [diff] [blame] | 35 | super(OpenstackManager, self).__init__( |
| 36 | config=config, underlay=underlay) |
Dennis Dmitriev | 010f4cd | 2016-11-01 20:43:51 +0200 | [diff] [blame] | 37 | |
| 38 | def install(self, commands): |
Dmitry Tyzhnenko | 2b730a0 | 2017-04-07 19:31:32 +0300 | [diff] [blame] | 39 | self.execute_commands(commands, |
| 40 | label='Install OpenStack services') |
vrovachev | 700a7b0 | 2017-05-23 18:36:48 +0400 | [diff] [blame] | 41 | self.__config.openstack.openstack_installed = True |
Tatyana Leontovich | 53bd1f9 | 2017-09-08 13:04:42 +0300 | [diff] [blame] | 42 | |
| 43 | def run_tempest( |
| 44 | self, |
Tatyana Leontovich | 53bd1f9 | 2017-09-08 13:04:42 +0300 | [diff] [blame] | 45 | target='gtw01', pattern=None, |
| 46 | conf_name='lvm_mcp.conf', |
Tatyana Leontovich | 8b70b90 | 2017-11-10 20:44:08 +0200 | [diff] [blame] | 47 | registry=None): |
| 48 | if not registry: |
ibumarskov | ed91a0d | 2017-11-21 10:17:53 +0300 | [diff] [blame] | 49 | registry = ('{0}/{1}'.format(settings.DOCKER_REGISTRY, |
| 50 | settings.DOCKER_NAME)) |
Tatyana Leontovich | 53bd1f9 | 2017-09-08 13:04:42 +0300 | [diff] [blame] | 51 | target_name = [node_name for node_name |
| 52 | in self.__underlay.node_names() if target in node_name] |
| 53 | |
| 54 | if pattern: |
| 55 | cmd = ("docker run --rm --net=host " |
| 56 | "-e TEMPEST_CONF={0} " |
| 57 | "-e SKIP_LIST=mcp_skip.list " |
| 58 | "-e SOURCE_FILE=keystonercv3 " |
| 59 | "-e CUSTOM='--pattern {1}' " |
Tatyana Leontovich | 8b70b90 | 2017-11-10 20:44:08 +0200 | [diff] [blame] | 60 | "-v /root/:/home/rally {2} " |
Dina Belova | e6fdffb | 2017-09-19 13:58:34 -0700 | [diff] [blame] | 61 | "-v /etc/ssl/certs/:/etc/ssl/certs/ >> image.output" |
Tatyana Leontovich | 8b70b90 | 2017-11-10 20:44:08 +0200 | [diff] [blame] | 62 | .format(conf_name, pattern, registry)) |
Tatyana Leontovich | 53bd1f9 | 2017-09-08 13:04:42 +0300 | [diff] [blame] | 63 | else: |
| 64 | cmd = ("docker run --rm --net=host " |
| 65 | "-e TEMPEST_CONF={0} " |
| 66 | "-e SKIP_LIST=mcp_skip.list " |
Tatyana Leontovich | 6051817 | 2017-11-14 17:39:58 +0200 | [diff] [blame] | 67 | "-e SET=full " |
Tatyana Leontovich | 53bd1f9 | 2017-09-08 13:04:42 +0300 | [diff] [blame] | 68 | "-e SOURCE_FILE=keystonercv3 " |
Leontii Istomin | 3982481 | 2017-11-14 14:09:04 +0300 | [diff] [blame] | 69 | "-v /root/:/home/rally {2} " |
Dina Belova | e6fdffb | 2017-09-19 13:58:34 -0700 | [diff] [blame] | 70 | "-v /etc/ssl/certs/:/etc/ssl/certs/ >> image.output" |
Tatyana Leontovich | 8b70b90 | 2017-11-10 20:44:08 +0200 | [diff] [blame] | 71 | .format(conf_name, pattern, registry)) |
Leontii Istomin | 05d0035 | 2017-11-10 17:12:11 +0400 | [diff] [blame] | 72 | LOG.info("Running tempest testing on node {0} using the following " |
| 73 | "command:\n{1}".format(target_name[0], cmd)) |
sgudz | 5d44f3d | 2017-09-25 19:27:46 +0300 | [diff] [blame] | 74 | |
Tatyana Leontovich | 53bd1f9 | 2017-09-08 13:04:42 +0300 | [diff] [blame] | 75 | with self.__underlay.remote(node_name=target_name[0]) as node_remote: |
sgudz | 5d44f3d | 2017-09-25 19:27:46 +0300 | [diff] [blame] | 76 | result = node_remote.execute(cmd, verbose=True) |
Tatyana Leontovich | 53bd1f9 | 2017-09-08 13:04:42 +0300 | [diff] [blame] | 77 | LOG.debug("Test execution result is {}".format(result)) |
| 78 | return result |
| 79 | |
| 80 | def download_tempest_report(self, file_fromat='xml', stored_node='gtw01'): |
| 81 | target_node_name = [node_name for node_name |
| 82 | in self.__underlay.node_names() |
| 83 | if stored_node in node_name] |
| 84 | with self.__underlay.remote(node_name=target_node_name[0]) as r: |
| 85 | result = r.execute('find /root -name "report_*.{}"'.format( |
| 86 | file_fromat)) |
| 87 | LOG.debug("Find result {0}".format(result)) |
Tatyana Leontovich | 62d1158 | 2017-11-09 14:05:52 +0200 | [diff] [blame] | 88 | assert len(result['stdout']) > 0, ('No report find, please check' |
| 89 | ' if test run was successful.') |
Tatyana Leontovich | 53bd1f9 | 2017-09-08 13:04:42 +0300 | [diff] [blame] | 90 | file_name = result['stdout'][0].rstrip() |
sgudz | 5d44f3d | 2017-09-25 19:27:46 +0300 | [diff] [blame] | 91 | LOG.debug("Found files {0}".format(file_name)) |
Tatyana Leontovich | 53bd1f9 | 2017-09-08 13:04:42 +0300 | [diff] [blame] | 92 | r.download(destination=file_name, target=os.getcwd()) |
Tatyana Leontovich | e5ccdb3 | 2017-10-09 20:10:43 +0300 | [diff] [blame] | 93 | |
| 94 | def get_node_name_by_subname(self, node_sub_name): |
| 95 | return [node_name for node_name |
| 96 | in self.__underlay.node_names() |
| 97 | if node_sub_name in node_name] |
| 98 | |
| 99 | def warm_shutdown_openstack_nodes(self, node_sub_name, timeout=10 * 60): |
| 100 | """Gracefully shutting down the node """ |
| 101 | node_names = self.get_node_name_by_subname(node_sub_name) |
| 102 | LOG.info('Shutting down nodes {}'.format(node_names)) |
| 103 | for node in node_names: |
| 104 | LOG.debug('Shutdown node {0}'.format(node)) |
| 105 | self.__underlay.check_call(cmd="shutdown +1", node_name=node) |
| 106 | for node in node_names: |
| 107 | LOG.info('Destroy node {}'.format(node)) |
| 108 | self.__hardware.destroy_node(node) |
| 109 | self.__hardware.wait_for_node_state( |
| 110 | node, state='offline', timeout=timeout) |
| 111 | |
| 112 | def warm_start_nodes(self, node_sub_name, timeout=10 * 60): |
| 113 | node_names = self.get_node_name_by_subname(node_sub_name) |
| 114 | LOG.info('Starting nodes {}'.format(node_names)) |
| 115 | for node in node_names: |
| 116 | self.__hardware.start_node(node) |
| 117 | self.__hardware.wait_for_node_state( |
| 118 | node, state='active', timeout=timeout) |
| 119 | |
| 120 | def warm_restart_nodes(self, node_names, timeout=10 * 60): |
| 121 | LOG.info('Reboot (warm restart) nodes {0}'.format(node_names)) |
| 122 | self.warm_shutdown_openstack_nodes(node_names, timeout=timeout) |
| 123 | self.warm_start_nodes(node_names) |