Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests/compose: Target FCOS 31, move off of PAPR #1959

Merged
merged 3 commits into from
Jan 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
141 changes: 83 additions & 58 deletions .cci.jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ parallel rpms: {
coreos.pod(image: COSA_BUILDROOT_IMAGE, runAsUser: 0) {
checkout scm
sh """
set -euo pipefail
set -xeuo pipefail
# fetch tags so `git describe` gives a nice NEVRA when building the RPM
git fetch origin --tags
ci/installdeps.sh
Expand All @@ -24,17 +24,18 @@ parallel rpms: {

cd packaging
make -f Makefile.dist-packaging rpm
mv \$(find . -name '*.rpm') ..
"""
// make it easy for anyone to download the RPMs
archiveArtifacts 'packaging/**/*.rpm'
stash includes: 'packaging/**/*.rpm', name: 'rpms'
archiveArtifacts '*.rpm'
stash excludes: '*.src.rpm', includes: '*.rpm', name: 'rpms'
}
},
codestyle: {
coreos.pod(image: COSA_IMAGE) {
checkout scm
sh """
set -euo pipefail
set -xeuo pipefail
# Jenkins by default only fetches the branch it's testing. Explicitly fetch master
# for ci-commitmessage-submodules.sh
git fetch origin +refs/heads/master:refs/remotes/origin/master
Expand All @@ -48,68 +49,92 @@ rust: {
checkout scm

sh """
set -euo pipefail
set -xeuo pipefail
ci/msrv.sh
cd rust && cargo test
"""
}
}}

stage("Build FCOS") {
coreos.pod(image: COSA_IMAGE, runAsUser: 0, kvm: true) {
unstash 'rpms'
sh """
set -euo pipefail

rpms=\$(find packaging/ ! -name '*.src.rpm' -name '*.rpm')

# install our built rpm-ostree
dnf install -y \${rpms}

# and build FCOS with our built rpm-ostree inside of it
coreos-assembler init --force https://github.com/coreos/fedora-coreos-config
mkdir -p overrides/rpm
mv \${rpms} overrides/rpm
rm -rf packaging

coreos-assembler build
"""
stash includes: 'builds/latest/*/*.qcow2', name: 'fcos'
}
}


stage("Run vmcheck") {
def nhosts = 6
def mem = (nhosts * 1024) + 512
coreos.pod(image: COSA_IMAGE, runAsUser: 0, kvm: true, memory: "${mem}Mi", cpu: "${nhosts}") {
checkout scm
unstash 'rpms'
sh """
set -euo pipefail
ci/installdeps.sh # really, we just need test deps, but meh...

# install our built rpm-ostree
find packaging/ ! -name '*.src.rpm' -name '*.rpm' | xargs dnf install -y
rm -rf packaging
"""
unstash 'fcos'
try {
timeout(time: 30, unit: 'MINUTES') {
stage("Test") {
parallel vmcheck: {
def nhosts = 6
def mem = (nhosts * 1024) + 512
coreos.pod(image: COSA_IMAGE, runAsUser: 0, kvm: true, memory: "${mem}Mi", cpu: "${nhosts}") {
stage("Build FCOS") {
checkout scm
unstash 'rpms'
// run this stage first without installing deps, so we match exactly the cosa pkgset
// (+ our built rpm-ostree)
sh """
set -xeuo pipefail
dnf install -y *.rpm
coreos-assembler init --force https://github.com/coreos/fedora-coreos-config
# include our built rpm-ostree in the image
mkdir -p overrides/rpm
mv *.rpm overrides/rpm
coreos-assembler build
"""
}
stage("Install Deps") {
sh """
set -xeuo pipefail
ci/installdeps.sh # really, we just need test deps, but meh...
"""
}
stage("Run") {
try {
timeout(time: 30, unit: 'MINUTES') {
sh """
set -xeuo pipefail
fcos=\$(ls builds/latest/*/*.qcow2) # */
ln -sf "\$(realpath \${fcos})" tests/vmcheck/image.qcow2
JOBS=${nhosts} tests/vmcheck.sh
"""
}
} finally {
sh """
set -xeuo pipefail
fcos=\$(ls builds/latest/*/*.qcow2) # */
ln -sf "\$(realpath \${fcos})" tests/vmcheck/image.qcow2
NHOSTS=${nhosts} tests/vmcheck.sh
if [ -d vmcheck-logs ]; then
tar -C vmcheck-logs -cf- . | xz -c9 > vmcheck-logs.tar.xz
fi
"""
archiveArtifacts allowEmptyArchive: true, artifacts: 'vmcheck-logs.tar.xz'
}
} finally {
sh """
if [ -d vmcheck-logs ]; then
tar -C vmcheck-logs -cf- . | xz -c9 > vmcheck-logs.tar.xz
fi
"""
archiveArtifacts allowEmptyArchive: true, artifacts: 'vmcheck-logs.tar.xz'
}
}
}
}
},
compose: {
def jobs = 5
def mem = (jobs * 2048) + 512
coreos.pod(image: COSA_IMAGE, runAsUser: 0, emptyDirs: ["/srv/tmpdir"], kvm: true, memory: "${mem}Mi", cpu: "${jobs}") {
checkout scm
unstash 'rpms'
stage("Install Deps") {
sh """
set -xeuo pipefail
ci/installdeps.sh # really, we just need test deps, but meh...
dnf install -y *.rpm # install our built rpm-ostree
"""
}
stage("Run") {
try {
timeout(time: 40, unit: 'MINUTES') {
sh """
set -xeuo pipefail
mkdir compose-logs
TMPDIR=/srv/tmpdir JOBS=${jobs} ./tests/compose.sh
"""
}
} finally {
sh """
set -xeuo pipefail
if [ -d compose-logs ]; then
tar -C compose-logs -cf- . | xz -c9 > compose-logs.tar.xz
fi
"""
archiveArtifacts allowEmptyArchive: true, artifacts: 'compose-logs.tar.xz'
}
}
}
}}
46 changes: 0 additions & 46 deletions .papr.yml

This file was deleted.

48 changes: 48 additions & 0 deletions tests/common/libtest-core.sh
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,51 @@ skip() {
echo "1..0 # SKIP" "$@"
exit 0
}

# https://github.com/coreos/coreos-assembler/pull/632. Ideally, we'd also cap
# based on memory available to us, but that's notoriously difficult to do for
# containers (see:
# https://fabiokung.com/2014/03/13/memory-inside-linux-containers/). We make an
# assumption here that we have at least e.g. 1G of RAM we can use per CPU
# available to us.
ncpus() {
if ! grep -q kubepods /proc/1/cgroup; then
# this might be a developer laptop; leave one cpu free to be nice
echo $(($(nproc) - 1))
return 0
fi

quota=$(cat /sys/fs/cgroup/cpu/cpu.cfs_quota_us)
period=$(cat /sys/fs/cgroup/cpu/cpu.cfs_period_us)
if [[ ${quota} != -1 ]] && [[ ${period} -gt 0 ]]; then
echo $(("${quota}" / "${period}"))
fi

# just fallback to 1
echo 1
}

filter_tests() {
local tests_dir=$1; shift
local skipped=0

local selected_tests=()
for tf in $(find "${tests_dir}" -name 'test-*.sh' | shuf); do
tfbn=$(basename "$tf" .sh)
tfbn=" ${tfbn#test-} "
if [ -n "${TESTS+ }" ]; then
if [[ " $TESTS " != *$tfbn* ]]; then
skipped=$((skipped + 1))
continue
fi
fi

selected_tests+=("${tfbn}")
done

if [ ${skipped} -gt 0 ]; then
echo "Skipping ${skipped} tests" >&2
fi

echo "${selected_tests[*]}"
}
31 changes: 29 additions & 2 deletions tests/common/libtest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,14 @@ _cleanup_tmpdir () {

# Create a tmpdir if we're running as a local test (i.e. through `make check`)
# or as a `vmcheck` test, which also needs some scratch space on the host.
if ( test -n "${UNINSTALLEDTESTS:-}" || test -n "${VMTESTS:-}" ) && ! test -f $PWD/.test; then
if { test -n "${UNINSTALLEDTESTS:-}" || \
test -n "${VMTESTS:-}" || \
test -n "${COMPOSETESTS:-}"; } && ! test -f "$PWD/.test"; then
# Use --tmpdir to keep it in /tmp. This also keeps paths short; this is
# important if we want to create UNIX sockets under there.
test_tmpdir=$(mktemp -d test.XXXXXX --tmpdir)
touch ${test_tmpdir}/.test
trap _cleanup_tmpdir EXIT
trap _cleanup_tmpdir EXIT SIGINT
cd ${test_tmpdir}
fi
if test -n "${UNINSTALLEDTESTS:-}"; then
Expand Down Expand Up @@ -404,6 +406,8 @@ EOF
case $section in
requires)
echo "Requires: $arg" >> $spec;;
recommends)
echo "Recommends: $arg" >> $spec;;
provides)
echo "Provides: $arg" >> $spec;;
conflicts)
Expand Down Expand Up @@ -577,3 +581,26 @@ assert_jq() {
fi
done
}

# This function below was taken and adapted from coreos-assembler. We
# should look into sharing this code more easily.

# Determine if current user has enough privileges for composes
_privileged=
has_compose_privileges() {
if [ -z "${_privileged:-}" ]; then
if [ -n "${FORCE_UNPRIVILEGED:-}" ]; then
echo "Detected FORCE_UNPRIVILEGED; using virt"
_privileged=0
elif ! capsh --print | grep -q 'Bounding.*cap_sys_admin'; then
echo "Missing CAP_SYS_ADMIN; using virt"
_privileged=0
elif [ "$(id -u)" != "0" ]; then
echo "Not running as root; using virt"
_privileged=0
else
_privileged=1
fi
fi
[ ${_privileged} == 1 ]
}