summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordongwenjuan <dong.wenjuan@zte.com.cn>2018-01-08 14:20:53 +0800
committerdongwenjuan <dong.wenjuan@zte.com.cn>2018-01-08 17:27:53 +0800
commit3e882aeb6b55ceef3bd3c20155f0014a7b8c058e (patch)
tree530549fa6e3832002fe57da5095f1f9db2ac65c9
parentbdbd22904733af311225a3315555bb39ea12ed55 (diff)
support daisy installer
JIRA: DOCTOR-118 Change-Id: Id4d586fd2b7ca043cfd8231b9c46bdc581f039ab Signed-off-by: dongwenjuan <dong.wenjuan@zte.com.cn>
-rw-r--r--doctor_tests/common/utils.py3
-rw-r--r--doctor_tests/installer/__init__.py5
-rw-r--r--doctor_tests/installer/daisy.py107
3 files changed, 111 insertions, 4 deletions
diff --git a/doctor_tests/common/utils.py b/doctor_tests/common/utils.py
index d2962a8a..01889d9a 100644
--- a/doctor_tests/common/utils.py
+++ b/doctor_tests/common/utils.py
@@ -57,8 +57,7 @@ class SSHClient(object):
key_filename=None, log=None, look_for_keys=False,
allow_agent=False):
self.client = paramiko.SSHClient()
- self.client.load_system_host_keys()
- self.client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
+ self.client.set_missing_host_key_policy(paramiko.WarningPolicy())
self.client.connect(ip, username=username, password=password,
pkey=pkey, key_filename=key_filename,
look_for_keys=look_for_keys,
diff --git a/doctor_tests/installer/__init__.py b/doctor_tests/installer/__init__.py
index 02735b11..1ee59d99 100644
--- a/doctor_tests/installer/__init__.py
+++ b/doctor_tests/installer/__init__.py
@@ -14,7 +14,7 @@ from oslo_utils import importutils
OPTS = [
cfg.StrOpt('type',
default=os.environ.get('INSTALLER_TYPE', 'local'),
- choices=['local', 'apex'],
+ choices=['local', 'apex', 'daisy'],
help='the type of installer',
required=True),
cfg.StrOpt('ip',
@@ -29,7 +29,8 @@ OPTS = [
_installer_name_class_mapping = {
'local': 'doctor_tests.installer.local.LocalInstaller',
- 'apex': 'doctor_tests.installer.apex.ApexInstaller'
+ 'apex': 'doctor_tests.installer.apex.ApexInstaller',
+ 'daisy': 'doctor_tests.installer.daisy.DaisyInstaller'
}
diff --git a/doctor_tests/installer/daisy.py b/doctor_tests/installer/daisy.py
new file mode 100644
index 00000000..65d7a7ea
--- /dev/null
+++ b/doctor_tests/installer/daisy.py
@@ -0,0 +1,107 @@
+##############################################################################
+# Copyright (c) 2017 ZTE Corporation and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+import getpass
+import grp
+import os
+import pwd
+import stat
+import subprocess
+
+from doctor_tests.common.utils import get_doctor_test_root_dir
+from doctor_tests.common.utils import SSHClient
+from doctor_tests.identity_auth import get_session
+from doctor_tests.installer.base import BaseInstaller
+from doctor_tests.os_clients import nova_client
+
+
+class DaisyInstaller(BaseInstaller):
+ node_user_name = 'root'
+
+ def __init__(self, conf, log):
+ super(DaisyInstaller, self).__init__(conf, log)
+ self.client = SSHClient(self.conf.installer.ip,
+ self.conf.installer.username,
+ password='r00tme')
+ self.key_file = None
+ self.controllers = list()
+ self.servers = list()
+ self.test_dir = get_doctor_test_root_dir()
+
+ def setup(self):
+ self.log.info('Setup Daisy installer start......')
+
+ self.get_ssh_key_from_installer()
+ self.get_controller_ips()
+ self.create_flavor()
+ self.setup_stunnel()
+
+ def cleanup(self):
+ for server in self.servers:
+ server.terminate()
+
+ def get_ssh_key_from_installer(self):
+ self.log.info('Get SSH keys from Daisy installer......')
+
+ if self.key_file is not None:
+ self.log.info('Already have SSH keys from Daisy installer......')
+ return self.key_file
+
+ ssh_key = '{0}/{1}'.format(self.test_dir, 'instack_key')
+ self.client.scp('/root/.ssh/id_dsa', ssh_key, method='get')
+ user = getpass.getuser()
+ uid = pwd.getpwnam(user).pw_uid
+ gid = grp.getgrnam(user).gr_gid
+ os.chown(ssh_key, uid, gid)
+ os.chmod(ssh_key, stat.S_IREAD)
+ self.key_file = ssh_key
+ return self.key_file
+
+ def get_controller_ips(self):
+ self.log.info('Get controller ips from Daisy installer......')
+
+ command = "source daisyrc_admin; " \
+ "daisy host-list | grep 'CONTROLLER_LB' | cut -d '|' -f 3 "
+ ret, controllers = self.client.ssh(command)
+ if ret:
+ raise Exception('Exec command to get controller ips'
+ 'in Daisy installer failed'
+ 'ret=%s, output=%s' % (ret, controllers))
+ controller_ips = []
+ for controller in controllers:
+ controller_ips.append(self.get_host_ip_from_hostname(controller))
+ self.log.info('Get controller_ips:%s from Daisy installer'
+ % controller_ips)
+ self.controllers = controller_ips
+
+ def get_host_ip_from_hostname(self, hostname):
+ self.log.info('Get host ip from host name......')
+
+ hostip = hostname.split('-')[1:]
+ host_ip = '.'.join(hostip)
+ self.log.info('Get host_ip:%s from host_name:%s'
+ % (host_ip, hostname))
+ return host_ip
+
+ def create_flavor(self):
+ self.nova = \
+ nova_client(self.conf.nova_version,
+ get_session())
+ flavors = {flavor.name: flavor for flavor in self.nova.flavors.list()}
+ if self.conf.flavor not in flavors:
+ self.nova.flavors.create(self.conf.flavor, 512, 1, 1)
+
+ def setup_stunnel(self):
+ self.log.info('Setup ssh stunnel in controller nodes in Daisy installer......')
+ for node_ip in self.controllers:
+ 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 &" \
+ % (self.key_file, self.node_user_name, node_ip,
+ self.conf.consumer.port, self.conf.consumer.port, node_ip)
+ server = subprocess.Popen(cmd, shell=True)
+ self.servers.append(server)
+ server.communicate()