commit ee4834c6d7200ee23cfc9756bdfd28916b0884c9 Author: Dario Faggioli Date: Thu Oct 30 18:10:21 2014 +0100 Osstest/TestSupport.pm: read hosts' hardware characteristics if defined, in the form of host properties. In standalone mode, that should happen via the config file. Methods are introduced to read those host properties or, if they are not defined, to fetch the information by querying the host directly. The host properties always take precedence. This means that, if they're defined, no command is run on the host, and the values stored in the properties are used. This commit also introduces a simple bash script that, if run on the host, retrieves and prints such host hardware properties, for convenience and/or testing. Signed-off-by: Dario Faggioli Cc: Wei Liu Cc: Ian Campbell Cc: Ian Jackson diff --git a/Osstest/TestSupport.pm b/Osstest/TestSupport.pm index 7cc5be6..251668a 100644 --- a/Osstest/TestSupport.pm +++ b/Osstest/TestSupport.pm @@ -58,7 +58,7 @@ BEGIN { target_put_guest_image target_editfile target_editfile_root target_file_exists target_catfile_stash target_catfile_root_stash - target_run_apt + target_file_contains target_run_apt target_install_packages target_install_packages_norec target_jobdir target_extract_jobdistpath_subdir target_extract_jobdistpath target_guest_lv_name @@ -67,6 +67,7 @@ BEGIN { contents_make_cpio file_simple_write_contents selecthost get_hostflags get_host_property + get_host_cpus get_host_numanodes get_host_memory get_host_native_linux_console power_state power_cycle power_cycle_time serial_fetch_logs @@ -519,6 +520,15 @@ sub target_file_exists ($$) { die "$rfile $out ?"; } +sub target_file_contains ($$$) { + my ($ho,$rfile,$filecont) = @_; + return 0 unless target_file_exists($ho,$rfile); + my $out= target_cmd_output($ho, "grep $filecont $rfile"); + return 1 if ($out ne ""); + return 0 if ($out eq ""); + die "$rfile $filecont $out ?"; +} + sub teditfileex { my $user= shift @_; my $code= pop @_; @@ -866,6 +876,11 @@ sub selecthost ($) { } $ho->{Ip}= $ho->{IpStatic}; + #----- HW specs ----- + $ho->{Cpus} = get_host_property($ho,'cpus'); + $ho->{Memory} = get_host_property($ho,'memory'); + $ho->{Nodes} = get_host_property($ho,'nodes'); + #----- tftp ----- my $tftpscope = get_host_property($ho, 'TftpScope', $c{TftpDefaultScope}); @@ -937,6 +952,66 @@ sub get_host_method_object ($$$) { return $mo; } +sub get_host_cpus ($) { + my ($ho) = @_; + + # Let's first try if there's an host property defined; + # if no, we'll "ask" the host directly. + my $cpus= get_host_property($ho,'cpus',undef); + return $cpus if defined $cpus; + + # Is the host running Dom0 or baremetal? + if (target_file_contains($ho,"/proc/xen/capabilities","control_d")) { + $cpus= target_cmd_output_root($ho, + "xl info | grep ^nr_cpus | awk '{print \$3}'"); + } else { + $cpus= target_cmd_output_root($ho, + "cat /proc/cpuinfo | grep '^processor' | wc -l"); + } + + return $cpus; +} + +sub get_host_numanodes ($) { + my ($ho) = @_; + + # Let's first try if there's an host property defined; + # if no, we'll "ask" the host directly. + my $nodes= get_host_property($ho,'nodes',undef); + return $nodes if defined $nodes; + + # Is the host running Dom0 or baremetal? + if (target_file_contains($ho,"/proc/xen/capabilities","control_d")) { + $nodes= target_cmd_output_root($ho, + "xl info | grep ^nr_nodes | awk '{print \$3}'"); + } else { + $nodes= target_cmd_output_root($ho, + "which numactl && numactl --hardware | grep ^available: | awk '{print \$2}'"); + } + + return $nodes; +} + +sub get_host_memory ($) { + my ($ho) = @_; + + # Let's first try if there's an host property defined; + # if no, we'll "ask" the host directly. + my $mem= get_host_property($ho,'memory',undef); + return $mem if defined $mem; + + # Is the host running Dom0 or baremetal? + if (target_file_contains($ho,"/proc/xen/capabilities","control_d")) { + $mem= target_cmd_output_root($ho, + "xl info | grep ^total_memory | awk '{print \$3}'"); + } else { + $mem= target_cmd_output_root($ho, + "free -m | grep ^Mem: | awk '{print \$2}'"); + } + + return $mem; +} + #---------- stashed files ---------- sub open_unique_stashfile ($) { diff --git a/README b/README index 45d1498..b3880b5 100644 --- a/README +++ b/README @@ -343,6 +343,21 @@ HostProp__TftpScope Defines the Tftp scope (i.e. subnet) where this host resides. See "TftpFoo_ and TftpFoo" below. +HostProp__Cpus + Tells how many physical CPUs the testbox has. If this is defined, + no further investigation is performed to figure out such information + and the value provided here is considered reliable and consumed. + +HostProp__Memory + Tells how much physical memory the testbox has. If this is defined, + no further investigation is performed to figure out such information + and the value provided here is considered reliable and consumed. + +HostProp__Nodes + Tells how many NUMA nodes the testbox has. If this is defined, + no further investigation is performed to figure out such information + and the value provided here is considered reliable and consumed. + HostFlags_ Defines a set of flags for the host. Flags is a list separated by whitespace, comma or semi-colon. A flag can be unset by prepending diff --git a/mg-host-hw-specs b/mg-host-hw-specs new file mode 100755 index 0000000..a47d72d --- /dev/null +++ b/mg-host-hw-specs @@ -0,0 +1,35 @@ +#!/bin/bash +# This is part of "osstest", an automated testing framework for Xen. +# Copyright (C) 2009-2014 Citrix Inc. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +set -e + +# Is the host running Dom0 or baremetal? +if [[ -e /proc/xen/capabilities ]] && \ + [[ `grep ^control_d$ /proc/xen/capabilities` == "control_d" ]]; then + cpus=`xl info | grep ^nr_cpus | awk '{print \$3}'` + memory=`xl info | grep ^total_memory | awk '{print \$3}'` + nodes=`xl info | grep ^nr_nodes | awk '{print \$3}'` +else + cpus=`cat /proc/cpuinfo | grep "^processor" | wc -l` + memory=`free -m | grep ^Mem: | awk '{print $2}'` + nodes="?" + if [[ `which numactl` != "" ]] && [ -x `which numactl` ]; then + nodes=`numactl --hardware | grep ^available: | awk '{print $2}'` + fi +fi + +echo >&2 "cpus=$cpus / memory=$memory / nodes=$nodes"