Skip to content

Commit 6baaf55

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 3c9632b commit 6baaf55

1 file changed

Lines changed: 11 additions & 12 deletions

File tree

lib/host.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -481,26 +481,25 @@ def pool_has_vm(self, vm_uuid: str, vm_type: str = 'vm') -> bool:
481481
return self.xe('vm-list', {'uuid': vm_uuid}, minimal=True) == vm_uuid
482482

483483
def get_system_uuid(self) -> str:
484-
"""Return system uuid of current host.
484+
"""Get system uuid of current host.
485485
486-
Intended for driving current host from its "parent host" in a **nested context**.
486+
In case host is nested, it uses `system-serial-number` instead of `system-uuid`.
487487
488-
.. note::
489-
If the current host is nested, it means it is not a physical host. It is a VM living inside a real host.::
490-
491-
[PH: Physical Host] -> [VM: emulation of an XCP-ng host] -> [vm: a vm inside nested host]
492-
| current working host |
493-
494-
So we need system-uuid of current working host (`VM`) which is
495-
the uuid seen in physical host's (`PH`) scope.
488+
If command result is empty or None, it raises an Error.
496489
497490
Performs the following command::
498491
499-
dmidecode -s system-uuid
492+
dmidecode -s [system-uuid|system-serial-number]
500493
501494
ref: `dmidecode(8) <https://man.archlinux.org/man/dmidecode.8.en#s>__`
502495
"""
503-
return self.ssh("dmidecode -s system-uuid").lower().strip()
496+
# TODO: This workaround is tracked in XCPNG-2775
497+
dmi_key = "system-serial-number" if self.is_nested else "system-uuid"
498+
system_uuid = self.ssh(f"dmidecode -s {dmi_key}").lower().strip()
499+
if not system_uuid:
500+
raise ValueError(f"The system uuid '{system_uuid}' is incorrect.")
501+
502+
return system_uuid
504503

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

0 commit comments

Comments
 (0)