Fix script file transformer and openssl command issues (#3473)

* skip installing packages when it is not specified

* fix -6 option not available in some distro

* handle the issue when use -cpu host

* set timeout for checking command to save time

* ntttcp: set system parameter net.ipv4.tcp_rmem to optimize network performance
This commit is contained in:
LiliDeng 2024-10-15 21:58:05 -07:00 коммит произвёл GitHub
Родитель e9df2a6c06
Коммит ff7e40674a
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
4 изменённых файлов: 66 добавлений и 12 удалений

Просмотреть файл

@ -134,6 +134,10 @@ class Ntttcp(Tool):
{"kernel.pid_max": "122880"},
{"vm.max_map_count": "655300"},
{"net.ipv4.ip_local_port_range": "1024 65535"},
# This parameter configures the minimum, default,
# and maximum sizes for TCP receive buffers to
# optimize network performance based on available bandwidth and latency.
{"net.ipv4.tcp_rmem": "4096 87380 16777216"},
]
sys_list_udp = [
{"net.core.rmem_max": "67108864"},
@ -162,13 +166,13 @@ class Ntttcp(Tool):
def setup_system(self, udp_mode: bool = False, set_task_max: bool = True) -> None:
sysctl = self.node.tools[Sysctl]
sys_list = self.sys_list_tcp
if set_task_max:
self._set_tasks_max()
if udp_mode:
sys_list = self.sys_list_udp
for sys in sys_list:
for variable, value in sys.items():
sysctl.write(variable, value)
if set_task_max:
self._set_tasks_max()
firewall = self.node.tools[Firewall]
firewall.stop()

Просмотреть файл

@ -19,6 +19,10 @@ class Qemu(Tool):
QEMU_INSTALL_LOCATIONS = ["qemu-system-x86_64", "qemu-kvm", "/usr/libexec/qemu-kvm"]
# qemu-kvm: unrecognized feature pcid
NO_PCID_PATTERN = re.compile(r".*unrecognized feature pcid", re.M)
# KVM: entry failed, hardware error 0xffffffff
ERROR_WHEN_USE_HOST_CPU = re.compile(
r"KVM: entry failed, hardware error 0xffffffff", re.M
)
@property
def command(self) -> str:
@ -75,8 +79,10 @@ class Qemu(Tool):
# for some qemu version, it doesn't support pcid flag
# e.g. QEMU emulator version 1.5.3 (qemu-kvm-1.5.3-175.el7_9.6)
# on centos 7.9
# use a timeout mechanism to prevent the command from waiting the full 600
# seconds before exiting.
try_pcid_flag = self.node.execute(
f"{self._qemu_command} -cpu host,pcid=no", sudo=True
f"timeout 20 {self._qemu_command} -cpu host,pcid=no", sudo=True
)
if not get_matched_str(try_pcid_flag.stdout, self.NO_PCID_PATTERN):
cmd += ",pcid=no"
@ -113,11 +119,6 @@ class Qemu(Tool):
f"-device virtio-scsi-pci -device scsi-hd,drive=datadisk-{i} "
)
# -enable-kvm: enable kvm
# -display: enable or disable display
# -daemonize: run in background
cmd += "-enable-kvm -display none -daemonize "
if cd_rom:
cmd += f" -cdrom {cd_rom} "
@ -125,13 +126,18 @@ class Qemu(Tool):
if stop_existing_vm:
self.delete_vm()
# start qemu
cmd = self._configure_qemu_command_for_cpu(cmd)
# -enable-kvm: enable kvm
# -display: enable or disable display
# -daemonize: run in background
cmd += "-enable-kvm -display none -daemonize "
result = self.run(
cmd,
sudo=True,
shell=True,
)
if result.exit_code != 0:
if "ret == cpu->kvm_msr_buf->nmsrs" in result.stdout:
# Known issue with qemu on AMD
@ -210,3 +216,18 @@ class Qemu(Tool):
"kvm_intel"
) or lsmod.module_exists("kvm_amd")
assert_that(is_kvm_successfully_enabled, "KVM could not be enabled").is_true()
def _configure_qemu_command_for_cpu(self, cmd: str) -> str:
# start qemu
result = self.node.execute(
f"timeout 20 {self.command} {cmd}",
sudo=True,
shell=True,
)
# using `-cpu host` is causing the issue
# using `-cpu EPYC` for AMD CPU works correctly
# if meet the failure pattern, use EPYC instead
if get_matched_str(result.stdout, self.ERROR_WHEN_USE_HOST_CPU):
cmd = cmd.replace("-cpu host", "-cpu EPYC")
return cmd

Просмотреть файл

@ -74,7 +74,8 @@ class ScriptFileTransformer(DeploymentTransformer):
def _internal_run(self) -> Dict[str, Any]:
runbook: ScriptFileTransformerSchema = self.runbook
self._node.os.install_packages(runbook.dependent_packages) # type: ignore
if runbook.dependent_packages:
self._node.os.install_packages(runbook.dependent_packages) # type: ignore
results: Dict[str, Any] = {}
failed_scripts = []

Просмотреть файл

@ -38,7 +38,35 @@ def _create_cloud_init_iso(
password: str,
host_name: str = "l2vm",
) -> str:
cmd_result = host.execute(f"openssl passwd -6 {password}", sudo=True, shell=True)
cmd_result = host.execute(
f"openssl passwd -6 {password}",
sudo=True,
shell=True,
)
# The expected exit code is 0, indicating success.
# If a non-zero exit code is encountered, try using the -1 option.
# Note: The -6 option may not be available in older versions.
# Output:
# Usage: passwd [options] [passwords]
# where options are
# -crypt standard Unix password algorithm (default)
# -1 MD5-based password algorithm
# -apr1 MD5-based password algorithm, Apache variant
# -salt string use provided salt
# -in file read passwords from file
# -stdin read passwords from stdin
# -noverify never verify when reading password from terminal
# -quiet no warnings
# -table format output as table
# -reverse switch table columns
if cmd_result.exit_code != 0:
cmd_result = host.execute(
f"openssl passwd -1 {password}",
sudo=True,
shell=True,
)
if cmd_result.exit_code != 0:
raise LisaException("fail to run openssl command to convert password")
user_data = {
"users": [
"default",