Dennis Dmitriev | 8cb2f41 | 2016-10-18 14:53:58 +0300 | [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. |
| 14 | import copy |
| 15 | import os |
| 16 | |
| 17 | import yaml |
| 18 | |
| 19 | from devops.helpers import helpers |
| 20 | |
| 21 | from tcp_tests.helpers import exceptions |
| 22 | from tcp_tests import logger |
| 23 | from tcp_tests import settings |
| 24 | |
| 25 | LOG = logger.logger |
| 26 | |
| 27 | |
| 28 | class TCPManager(object): |
| 29 | """docstring for TCPManager""" |
| 30 | |
| 31 | __config = None |
| 32 | __underlay = None |
| 33 | |
| 34 | def __init__(self, config, underlay): |
| 35 | self.__config = config |
| 36 | self.__underlay = underlay |
| 37 | self._api_client = None |
| 38 | |
| 39 | if self.__config.tcp.tcp_host == '0.0.0.0': |
| 40 | # Temporary workaround. Underlay should be extended with roles |
| 41 | tcp_nodes = self.__underlay.node_names() |
| 42 | self.__config.tcp.tcp_host = \ |
| 43 | self.__underlay.host_by_node_name(tcp_nodes[0]) |
| 44 | |
| 45 | super(TCPManager, self).__init__() |
| 46 | |
| 47 | def show_tcp_config(self): |
| 48 | cmd = 'reclass -n {0}'.format(self.__underlay.node_names()[0]) |
Dennis Dmitriev | 75fce1b | 2016-10-18 15:04:28 +0300 | [diff] [blame] | 49 | self.__underlay.sudo_check_call(cmd, host=self.__config.tcp.tcp_host, |
| 50 | verbose=True) |
Dennis Dmitriev | 8cb2f41 | 2016-10-18 14:53:58 +0300 | [diff] [blame] | 51 | |
| 52 | def install_tcp(self): |
| 53 | raise Exception("Not implemented!") |
Dennis Dmitriev | 423a7ff | 2016-10-21 18:31:36 +0300 | [diff] [blame^] | 54 | |
| 55 | def check_salt_service(self, service_name, node_name, check_cmd): |
| 56 | cmd = "service {0} status | grep -q 'start/running'".format( |
| 57 | service_name) |
| 58 | with self.__underlay.remote(node_name=node_name) as remote: |
| 59 | result = remote.execute(cmd) |
| 60 | if result.exit_code != 0: |
| 61 | LOG.info("{0} is not in running state on the node {1}," |
| 62 | " restarting".format(service_name, node_name)) |
| 63 | cmd = ("service {0} stop;" |
| 64 | " sleep 3; killall -9 {0};" |
| 65 | "service {0} start; sleep 5;" |
| 66 | .format(service_name)) |
| 67 | remote.execute(cmd) |
| 68 | |
| 69 | remote.execute(check_cmd) |
| 70 | remote.execute(check_cmd) |