Merge pull request #31 from katlapinka/kasiat/initramfs-update

Add method for updating initramfs accordingly to OS version
This commit is contained in:
Katarzyna Treder 2024-11-27 10:24:06 +01:00 committed by GitHub
commit 072c72b08c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 40 additions and 2 deletions

19
test_tools/initramfs.py Normal file
View File

@ -0,0 +1,19 @@
#
# Copyright(c) 2024 Huawei Technologies Co., Ltd.
# SPDX-License-Identifier: BSD-3-Clause
#
from core.test_run import TestRun
from test_utils.os_utils import get_distro, Distro
def update():
distro = get_distro()
TestRun.LOGGER.info("Updating initramfs")
match distro:
case Distro.DEBIAN | Distro.UBUNTU:
TestRun.executor.run_expect_success("update-initramfs -u")
case Distro.OPENEULER | Distro.CENTOS | Distro.REDHAT:
TestRun.executor.run_expect_success(
"dracut -f /boot/initramfs-$(uname -r).img $(uname -r)"
)

View File

@ -8,9 +8,9 @@ import math
import posixpath
import re
import time
from datetime import timedelta, datetime
from aenum import IntFlag, Enum, IntEnum
from datetime import timedelta, datetime
from enum import IntFlag, Enum, IntEnum, StrEnum
from packaging import version
from typing import List
@ -28,6 +28,14 @@ DEBUGFS_MOUNT_POINT = "/sys/kernel/debug"
MEMORY_MOUNT_POINT = "/mnt/memspace"
class Distro(StrEnum):
UBUNTU = "ubuntu"
DEBIAN = "debian"
REDHAT = "rhel"
OPENEULER = "openeuler"
CENTOS = "centos"
class DropCachesMode(IntFlag):
PAGECACHE = 1
SLAB = 2
@ -102,6 +110,17 @@ class SystemManagerType(Enum):
systemd = 1
def get_distro():
output = TestRun.executor.run(
"cat /etc/os-release | grep -e \"^ID=\" | awk -F= '{print$2}' | tr -d '\"'"
).stdout.lower()
try:
return Distro(output)
except ValueError:
raise ValueError(f"Could not resolve distro name. Command output: {output}")
def get_system_manager():
output = TestRun.executor.run_expect_success("ps -p 1").stdout
type = output.split('\n')[1].split()[3]