blob: 705816d0f11fbdd8a51af0455a8196a47c146923 [file] [log] [blame]
Tatyana Leontovichc8b8ca22017-05-19 13:37:05 +03001# 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
Tatyana Leontovich063d0ff2017-09-05 18:11:55 +030015import os
16
Tatyana Leontovichc8b8ca22017-05-19 13:37:05 +030017from tcp_tests.managers.execute_commands import ExecuteCommandsMixin
Tatyana Leontovich09b7b012017-07-10 12:53:45 +030018from tcp_tests.managers.clients.prometheus import prometheus_client
Tatyana Leontovich126b0032017-08-30 20:51:20 +030019from tcp_tests import logger
20
21LOG = logger.logger
Tatyana Leontovichc8b8ca22017-05-19 13:37:05 +030022
23
24class SLManager(ExecuteCommandsMixin):
25 """docstring for OpenstackManager"""
26
27 __config = None
28 __underlay = None
29
30 def __init__(self, config, underlay, salt):
31 self.__config = config
32 self.__underlay = underlay
33 self._salt = salt
Tatyana Leontovich09b7b012017-07-10 12:53:45 +030034 self._p_client = None
Tatyana Leontovichc8b8ca22017-05-19 13:37:05 +030035 super(SLManager, self).__init__(
36 config=config, underlay=underlay)
37
38 def install(self, commands):
39 self.execute_commands(commands,
40 label='Install SL services')
vrovachev700a7b02017-05-23 18:36:48 +040041 self.__config.stack_light.sl_installed = True
Tatyana Leontovich09b7b012017-07-10 12:53:45 +030042 self.__config.stack_light.sl_vip_host = self.get_sl_vip()
43
44 def get_sl_vip(self):
45 sl_vip_address_pillars = self._salt.get_pillar(
46 tgt='I@keepalived:cluster:enabled:true and not ctl*',
47 pillar='keepalived:cluster:instance:prometheus_server_vip:address')
48 sl_vip_ip = set([ip
49 for item in sl_vip_address_pillars
50 for node,ip in item.items() if ip])
51 assert len(sl_vip_ip) == 1, (
52 "Found more than one SL VIP in pillars:{0}, "
53 "expected one!").format(sl_vip_ip)
54 sl_vip_ip_host = sl_vip_ip.pop()
55 return sl_vip_ip_host
56
57 @property
58 def api(self):
59 if self._p_client is None:
60 self._p_client = prometheus_client.PrometheusClient(
61 host=self.__config.stack_light.sl_vip_host,
62 port=self.__config.stack_light.sl_prometheus_port,
63 proto=self.__config.stack_light.sl_prometheus_proto)
64 return self._p_client
Tatyana Leontovich126b0032017-08-30 20:51:20 +030065
66 def get_monitoring_nodes(self):
67 return [node_name for node_name
68 in self.__underlay.node_names() if 'mon' in node_name]
69
70 def get_service_info_from_node(self, node_name):
71 service_stat_dict = {}
72 with self.__underlay.remote(node_name=node_name) as node_remote:
73 result = node_remote.execute(
74 "docker service ls --format '{{.Name}}:{{.Replicas}}'")
75 LOG.debug("Service ls result {0} from node {1}".format(
76 result['stdout'], node_name))
77 for line in result['stdout']:
78 tmp = line.split(':')
79 service_stat_dict.update({tmp[0]: tmp[1]})
80 return service_stat_dict
Tatyana Leontovich063d0ff2017-09-05 18:11:55 +030081
82 def run_sl_functional_tests(self, node_to_run, path_tests_to_run):
83 target_node_name = [node_name for node_name
84 in self.__underlay.node_names()
85 if node_to_run in node_name]
86 with self.__underlay.remote(node_name=target_node_name[0]) as node_remote:
87 cmd = "python -k {}".format(path_tests_to_run)
88 result = node_remote.execute(cmd)
89 LOG.debug("Test execution result is {}".format(result))
90 return result
91
92 def download_sl_test_report(self, stored_node, file_path):
93 target_node_name = [node_name for node_name
94 in self.__underlay.node_names()
95 if stored_node in node_name]
96 with self.__underlay.remote(node_name=target_node_name[0]) as r:
97 r.download(
98 destination=file_path,
99 target=os.getcwd())