blob: ccb60309f66ffced9655edc0977c0da130a6d589 [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
15from tcp_tests.managers.execute_commands import ExecuteCommandsMixin
Tatyana Leontovich09b7b012017-07-10 12:53:45 +030016from tcp_tests.managers.clients.prometheus import prometheus_client
Tatyana Leontovich126b0032017-08-30 20:51:20 +030017from tcp_tests import logger
18
19LOG = logger.logger
Tatyana Leontovichc8b8ca22017-05-19 13:37:05 +030020
21
22class SLManager(ExecuteCommandsMixin):
23 """docstring for OpenstackManager"""
24
25 __config = None
26 __underlay = None
27
28 def __init__(self, config, underlay, salt):
29 self.__config = config
30 self.__underlay = underlay
31 self._salt = salt
Tatyana Leontovich09b7b012017-07-10 12:53:45 +030032 self._p_client = None
Tatyana Leontovichc8b8ca22017-05-19 13:37:05 +030033 super(SLManager, self).__init__(
34 config=config, underlay=underlay)
35
36 def install(self, commands):
37 self.execute_commands(commands,
38 label='Install SL services')
vrovachev700a7b02017-05-23 18:36:48 +040039 self.__config.stack_light.sl_installed = True
Tatyana Leontovich09b7b012017-07-10 12:53:45 +030040 self.__config.stack_light.sl_vip_host = self.get_sl_vip()
41
42 def get_sl_vip(self):
43 sl_vip_address_pillars = self._salt.get_pillar(
44 tgt='I@keepalived:cluster:enabled:true and not ctl*',
45 pillar='keepalived:cluster:instance:prometheus_server_vip:address')
46 sl_vip_ip = set([ip
47 for item in sl_vip_address_pillars
48 for node,ip in item.items() if ip])
49 assert len(sl_vip_ip) == 1, (
50 "Found more than one SL VIP in pillars:{0}, "
51 "expected one!").format(sl_vip_ip)
52 sl_vip_ip_host = sl_vip_ip.pop()
53 return sl_vip_ip_host
54
55 @property
56 def api(self):
57 if self._p_client is None:
58 self._p_client = prometheus_client.PrometheusClient(
59 host=self.__config.stack_light.sl_vip_host,
60 port=self.__config.stack_light.sl_prometheus_port,
61 proto=self.__config.stack_light.sl_prometheus_proto)
62 return self._p_client
Tatyana Leontovich126b0032017-08-30 20:51:20 +030063
64 def get_monitoring_nodes(self):
65 return [node_name for node_name
66 in self.__underlay.node_names() if 'mon' in node_name]
67
68 def get_service_info_from_node(self, node_name):
69 service_stat_dict = {}
70 with self.__underlay.remote(node_name=node_name) as node_remote:
71 result = node_remote.execute(
72 "docker service ls --format '{{.Name}}:{{.Replicas}}'")
73 LOG.debug("Service ls result {0} from node {1}".format(
74 result['stdout'], node_name))
75 for line in result['stdout']:
76 tmp = line.split(':')
77 service_stat_dict.update({tmp[0]: tmp[1]})
78 return service_stat_dict