blob: 3995aaa45247c7ab718a24f777d6cdc9eb7db421 [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
Dennis Dmitriev010f4cd2016-11-01 20:43:51 +020027
Dmitry Tyzhnenko2b730a02017-04-07 19:31:32 +030028 def __init__(self, config, underlay, salt):
Dmitry Tyzhnenkobc0f8262017-04-28 15:39:26 +030029 self.__config = config
30 self.__underlay = underlay
Dmitry Tyzhnenko2b730a02017-04-07 19:31:32 +030031 self._salt = salt
Dmitry Tyzhnenkobc0f8262017-04-28 15:39:26 +030032 super(OpenstackManager, self).__init__(
33 config=config, underlay=underlay)
Dennis Dmitriev010f4cd2016-11-01 20:43:51 +020034
35 def install(self, commands):
Dmitry Tyzhnenko2b730a02017-04-07 19:31:32 +030036 self.execute_commands(commands,
37 label='Install OpenStack services')
vrovachev700a7b02017-05-23 18:36:48 +040038 self.__config.openstack.openstack_installed = True
Tatyana Leontovich53bd1f92017-09-08 13:04:42 +030039
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 Belovae6fdffb2017-09-19 13:58:34 -070056 "-v /etc/ssl/certs/:/etc/ssl/certs/ >> image.output"
57 .format(conf_name, pattern, registry, image_name))
Tatyana Leontovich53bd1f92017-09-08 13:04:42 +030058 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 Belovae6fdffb2017-09-19 13:58:34 -070064 "-v /etc/ssl/certs/:/etc/ssl/certs/ >> image.output"
65 .format(conf_name, pattern, registry, image_name))
sgudz5d44f3d2017-09-25 19:27:46 +030066 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 Leontovich53bd1f92017-09-08 13:04:42 +030075 with self.__underlay.remote(node_name=target_name[0]) as node_remote:
sgudz5d44f3d2017-09-25 19:27:46 +030076 result = node_remote.execute(cmd, verbose=True)
Tatyana Leontovich53bd1f92017-09-08 13:04:42 +030077 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()
sgudz5d44f3d2017-09-25 19:27:46 +030089 LOG.debug("Found files {0}".format(file_name))
Tatyana Leontovich53bd1f92017-09-08 13:04:42 +030090 r.download(destination=file_name, target=os.getcwd())