Skip to content

Commit cce5411

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 7e50e42 commit cce5411

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
@@ -480,26 +480,24 @@ def pool_has_vm(self, vm_uuid: str, vm_type: str = 'vm') -> bool:
480480
return self.xe('vm-list', {'uuid': vm_uuid}, minimal=True) == vm_uuid
481481

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

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

0 commit comments

Comments
 (0)