############################################################################### # Copyright (c) 2015 Ericsson AB and others. # szilard.cserey@ericsson.com # 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 time import os import glob from ssh_client import SSHClient from dha_adapters.libvirt_adapter import LibvirtAdapter from common import ( log, err, clean, delete, ) TRANSPLANT_FUEL_SETTINGS = 'transplant_fuel_settings.py' BOOTSTRAP_ADMIN = '/usr/local/sbin/bootstrap_admin_node' FUEL_CLIENT_CONFIG = '/etc/fuel/client/config.yaml' PLUGINS_DIR = '~/plugins' LOCAL_PLUGIN_FOLDER = '/opt/opnfv' IGNORABLE_FUEL_ERRORS = ['does not update installed package', 'Couldn\'t resolve host'] class InstallFuelMaster(object): def __init__(self, dea_file, dha_file, fuel_ip, fuel_username, fuel_password, fuel_node_id, iso_file, work_dir, fuel_plugins_dir, no_plugins): self.dea_file = dea_file self.dha = LibvirtAdapter(dha_file) self.fuel_ip = fuel_ip self.fuel_username = fuel_username self.fuel_password = fuel_password self.fuel_node_id = fuel_node_id self.iso_file = iso_file self.iso_dir = os.path.dirname(self.iso_file) self.work_dir = work_dir self.fuel_plugins_dir = fuel_plugins_dir self.no_plugins = no_plugins self.file_dir = os.path.dirname(os.path.realpath(__file__)) self.ssh = SSHClient(self.fuel_ip, self.fuel_username, self.fuel_password) def install(self): log('Start Fuel Installation') self.dha.node_power_off(self.fuel_node_id) log('Zero the MBR') self.dha.node_zero_mbr(self.fuel_node_id) self.dha.node_set_boot_order(self.fuel_node_id, ['disk', 'iso']) try: self.proceed_with_installation() except Exception as e: self.post_install_cleanup() err(e) def proceed_with_installation(self): log('Eject ISO') self.dha.node_eject_iso(self.fuel_node_id) log('Insert ISO %s' % self.iso_file) self.dha.node_insert_iso(self.fuel_node_id, self.iso_file) self.dha.node_power_on(self.fuel_node_id) log('Waiting for Fuel master to accept SSH') self.wait_for_node_up() log('Wait until Fuel menu is up') fuel_menu_pid = self.wait_until_fuel_menu_up() log('Inject our own astute.yaml settings') self.inject_own_astute_yaml() log('Let the Fuel deployment continue') log('Found FUEL menu as PID %s, now killing it' % fuel_menu_pid) self.ssh_exec_cmd('kill %s' % fuel_menu_pid, False) log('Wait until installation is complete') self.wait_until_installation_completed() log('Waiting for one minute for Fuel to stabilize') time.sleep(60) self.delete_deprecated_fuel_client_config() if not self.no_plugins: self.collect_plugin_files() self.install_plugins() self.post_install_cleanup() log('Fuel Master installed successfully !') def collect_plugin_files(self): with self.ssh as s: s.exec_cmd('mkdir %s' % PLUGINS_DIR) if self.fuel_plugins_dir: for f in glob.glob('%s/*.rpm' % self.fuel_plugins_dir): s.scp_put(f, PLUGINS_DIR) def install_plugins(self): log('Installing Fuel Plugins') plugin_files = [] with self.ssh as s: for plugin_location in [PLUGINS_DIR, LOCAL_PLUGIN_FOLDER]: s.exec_cmd('mkdir -p %s' % plugin_location) r = s.exec_cmd('find %s -type f -name \'*.rpm\'' % plugin_location) plugin_files.extend(r.splitlines()) for f in plugin_files: log('Found plugin %s, installing ...' % f) r, e = s.exec_cmd('fuel plugins --install %s' % f, False) printout = r + e if e else r if e and all([err not in printout for err in IGNORABLE_FUEL_ERRORS]): raise Exception('Installation of Fuel Plugin %s '