Skip to content

Commit

Permalink
Merge pull request #31 from katlapinka/kasiat/initramfs-update
Browse files Browse the repository at this point in the history
Add method for updating initramfs accordingly to OS version
  • Loading branch information
katlapinka authored Nov 27, 2024
2 parents 2b085c1 + 2bec959 commit 072c72b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
19 changes: 19 additions & 0 deletions test_tools/initramfs.py
Original file line number Diff line number Diff line change
@@ -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)"
)
23 changes: 21 additions & 2 deletions test_utils/os_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
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

Expand All @@ -28,6 +28,14 @@
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
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit 072c72b

Please sign in to comment.