Skip to content

Commit 1143e0b

Browse files
authored
Merge pull request #576 from xcp-ng/ohu/01/fix-dmidecode-system-uuid
tools/update: fix use of dmidecode in context of nested hosts
2 parents 61239d9 + 6baaf55 commit 1143e0b

2 files changed

Lines changed: 13 additions & 15 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.

lib/tools/tasks/update.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,10 @@ def update_pools(inventory: Inventory) -> None:
3636
pools.append(p)
3737
hosting_pool = inventory_hosts[host]["hosting_pool"]
3838
if hosting_pool is not None:
39-
# we assume all hosts are nested, not only master
4039
if nested_hosts.get(hosting_pool) is not None:
41-
nested_hosts[hosting_pool].extend(p.hosts)
40+
nested_hosts[hosting_pool].extend([h for h in p.hosts if h.is_nested])
4241
else:
43-
nested_hosts[hosting_pool] = p.hosts
42+
nested_hosts[hosting_pool] = [h for h in p.hosts if h.is_nested]
4443
except NotAMasterHostError:
4544
logger.warning(f"[{host}] Skipping: not a master host")
4645

0 commit comments

Comments
 (0)