blob: bd3e8891109c6a1a2ff0df02d0c7c488e6463e80 [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
18
19LOG = logger.logger
Dmitry Tyzhnenko2b730a02017-04-07 19:31:32 +030020
21
22class OpenstackManager(ExecuteCommandsMixin):
Dennis Dmitriev010f4cd2016-11-01 20:43:51 +020023 """docstring for OpenstackManager"""
24
Dmitry Tyzhnenkobc0f8262017-04-28 15:39:26 +030025 __config = None
26 __underlay = None
Tatyana Leontoviche5ccdb32017-10-09 20:10:43 +030027 __hardware = None
Dennis Dmitriev010f4cd2016-11-01 20:43:51 +020028
Tatyana Leontoviche5ccdb32017-10-09 20:10:43 +030029 def __init__(self, config, underlay, hardware, salt):
Dmitry Tyzhnenkobc0f8262017-04-28 15:39:26 +030030 self.__config = config
31 self.__underlay = underlay
Tatyana Leontoviche5ccdb32017-10-09 20:10:43 +030032 self.__hardware = hardware
Dmitry Tyzhnenko2b730a02017-04-07 19:31:32 +030033 self._salt = salt
Dmitry Tyzhnenkobc0f8262017-04-28 15:39:26 +030034 super(OpenstackManager, self).__init__(
35 config=config, underlay=underlay)
Dennis Dmitriev010f4cd2016-11-01 20:43:51 +020036
37 def install(self, commands):
Dmitry Tyzhnenko2b730a02017-04-07 19:31:32 +030038 self.execute_commands(commands,
39 label='Install OpenStack services')
vrovachev700a7b02017-05-23 18:36:48 +040040 self.__config.openstack.openstack_installed = True
Tatyana Leontovich53bd1f92017-09-08 13:04:42 +030041
42 def run_tempest(
43 self,
44 image_name='rally-tempest:with_designate',
45 target='gtw01', pattern=None,
46 conf_name='lvm_mcp.conf',
47 registry='docker-sandbox.sandbox.mirantis.net/rally-tempest/'):
48 target_name = [node_name for node_name
49 in self.__underlay.node_names() if target in node_name]
50
51 if pattern:
52 cmd = ("docker run --rm --net=host "
53 "-e TEMPEST_CONF={0} "
54 "-e SKIP_LIST=mcp_skip.list "
55 "-e SOURCE_FILE=keystonercv3 "
56 "-e CUSTOM='--pattern {1}' "
57 "-v /root/:/home/rally {2}{3} "
Dina Belovae6fdffb2017-09-19 13:58:34 -070058 "-v /etc/ssl/certs/:/etc/ssl/certs/ >> image.output"
59 .format(conf_name, pattern, registry, image_name))
Tatyana Leontovich53bd1f92017-09-08 13:04:42 +030060 else:
61 cmd = ("docker run --rm --net=host "
62 "-e TEMPEST_CONF={0} "
63 "-e SKIP_LIST=mcp_skip.list "
64 "-e SOURCE_FILE=keystonercv3 "
65 "-v /root/:/home/rally {2}{3} "
Dina Belovae6fdffb2017-09-19 13:58:34 -070066 "-v /etc/ssl/certs/:/etc/ssl/certs/ >> image.output"
67 .format(conf_name, pattern, registry, image_name))
Dennis Dmitrievcdef4632017-09-28 08:20:22 +030068 LOG.info("Restart keepalived service before running tempest tests")
sgudz5d44f3d2017-09-25 19:27:46 +030069 restart_keepalived_cmd = ("salt --hard-crash "
70 "--state-output=mixed "
71 "--state-verbose=True "
72 "-C 'I@keepalived:cluster:enabled:True' "
73 "service.restart keepalived")
74 self.__underlay.check_call(cmd=restart_keepalived_cmd,
75 host=self.__config.salt.salt_master_host)
Leontii Istomin05d00352017-11-10 17:12:11 +040076 LOG.info("Running tempest testing on node {0} using the following "
77 "command:\n{1}".format(target_name[0], cmd))
sgudz5d44f3d2017-09-25 19:27:46 +030078
Tatyana Leontovich53bd1f92017-09-08 13:04:42 +030079 with self.__underlay.remote(node_name=target_name[0]) as node_remote:
sgudz5d44f3d2017-09-25 19:27:46 +030080 result = node_remote.execute(cmd, verbose=True)
Tatyana Leontovich53bd1f92017-09-08 13:04:42 +030081 LOG.debug("Test execution result is {}".format(result))
82 return result
83
84 def download_tempest_report(self, file_fromat='xml', stored_node='gtw01'):
85 target_node_name = [node_name for node_name
86 in self.__underlay.node_names()
87 if stored_node in node_name]
88 with self.__underlay.remote(node_name=target_node_name[0]) as r:
89 result = r.execute('find /root -name "report_*.{}"'.format(
90 file_fromat))
91 LOG.debug("Find result {0}".format(result))
Tatyana Leontovich62d11582017-11-09 14:05:52 +020092 assert len(result['stdout']) > 0, ('No report find, please check'
93 ' if test run was successful.')
Tatyana Leontovich53bd1f92017-09-08 13:04:42 +030094 file_name = result['stdout'][0].rstrip()
sgudz5d44f3d2017-09-25 19:27:46 +030095 LOG.debug("Found files {0}".format(file_name))
Tatyana Leontovich53bd1f92017-09-08 13:04:42 +030096 r.download(destination=file_name, target=os.getcwd())
Tatyana Leontoviche5ccdb32017-10-09 20:10:43 +030097
98 def get_node_name_by_subname(self, node_sub_name):
99 return [node_name for node_name
100 in self.__underlay.node_names()
101 if node_sub_name in node_name]
102
103 def warm_shutdown_openstack_nodes(self, node_sub_name, timeout=10 * 60):
104 """Gracefully shutting down the node """
105 node_names = self.get_node_name_by_subname(node_sub_name)
106 LOG.info('Shutting down nodes {}'.format(node_names))
107 for node in node_names:
108 LOG.debug('Shutdown node {0}'.format(node))
109 self.__underlay.check_call(cmd="shutdown +1", node_name=node)
110 for node in node_names:
111 LOG.info('Destroy node {}'.format(node))
112 self.__hardware.destroy_node(node)
113 self.__hardware.wait_for_node_state(
114 node, state='offline', timeout=timeout)
115
116 def warm_start_nodes(self, node_sub_name, timeout=10 * 60):
117 node_names = self.get_node_name_by_subname(node_sub_name)
118 LOG.info('Starting nodes {}'.format(node_names))
119 for node in node_names:
120 self.__hardware.start_node(node)
121 self.__hardware.wait_for_node_state(
122 node, state='active', timeout=timeout)
123
124 def warm_restart_nodes(self, node_names, timeout=10 * 60):
125 LOG.info('Reboot (warm restart) nodes {0}'.format(node_names))
126 self.warm_shutdown_openstack_nodes(node_names, timeout=timeout)
127 self.warm_start_nodes(node_names)