fix the username to login undercloud in Apex
[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     installer_username = 'root'
16
17     def __init__(self, conf, log):
18         super(DaisyInstaller, self).__init__(conf, log)
19         self.client = SSHClient(self.conf.installer.ip,
20                                 self.installer_username,
21                                 password='r00tme')
22         self.key_file = None
23         self.controllers = list()
24
25     def setup(self):
26         self.log.info('Setup Daisy installer start......')
27
28         self.key_file = self.get_ssh_key_from_installer()
29         self.controllers = self.get_controller_ips()
30         self.create_flavor()
31         self.setup_stunnel()
32
33     def cleanup(self):
34         for server in self.servers:
35             server.terminate()
36
37     def get_ssh_key_from_installer(self):
38         key_path = '/root/.ssh/id_dsa'
39         return self._get_ssh_key(self.client, key_path)
40
41     def get_controller_ips(self):
42         self.log.info('Get controller ips from Daisy installer......')
43
44         command = "source daisyrc_admin; " \
45                   "daisy host-list | grep 'CONTROLLER_LB' | cut -d '|' -f 3 "
46         controller_names = self._run_cmd_remote(self.client, command)
47         controllers = \
48             [self.get_host_ip_from_hostname(controller)
49              for controller in controller_names]
50         self.log.info('Get controller_ips:%s from Daisy installer'
51                       % controllers)
52         return controllers
53
54     def get_host_ip_from_hostname(self, hostname):
55         self.log.info('Get host ip from host name......')
56
57         hostip = hostname.split('-')[1:]
58         host_ip = '.'.join(hostip)
59         self.log.info('Get host_ip:%s from host_name:%s'
60                       % (host_ip, hostname))
61         return host_ip