
- Additionally, add password validation function. - Breaks Parser.py into more manageable functions. - Changes where defaults are set (Parser.py instead of class under /consts) The goal is to not have any reference to a password in the code itself, only in configuration files or README files, if strictly necessary. The new password validation function, besides failing fast at the argument parser, makes sure the password will be allowed by Debian later on the installation. This commit is not touching any Shell script because they will probably be removed or change in follow-up commits. Test Plan: PASS: Operating system password should be set to value passed via --password Failure Path: PASS: Script fails fast without the parameter --password PASS: Script fails fast if password requirements are not met Regression: PASS: AIO-SX install works Story: 2005051 Task: 47960 Task: 48230 Change-Id: Ibf42b792ef825cee61cc69d1b5afa807361037b7 Signed-off-by: Bruno Muniz <bruno.muniz@encora.com>
148 lines
4.5 KiB
Python
148 lines
4.5 KiB
Python
#!/usr/bin/python3
|
|
#
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
#
|
|
|
|
"""
|
|
This module provides functions to interact with a StarlingX controller-0 server via a
|
|
serial connection. The functions can be used to perform operations such as unlocking,
|
|
locking, rebooting, and installing a host. The module uses streamexpect library to
|
|
facilitate stream parsing.
|
|
"""
|
|
|
|
import time
|
|
import streamexpect
|
|
from consts.timeout import HostTimeout
|
|
from utils import serial
|
|
from utils.install_log import LOG
|
|
|
|
|
|
def unlock_host(stream, hostname):
|
|
"""
|
|
Unlocks given host
|
|
Args:
|
|
stream(stream): Stream to active controller
|
|
hostname(str): Name of host to unlock
|
|
Steps:
|
|
- Check that host is locked
|
|
- Unlock host
|
|
"""
|
|
|
|
LOG.info("#### Unlock %s", hostname)
|
|
serial.send_bytes(stream, f"system host-list | grep {hostname}", expect_prompt=False)
|
|
try:
|
|
serial.expect_bytes(stream, "locked")
|
|
except streamexpect.ExpectTimeout:
|
|
LOG.info("Host %s not locked", hostname)
|
|
return 1
|
|
serial.send_bytes(stream, f"system host-unlock {hostname}", expect_prompt=False)
|
|
LOG.info("Unlocking %s", hostname)
|
|
return None
|
|
|
|
|
|
def lock_host(stream, hostname):
|
|
"""
|
|
Locks the specified host.
|
|
Args:
|
|
stream(stream): Stream to controller-0
|
|
hostname(str): Name of host to lock
|
|
Steps:
|
|
- Check that host is unlocked
|
|
- Lock host
|
|
"""
|
|
|
|
LOG.info("Lock %s", hostname)
|
|
serial.send_bytes(stream, f"system host-list |grep {hostname}", expect_prompt=False)
|
|
try:
|
|
serial.expect_bytes(stream, "unlocked")
|
|
except streamexpect.ExpectTimeout:
|
|
LOG.info("Host %s not unlocked", hostname)
|
|
return 1
|
|
serial.send_bytes(stream, f"system host-lock {hostname}", expect_prompt="keystone")
|
|
LOG.info("Locking %s", hostname)
|
|
return None
|
|
|
|
|
|
def reboot_host(stream, hostname):
|
|
"""
|
|
Reboots host specified
|
|
Args:
|
|
stream():
|
|
hostname(str): Host to reboot
|
|
"""
|
|
|
|
LOG.info("Rebooting %s", hostname)
|
|
serial.send_bytes(stream, f"system host-reboot {hostname}", expect_prompt=False)
|
|
serial.expect_bytes(stream, "rebooting", HostTimeout.REBOOT)
|
|
|
|
|
|
def install_host(stream, hostname, host_type, host_id):
|
|
"""
|
|
Initiates install of specified host. Requires controller-0 to be installed already.
|
|
Args:
|
|
stream(stream): Stream to cont0
|
|
hostname(str): Name of host
|
|
host_type(str): Type of host being installed e.g. 'storage' or 'compute'
|
|
host_id(int): id to identify host
|
|
"""
|
|
|
|
time.sleep(10)
|
|
LOG.info("Installing %s with id %s", hostname, host_id)
|
|
if host_type == 'controller':
|
|
serial.send_bytes(stream,
|
|
f"system host-update {host_id} personality=controller",
|
|
expect_prompt=False)
|
|
elif host_type == 'storage':
|
|
serial.send_bytes(stream,
|
|
f"system host-update {host_id} personality=storage",
|
|
expect_prompt=False)
|
|
else:
|
|
serial.send_bytes(stream,
|
|
f"system host-update {host_id} personality=compute hostname={hostname}",
|
|
expect_prompt=False)
|
|
time.sleep(30)
|
|
|
|
|
|
def disable_logout(stream):
|
|
"""
|
|
Disables automatic logout of users.
|
|
Args:
|
|
stream(stream): stream to cont0
|
|
"""
|
|
|
|
LOG.info('Disabling automatic logout')
|
|
serial.send_bytes(stream, "export TMOUT=0")
|
|
|
|
|
|
def change_password(stream, username, password):
|
|
"""
|
|
changes the default password (username) on initial login.
|
|
Args:
|
|
stream(stream): stream to cont0
|
|
username: the current username (which should also be the password)
|
|
password: the new password
|
|
"""
|
|
|
|
LOG.info('Changing password to %s', password)
|
|
serial.send_bytes(stream, username, expect_prompt=False)
|
|
serial.expect_bytes(stream, "Password:")
|
|
serial.send_bytes(stream, username, expect_prompt=False)
|
|
serial.expect_bytes(stream, "Current password:")
|
|
serial.send_bytes(stream, username, expect_prompt=False)
|
|
serial.expect_bytes(stream, "New password:")
|
|
serial.send_bytes(stream, password, expect_prompt=False)
|
|
serial.expect_bytes(stream, "Retype new password")
|
|
serial.send_bytes(stream, password)
|
|
|
|
|
|
def check_password(stream, password):
|
|
"""
|
|
Checks the password.
|
|
Args:
|
|
stream(stream): Stream to cont0
|
|
password(str): password to check.
|
|
"""
|
|
ret = serial.expect_bytes(stream, 'assword', fail_ok=True, timeout=5)
|
|
if ret == 0:
|
|
serial.send_bytes(stream, password, expect_prompt=False)
|