diff options
author | Bertrand Souville <souville@docomolab-euro.com> | 2018-03-28 23:36:33 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@opnfv.org> | 2018-03-28 23:36:33 +0000 |
commit | 4c1ff363e85c9f49b783c99b6f45dac66b045c60 (patch) | |
tree | 020e78f77869be50b5bfc0861f92495f371de42e /doctor_tests/installer/base.py | |
parent | 631c3f99f0e499edd1adcbc7550dd3d0de393e31 (diff) | |
parent | 6bd4e026fca92b281382a3f6b46f7ab7eeb31f45 (diff) |
Merge "support MCP installer"
Diffstat (limited to 'doctor_tests/installer/base.py')
-rw-r--r-- | doctor_tests/installer/base.py | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/doctor_tests/installer/base.py b/doctor_tests/installer/base.py index 27e75024..76bbeb1e 100644 --- a/doctor_tests/installer/base.py +++ b/doctor_tests/installer/base.py @@ -7,8 +7,15 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## import abc +import getpass +import grp +import os +import pwd import six +import stat +import subprocess +from doctor_tests.common.utils import get_doctor_test_root_dir from doctor_tests.identity_auth import get_session from doctor_tests.os_clients import nova_client @@ -18,6 +25,7 @@ class BaseInstaller(object): def __init__(self, conf, log): self.conf = conf self.log = log + self.servers = list() @abc.abstractproperty def node_user_name(self): @@ -46,3 +54,69 @@ class BaseInstaller(object): 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 %s installer......' + % self.conf.installer.type) + + 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.log" + " 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() + + def _get_ssh_key(self, client, key_path): + self.log.info('Get SSH keys from %s installer......' + % self.conf.installer.type) + + if self.key_file is not None: + self.log.info('Already have SSH keys from %s installer......' + % self.conf.installer.type) + return self.key_file + + ssh_key = '{0}/{1}'.format(get_doctor_test_root_dir(), 'instack_key') + client.scp(key_path, 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) + return ssh_key + + def _run_cmd_remote(self, client, command): + self.log.info('Run command=%s in %s installer......' + % (command, self.conf.installer.type)) + + ret, output = client.ssh(command) + if ret: + raise Exception('Exec command in %s installer failed,' + 'ret=%s, output=%s' + % (self.conf.installer.type, + ret, output)) + self.log.info('Output=%s command=%s in %s installer' + % (output, command, self.conf.installer.type)) + return output + + def _run_apply_patches(self, client, restart_cmd, script_name): + installer_dir = os.path.dirname(os.path.realpath(__file__)) + script_abs_path = '{0}/{1}/{2}'.format(installer_dir, + 'common', script_name) + + client.scp(script_abs_path, script_name) + cmd = 'sudo python %s' % script_name + ret, output = client.ssh(cmd) + if ret: + raise Exception('Do the command in controller' + ' node failed, ret=%s, cmd=%s, output=%s' + % (ret, cmd, output)) + client.ssh(restart_cmd) |