1 ##############################################################################
2 # Copyright (c) 2017 ZTE Corporation and others.
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 ##############################################################################
16 from doctor_tests.common.utils import get_doctor_test_root_dir
17 from doctor_tests.common.utils import SSHClient
18 from doctor_tests.identity_auth import get_session
19 from doctor_tests.installer.base import BaseInstaller
20 from doctor_tests.os_clients import nova_client
23 class DaisyInstaller(BaseInstaller):
24 node_user_name = 'root'
26 def __init__(self, conf, log):
27 super(DaisyInstaller, self).__init__(conf, log)
28 self.client = SSHClient(self.conf.installer.ip,
29 self.conf.installer.username,
32 self.controllers = list()
34 self.test_dir = get_doctor_test_root_dir()
37 self.log.info('Setup Daisy installer start......')
39 self.get_ssh_key_from_installer()
40 self.get_controller_ips()
45 for server in self.servers:
48 def get_ssh_key_from_installer(self):
49 self.log.info('Get SSH keys from Daisy installer......')
51 if self.key_file is not None:
52 self.log.info('Already have SSH keys from Daisy installer......')
55 ssh_key = '{0}/{1}'.format(self.test_dir, 'instack_key')
56 self.client.scp('/root/.ssh/id_dsa', ssh_key, method='get')
57 user = getpass.getuser()
58 uid = pwd.getpwnam(user).pw_uid
59 gid = grp.getgrnam(user).gr_gid
60 os.chown(ssh_key, uid, gid)
61 os.chmod(ssh_key, stat.S_IREAD)
62 self.key_file = ssh_key
65 def get_controller_ips(self):
66 self.log.info('Get controller ips from Daisy installer......')
68 command = "source daisyrc_admin; " \
69 "daisy host-list | grep 'CONTROLLER_LB' | cut -d '|' -f 3 "
70 ret, controllers = self.client.ssh(command)
72 raise Exception('Exec command to get controller ips'
73 'in Daisy installer failed'
74 'ret=%s, output=%s' % (ret, controllers))
76 for controller in controllers:
77 controller_ips.append(self.get_host_ip_from_hostname(controller))
78 self.log.info('Get controller_ips:%s from Daisy installer'
80 self.controllers = controller_ips
82 def get_host_ip_from_hostname(self, hostname):
83 self.log.info('Get host ip from host name......')
85 hostip = hostname.split('-')[1:]
86 host_ip = '.'.join(hostip)
87 self.log.info('Get host_ip:%s from host_name:%s'
88 % (host_ip, hostname))
91 def create_flavor(self):
93 nova_client(self.conf.nova_version,
95 flavors = {flavor.name: flavor for flavor in self.nova.flavors.list()}
96 if self.conf.flavor not in flavors:
97 self.nova.flavors.create(self.conf.flavor, 512, 1, 1)
99 def setup_stunnel(self):
100 self.log.info('Setup ssh stunnel in controller nodes in Daisy installer......')
101 for node_ip in self.controllers:
102 cmd = "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i %s %s@%s -R %s:localhost:%s sleep 600 > ssh_tunnel.%s 2>&1 < /dev/null &" \
103 % (self.key_file, self.node_user_name, node_ip,
104 self.conf.consumer.port, self.conf.consumer.port, node_ip)
105 server = subprocess.Popen(cmd, shell=True)
106 self.servers.append(server)