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 |
| 18 | |
| 19 | LOG = logger.logger |
Dmitry Tyzhnenko | 2b730a0 | 2017-04-07 19:31:32 +0300 | [diff] [blame] | 20 | |
| 21 | |
| 22 | class OpenstackManager(ExecuteCommandsMixin): |
Dennis Dmitriev | 010f4cd | 2016-11-01 20:43:51 +0200 | [diff] [blame] | 23 | """docstring for OpenstackManager""" |
| 24 | |
Dmitry Tyzhnenko | bc0f826 | 2017-04-28 15:39:26 +0300 | [diff] [blame] | 25 | __config = None |
| 26 | __underlay = None |
Dennis Dmitriev | 010f4cd | 2016-11-01 20:43:51 +0200 | [diff] [blame] | 27 | |
Dmitry Tyzhnenko | 2b730a0 | 2017-04-07 19:31:32 +0300 | [diff] [blame] | 28 | def __init__(self, config, underlay, salt): |
Dmitry Tyzhnenko | bc0f826 | 2017-04-28 15:39:26 +0300 | [diff] [blame] | 29 | self.__config = config |
| 30 | self.__underlay = underlay |
Dmitry Tyzhnenko | 2b730a0 | 2017-04-07 19:31:32 +0300 | [diff] [blame] | 31 | self._salt = salt |
Dmitry Tyzhnenko | bc0f826 | 2017-04-28 15:39:26 +0300 | [diff] [blame] | 32 | super(OpenstackManager, self).__init__( |
| 33 | config=config, underlay=underlay) |
Dennis Dmitriev | 010f4cd | 2016-11-01 20:43:51 +0200 | [diff] [blame] | 34 | |
| 35 | def install(self, commands): |
Dmitry Tyzhnenko | 2b730a0 | 2017-04-07 19:31:32 +0300 | [diff] [blame] | 36 | self.execute_commands(commands, |
| 37 | label='Install OpenStack services') |
vrovachev | 700a7b0 | 2017-05-23 18:36:48 +0400 | [diff] [blame] | 38 | self.__config.openstack.openstack_installed = True |
Tatyana Leontovich | 53bd1f9 | 2017-09-08 13:04:42 +0300 | [diff] [blame] | 39 | |
| 40 | def run_tempest( |
| 41 | self, |
| 42 | image_name='rally-tempest:with_designate', |
| 43 | target='gtw01', pattern=None, |
| 44 | conf_name='lvm_mcp.conf', |
| 45 | registry='docker-sandbox.sandbox.mirantis.net/rally-tempest/'): |
| 46 | target_name = [node_name for node_name |
| 47 | in self.__underlay.node_names() if target in node_name] |
| 48 | |
| 49 | if pattern: |
| 50 | cmd = ("docker run --rm --net=host " |
| 51 | "-e TEMPEST_CONF={0} " |
| 52 | "-e SKIP_LIST=mcp_skip.list " |
| 53 | "-e SOURCE_FILE=keystonercv3 " |
| 54 | "-e CUSTOM='--pattern {1}' " |
| 55 | "-v /root/:/home/rally {2}{3} " |
Dina Belova | e6fdffb | 2017-09-19 13:58:34 -0700 | [diff] [blame] | 56 | "-v /etc/ssl/certs/:/etc/ssl/certs/ >> image.output" |
| 57 | .format(conf_name, pattern, registry, image_name)) |
Tatyana Leontovich | 53bd1f9 | 2017-09-08 13:04:42 +0300 | [diff] [blame] | 58 | else: |
| 59 | cmd = ("docker run --rm --net=host " |
| 60 | "-e TEMPEST_CONF={0} " |
| 61 | "-e SKIP_LIST=mcp_skip.list " |
| 62 | "-e SOURCE_FILE=keystonercv3 " |
| 63 | "-v /root/:/home/rally {2}{3} " |
Dina Belova | e6fdffb | 2017-09-19 13:58:34 -0700 | [diff] [blame] | 64 | "-v /etc/ssl/certs/:/etc/ssl/certs/ >> image.output" |
| 65 | .format(conf_name, pattern, registry, image_name)) |
sgudz | 5d44f3d | 2017-09-25 19:27:46 +0300 | [diff] [blame] | 66 | logger.info("Restart keepalived service before running tempest tests") |
| 67 | restart_keepalived_cmd = ("salt --hard-crash " |
| 68 | "--state-output=mixed " |
| 69 | "--state-verbose=True " |
| 70 | "-C 'I@keepalived:cluster:enabled:True' " |
| 71 | "service.restart keepalived") |
| 72 | self.__underlay.check_call(cmd=restart_keepalived_cmd, |
| 73 | host=self.__config.salt.salt_master_host) |
| 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)) |
| 88 | file_name = result['stdout'][0].rstrip() |
sgudz | 5d44f3d | 2017-09-25 19:27:46 +0300 | [diff] [blame] | 89 | LOG.debug("Found files {0}".format(file_name)) |
Tatyana Leontovich | 53bd1f9 | 2017-09-08 13:04:42 +0300 | [diff] [blame] | 90 | r.download(destination=file_name, target=os.getcwd()) |