Skip to content

Commit 8cb76c6

Browse files
committed
tools/update: use system-serial-number with dmidecode for nested hosts
Sometimes, the command dmidecode with the dmi key `system-uuid` works with unexpected results (bits are shifted). For nested hosts, we need to use dmi key `system-serial-number`. Take a look at #567 (comment) Signed-off-by: Olivier Hoareau <olivier.hoareau@vates.tech>
1 parent f9d4d64 commit 8cb76c6

1 file changed

Lines changed: 10 additions & 12 deletions

File tree

lib/host.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -472,26 +472,24 @@ def pool_has_vm(self, vm_uuid: str, vm_type: str = 'vm') -> bool:
472472
return self.xe('vm-list', {'uuid': vm_uuid}, minimal=True) == vm_uuid
473473

474474
def get_system_uuid(self) -> str:
475-
"""Return system uuid of current host.
475+
"""Get system uuid of current host.
476476
477-
Intended for driving current host from its "parent host" in a **nested context**.
477+
In case host is nested, it uses `system-serial-number` instead of `system-uuid`.
478478
479-
.. note::
480-
If the current host is nested, it means it is not a physical host. It is a VM living inside a real host.::
481-
482-
[PH: Physical Host] -> [VM: emulation of an XCP-ng host] -> [vm: a vm inside nested host]
483-
| current working host |
484-
485-
So we need system-uuid of current working host (`VM`) which is
486-
the uuid seen in physical host's (`PH`) scope.
479+
If command result is empty or None, it raises an Error.
487480
488481
Performs the following command::
489482
490-
dmidecode -s system-uuid
483+
dmidecode -s [system-uuid|system-serial-number]
491484
492485
ref: `dmidecode(8) <https://man.archlinux.org/man/dmidecode.8.en#s>__`
493486
"""
494-
return self.ssh("dmidecode -s system-uuid").lower().strip()
487+
dmi_key = "system-serial-number" if self.nested else "system-uuid"
488+
system_uuid = self.ssh(f"dmidecode -s {dmi_key}").lower().strip()
489+
if not system_uuid:
490+
raise ValueError(f"The system uuid '{system_uuid}' incorrect.")
491+
492+
return system_uuid
495493

496494
def yum_clean_metadata(self) -> str:
497495
"""Quietly removes cached metadata on target.

0 commit comments

Comments
 (0)