Skip to content

Commit

Permalink
ds-identify/dmi: fix and extend unittests
Browse files Browse the repository at this point in the history
  • Loading branch information
igalic committed Dec 6, 2023
1 parent 5de30f6 commit 5e9a77d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
3 changes: 1 addition & 2 deletions tests/unittests/test_dmi.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def patch_mapping(self, new_mapping):

def test_sysfs_used_with_key_in_mapping_and_file_on_disk(self):
self.patch_mapping(
{"mapped-key": dmi.KernelNames("mapped-value", None)}
{"mapped-key": dmi.KernelNames("mapped-value", None, None)}
)
expected_dmi_value = "sys-used-correctly"
self._create_sysfs_file("mapped-value", expected_dmi_value)
Expand Down Expand Up @@ -173,7 +173,6 @@ def test_freebsd_uses_kenv(self):


class TestSubDMIVars:

DMI_SRC = (
"dmi.nope__dmi.system-uuid__/__dmi.uuid____dmi.smbios.system.uuid__"
)
Expand Down
34 changes: 22 additions & 12 deletions tests/unittests/test_ds_identify.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@
)

UNAME_MYSYS = (
"Linux bart 4.4.0-62-generic #83-Ubuntu "
"SMP Wed Jan 18 14:10:15 UTC 2017 x86_64 GNU/Linux"
"Linux 4.4.0-62-generic #83-Ubuntu SMP Wed Jan 18 14:10:15 UTC 2017 x86_64"
)
UNAME_PPC64EL = (
"Linux diamond 4.4.0-83-generic #106-Ubuntu SMP "
"Linux 4.4.0-83-generic #106-Ubuntu SMP "
"Mon Jun 26 17:53:54 UTC 2017 "
"ppc64le ppc64le ppc64le GNU/Linux"
"ppc64le ppc64le ppc64le"
)
UNAME_FREEBSD = (
"FreeBSD fbsd12-1 12.1-RELEASE-p10 FreeBSD 12.1-RELEASE-p10 GENERIC amd64"
"FreeBSD 12.1-RELEASE-p10 FreeBSD 12.1-RELEASE-p10 GENERIC amd64"
)
UNAME_OPENBSD = "OpenBSD GENERIC.MP#1397 amd64"

BLKID_EFI_ROOT = """
DEVNAME=/dev/sda1
Expand Down Expand Up @@ -246,6 +246,7 @@
MOCK_VIRT_IS_XEN = {"name": "detect_virt", "RET": "xen", "ret": 0}
MOCK_UNAME_IS_PPC64 = {"name": "uname", "out": UNAME_PPC64EL, "ret": 0}
MOCK_UNAME_IS_FREEBSD = {"name": "uname", "out": UNAME_FREEBSD, "ret": 0}
MOCK_UNAME_IS_OPENBSD = {"name": "uname", "out": UNAME_OPENBSD, "ret": 0}

shell_true = 0
shell_false = 1
Expand Down Expand Up @@ -434,11 +435,8 @@ def test_wb_print_variables(self):
"KERNEL_CMDLINE",
"VIRT",
"UNAME_KERNEL_NAME",
"UNAME_KERNEL_RELEASE",
"UNAME_KERNEL_VERSION",
"UNAME_MACHINE",
"UNAME_NODENAME",
"UNAME_OPERATING_SYSTEM",
"DSNAME",
"DSLIST",
"MODE",
Expand Down Expand Up @@ -1062,6 +1060,7 @@ class TestBSDNoSys(DsIdentifyBase):
"""Test *BSD code paths
FreeBSD doesn't have /sys so we use kenv(1) here.
OpenBSD uses sysctl(8).
Other BSD systems fallback to dmidecode(8).
BSDs also doesn't have systemd-detect-virt(8), so we use sysctl(8) to query
kern.vm_guest, and optionally map it"""
Expand All @@ -1073,6 +1072,13 @@ def test_dmi_kenv(self):
"""
self._test_ds_found("Hetzner-kenv")

def test_dmi_sysctl(self):
"""Test that sysctl(8) works on systems which don't have /sys
This will be used on OpenBSD systems.
"""
self._test_ds_found("Hetzner-sysctl")

def test_dmi_dmidecode(self):
"""Test that dmidecode(8) works on systems which don't have /sys
Expand Down Expand Up @@ -1616,6 +1622,13 @@ def _print_run_output(rc, out, err, cfg, files):
{"name": "get_kenv_field", "ret": 0, "RET": "Hetzner"},
],
},
"Hetzner-sysctl": {
"ds": "Hetzner",
"mocks": [
MOCK_UNAME_IS_OPENBSD,
{"name": "get_sysctl_field", "ret": 0, "RET": "Hetzner"},
],
},
"Hetzner-dmidecode": {
"ds": "Hetzner",
"mocks": [{"name": "dmi_decode", "ret": 0, "RET": "Hetzner"}],
Expand Down Expand Up @@ -1766,10 +1779,7 @@ def _print_run_output(rc, out, err, cfg, files):
{
"name": "uname",
"ret": 0,
"out": (
"Linux d43da87a-daca-60e8-e6d4-d2ed372662a3 4.3.0 "
"BrandZ virtual linux x86_64 GNU/Linux"
),
"out": ("Linux BrandZ virtual linux x86_64"),
},
{"name": "blkid", "ret": 2, "out": ""},
],
Expand Down

0 comments on commit 5e9a77d

Please sign in to comment.