Tatyana Leontovich | c8b8ca2 | 2017-05-19 13:37:05 +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 | |
| 15 | from tcp_tests.managers.execute_commands import ExecuteCommandsMixin |
Tatyana Leontovich | 09b7b01 | 2017-07-10 12:53:45 +0300 | [diff] [blame] | 16 | from tcp_tests.managers.clients.prometheus import prometheus_client |
Tatyana Leontovich | c8b8ca2 | 2017-05-19 13:37:05 +0300 | [diff] [blame] | 17 | |
| 18 | |
| 19 | class 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 Leontovich | 09b7b01 | 2017-07-10 12:53:45 +0300 | [diff] [blame] | 29 | self._p_client = None |
Tatyana Leontovich | c8b8ca2 | 2017-05-19 13:37:05 +0300 | [diff] [blame] | 30 | 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') |
vrovachev | 700a7b0 | 2017-05-23 18:36:48 +0400 | [diff] [blame] | 36 | self.__config.stack_light.sl_installed = True |
Tatyana Leontovich | 09b7b01 | 2017-07-10 12:53:45 +0300 | [diff] [blame] | 37 | 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 |