mirror of
https://github.com/vagrant-libvirt/vagrant-libvirt.git
synced 2025-02-25 18:55:27 -06:00
Use Github actions for integration tests against Vagrant-libvirt (#1091)
Allows to spin up vagrant boxes via vagrant-libvirt in CI replacing the need for vagrant-libvirt-qa to be executed separately before/after releases. * Adds a github integration tests workflow * Installs the needed toolset in separate groups for easier tracking * Add Vagrantfile definitions for the first simple test cases in tests/ using tinycore linux, using the installed master version these boxes are spun up and destroyed via a test matrix. Should help reduce effort for new maintainers to help with #1069
This commit is contained in:
committed by
GitHub
parent
4548e19be9
commit
97ea81d2be
101
.github/workflows/integration-tests.yml
vendored
Normal file
101
.github/workflows/integration-tests.yml
vendored
Normal file
@@ -0,0 +1,101 @@
|
||||
name: Integration Tests
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
test:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
test_name:
|
||||
- destroy simple vm
|
||||
- simple vm provision via shell
|
||||
- bring up with custom default prefix
|
||||
- bring up with second disk
|
||||
- bring up with adjusted memory settings
|
||||
- bring up with adjusted cpu settings
|
||||
- ip is reachable with private network
|
||||
|
||||
env:
|
||||
NOKOGIRI_USE_SYSTEM_LIBRARIES: true
|
||||
VAGRANT_VERSION: v2.2.14
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Set up libvirt
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y \
|
||||
bridge-utils \
|
||||
dnsmasq-base \
|
||||
ebtables \
|
||||
libvirt-clients \
|
||||
libvirt-daemon \
|
||||
libvirt-daemon-system \
|
||||
qemu-kvm \
|
||||
qemu-utils \
|
||||
libarchive-tools \
|
||||
;
|
||||
sudo apt-get install \
|
||||
libvirt-dev \
|
||||
libz-dev \
|
||||
;
|
||||
sudo apt-get install \
|
||||
bats \
|
||||
fping \
|
||||
;
|
||||
|
||||
# start daemon
|
||||
sudo systemctl start libvirtd
|
||||
|
||||
# add user to group
|
||||
sudo usermod -a -G libvirt $USER
|
||||
- uses: actions/cache@v2
|
||||
with:
|
||||
path: vendor/bundle
|
||||
key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-gems-
|
||||
- uses: actions/cache@v2
|
||||
with:
|
||||
path: ~/.vagrant.d/boxes
|
||||
key: ${{ runner.os }}-${{ env.VAGRANT_VERSION }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-
|
||||
- name: Set up Ruby
|
||||
uses: ruby/setup-ruby@v1
|
||||
with:
|
||||
ruby-version: 2.6.6
|
||||
- name: Set up rubygems
|
||||
run: |
|
||||
gem update --system --conservative || (gem i "rubygems-update:~>2.7" --no-document && update_rubygems)
|
||||
gem update bundler --conservative
|
||||
- name: Run bundler using cached path
|
||||
run: |
|
||||
bundle config path vendor/bundle
|
||||
bundle install --jobs 4 --retry 3
|
||||
- name: Install binstubs
|
||||
run: |
|
||||
bundle binstubs --all --path=./bin 1>/dev/null
|
||||
./bin/vagrant --version
|
||||
- name: Run tests
|
||||
run: |
|
||||
mkdir -p $HOME/.vagrant.d/
|
||||
# use software emulation due to lack of nested emulation
|
||||
cat <<EOF > $HOME/.vagrant.d/Vagrantfile
|
||||
Vagrant.configure("2") do |config|
|
||||
config.vm.provider :libvirt do |libvirt|
|
||||
libvirt.driver = "qemu"
|
||||
end
|
||||
end
|
||||
EOF
|
||||
# run under libvirt group
|
||||
sg libvirt -c "bats -f '${{ matrix.test_name }}' ./tests/runtests.bats"
|
||||
env:
|
||||
VAGRANT_HOME: ~/.vagrant.d
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -6,6 +6,7 @@
|
||||
Gemfile.lock
|
||||
InstalledFiles
|
||||
_yardoc
|
||||
bin/
|
||||
coverage
|
||||
doc/
|
||||
lib/bundler/man
|
||||
@@ -16,6 +17,7 @@ test/tmp
|
||||
test/version_tmp
|
||||
tmp
|
||||
Vagrantfile
|
||||
!tests/*/Vagrantfile
|
||||
!example_box/Vagrantfile
|
||||
.vagrant
|
||||
*.swp
|
||||
|
||||
11
tests/cpus/Vagrantfile
vendored
Normal file
11
tests/cpus/Vagrantfile
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
# -*- mode: ruby -*-
|
||||
# vi: set ft=ruby :
|
||||
|
||||
Vagrant.configure("2") do |config|
|
||||
config.vm.box = "infernix/tinycore"
|
||||
config.ssh.shell = "/bin/sh"
|
||||
config.vm.synced_folder ".", "/vagrant", disabled: true
|
||||
config.vm.provider :libvirt do |libvirt|
|
||||
libvirt.cpus = 2
|
||||
end
|
||||
end
|
||||
11
tests/default_prefix/Vagrantfile
vendored
Normal file
11
tests/default_prefix/Vagrantfile
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
# -*- mode: ruby -*-
|
||||
# vi: set ft=ruby :
|
||||
|
||||
Vagrant.configure("2") do |config|
|
||||
config.vm.box = "infernix/tinycore"
|
||||
config.ssh.shell = "/bin/sh"
|
||||
config.vm.synced_folder ".", "/vagrant", disabled: true
|
||||
config.vm.provider :libvirt do |libvirt|
|
||||
libvirt.default_prefix = "changed_default_prefix"
|
||||
end
|
||||
end
|
||||
11
tests/memory/Vagrantfile
vendored
Normal file
11
tests/memory/Vagrantfile
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
# -*- mode: ruby -*-
|
||||
# vi: set ft=ruby :
|
||||
|
||||
Vagrant.configure("2") do |config|
|
||||
config.vm.box = "infernix/tinycore"
|
||||
config.ssh.shell = "/bin/sh"
|
||||
config.vm.synced_folder ".", "/vagrant", disabled: true
|
||||
config.vm.provider :libvirt do |libvirt|
|
||||
libvirt.memory = 1000
|
||||
end
|
||||
end
|
||||
12
tests/private_network/Vagrantfile
vendored
Normal file
12
tests/private_network/Vagrantfile
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
# -*- mode: ruby -*-
|
||||
# vi: set ft=ruby :
|
||||
|
||||
Vagrant.configure("2") do |config|
|
||||
# private network doesnt work with tinycore, use
|
||||
# debian10 box for test
|
||||
config.vm.box = "generic/debian10"
|
||||
config.vm.synced_folder ".", "/vagrant", disabled: true
|
||||
config.vm.define :test_vm1 do |test_vm1|
|
||||
test_vm1.vm.network :private_network, :ip => "10.20.30.40"
|
||||
end
|
||||
end
|
||||
118
tests/runtests.bats
Normal file
118
tests/runtests.bats
Normal file
@@ -0,0 +1,118 @@
|
||||
SCRIPT_DIR="$( cd "$BATS_TEST_DIRNAME" &> /dev/null && pwd )"
|
||||
export PATH=$(dirname ${SCRIPT_DIR})/bin:${PATH}
|
||||
|
||||
VAGRANT_CMD=vagrant
|
||||
VAGRANT_OPT="--provider=libvirt"
|
||||
|
||||
TEMPDIR=
|
||||
|
||||
setup_file() {
|
||||
# set VAGRANT_HOME to something else to reuse for tests to avoid clashes with
|
||||
# user installed plugins when running tests locally.
|
||||
if [ -z "${VAGRANT_HOME:-}" ]
|
||||
then
|
||||
TEMPDIR=$(mktemp -d 2>/dev/null)
|
||||
|
||||
export VAGRANT_HOME=${TEMPDIR}/.vagrant.d
|
||||
echo "# Using ${VAGRANT_HOME} for VAGRANT_HOME" >&3
|
||||
fi
|
||||
}
|
||||
|
||||
teardown_file() {
|
||||
[ -n "${TEMPDIR:-}" ] && [ -d "${TEMPDIR:-}" ] && rm -rf ${TEMPDIR}
|
||||
}
|
||||
|
||||
cleanup() {
|
||||
${VAGRANT_CMD} destroy -f
|
||||
if [ $? == "0" ]; then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
@test "destroy simple vm" {
|
||||
export VAGRANT_LOG=debug
|
||||
export VAGRANT_CWD=tests/simple
|
||||
run ${VAGRANT_CMD} up ${VAGRANT_OPT}
|
||||
echo "${output}"
|
||||
echo "status = ${status}"
|
||||
[ "$status" -eq 0 ]
|
||||
cleanup
|
||||
}
|
||||
|
||||
@test "simple vm provision via shell" {
|
||||
export VAGRANT_CWD=tests/simple_provision_shell
|
||||
cleanup
|
||||
run ${VAGRANT_CMD} up ${VAGRANT_OPT}
|
||||
echo "status = ${status}"
|
||||
echo "${output}"
|
||||
[ "$status" -eq 0 ]
|
||||
[ $(expr "$output" : ".*Hello.*") -ne 0 ]
|
||||
echo "${output}"
|
||||
cleanup
|
||||
}
|
||||
|
||||
@test "bring up with custom default prefix" {
|
||||
export VAGRANT_CWD=tests/default_prefix
|
||||
cleanup
|
||||
run ${VAGRANT_CMD} up ${VAGRANT_OPT}
|
||||
[ "$status" -eq 0 ]
|
||||
echo "${output}"
|
||||
echo "status = ${status}"
|
||||
[ $(expr "$output" : ".*changed_default_prefixdefault.*") -ne 0 ]
|
||||
echo "${output}"
|
||||
cleanup
|
||||
}
|
||||
|
||||
@test "bring up with second disk" {
|
||||
export VAGRANT_CWD=tests/second_disk
|
||||
cleanup
|
||||
run ${VAGRANT_CMD} up ${VAGRANT_OPT}
|
||||
echo "${output}"
|
||||
echo "status = ${status}"
|
||||
[ "$status" -eq 0 ]
|
||||
echo "${output}"
|
||||
[ $(expr "$output" : ".*second_disk_default-vdb.*") -ne 0 ]
|
||||
cleanup
|
||||
}
|
||||
|
||||
@test "bring up with adjusted memory settings" {
|
||||
export VAGRANT_CWD=tests/memory
|
||||
cleanup
|
||||
run ${VAGRANT_CMD} up ${VAGRANT_OPT}
|
||||
echo "${output}"
|
||||
echo "status = ${status}"
|
||||
[ "$status" -eq 0 ]
|
||||
echo "${output}"
|
||||
[ $(expr "$output" : ".*Memory.*1000M.*") -ne 0 ]
|
||||
cleanup
|
||||
}
|
||||
|
||||
@test "bring up with adjusted cpu settings" {
|
||||
export VAGRANT_CWD=tests/cpus
|
||||
cleanup
|
||||
run ${VAGRANT_CMD} up ${VAGRANT_OPT}
|
||||
echo "${output}"
|
||||
echo "status = ${status}"
|
||||
[ "$status" -eq 0 ]
|
||||
echo "${output}"
|
||||
[ $(expr "$output" : ".*Cpus.*2.*") -ne 0 ]
|
||||
cleanup
|
||||
}
|
||||
|
||||
@test "ip is reachable with private network" {
|
||||
export VAGRANT_CWD=tests/private_network
|
||||
cleanup
|
||||
run ${VAGRANT_CMD} up ${VAGRANT_OPT}
|
||||
echo "${output}"
|
||||
echo "status = ${status}"
|
||||
[ "$status" -eq 0 ]
|
||||
echo "${output}"
|
||||
[ $(expr "$output" : ".*Cpus.*2.*") -ne 0 ]
|
||||
run fping 10.20.30.40
|
||||
[ "$status" -eq 0 ]
|
||||
echo "${output}"
|
||||
[ $(expr "$output" : ".*alive.*") -ne 0 ]
|
||||
cleanup
|
||||
}
|
||||
12
tests/second_disk/Vagrantfile
vendored
Normal file
12
tests/second_disk/Vagrantfile
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
# -*- mode: ruby -*-
|
||||
# vi: set ft=ruby :
|
||||
|
||||
Vagrant.configure("2") do |config|
|
||||
config.vm.box = "infernix/tinycore"
|
||||
config.ssh.shell = "/bin/sh"
|
||||
config.vm.synced_folder ".", "/vagrant", disabled: true
|
||||
|
||||
config.vm.provider :libvirt do |libvirt|
|
||||
libvirt.storage :file, :size => '1G'
|
||||
end
|
||||
end
|
||||
8
tests/simple/Vagrantfile
vendored
Normal file
8
tests/simple/Vagrantfile
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
# -*- mode: ruby -*-
|
||||
# vi: set ft=ruby :
|
||||
|
||||
Vagrant.configure("2") do |config|
|
||||
config.vm.box = "infernix/tinycore"
|
||||
config.ssh.shell = "/bin/sh"
|
||||
config.vm.synced_folder ".", "/vagrant", disabled: true
|
||||
end
|
||||
9
tests/simple_provision_shell/Vagrantfile
vendored
Normal file
9
tests/simple_provision_shell/Vagrantfile
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
# -*- mode: ruby -*-
|
||||
# vi: set ft=ruby :
|
||||
|
||||
Vagrant.configure("2") do |config|
|
||||
config.vm.box = "infernix/tinycore"
|
||||
config.ssh.shell = "/bin/sh"
|
||||
config.vm.synced_folder ".", "/vagrant", disabled: true
|
||||
config.vm.provision "shell", inline: "echo Hello, World", privileged: false
|
||||
end
|
||||
Reference in New Issue
Block a user