Only the files libvirt actually parses are copied over, to avoid needlessly increasing the size of the repository and causing dist issues (eg. symlinks loops). --- tests/nodeinfodata/copy-from-host.sh | 113 +++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100755 tests/nodeinfodata/copy-from-host.sh diff --git a/tests/nodeinfodata/copy-from-host.sh b/tests/nodeinfodata/copy-from-host.sh new file mode 100755 index 0000000..ed37865 --- /dev/null +++ b/tests/nodeinfodata/copy-from-host.sh @@ -0,0 +1,113 @@ +#!/bin/bash + +# copy-from-host.sh - Copy nodeinfo test data from a running host +# Copyright (C) 2015 Red Hat, Inc. +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library 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 +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library. If not, see +# <http://www.gnu.org/licenses/>. +# +# Author: Andrea Bolognani <abologna@xxxxxxxxxx> + +SYSFS_PATH="/sys/devices/system" +NODE_TOPLEVEL_COPY="online possible" +NODE_COPY="cpu[0-9]* cpulist cpumap meminfo" +CPU_TOPLEVEL_COPY="kernel_max offline online possible present" +CPU_COPY="online topology" + +die() { + local message=$1 + + echo "$message" >&2 + + exit 1 +} + +create() { + local directory=$1 + + if ! mkdir -p "$directory" >/dev/null 2>&1; then + die "$directory: Unable to create directory" + fi +} + +copy() { + local pattern=$1 + local from=$2 + local to=$3 + + local item + + echo " $to/$pattern" + + for item in "$from/"$pattern; do + # Some files, like cpu/cpu0/online on Intel systems or cpu/present on + # older kernels, just don't exist. Skip them without making a fuss + if ! test -e "$item"; then + continue + fi + if ! cp -r "$item" "$to" >/dev/null 2>&1; then + die "$item: Unable to copy item" + fi + done +} + +main() { + local name=$1 + + if test "$#" -lt 1; then + die "Usage: $SELF NAME" + fi + + # Create destination directories + if test -e "$name"; then + die "$name: File or directory already exists" + fi + for directory in "$name" "$name/node" "$name/cpu"; do + create "$directory" + done + + # Copy host files + echo "Global node information..." + for pattern in $NODE_TOPLEVEL_COPY; do + copy "$pattern" "$SYSFS_PATH/node" "$name/node" + done + echo "Per-node information..." + for node in "$SYSFS_PATH/node/node"[0-9]*; do + node=${node##*/} + create "$name/node/$node" + for pattern in $NODE_COPY; do + copy "$pattern" "$SYSFS_PATH/node/$node" "$name/node/$node" + done + done + echo "Global CPU information..." + for pattern in $CPU_TOPLEVEL_COPY; do + copy "$pattern" "$SYSFS_PATH/cpu" "$name/cpu" + done + echo "Per-CPU information..." + for cpu in "$SYSFS_PATH/cpu/cpu"[0-9]*; do + cpu=${cpu##*/} + create "$name/cpu/$cpu" + for pattern in $CPU_COPY; do + copy "$pattern" "$SYSFS_PATH/cpu/$cpu" "$name/cpu/$cpu" + done + done + + echo "All done" + + return 0 +} + +SELF=$0 +main "$@" +exit $? -- 2.4.3 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list