diff --git a/tests/unittests/test_ds_identify.py b/tests/unittests/test_ds_identify.py index 63c58b680d1..f31edeeda15 100644 --- a/tests/unittests/test_ds_identify.py +++ b/tests/unittests/test_ds_identify.py @@ -95,6 +95,10 @@ } MOCK_NOT_LXD_DATASOURCE = {"name": "dscheck_LXD", "ret": 1} MOCK_VIRT_IS_KVM = {"name": "detect_virt", "RET": "kvm", "ret": 0} +# qemu support for LXD is only for host systems > 5.10 kernel as lxd +# passed `hv_passthrough` which causes systemd < v.251 to misinterpret CPU +# as "qemu" instead of "kvm" +MOCK_VIRT_IS_KVM_QEMU = {"name": "detect_virt", "RET": "qemu", "ret": 0} MOCK_VIRT_IS_VMWARE = {"name": "detect_virt", "RET": "vmware", "ret": 0} # currenty' SmartOS hypervisor "bhyve" is unknown by systemd-detect-virt. MOCK_VIRT_IS_VM_OTHER = {"name": "detect_virt", "RET": "vm-other", "ret": 0} @@ -338,6 +342,20 @@ def test_lxd_kvm(self): """LXD KVM has race on absent /dev/lxd/socket. Use DMI board_name.""" self._test_ds_found("LXD-kvm") + def test_lxd_kvm_jammy(self): + """LXD KVM on host systems with a kernel > 5.10 need to match "qemu". + LXD provides `hv_passthrough` when launching kvm instances when host + kernel is > 5.10. This results in systemd being unable to detect the + virtualized CPUID="Linux KVM Hv" as type "kvm" and results in + systemd-detect-virt returning "qemu" in this case. + + Assert ds-identify can match systemd-detect-virt="qemu" and + /sys/class/dmi/id/board_name = LXD. + Once systemd 251 is available on a target distro, the virtualized + CPUID will be represented properly as "kvm" + """ + self._test_ds_found("LXD-kvm-qemu-kernel-gt-5.10") + def test_lxd_containers(self): """LXD containers will have /dev/lxd/socket at generator time.""" self._test_ds_found("LXD") @@ -1031,6 +1049,13 @@ def _print_run_output(rc, out, err, cfg, files): "mocks": [{"name": "is_socket_file", "ret": 1}, MOCK_VIRT_IS_KVM], "no_mocks": ["dscheck_LXD"], # Don't default mock dscheck_LXD }, + "LXD-kvm-qemu-kernel-gt-5.10": { # LXD host > 5.10 kvm launch virt==qemu + "ds": "LXD", + "files": {P_BOARD_NAME: "LXD\n"}, + # /dev/lxd/sock does not exist and KVM virt-type + "mocks": [{"name": "is_socket_file", "ret": 1}, MOCK_VIRT_IS_KVM_QEMU], + "no_mocks": ["dscheck_LXD"], # Don't default mock dscheck_LXD + }, "LXD": { "ds": "LXD", # /dev/lxd/sock exists diff --git a/tools/ds-identify b/tools/ds-identify index 26974a87ea7..711cb36a43a 100755 --- a/tools/ds-identify +++ b/tools/ds-identify @@ -823,7 +823,11 @@ dscheck_LXD() { # On LXD KVM instances, /dev/lxd/sock is not yet setup by # lxd-agent-loader's systemd lxd-agent.service. # Rely on DMI product information that is present on all LXD images. - if [ "${DI_VIRT}" = "kvm" ]; then + # Note "qemu" is returned on kvm instances launched from a host kernel + # kernels >=5.10, due to `hv_passthrough` option. + # systemd v. 251 should properly return "kvm" in this scenario + # https://github.com/systemd/systemd/issues/22709 + if [ "${DI_VIRT}" = "kvm" -o "${DI_VIRT}" = "qemu" ]; then [ "${DI_DMI_BOARD_NAME}" = "LXD" ] && return ${DS_FOUND} fi return ${DS_NOT_FOUND}