forked from containerbuildsystem/osbs-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.sh
executable file
·110 lines (97 loc) · 3.06 KB
/
test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/bin/bash
set -eux
# Prepare env vars
ENGINE=${ENGINE:="podman"}
OS=${OS:="centos"}
OS_VERSION=${OS_VERSION:="7"}
PYTHON_VERSION=${PYTHON_VERSION:="2"}
ACTION=${ACTION:="test"}
IMAGE="$OS:$OS_VERSION"
CONTAINER_NAME="osbs-client-$OS-$OS_VERSION-py$PYTHON_VERSION"
# Use arrays to prevent globbing and word splitting
engine_mounts=(-v "$PWD":"$PWD":z)
for dir in ${EXTRA_MOUNT:-}; do
engine_mounts=("${engine_mounts[@]}" -v "$dir":"$dir":z)
done
# Create or resurrect container if needed
if [[ $($ENGINE ps -qa -f name="$CONTAINER_NAME" | wc -l) -eq 0 ]]; then
$ENGINE run --name "$CONTAINER_NAME" -d "${engine_mounts[@]}" -w "$PWD" -ti "$IMAGE" sleep infinity
elif [[ $($ENGINE ps -q -f name="$CONTAINER_NAME" | wc -l) -eq 0 ]]; then
echo found stopped existing container, restarting. volume mounts cannot be updated.
$ENGINE container start "$CONTAINER_NAME"
fi
function setup_osbs() {
RUN="$ENGINE exec -i $CONTAINER_NAME"
if [[ $OS == "centos" ]]; then
PYTHON="python"
PIP_PKG="python-pip"
PIP="pip"
PKG="yum"
PKG_EXTRA=(yum-utils epel-release)
BUILDDEP="yum-builddep"
else
PYTHON="python$PYTHON_VERSION"
PIP_PKG="$PYTHON-pip"
PIP="pip$PYTHON_VERSION"
PKG="dnf"
PKG_EXTRA=(dnf-plugins-core "$PYTHON"-pylint)
BUILDDEP=(dnf builddep)
fi
PIP_INST=("$PIP" install --index-url "${PYPI_INDEX:-https://pypi.org/simple}")
# Install dependencies
$RUN $PKG install -y "${PKG_EXTRA[@]}"
[[ ${PYTHON_VERSION} == '3' ]] && WITH_PY3=1 || WITH_PY3=0
$RUN "${BUILDDEP[@]}" --define "with_python3 ${WITH_PY3}" -y osbs-client.spec
if [[ $OS = centos ]]; then
# Install dependecies for test, as check is disabled for rhel
$RUN yum install -y python-flexmock \
python-six \
python-dockerfile-parse \
python-requests \
python-requests-kerberos
fi
# Install pip package
$RUN $PKG install -y $PIP_PKG
if [[ $PYTHON_VERSION == 3 ]]; then
# https://fedoraproject.org/wiki/Changes/Making_sudo_pip_safe
$RUN mkdir -p /usr/local/lib/python3.6/site-packages/
fi
# pip update pip/setuptools for Cent
if [[ $OS == centos && $OS_VERSION == 7 ]]; then
$RUN "${PIP_INST[@]}" -U pip==20.3.4
$RUN "${PIP_INST[@]}" -U setuptools
fi
# Setuptools install osbs-client from source
$RUN $PYTHON setup.py install
# Pip install packages for unit tests
$RUN "${PIP_INST[@]}" -r tests/requirements.txt
}
case ${ACTION} in
"test")
setup_osbs
TEST_CMD="coverage run --source=osbs -m pytest tests -ra --color=auto --html=__pytest_reports/osbs-unit-tests.html --self-contained-html"
;;
"pylint")
setup_osbs
PACKAGES='osbs tests'
TEST_CMD="${PYTHON} -m pylint ${PACKAGES}"
;;
"bandit")
setup_osbs
if [[ $PYTHON_VERSION == 2 ]]; then
$RUN $PIP install 'bandit==1.6.*'
else
$RUN $PIP install bandit
fi
TEST_CMD="bandit-baseline -r osbs -ll -ii"
;;
*)
echo "Unknown action: ${ACTION}"
exit 2
;;
esac
# Run tests
# shellcheck disable=SC2086
$RUN ${TEST_CMD} "$@"
echo "To run tests again:"
echo "$RUN ${TEST_CMD}"