Skip to content

Commit

Permalink
tests: Add a test to verify the distro matches expectations
Browse files Browse the repository at this point in the history
Verify that the container image has an /etc/os-release that matches what
we would expect for the distro specified when building the image.

Signed-off-by: Randy Witt <randy.e.witt@intel.com>
  • Loading branch information
Randy Witt committed Feb 26, 2020
1 parent 531a5e8 commit b5a1a27
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
54 changes: 54 additions & 0 deletions tests/distro-check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/bash

# distro-check.sh
#
# Copyright (C) 2020 Intel Corporation
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

# Verify that the distro inside the container matches the one we expect based
# on the build

ENGINE_CMD=$1
IMAGE=$2
BASE_DISTRO="$3"

declare -A distros

distros["centos-7"]="CentOS Linux 7 (Core)"
distros["debian-9"]="Debian GNU/Linux 9 (stretch)"
distros["debian-10"]="Debian GNU/Linux 10 (buster)"
distros["fedora-28"]="Fedora 28 (Twenty Eight)"
distros["fedora-29"]="Fedora 29 (Container Image)"
distros["fedora-30"]="Fedora 30 (Container Image)"
distros["opensuse-15.0"]="openSUSE Leap 15.0"
distros["opensuse-15.1"]="openSUSE Leap 15.1"
distros["ubuntu-16.04"]="Ubuntu 16.04"
distros["ubuntu-18.04"]="Ubuntu 18.04"
distros["ubuntu-19.04"]="Ubuntu 19.04"

# If the distro is unknown it is a failure
if [ "${distros[${BASE_DISTRO}]}" = "" ]; then
echo "Unknown distro \"${BASE_DISTRO}\""
exit 1
fi

${ENGINE_CMD} run --rm -t $IMAGE grep "${distros[${BASE_DISTRO}]}" /etc/os-release &> /dev/null
RET=$?
if [ $RET != 0 ]; then
echo "Distro check failed. Outputting /etc/os-release:"
${ENGINE_CMD} run --rm -t $IMAGE cat /etc/os-release
echo ""
fi
exit $RET
9 changes: 9 additions & 0 deletions tests/runtests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,13 @@ if [ ${RET} != 0 ]; then
fi
rm $LOCAL_WDIR -rf


echo Running Distro Check Test
./distro-check.sh ${ENGINE_CMD} ${IMAGE} ${BASE_DISTRO}
RET=$?
if [ ${RET} != 0 ]; then
echo "Test \"Distro Check\" failed"
exit ${RET}
fi

echo "All tests PASSED"

0 comments on commit b5a1a27

Please sign in to comment.