blob: 23d362e792bbe6f97483003ed1164d7efbac4c77 [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 Leontovichc8b8ca22017-05-19 13:37:05 +030017
18
19class SLManager(ExecuteCommandsMixin):
20 """docstring for OpenstackManager"""
21
22 __config = None
23 __underlay = None
24
25 def __init__(self, config, underlay, salt):
26 self.__config = config
27 self.__underlay = underlay
28 self._salt = salt
Tatyana Leontovich09b7b012017-07-10 12:53:45 +030029 self._p_client = None
Tatyana Leontovichc8b8ca22017-05-19 13:37:05 +030030 super(SLManager, self).__init__(
31 config=config, underlay=underlay)
32
33 def install(self, commands):
34 self.execute_commands(commands,
35 label='Install SL services')
vrovachev700a7b02017-05-23 18:36:48 +040036 self.__config.stack_light.sl_installed = True
Tatyana Leontovich09b7b012017-07-10 12:53:45 +030037 self.__config.stack_light.sl_vip_host = self.get_sl_vip()
38
39 def get_sl_vip(self):
40 sl_vip_address_pillars = self._salt.get_pillar(
41 tgt='I@keepalived:cluster:enabled:true and not ctl*',
42 pillar='keepalived:cluster:instance:prometheus_server_vip:address')
43 sl_vip_ip = set([ip
44 for item in sl_vip_address_pillars
45 for node,ip in item.items() if ip])
46 assert len(sl_vip_ip) == 1, (
47 "Found more than one SL VIP in pillars:{0}, "
48 "expected one!").format(sl_vip_ip)
49 sl_vip_ip_host = sl_vip_ip.pop()
50 return sl_vip_ip_host
51
52 @property
53 def api(self):
54 if self._p_client is None:
55 self._p_client = prometheus_client.PrometheusClient(
56 host=self.__config.stack_light.sl_vip_host,
57 port=self.__config.stack_light.sl_prometheus_port,
58 proto=self.__config.stack_light.sl_prometheus_proto)
59 return self._p_client