Merge pull request #922 from sm00th/intupd

Scripts for running integration tests within vagrant vms
This commit is contained in:
Joe Lawrence 2018-11-14 11:14:17 -05:00 committed by GitHub
commit be6d20aba5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 432 additions and 0 deletions

View File

@ -7,10 +7,14 @@ UNINSTALL_DIRS = $(SUBDIRS:%=uninstall-%)
CLEAN_DIRS = $(SUBDIRS:%=clean-%)
UNITTEST_DIR = test/unit
INTEGRATION_DIR = test/integration
CLEAN_DIRS += clean-$(UNITTEST_DIR)
.PHONY: all install uninstall clean check unit
.PHONY: $(SUBDIRS) $(BUILD_DIRS) $(INSTALL_DIRS) $(CLEAN_DIRS)
.PHONY: integration integration-slow integration-quick
.PHONY: vagrant-integration-slow vagrant-integration-quick vagrant-integration
.PHONY: vagrant-install
all: $(BUILD_DIRS)
@ -32,5 +36,30 @@ $(CLEAN_DIRS):
unit: $(UNITTEST_DIR)/Makefile build-kpatch-build
$(MAKE) -C $(UNITTEST_DIR)
integration: integration-quick
integration-slow: $(INTEGRATION_DIR)/Makefile build-kpatch-build build-kpatch build-kmod
$(MAKE) -C $(INTEGRATION_DIR) slow
integration-quick: $(INTEGRATION_DIR)/Makefile build-kpatch-build build-kpatch build-kmod
$(MAKE) -C $(INTEGRATION_DIR) quick
vagrant-install: $(INTEGRATION_DIR)/lib.sh
ifneq ($(shell id -u), 0)
@echo "WARNING: This target is intended for use on freshly-installed machines/vms only." && \
echo "Do not proceed unless you read $(INTEGRATION_DIR)/lib.sh and realise what this target does." && \
echo "Press ctrl-c to abort, return to proceed." && \
read
endif
source $(INTEGRATION_DIR)/lib.sh && kpatch_check_install_vagrant
vagrant-integration: vagrant-integration-quick
vagrant-integration-slow:
$(MAKE) -C $(INTEGRATION_DIR) vagrant-slow
vagrant-integration-quick:
$(MAKE) -C $(INTEGRATION_DIR) vagrant-quick
check:
shellcheck kpatch/kpatch kpatch-build/kpatch-build kpatch-build/kpatch-gcc

View File

@ -18,6 +18,14 @@ quick: clean
cached:
./kpatch-test -d $(PATCH_DIR) --cached $(PATCHES)
vagrant: vagrant_quick
vagrant-quick:
./test-vagrant
vagrant-slow:
./test-vagrant --slow
clean:
rm -f *.ko *.log COMBINED.patch

301
test/integration/lib.sh Normal file
View File

@ -0,0 +1,301 @@
#!/bin/bash
kpatch_set_ccache_max_size()
{
local ccache_max_size=${1:-10G}
ccache --max-size="${ccache_max_size}"
}
kpatch_fedora_dependencies()
{
local kernel_version
kernel_version=$(uname -r)
sudo dnf install -y gcc "kernel-devel-${kernel_version%.*}" elfutils elfutils-devel
sudo dnf install -y pesign yum-utils openssl wget numactl-devel
sudo dnf builddep -y "kernel-${kernel_version%.*}"
sudo dnf debuginfo-install -y "kernel-${kernel_version%.*}"
sudo dnf install -y ccache
}
kpatch_ubuntu_dependencies()
{
sudo sed -i 's/# deb-src/deb-src/' /etc/apt/sources.list
sudo apt-get update
sudo apt-get install -y make gcc libelf-dev elfutils
sudo apt-get install -y dpkg-dev devscripts
sudo apt-get build-dep -y linux
sudo apt-get install -y ccache
# Add ddebs repository
if ! grep -q 'ddebs.ubuntu.com' /etc/apt/sources.list.d/ddebs.list; then
local codename
codename=$(lsb_release -sc)
sudo tee /etc/apt/sources.list.d/ddebs.list <<-EOF
deb http://ddebs.ubuntu.com/ ${codename} main restricted universe multiverse
deb http://ddebs.ubuntu.com/ ${codename}-security main restricted universe multiverse
deb http://ddebs.ubuntu.com/ ${codename}-updates main restricted universe multiverse
deb http://ddebs.ubuntu.com/ ${codename}-proposed main restricted universe multiverse
EOF
# add APT key
wget -Nq http://ddebs.ubuntu.com/dbgsym-release-key.asc -O- | sudo apt-key add -
sudo apt-get update
fi
sudo apt-get install -y "linux-image-$(uname -r)-dbgsym"
}
kpatch_rhel_dependencies()
{
local kernel_version
local arch
kernel_version=$(uname -r)
arch=$(uname -m)
sudo yum install -y git gcc gcc-c++ "kernel-devel-${kernel_version%.*}" elfutils elfutils-devel
sudo yum install -y yum-utils zlib-devel binutils-devel newt-devel \
python-devel perl-ExtUtils-Embed audit-libs-devel numactl-devel \
pciutils-devel bison ncurses-devel rpm-build java-devel
sudo yum-builddep -y "kernel-${kernel_version%.*}"
sudo debuginfo-install -y "kernel-${kernel_version%.*}"
[ "${arch}" == "x86_64" ] && sudo yum install -y pesign
[ "${arch}" == "ppc64le" ] && sudo yum install -y gcc-plugin-devel
sudo yum install -y "https://dl.fedoraproject.org/pub/epel/7/${arch}/Packages/c/ccache-3.3.4-1.el7.${arch}.rpm"
}
kpatch_centos_dependencies()
{
local kernel_version
kernel_version=$(uname -r)
sudo yum install -y gcc gcc-c++ "kernel-devel-${kernel_version%.*}" elfutils elfutils-devel
sudo yum install -y yum-utils zlib-devel binutils-devel newt-devel \
python-devel perl-ExtUtils-Embed audit-libs-devel numactl-devel \
pciutils-devel bison ncurses-devel rpm-build java-devel pesign
sudo yum-config-manager --enable debug
sudo yum-builddep -y "kernel-${kernel_version%.*}"
sudo debuginfo-install -y "kernel-${kernel_version%.*}"
sudo yum install -y ccache
}
kpatch_dependencies()
{
# shellcheck disable=SC1091
source /etc/os-release
eval "kpatch_${ID}_dependencies" || { echo "Unsupported distro: ${ID}"; exit 1; }
}
kpatch_separate_partition_cache()
{
local partition=${1}
local mountpoint=${2}
local reformat=${3}
local owner=${USER}
if [[ "${reformat}" == "y" ]]; then
sudo mkfs.xfs -f "${partition}"
fi
sudo mkdir -p "${mountpoint}"
sudo mount "${partition}" "${mountpoint}"
sudo chown "${owner}":"${owner}" "${mountpoint}"
rm -rf "${mountpoint}/.ccache"
rm -rf "${mountpoint}/.kpatch"
mkdir "${mountpoint}/.ccache"
mkdir "${mountpoint}/.kpatch"
rm -rf "${HOME}/.ccache"
rm -rf "${HOME}/.kpatch"
ln -sv "${mountpoint}/.ccache" "${HOME}/.ccache"
ln -sv "${mountpoint}/.kpatch" "${HOME}/.kpatch"
}
kpatch_separate_disk_cache()
{
local device=${1}
local mountpoint=${2}
local partition="${device}1"
echo -e "o\\nn\\np\\n1\\n\\n\\nw\\n" | sudo fdisk "${device}"
kpatch_separate_partition_cache "${partition}" "${mountpoint}" y
}
kpatch_install_vagrant_centos()
{
local image_path=${1}
sudo yum group install -y "Development Tools"
sudo yum -y install qemu-kvm libvirt virt-install bridge-utils libvirt-devel libxslt-devel libxml2-devel libvirt-devel libguestfs-tools-c libvirt-client
echo "net.ipv4.ip_forward = 1" | sudo tee /etc/sysctl.d/99-ipforward.conf
sudo sysctl -p /etc/sysctl.d/99-ipforward.conf
sudo systemctl enable libvirtd
sudo systemctl start libvirtd || exit 1
if [[ -n "${image_path}" ]]; then
mkdir -p "${image_path}/libvirt/images"
virsh pool-define-as --target "${image_path}/libvirt/images" default dir || exit 1
virsh pool-start default || exit 1
fi
sudo yum install -y https://releases.hashicorp.com/vagrant/2.1.2/vagrant_2.1.2_x86_64.rpm || exit 1
vagrant plugin install vagrant-libvirt
}
kpatch_install_vagrant_rhel()
{
local image_path=${1}
kpatch_install_vagrant_centos "${image_path}"
sudo systemctl enable nfs
sudo systemctl start nfs || exit 1
}
kpatch_install_vagrant_fedora()
{
local image_path=${1}
echo "net.ipv4.ip_forward = 1" | sudo tee /etc/sysctl.d/99-ipforward.conf
sudo sysctl -p /etc/sysctl.d/99-ipforward.conf
sudo dnf install -y libvirt virt-install libvirt-client nfs-utils vagrant vagrant-libvirt
echo "[nfsd]" | sudo tee -a /etc/nfs.conf
echo "udp=y" | sudo tee -a /etc/nfs.conf
echo "vers3=y" | sudo tee -a /etc/nfs.conf
sudo systemctl restart nfs
sudo systemctl enable libvirtd
sudo systemctl start libvirtd || exit 1
if [[ -n "${image_path}" ]]; then
mkdir -p "${image_path}/libvirt/images"
virsh pool-define-as --target "${image_path}/libvirt/images" default dir || exit 1
virsh pool-start default || exit 1
fi
}
kpatch_install_vagrant()
{
local image_path=${1}
# shellcheck disable=SC1091
source /etc/os-release
eval "kpatch_install_vagrant_${ID} ${image_path}" || { echo "Unsupported distro: ${ID}"; exit 1; }
}
kpatch_check_install_vagrant()
{
local image_path=${1}
[ "$(which vagrant)" == "" ] && kpatch_install_vagrant "${image_path}"
return 0
}
kpatch_write_vagrantfile_template()
{
local target_distro=${1}
local box_prefix="kpatch"
if [ "${target_distro}" == "centos7" ]; then
box_prefix="generic"
fi
cat >Vagrantfile <<EOF
Vagrant.configure("2") do |config|
config.vm.provider :libvirt do |libvirt|
libvirt.storage :file, :size => '40G'
libvirt.cpus = $(getconf _NPROCESSORS_ONLN)
libvirt.memory = $(awk '/MemTotal/ {printf("%d\n", ($2*0.8)/1024)}' /proc/meminfo)
libvirt.graphics_type = "none"
libvirt.disk_bus = 'virtio'
libvirt.disk_device = 'vda'
end
config.vm.box = "${box_prefix}/${target_distro}"
config.vm.synced_folder ".", "/vagrant", type: "nfs"
EOF
}
kpatch_write_vagrantfile_centos_provision()
{
cat >>Vagrantfile <<EOF
config.vm.provision "shell", inline: "yum install -y git"
EOF
}
kpatch_write_vagrantfile()
{
local target_distro=${1}
kpatch_write_vagrantfile_template "${target_distro}"
if echo "${target_distro}" | grep -qE "^centos"; then
kpatch_write_vagrantfile_centos_provision
fi
echo 'end' >>Vagrantfile
}
kpatch_integration_tests_vagrant_distro()
{
local target_distro=${1}
local test_script=${2}
local slowtest=${3}
local testdir
local workdir
local logdir
testdir="$(pwd)"
workdir="${target_distro}.vagrant"
rm -rf "${workdir}"
mkdir -p "${workdir}"
cd "${workdir}" || exit 1
kpatch_write_vagrantfile "${target_distro}"
vagrant up || { vagrant destroy -f; exit 1; }
local test_cmd="bash /vagrant/runtest.sh"
if [ "${slowtest}" == "1" ]; then
test_cmd="${test_cmd} --slow"
fi
cp "${test_script}" ./runtest.sh
vagrant ssh -c "${test_cmd}"
local rc=$?
if [ $rc -eq 0 ]; then
echo "${target_distro} PASS"
else
echo "${target_distro} FAIL"
fi
logdir="${testdir}/${target_distro}_log"
rm -rf "${logdir}"
mkdir -p "${logdir}"
cp logs/* "${logdir}"
vagrant destroy -f
cd "${testdir}" || exit 1
if [ $rc -eq 0 ]; then
rm -rf "${workdir}"
fi
return "${rc}"
}

42
test/integration/test-vagrant Executable file
View File

@ -0,0 +1,42 @@
#!/bin/bash
SCRIPTDIR=$(readlink -f "$(dirname "$(type -p "${0}")")")
ROOTDIR=$(readlink -f "${SCRIPTDIR}/../..")
SLOWTEST=0
# shellcheck disable=SC1090
source "${ROOTDIR}/test/integration/lib.sh"
usage()
{
echo "usage: $(basename "${0}") [options]" >&2
echo "-h, --help This message" >&2
echo "-s, --slow Run all of the tests" >&2
}
options="$(getopt -o hs -l "help,slow" -- "$@")" || "getopt failed"
eval set -- "${options}"
while [[ $# -gt 0 ]]; do
case "$1" in
-s|--slow)
SLOWTEST=1
;;
-h|--help)
usage
exit 0
;;
esac
shift
done
declare -a distros=("fedora27" "ubuntu1604" "centos7")
ret=0
for distro in "${distros[@]}"; do
kpatch_integration_tests_vagrant_distro "${distro}" "${ROOTDIR}/test/integration/vm-integration-run" "${SLOWTEST}"
rc=$?
ret=$((ret + rc))
done
exit ${ret}

View File

@ -0,0 +1,52 @@
#!/bin/bash
KPATCH_SLOW=0
LOGDIR="/vagrant/logs"
usage()
{
echo "usage: $(basename "${0}") [options]" >&2
echo "-h, --help This message" >&2
echo "-s, --slow Run all of the tests" >&2
}
options="$(getopt -o s -l "slow" -- "$@")" || "getopt failed"
eval set -- "${options}"
while [[ $# -gt 0 ]]; do
case "$1" in
-s|--slow)
KPATCH_SLOW=1
;;
-h|--help)
usage
exit 0
;;
esac
shift
done
git clone https://github.com/dynup/kpatch.git || exit 1
cd kpatch || exit 1
# shellcheck disable=SC1091
source test/integration/lib.sh
kpatch_dependencies
kpatch_separate_disk_cache /dev/vdb /mnt/build
kpatch_set_ccache_max_size 10G
if [ ${KPATCH_SLOW} -eq 1 ]; then
make integration-slow 2>&1
else
make integration-quick 2>&1
fi
rc=${PIPESTATUS[0]}
rm -rf "${LOGDIR}"
mkdir -p "${LOGDIR}"
cp ./test/integration/*.log "${LOGDIR}"
exit "${rc}"