X-Git-Url: https://gerrit.akraino.org/r/gitweb?a=blobdiff_plain;f=src%2Fremoteinstaller%2Finstaller%2Finstall.py;h=4e0043a36bab9768781ee570f1d93a7f3dd717e9;hb=HEAD;hp=d453bad2a01c9ca6e4ae7e4ebf6a8f1ca6ee6055;hpb=a772a381a84dd9b906a06c314b113b997bce71f4;p=ta%2Fremote-installer.git diff --git a/src/remoteinstaller/installer/install.py b/src/remoteinstaller/installer/install.py index d453bad..4e0043a 100644 --- a/src/remoteinstaller/installer/install.py +++ b/src/remoteinstaller/installer/install.py @@ -19,6 +19,7 @@ import subprocess import os import importlib import time +import distutils.util from yaml import load from netaddr import IPNetwork @@ -34,9 +35,9 @@ class InstallException(Exception): pass class Installer(object): - SSH_OPTS = '-o StrictHostKeyChecking=no \ - -o UserKnownHostsFile=/dev/null \ - -o ServerAliveInterval=60' + SSH_OPTS = ('-o StrictHostKeyChecking=no ' + '-o UserKnownHostsFile=/dev/null ' + '-o ServerAliveInterval=60') def __init__(self, callback_server, callback_uuid, yaml, logdir, args=None): self._callback_server = callback_server @@ -53,13 +54,12 @@ class Installer(object): self._ca_cert = None self._own_ip = None self._tag = None - if args: - self._set_arguments(args) - - # TODO self._disable_bmc_initial_reset = False self._disable_other_bmc_reset = True + if args: + self._set_arguments(args) + self._vip = None self._first_controller = None self._first_controller_ip = None @@ -67,7 +67,25 @@ class Installer(object): self._define_first_controller() + def _get_bool_arg(self, args, arg, default): + if hasattr(args, arg): + arg_value = vars(args)[arg] + if not isinstance(arg_value, bool): + if isinstance(arg_value, basestring): + try: + arg_value = bool(distutils.util.strtobool(arg_value)) + return arg_value + except ValueError: + logging.warning('Invalid value for %s: %s', arg, arg_value) + else: + return arg_value + + return default + def _set_arguments(self, args): + self._disable_bmc_initial_reset = self._get_bool_arg(args, 'disable_bmc_initial_reset', self._disable_bmc_initial_reset) + self._disable_other_bmc_reset = self._get_bool_arg(args, 'disable_other_bmc_reset', self._disable_other_bmc_reset) + self._boot_iso_path = args.boot_iso self._iso_url = args.iso self._callback_url = args.callback_url @@ -118,11 +136,12 @@ class Installer(object): host = self._uc['hosts'][hw]['hwmgmt']['address'] user = self._uc['hosts'][hw]['hwmgmt']['user'] passwd = self._uc['hosts'][hw]['hwmgmt']['password'] + priv_level = self._uc['hosts'][hw]['hwmgmt'].get('priv_level', 'ADMINISTRATOR') try: - hw_data = hw_detect.get_hw_data(host, user, passwd, False) + hw_data = hw_detect.get_hw_data(host, user, passwd, priv_level, False) except HWException as e: - error = "Harware not detected for {}: {}".format(hw, str(e)) + error = "Hardware not detected for {}: {}".format(hw, str(e)) logging.error(error) raise BMCException(error) @@ -135,7 +154,7 @@ class Installer(object): bmc_mod_name = 'remoteinstaller.installer.bmc_management.{}'.format(hw_data['product_family'].lower()) bmc_mod = importlib.import_module(bmc_mod_name) bmc_class = getattr(bmc_mod, hw_data['product_family']) - bmc = bmc_class(host, user, passwd, bmc_log_path) + bmc = bmc_class(host, user, passwd, priv_level, bmc_log_path) bmc.set_host_name(hw) return bmc @@ -161,7 +180,8 @@ class Installer(object): pre_allocated_ips = self._uc['hosts'][self._first_controller].get('pre_allocated_ips', None) if pre_allocated_ips: pre_allocated_infra_external_ip = pre_allocated_ips.get('infra_external', None) - self._first_controller_ip = str(IPAddress(pre_allocated_infra_external_ip)) + if pre_allocated_infra_external_ip: + self._first_controller_ip = str(IPAddress(pre_allocated_infra_external_ip)) if not self._first_controller_ip: self._first_controller_ip = str(IPAddress(first_ip)+1) @@ -259,16 +279,34 @@ class Installer(object): file_name, self._logdir), 'get file') + def _run_node_command(self, ip, user, passwd, command): + self._execute_shell('sshpass -p {} ssh {} {}@{} {}'.format(passwd, + Installer.SSH_OPTS, + user, + ip, + command), 'run command: {}'.format(command)) + def _get_node_logs(self, ip, user, passwd): self._get_file(ip, user, passwd, '/srv/deployment/log/cm.log') self._get_file(ip, user, passwd, '/srv/deployment/log/bootstrap.log') self._get_file(ip, user, passwd, '/var/log/ironic', recursive=True) + def _create_hosts_file(self, file_name): + with open(file_name, 'w') as hosts_file: + for host in self._uc['hosts'].keys(): + hosts_file.write('{}\n'.format(host)) + def _get_journal_logs(self, ip, user, passwd): + hosts_file_name = 'host_names' + hosts_file_path = '{}/{}'.format(self._logdir, hosts_file_name) + self._create_hosts_file(hosts_file_name) + + host_list = ' '.join(self._uc['hosts'].keys()) + + self._put_file(ip, user, passwd, hosts_file_name) self._put_file(ip, user, passwd, '/opt/scripts/get_journals.sh') - self._put_file(ip, user, passwd, '/opt/scripts/print_hosts.py') - self._execute_shell('sh ./get_journals.sh', 'run get_journals.sh') + self._run_node_command(ip, user, passwd, 'sh ./get_journals.sh {}'.format(hosts_file_name)) self._get_file(ip, user, passwd, '/tmp/node_journals.tgz') @@ -276,15 +314,16 @@ class Installer(object): bmc_host = bmc.get_host() bmc_user = bmc.get_user() bmc_passwd = bmc.get_passwd() - + bmc_priv_level = bmc.get_priv_level() + log_file = '{}/cat_bootstrap.log'.format(self._logdir) try: - cat_file = CatFile(bmc_host, bmc_user, bmc_passwd, admin_user, admin_passwd) + cat_file = CatFile(bmc_host, bmc_user, bmc_passwd, bmc_priv_level, admin_user, admin_passwd) cat_file.cat('/srv/deployment/log/bootstrap.log', log_file) except CatFileException as ex: logging.info('Could not cat file from console: %s', str(ex)) - cat_file = CatFile(bmc_host, bmc_user, bmc_passwd, 'root', 'root') + cat_file = CatFile(bmc_host, bmc_user, bmc_passwd, bmc_priv_level, 'root', 'root') cat_file.cat('/srv/deployment/log/bootstrap.log', log_file) def get_logs(self, admin_passwd): @@ -388,6 +427,8 @@ class Installer(object): self._set_progress('Wait for bootup') self._first_controller_bmc.wait_for_bootup() + self._set_progress('Wait deployment start') + self._first_controller_bmc.close() except BMCException as ex: logging.error('Installation failed: %s', str(ex))