52ccb7c889def065fc10a52ce4d77a7f0365cc99
[doctor.git] / doctor_tests / installer / daisy.py
1 ##############################################################################
2 # Copyright (c) 2017 ZTE Corporation and others.
3 #
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9 from doctor_tests.common.utils import SSHClient
10 from doctor_tests.installer.base import BaseInstaller
11
12
13 class DaisyInstaller(BaseInstaller):
14     node_user_name = 'root'
15
16     def __init__(self, conf, log):
17         super(DaisyInstaller, self).__init__(conf, log)
18         self.client = SSHClient(self.conf.installer.ip,
19                                 self.conf.installer.username,
20                                 password='r00tme')
21         self.key_file = None
22         self.controllers = list()
23
24     def setup(self):
25         self.log.info('Setup Daisy installer start......')
26
27         self.key_file = self.get_ssh_key_from_installer()
28         self.controllers = self.get_controller_ips()
29         self.create_flavor()
30         self.setup_stunnel()
31
32     def cleanup(self):
33         for server in self.servers:
34             server.terminate()
35
36     def get_ssh_key_from_installer(self):
37         key_path = '/root/.ssh/id_dsa'
38         return self._get_ssh_key(self.client, key_path)
39
40     def get_controller_ips(self):
41         self.log.info('Get controller ips from Daisy installer......')
42
43         command = "source daisyrc_admin; " \
44                   "daisy host-list | grep 'CONTROLLER_LB' | cut -d '|' -f 3 "
45         controller_names = self._run_cmd_remote(self.client, command)
46         controllers = \
47             [self.get_host_ip_from_hostname(controller)
48              for controller in controller_names]
49         self.log.info('Get controller_ips:%s from Daisy installer'
50                       % controllers)
51         return controllers
52
53     def get_host_ip_from_hostname(self, hostname):
54         self.log.info('Get host ip from host name......')
55
56         hostip = hostname.split('-')[1:]
57         host_ip = '.'.join(hostip)
58         self.log.info('Get host_ip:%s from host_name:%s'
59                       % (host_ip, hostname))
60         return host_ip