diff --git a/xCAT-test/autotest/testcase/commoncmd/vm_machine_type.sh b/xCAT-test/autotest/testcase/commoncmd/vm_machine_type.sh index 412a16c771..0f5914bdd2 100755 --- a/xCAT-test/autotest/testcase/commoncmd/vm_machine_type.sh +++ b/xCAT-test/autotest/testcase/commoncmd/vm_machine_type.sh @@ -33,17 +33,84 @@ vm_machine_type_private_dir() fi } -vm_machine_type_for_arch() +# alias -- the machine name qemu keeps pointed at the newest machine of a family. +vm_machine_type_alias() { case "$1" in - ppc64*) echo 'machine:pseries-rhel7.6.0' ;; - x86_64) echo 'machine:pc' ;; - riscv64) echo 'machine:virt' ;; - aarch64) echo 'machine:virt' ;; + ppc64*) echo 'pseries' ;; + x86_64) echo 'pc' ;; + riscv64) echo 'virt' ;; + aarch64) echo 'virt' ;; *) return 1 ;; esac } +# libvirt and qemu call the ppc64le guest architecture ppc64. A node on an +# Ubuntu cell names it ppc64el. +vm_machine_type_libvirt_arch() +{ + case "$1" in + ppc64*) echo 'ppc64' ;; + x86_64) echo 'x86_64' ;; + riscv64) echo 'riscv64' ;; + aarch64) echo 'aarch64' ;; + *) return 1 ;; + esac +} + +# virsh on , or here when is empty. kvm.pm reaches the vmhost over +# qemu+ssh://root@/system, so root can ssh there from this node. +vm_machine_type_virsh() +{ + local host="$1" + shift + if [ -n "$host" ]; then + ssh -o BatchMode=yes -o ConnectTimeout=10 -n "$host" virsh "$@" + else + virsh "$@" + fi +} + +# supported -- whether libvirt on accepts . +vm_machine_type_supported() +{ + vm_machine_type_virsh "$1" domcapabilities --arch "$2" --machine "$3" >/dev/null 2>&1 +} + +# default -- the machine type libvirt on uses for . +vm_machine_type_default() +{ + vm_machine_type_virsh "$1" domcapabilities --arch "$2" 2>/dev/null | + sed -n 's|.*\(.*\).*|\1|p' | head -n 1 +} + +# for_arch [] -- the machine type to write, as "machine:". +# +# The vmhost is what refuses the domain, so its libvirt picks the name: the plain +# alias when that libvirt accepts it, its own default when it does not, and the +# alias again when the vmhost cannot be asked. A versioned name does not survive +# a host upgrade -- no qemu on AlmaLinux 10 has a pseries-rhel machine type. +vm_machine_type_for_arch() +{ + local arch="$1" vmhost="${2-}" generic libvirt_arch name + + generic="$(vm_machine_type_alias "$arch")" || return 1 + libvirt_arch="$(vm_machine_type_libvirt_arch "$arch")" || return 1 + if vm_machine_type_supported "$vmhost" "$libvirt_arch" "$generic"; then + printf 'machine:%s\n' "$generic" + return + fi + name="$(vm_machine_type_default "$vmhost" "$libvirt_arch")" + printf 'machine:%s\n' "${name:-$generic}" +} + +# vmhost -- the host whose libvirt runs the guest, empty when unset. +vm_machine_type_vmhost() +{ + lsdef "$1" -i vmhost 2>/dev/null | + sed -n 's/^[[:space:]]*vmhost=//p' | head -n 1 +} + vm_machine_type_get() { local out @@ -109,7 +176,7 @@ vm_machine_type_apply() chdef "$node" "vmothersetting=$original" return fi - if ! machine="$(vm_machine_type_for_arch "$arch")"; then + if ! machine="$(vm_machine_type_for_arch "$arch" "$(vm_machine_type_vmhost "$node")")"; then echo "vm_machine_type.sh: no machine type for arch '$arch'" >&2 return 1 fi