def config_controller(stream, config_file=None, password='******'): """ Configure controller-0 using optional arguments """ args = '' if config_file: args += '--config-file ' + config_file + ' ' serial.send_bytes(stream, "sudo config_controller {}".format(args), expect_prompt=False) host_helper.check_password(stream, password=password) ret = serial.expect_bytes(stream, "unlock controller to proceed.", timeout=HostTimeout.LAB_CONFIG) if ret != 0: LOG.info("Configuration failed. Exiting installer.") raise Exception("Configcontroller failed")
def config_controller(stream, default=True, release='R6', config_file=None, backup=None, clone_iso=None, restore_system=None, restore_images=None, remote_host=None, password='******'): """ Configure controller-0 using optional arguments Args: stream(stream): stream to controller-0 default(bool): Use default settings config_file(str): Config file to use. backup(str): clone_iso(str): release(str): Release version restore_system(str): restore_images(str): remote_host(str): Host to retrieve licence from if necessary Steps: - Checks for license file - Runs config_controller with default argument or with config-file if requested """ # TODO:Currently only uses config_file and default as optional arguments args = '' if config_file: args += '--config-file ' + config_file if release != 'R6': ret = serial.send_bytes(stream, "ls | grep license.lic", prompt='license.lic', fail_ok=True, timeout=10) if ret != 0: LOG.info("License file not found. Please retrieve license and press enter to continue.") input() if (release == 'R4' or release == 'R3') and not config_file: LOG.info("Configuration fails for R4/3 when using --default. " "Please configure manually before continuing the installation") return 1 LOG.info("Configuring controller-0") start = time.time() serial.send_bytes(stream, "sudo config_controller {}".format(args), expect_prompt=False) host_helper.check_password(stream, password=password) ret = serial.expect_bytes(stream, "Configuration was applied", timeout=HostTimeout.LAB_CONFIG) if ret != 0: LOG.info("Configuration failed. Exiting installer.") exit() kpi.CONFIGTIME = time.time() - start LOG.info("Configuration time: {} minutes".format(kpi.CONFIGTIME/60))
def setup_networking(stream, release, ctrlr0_ip, hostadapter_ip, password='******'): """ Setup initial networking so we can transfer files. """ ip = ctrlr0_ip host_ip = hostadapter_ip if release == "R2": interface = "eth0" else: interface = "enp0s3" ret = serial.send_bytes(stream, "/sbin/ip address list", prompt=ctrlr0_ip, fail_ok=True, timeout=10) if ret != 0: LOG.info("Setting networking up.") else: LOG.info("Skipping networking setup") return LOG.info("{} being set up with ip {}".format(interface, ip)) serial.send_bytes(stream, "sudo /sbin/ip addr add {}/24 dev {}".format(ip, interface), expect_prompt=False) host_helper.check_password(stream, password=password) time.sleep(2) serial.send_bytes(stream, "sudo /sbin/ip link set {} up".format(interface), expect_prompt=False) host_helper.check_password(stream, password=password) time.sleep(2) serial.send_bytes(stream, "sudo route add default gw {}".format(host_ip), expect_prompt=False) host_helper.check_password(stream, password=password) NETWORKING_TIME = 60 LOG.info("Wait a minute for networking to be established") time.sleep(NETWORKING_TIME)
def run_install_scripts(stream, host_list, aio_type=None, storage=False, release='R6', socks=None, streams=None, labname=None, username='******', password='******', conf_files={}): """ Runs lab install.sh iterations. Currently does not support Simplex systems Args: stream: Stream to controller-0 host_list: list of hosts, used when running aio scripts to install controller-1 at the appropriate time release: Release that is installed. aio_type: Option to run the script for aio setup storage: Option to run the script for storage setup streams: Dictionary of streams to nodes Steps: - Checks for lab_setup files - Runs lab_setup iterations - Unlocks nodes """ LOG.info("Starting to run the second round of lab_setup script. ") if release == 'R6' or release == 'R5' or release == 'R4': ret = serial.send_bytes(stream, '/bin/ls /home/' + username + '/images/ | grep tis-centos-guest.img', prompt="tis-centos-guest.img", fail_ok=True, timeout=10) else: ret = serial.send_bytes(stream, '/bin/ls /home/' + username + '/images/ | grep cgcs-guest.img', prompt="cgcs-guest.img", fail_ok=True, timeout=10) if ret != 0: LOG.info("Guest image not found. Please transfer the file before continuing. " "Press enter once guest image is obtained.") input() time.sleep(5) serial.send_bytes(stream, "chmod +x *.sh", timeout=20) ret = serial.send_bytes(stream, '/bin/ls /home/' + username + '/ | grep lab_setup.sh', prompt="lab_setup.sh", fail_ok=True, timeout=10) if ret != 0: LOG.info("Lab_setup.sh not found. Please transfer the " "required files before continuing. Press enter once files are obtained.") input() conf_str = "" for file in conf_files: conf_str = conf_str + " -f {}".format(file) LOG.info("lab_setup.sh will be run with options: {}".format(conf_str)) start = time.time() if aio_type: ## FOR AIO serial.send_bytes(stream, "source /etc/nova/openrc", prompt='keystone') if release != 'R6': serial.send_bytes(stream, "./lab_setup.sh {}".format(conf_str), expect_prompt=False, fail_ok=True) host_helper.check_password(stream, password=password) ret = serial.expect_bytes(stream, "topping after", timeout=HostTimeout.LAB_INSTALL, fail_ok=True) if ret != 0: LOG.info("Lab_setup.sh failed. Pausing to allow for debugging. " "Please re-run the iteration before continuing. Press enter to continue.") input() LOG.info("Running system compute-config-complete, " "installation will resume once controller-0 reboots and services are active") serial.send_bytes(stream, "source /etc/nova/openrc", prompt='keystone') serial.send_bytes(stream, "system compute-config-complete", expect_prompt=False) serial.expect_bytes(stream, "login:"******"Installing {} ".format(ctrlr1)) host_helper.install_host(stream, ctrlr1, host_type='controller', host_id=2) # Now wait for controller-1 to come up. Look for "login" on the serial port. # Close the socket if we are done try: serial.expect_bytes(cont1_stream, "ontroller-1 login:"******"{} installation complete".format(ctrlr1)) except Exception as e: LOG.info("Connection failed for {} with {}.".format(ctrlr1, e)) ## Sometimes we get UnicodeDecodeError exception due to the output ## of installation on the serial port, so ignore the exception and try one more time. if HostTimeout.HOST_INSTALL > (time.time()-start_time): LOG.info("Ignore the exception and wait for {} to be installed.".format(ctrlr1)) serial.expect_bytes(cont1_stream, "ontroller-1 login:"******"./lab_setup.sh {}".format(conf_str), expect_prompt=False) host_helper.check_password(stream, password=password) ret = serial.expect_bytes(stream, "topping after", timeout=HostTimeout.LAB_INSTALL, fail_ok=True) if ret != 0: LOG.info("Lab_setup.sh failed. Pausing to allow for debugging." " Please re-run the iteration before continuing. Press enter to continue.") input() ## Unlock controller-1 now = time.time() ret = host_helper.unlock_host(stream, ctrlr1) if ret == 1: LOG.info("Cannot unlock controller-1, pausing to allow for debugging. " "Please unlock before continuing. Press enter to continue.") input() retry = 0 while retry < 5: serial.send_bytes(cont1_stream, '\n', expect_prompt=False) try: ret = serial.expect_bytes(cont1_stream, "ontroller-1 login:"******"Unlocking controller-1 timed-out. pausing to allow for debugging. " "Please unlock before continuing. Press enter to continue.") input() break else: LOG.info("Unlocking controller-1 time (mins): {}".format((time.time() - now)/60)) if (time.time() - now)/60 < 15.0: LOG.info("login is found right after host-unlock. Wait and try again.") now = time.time() time.sleep(10) retry += 1 else: break except Exception as e: LOG.info("Unlocking controller-1 failed with {}".format(e)) LOG.info("Pausing to allow for debugging. " "Please unlock before continuing. Press enter to continue.") input() break serial.disconnect(socks[labname + '-' + ctrlr1]) serial.send_bytes(stream, "./lab_setup.sh {}".format(conf_str), expect_prompt=False) host_helper.check_password(stream, password=password) ret = serial.expect_bytes(stream, "topping after", timeout=HostTimeout.LAB_INSTALL, fail_ok=True) if ret != 0: LOG.info("Lab_setup.sh failed. Pausing to allow for debugging. " "Please re-run the iteration before continuing. Press enter to continue.") input() LOG.info("Completed install successfully.") else: ## FOR NON-AIO cases serial.send_bytes(stream, "source /etc/nova/openrc", prompt='keystone') # TODO (WEI): double check this # Why only if not R5, we run lab_setup.sh here? #if release != 'R5': serial.send_bytes(stream, "./lab_setup.sh {}".format(conf_str), expect_prompt=False) host_helper.check_password(stream, password=password) ret = serial.expect_bytes(stream, "topping after", timeout=HostTimeout.LAB_INSTALL, fail_ok=True) if ret != 0: LOG.info("Lab_setup.sh failed. Pausing to allow for debugging. " "Please re-run the iteration before continuing. Press enter to continue.") input() ## TODO: ## 1. Unlock sometimes won't bring a node into enabled state. Need to reboot/reset it. ## 2. When unlocking a node, sometimes the node will reboot again after the "login" ## prompt is seen on the serial port, so seeing "login" doesn't mean the node becomes ## "unlocked/enabled". The workaround can be: ## 1) time.sleep(10) and repeat the wait for "login" logic again. ## 2) After seeing "login" prompt, send to controller-0 ## "system host-list | grep node" to look for "enabled". ## Unlock controller-1 now = time.time() ret = host_helper.unlock_host(stream, "controller-1") if ret == 1: LOG.info("Cannot unlock controller-1, pausing to allow for debugging. " "Please unlock before continuing. Press enter to continue.") input() ## Wait for controller-1 to come up retry = 0 ctrlr_1 = labname + "-controller-1" while retry < 5: serial.send_bytes(streams[ctrlr_1], '\n', expect_prompt=False) try: ret = serial.expect_bytes(streams[ctrlr_1], "ontroller-1 login:"******"Unlocking controller-1 timed-out. pausing to allow for debugging. Press enter to continue.") input() break else: LOG.info("Unlock controller-1 time (mins): {}".format((time.time() - now)/60)) ## Sometimes "login" is found right after "host-unlock" is issued, so we need to wait and try again. ## Also sometimes the node will go thru reboot again after "login" is detected on the serial port. ## As the node unlock time is usually longer than 15 mins, as a temperary workaround ## let's wait at least for 15 mins now. if (time.time() - now)/60 < 15.0: LOG.info("Found controller-1 login right away. Need to wait and try again.") now = time.time() time.sleep(10) retry += 1 else: break except Exception as e: LOG.info("Unlock controller-1 failed with {} pausing to allow for debugging. Press enter to continue.".format(e)) input() break serial.disconnect(socks[ctrlr_1]) host_list.remove(ctrlr_1) ## TODO: Well, there is a chance that controller-1 is not "unlocked/enabled" yet. ## See comment #2 above. ## If it is a storage lab if storage: LOG.info("Re-running lab_setup.sh to configure storage nodes.") serial.send_bytes(stream, "./lab_setup.sh {}".format(conf_str), expect_prompt=False) host_helper.check_password(stream, password=password) ret = serial.expect_bytes(stream, "topping after", timeout=HostTimeout.LAB_INSTALL, fail_ok=True) if ret != 0: LOG.info("Lab_setup.sh failed. Pausing to allow for debugging. " "Please re-run the iteration before continuing. Press enter to continue.") input() now = time.time() for host in host_list: host = host[len(labname)+1:] if host.startswith('storage'): LOG.info("Unlock {}".format(host)) ret = host_helper.unlock_host(stream, host) if ret == 1: LOG.info("Cannot unlock {}, pausing to allow for debugging. " "Please unlock before continuing. Press enter to continue.".format(host)) input() time.sleep(20) ## TODO: Need the retry strategy here too. for host in host_list: if 'storage' in host: serial.send_bytes(streams[host], '\n', expect_prompt=False) try: ret = serial.expect_bytes(streams[host], "{} login:"******"Unlocking {} timed-out. Pause for debugging. Press enter to continue.".format(host)) input() else: LOG.info("Unlocking {} time (mins): {}".format(host, (time.time() - now)/60)) if (time.time() - now)/60 < 15.0: LOG.info("Found {} login too soon. Make sure it is up. Press enter to continue.".format(host)) input() except Exception as e: LOG.info("Unlock {} failed with {}. Pause for debugging. Press enter to continue.".format(host, e)) input() serial.disconnect(socks[host]) host_list.remove(host) LOG.info("Completed storage node unlock") LOG.info("Re-running lab_setup.sh before unlocking compute nodes.") serial.send_bytes(stream, "./lab_setup.sh {}".format(conf_str), expect_prompt=False) host_helper.check_password(stream, password=password) ret = serial.expect_bytes(stream, "topping after", timeout=HostTimeout.LAB_INSTALL, fail_ok=True) if ret != 0: LOG.info("Lab_setup.sh failed. Pausing to allow for debugging. " "Please re-run the iteration before continuing. Press enter to continue.") input() # unlock compute nodes now = time.time() for host in host_list: host = host[len(labname)+1:] ret = host_helper.unlock_host(stream, host) if ret == 1: LOG.info("Cannot unlock {}, pausing to allow for debugging. " "Please unlock before continuing. Press enter to continue.".format(host)) input() time.sleep(20) LOG.info("Waiting for {} to unlock.".format(host_list)) ## Check unlocking status failed_nodes = [] for host in host_list: # TODO Fix it! 'ogin:' is always found immediately after unlock # WEI: fixed it by retrying retry = 0 while retry < 5: serial.send_bytes(streams[host], '\n', expect_prompt=False) try: ret = serial.expect_bytes(streams[host], "{} login:"******"Unlock {} timed-out.".format(host)) failed_nodes.append(host) break else: LOG.info("Unlock {} time (mins): {}".format(host, (time.time() - now)/60)) if (time.time() - now)/60 < 15.0: LOG.info("login is found right after host-unlock. Wait and try again.") now = time.time() time.sleep(10) retry += 1 else: break except Exception as e: LOG.info("Unlock {} failed with {}".format(host, e)) failed_nodes.append(host) break serial.disconnect(socks[host]) ## Let's reset the VMs that failed to unlock if failed_nodes: vboxmanage.vboxmanage_controlvms(failed_nodes, action="reset") time.sleep(10) tmp_streams = {} tmp_socks = {} LOG.info(failed_nodes) port = 10001 for host in failed_nodes: tmp_sock = serial.connect('{}'.format(host), port) tmp_stream = streamexpect.wrap(tmp_sock, echo=True, close_stream=False) time.sleep(10) tmp_socks[host] = tmp_sock tmp_streams[host] = tmp_stream port += 1 host_failed = False for host in failed_nodes: serial.send_bytes(tmp_streams[host], '\n', expect_prompt=False) try: ret = serial.expect_bytes(tmp_streams[host], "{} login:"******"{} timed-out to become unlocked/available after reset.".format(host)) host_failed = True else: LOG.info("{} became unlocked/available after reset. time (mins): {}".format(host, (time.time() - now)/60)) except Exception as e: LOG.info("{} failed to become unlocked/available after reset with {}".format(host, e)) host_failed = True serial.disconnect(tmp_socks[host]) if host_failed: LOG.info("Not all the nodes are unlocked successfully. Pausing to allow for debugging. " "Once they all become unlocked/enabled/available, press enter to continue.") input() serial.send_bytes(stream, "./lab_setup.sh {}".format(conf_str), expect_prompt=False) host_helper.check_password(stream, password=password) ret = serial.expect_bytes(stream, "Done", timeout=HostTimeout.LAB_INSTALL, fail_ok=True) if ret != 0: LOG.info("Lab_setup.sh failed. Pausing to allow for debugging. " "Please re-run the iteration before continuing." " Press enter to continue.") input() LOG.info("Completed lab install.") kpi.LABTIME = time.time()-start LOG.info("Lab install time: {}".format(kpi.LABTIME/60))
def lab_setup_controller_0_locked(stream, username='******', password='******', conf_files={}): """ Runs initial lab_setup when controller-0 is locked. This is for R5 only. Args: stream: Stream to controller-0 Steps: - Checks if controller-0 is locked - Checks for lab_setup files - Runs first lab_setup iteration - Unlocks controller-0 """ time.sleep(10) serial.send_bytes(stream, "source /etc/nova/openrc", prompt='keystone') serial.send_bytes(stream, "system host-list", expect_prompt=False) try: serial.expect_bytes(stream, "locked") except streamexpect.ExpectTimeout: LOG.info("Controller should be locked when configuration is completed.") return 1 ret = serial.send_bytes(stream, '/bin/ls /home/' + username + '/images/ | grep tis-centos-guest.img', prompt="tis-centos-guest.img", fail_ok=True, timeout=10) if ret != 0: LOG.info("Guest image not found. Please transfer the " "required files before continuing. Press enter once files are obtained.") input() time.sleep(5) ret = serial.send_bytes(stream, '/bin/ls /home/' + username + '/ | grep lab_setup.sh', prompt="lab_setup.sh", fail_ok=True, timeout=10) if ret != 0: LOG.info("Lab_setup.sh not found. Please transfer the " "required files before continuing. Press enter once files are obtained.") input() time.sleep(5) conf_str = "" for file in conf_files: conf_str = conf_str + " -f {}".format(file) serial.send_bytes(stream, "sh lab_setup.sh {}".format(conf_str), timeout=HostTimeout.LAB_INSTALL, expect_prompt=False) host_helper.check_password(stream, password=password) ret = serial.expect_bytes(stream, "topping after", timeout=3500, fail_ok=True) if ret != 0: LOG.info("Lab_setup.sh failed. Pausing to allow for debugging. " "Please re-run the iteration before continuing. Press enter to continue.") input() start = time.time() host_helper.unlock_host(stream, 'controller-0') try: ret = serial.expect_bytes(stream, 'login:', timeout=HostTimeout.CONTROLLER_UNLOCK) if ret != 0: LOG.info("Controller-0 not unlocked,Pausing to allow for debugging. " "Please re-run the iteration before continuing. Press enter to continue.") input() except Exception as e: LOG.info("Unlock controller-0 failed with {}. ".format(e)) ## Sometimes we get UnicodeDecodeError exception due to the output ## on the serial port, so ignore that and try one more time. LOG.info("Ignore the exception and wait for controller-0 to be unlocked again.") if HostTimeout.CONTROLLER_UNLOCK > (time.time()-start): serial.expect_bytes(stream, "login:"******"Controller-0 unlock time: {} minutes".format(end)) LOG.info("Waiting for services to activate.") time.sleep(60)
LOG.info("Length of reboot {} minutes".format(kpi.REBOOTTIME/60)) host_helper.login(stream, username=username, password=password) ## TODO (WEI): Remove it def enable_lvm(stream, release, password='******'): """ Enables LVM backend Args: stream: stream to controller-0. release: Release version installed. """ if release != 'R6': LOG.info("Storage backends configured in config_controller for non R6 releases.") return serial.send_bytes(stream, "NODE=controller-0;DEVICE=/dev/sdb;SIZE=10237") serial.send_bytes(stream, "sudo parted -s $DEVICE mktable gpt", expect_prompt=False) host_helper.check_password(stream, password=password) serial.send_bytes(stream, "system host-disk-list 1 | grep /dev/sdb", prompt="10237") serial.send_bytes(stream, "DISK=$(system host-disk-list $NODE | grep $DEVICE | awk '{print $2}')") serial.send_bytes(stream, "system host-disk-partition-add $NODE $DISK $SIZE -t lvm_phys_vol") serial.send_bytes(stream, "system host-lvg-add $NODE cinder-volumes") serial.send_bytes(stream, "while true; do system host-disk-partition-list $NODE --nowrap | grep $DEVICE | " "grep Ready; if [ $? -eq 0 ]; then break; fi; sleep 1; done") serial.send_bytes(stream, "PARTITION=$(system host-disk-partition-list $NODE --disk $DISK --nowrap | grep " "part1 | awk '{print $2}')") serial.send_bytes(stream, "system host-pv-add $NODE cinder-volumes $PARTITION") serial.send_bytes(stream, "system storage-backend-add lvm -s cinder --confirmed") serial.send_bytes(stream, "while true; do system storage-backend-list | grep lvm | grep configured; if " "[ $? -eq 0 ]; then break; else sleep 10; fi; done")