blob: 24971b889539583d0770804d9c2b93a70ad5d8bf [file] [log] [blame]
Dennis Dmitriev010f4cd2016-11-01 20:43:51 +02001# 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 Leontovich53bd1f92017-09-08 13:04:42 +030014import os
Dennis Dmitriev010f4cd2016-11-01 20:43:51 +020015
Dmitry Tyzhnenko2b730a02017-04-07 19:31:32 +030016from tcp_tests.managers.execute_commands import ExecuteCommandsMixin
Tatyana Leontovich53bd1f92017-09-08 13:04:42 +030017from tcp_tests import logger
Tatyana Leontovich8b70b902017-11-10 20:44:08 +020018from tcp_tests import settings
Tatyana Leontovich53bd1f92017-09-08 13:04:42 +030019
20LOG = logger.logger
Dmitry Tyzhnenko2b730a02017-04-07 19:31:32 +030021
22
23class OpenstackManager(ExecuteCommandsMixin):
Dennis Dmitriev010f4cd2016-11-01 20:43:51 +020024 """docstring for OpenstackManager"""
25
Dmitry Tyzhnenkobc0f8262017-04-28 15:39:26 +030026 __config = None
27 __underlay = None
Tatyana Leontoviche5ccdb32017-10-09 20:10:43 +030028 __hardware = None
Dennis Dmitriev010f4cd2016-11-01 20:43:51 +020029
Tatyana Leontoviche5ccdb32017-10-09 20:10:43 +030030 def __init__(self, config, underlay, hardware, salt):
Dmitry Tyzhnenkobc0f8262017-04-28 15:39:26 +030031 self.__config = config
32 self.__underlay = underlay
Tatyana Leontoviche5ccdb32017-10-09 20:10:43 +030033 self.__hardware = hardware
Dmitry Tyzhnenko2b730a02017-04-07 19:31:32 +030034 self._salt = salt
Dmitry Tyzhnenkobc0f8262017-04-28 15:39:26 +030035 super(OpenstackManager, self).__init__(
36 config=config, underlay=underlay)
Dennis Dmitriev010f4cd2016-11-01 20:43:51 +020037
38 def install(self, commands):
Dmitry Tyzhnenko2b730a02017-04-07 19:31:32 +030039 self.execute_commands(commands,
40 label='Install OpenStack services')
vrovachev700a7b02017-05-23 18:36:48 +040041 self.__config.openstack.openstack_installed = True
Tatyana Leontovich53bd1f92017-09-08 13:04:42 +030042
43 def run_tempest(
44 self,
Tatyana Leontovich53bd1f92017-09-08 13:04:42 +030045 target='gtw01', pattern=None,
46 conf_name='lvm_mcp.conf',
Tatyana Leontovich8b70b902017-11-10 20:44:08 +020047 registry=None):
48 if not registry:
49 registry = ('{}/mirantis'
50 '/oscore/rally-tempest'
51 ':latest'.format(settings.DOCKER_REGISTRY))
Tatyana Leontovich53bd1f92017-09-08 13:04:42 +030052 target_name = [node_name for node_name
53 in self.__underlay.node_names() if target in node_name]
54
55 if pattern:
56 cmd = ("docker run --rm --net=host "
57 "-e TEMPEST_CONF={0} "
58 "-e SKIP_LIST=mcp_skip.list "
59 "-e SOURCE_FILE=keystonercv3 "
60 "-e CUSTOM='--pattern {1}' "
Tatyana Leontovich8b70b902017-11-10 20:44:08 +020061 "-v /root/:/home/rally {2} "
Dina Belovae6fdffb2017-09-19 13:58:34 -070062 "-v /etc/ssl/certs/:/etc/ssl/certs/ >> image.output"
Tatyana Leontovich8b70b902017-11-10 20:44:08 +020063 .format(conf_name, pattern, registry))
Tatyana Leontovich53bd1f92017-09-08 13:04:42 +030064 else:
65 cmd = ("docker run --rm --net=host "
66 "-e TEMPEST_CONF={0} "
67 "-e SKIP_LIST=mcp_skip.list "
Tatyana Leontovich60518172017-11-14 17:39:58 +020068 "-e SET=full "
Tatyana Leontovich53bd1f92017-09-08 13:04:42 +030069 "-e SOURCE_FILE=keystonercv3 "
Leontii Istomin39824812017-11-14 14:09:04 +030070 "-v /root/:/home/rally {2} "
Dina Belovae6fdffb2017-09-19 13:58:34 -070071 "-v /etc/ssl/certs/:/etc/ssl/certs/ >> image.output"
Tatyana Leontovich8b70b902017-11-10 20:44:08 +020072 .format(conf_name, pattern, registry))
Dennis Dmitrievcdef4632017-09-28 08:20:22 +030073 LOG.info("Restart keepalived service before running tempest tests")
sgudz5d44f3d2017-09-25 19:27:46 +030074 restart_keepalived_cmd = ("salt --hard-crash "
75 "--state-output=mixed "
76 "--state-verbose=True "
77 "-C 'I@keepalived:cluster:enabled:True' "
78 "service.restart keepalived")
79 self.__underlay.check_call(cmd=restart_keepalived_cmd,
80 host=self.__config.salt.salt_master_host)
Leontii Istomin05d00352017-11-10 17:12:11 +040081 LOG.info("Running tempest testing on node {0} using the following "
82 "command:\n{1}".format(target_name[0], cmd))
sgudz5d44f3d2017-09-25 19:27:46 +030083
Tatyana Leontovich53bd1f92017-09-08 13:04:42 +030084 with self.__underlay.remote(node_name=target_name[0]) as node_remote:
sgudz5d44f3d2017-09-25 19:27:46 +030085 result = node_remote.execute(cmd, verbose=True)
Tatyana Leontovich53bd1f92017-09-08 13:04:42 +030086 LOG.debug("Test execution result is {}".format(result))
87 return result
88
89 def download_tempest_report(self, file_fromat='xml', stored_node='gtw01'):
90 target_node_name = [node_name for node_name
91 in self.__underlay.node_names()
92 if stored_node in node_name]
93 with self.__underlay.remote(node_name=target_node_name[0]) as r:
94 result = r.execute('find /root -name "report_*.{}"'.format(
95 file_fromat))
96 LOG.debug("Find result {0}".format(result))
Tatyana Leontovich62d11582017-11-09 14:05:52 +020097 assert len(result['stdout']) > 0, ('No report find, please check'
98 ' if test run was successful.')
Tatyana Leontovich53bd1f92017-09-08 13:04:42 +030099 file_name = result['stdout'][0].rstrip()
sgudz5d44f3d2017-09-25 19:27:46 +0300100 LOG.debug("Found files {0}".format(file_name))
Tatyana Leontovich53bd1f92017-09-08 13:04:42 +0300101 r.download(destination=file_name, target=os.getcwd())
Tatyana Leontoviche5ccdb32017-10-09 20:10:43 +0300102
103 def get_node_name_by_subname(self, node_sub_name):
104 return [node_name for node_name
105 in self.__underlay.node_names()
106 if node_sub_name in node_name]
107
108 def warm_shutdown_openstack_nodes(self, node_sub_name, timeout=10 * 60):
109 """Gracefully shutting down the node """
110 node_names = self.get_node_name_by_subname(node_sub_name)
111 LOG.info('Shutting down nodes {}'.format(node_names))
112 for node in node_names:
113 LOG.debug('Shutdown node {0}'.format(node))
114 self.__underlay.check_call(cmd="shutdown +1", node_name=node)
115 for node in node_names:
116 LOG.info('Destroy node {}'.format(node))
117 self.__hardware.destroy_node(node)
118 self.__hardware.wait_for_node_state(
119 node, state='offline', timeout=timeout)
120
121 def warm_start_nodes(self, node_sub_name, timeout=10 * 60):
122 node_names = self.get_node_name_by_subname(node_sub_name)
123 LOG.info('Starting nodes {}'.format(node_names))
124 for node in node_names:
125 self.__hardware.start_node(node)
126 self.__hardware.wait_for_node_state(
127 node, state='active', timeout=timeout)
128
129 def warm_restart_nodes(self, node_names, timeout=10 * 60):
130 LOG.info('Reboot (warm restart) nodes {0}'.format(node_names))
131 self.warm_shutdown_openstack_nodes(node_names, timeout=timeout)
132 self.warm_start_nodes(node_names)