Bruno Muniz 07051a09aa Remove all hard-coded passwords and require it
- 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>
2023-06-30 14:28:02 -03:00

60 lines
1.5 KiB
Python

#!/usr/bin/python3
#
# SPDX-License-Identifier: Apache-2.0
#
"""
Contains helper functions that will configure basic system settings.
"""
from consts.timeout import HostTimeout
from utils import serial
from utils.install_log import LOG
from helper import host_helper
def update_platform_cpus(stream, hostname, cpu_num=5):
"""
Update platform CPU allocation.
"""
LOG.info("Allocating %s CPUs for use by the %s platform.", cpu_num, hostname)
serial.send_bytes(
stream,
"\nsource /etc/platform/openrc; system host-cpu-modify "
f"{hostname} -f platform -p0 {cpu_num}",
prompt="keystone",
timeout=300,
)
def set_dns(stream, dns_ip):
"""
Perform DNS configuration on the system.
"""
LOG.info("Configuring DNS to %s.", dns_ip)
serial.send_bytes(
stream,
"source /etc/platform/openrc; system dns-modify "
f"nameservers={dns_ip}",
prompt="keystone",
)
def config_controller(stream, password):
"""
Configure controller-0 using optional arguments
"""
serial.send_bytes(
stream,
"ansible-playbook /usr/share/ansible/stx-ansible/playbooks/bootstrap.yml",
expect_prompt=False,
)
host_helper.check_password(stream, password=password)
ret = serial.expect_bytes(stream, "~$", timeout=HostTimeout.LAB_CONFIG)
if ret != 0:
LOG.info("Configuration failed. Exiting installer.")
raise Exception("Configcontroller failed") # pylint: disable=E0012, W0719