Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions irods/test/demo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

echo "$0 running"
echo args:
for arg in $*; do
echo $((++x)): "[$arg]"
done

exit 118
1 change: 1 addition & 0 deletions irods/test/demo_A.sh
1 change: 1 addition & 0 deletions irods/test/demo_B.sh
3 changes: 3 additions & 0 deletions irods/test/demo_hook.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
echo "-- HOOK RUNNING --"
command "/prc/$ORIGINAL_SCRIPT_RELATIVE_TO_ROOT" $*
14 changes: 14 additions & 0 deletions irods/test/harness/000_install-irods.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM ubuntu:22.04
COPY install.sh /
ARG irods_package_version
ENV IRODS_PACKAGE_VERSION "$irods_package_version"
RUN for phase in initialize install-essential-packages add-package-repo; do \
bash /install.sh --w=$phase 0; \
done
RUN /install.sh 4
COPY start_postgresql_and_irods.sh /
RUN apt install -y sudo
RUN useradd -ms/bin/bash testuser
RUN echo 'testuser ALL=(ALL) NOPASSWD: ALL' >>/etc/sudoers
RUN apt install -y faketime
CMD bash /start_postgresql_and_irods.sh
5 changes: 5 additions & 0 deletions irods/test/harness/001_bats-python3.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from install-irods
run apt update; apt install -y python3-pip bats
run python3 -m pip install --upgrade pip
run python3 -m pip install virtualenv
run python3 -m virtualenv /py3
1 change: 1 addition & 0 deletions irods/test/harness/002_ssl-and-pam.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FROM bats-python3
15 changes: 15 additions & 0 deletions irods/test/harness/003_compile-specific-python.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from ssl-and-pam
run apt update
run apt install -y wget build-essential
run apt install -y libssl-dev zlib1g-dev libffi-dev libncurses-dev wget build-essential
arg python_version
run wget https://www.python.org/ftp/python/${python_version}/Python-${python_version}.tar.xz
run tar xf Python-${python_version}.tar.xz
workdir /Python-${python_version}
run ./configure --prefix /root/python --with-ensurepip=install
run make -j
run mkdir /root/python
run make install
workdir /
run /root/python/bin/python3 -m pip install python-irodsclient
run chmod a+rx /root
47 changes: 47 additions & 0 deletions irods/test/harness/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
SAMPLE RUNS

To build required images
------------------------
Examples

1) ./build-docker.sh
DEFAULT: build single-node system based on latest iRODS release

2) IRODS_PACKAGE_VERSION=4.2.12 NO_CACHE='1' ./build-docker.sh [ ... optional in-directory dockerfiles in sequence ... ]
Build (ignoring docker cache) single-node system based on specified package version string.

simple examples
---------------
./docker_container_driver.sh tests/test_1.sh
./docker_container_driver.sh tests/test_2.sh

Any script in a subdirectory of the repo (mounted at /prc within the container) can be
executed and will be able to find other scripts and source include files within the tree.
[See "experiment.sh" example below.]

Examples of options in driver script
------------------------------------

1. To start container and run test script:
C=$( ./docker_container_driver.sh -c -L -u testuser ../scripts/experiment.sh )

2. To manually examine results afterward:
docker exec -it $C bash

For both scripts, the environment variable DOCKER may be set to "podman" to run the alternative virtualizer.

Demo / Demo hook / args
------------------------

$ ~/python-irodsclient/irods/test/harness$ ./docker_container_driver.sh ../demo.sh
ORIGINAL_SCRIPT_RELATIVE_TO_ROOT=[irods/test/demo.sh]
image=[ssl-and-pam]
.......-- HOOK RUNNING --
/prc/irods/test/demo.sh running
args:
1: [arg1]
2: [arg2]
Killed: 1358fbff6eadac24f0915ffb414f0367deedc84b0c3e4de69a23bd3a8726298f
daniel@prec3431:~/python-irodsclient/irods/test/harness$ echo $?
118

37 changes: 37 additions & 0 deletions irods/test/harness/build-docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env bash

# environment variables for build
# IRODS_PACKAGE_VERSION if defined is like "4.3.4" or "5.0.1".
# (but contains no '~' suffix for irods versions <= 4.2.10)
# PYTHON_VERSION is usually two dot-separated numbers: example "3.13", but could also have zero, one or three version numbers.
# (Do not specify the triple form, X.Y.Z, if that release is not known to exist - not counting alphas and release candidates)

BASE=$(basename "$0")
DIR=$(realpath "$(dirname "$0")")
cd "$DIR"
: ${DOCKER:=docker}
if [ $# -gt 0 ]; then
ARGS=("$@")
else
ARGS=([0-9]*.Dockerfile)
fi
for dockerfile in "${ARGS[@]}"; do
image_name=${dockerfile#[0-9]*_}
image_name=${image_name%.Dockerfile}
irods_package_version_option=""
python_version_option=""
if [ "$image_name" = "install-irods" ]; then
irods_package_version_option=${IRODS_PACKAGE_VERSION:+"--build-arg=irods_package_version=$IRODS_PACKAGE_VERSION"}
elif [ "$image_name" = "compile-specific-python" ]; then
temp=$(./most_recent_python.sh $PYTHON_VERSION)
if [ -n "$temp" ]; then
PYTHON_VERSION="$temp"
fi
python_version_option=${PYTHON_VERSION:+"--build-arg=python_version=$PYTHON_VERSION"}
else
package_version_option=""
fi
$DOCKER build -f $dockerfile -t $image_name . $irods_package_version_option $python_version_option \
${NO_CACHE+"--no-cache"} ||
{ STATUS=$?; echo "*** Failure while building [$image_name]"; exit $STATUS; }
done
111 changes: 111 additions & 0 deletions irods/test/harness/docker_container_driver.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#!/usr/bin/env bash

KILL_TEST_CONTAINER=1
RUN_AS_USER=""
ECHO_CONTAINER=""

EXPLICIT_WORKDIR=""
while [[ $1 = -* ]]; do
if [ "$1" = -c ]; then
ECHO_CONTAINER=1
shift
fi
if [ "$1" = -L ]; then
KILL_TEST_CONTAINER=0
shift
fi
if [ "$1" = -u ]; then
RUN_AS_USER="$2"
shift 2
fi
if [ "$1" = -w ]; then
EXPLICIT_WORKDIR="$2"
shift 2
fi
done

if [ "$1" = "" ]; then
echo >&2 "Usage: $0 [options] /path/to/script"
echo >&2 "With options: [-L] to leak, [-u username] to run as non-root user"
exit 1
fi

DIR=$(dirname $0)
. "$DIR"/test_script_parameters

testscript=${1}

testscript_basename=$(basename "$testscript")
arglist=${wrapper_arglist[$testscript_basename]} # arglist dominated by symbolic link name if any

if [ -L "$testscript" ]; then
testscript=$(realpath "$testscript")
testscript_basename=$(basename "$testscript")
fi

original_testscript_abspath=$(realpath "$testscript")

wrapped=${wrappers["$testscript_basename"]}

if [ -n "$wrapped" ]; then
# wrapped is assumed to contain a leading path element relative to the referencing script's containing directory
testscript="$(dirname "$testscript")/$wrapped"
testscript_basename=$(basename "$testscript")
fi

testscript_abspath=$(realpath "$testscript")

cd "$DIR"

image=${images[$testscript_basename]}

if [ -z "$RUN_AS_USER" ]; then
RUN_AS_USER=${user[$testscript_basename]}
fi

# Tests are run as testuser by default
: ${RUN_AS_USER:='testuser'}

WORKDIR=""
if [ -n "$EXPLICIT_WORKDIR" ]; then
WORKDIR="$EXPLICIT_WORKDIR"
else
WORKDIR=${workdirs[$RUN_AS_USER]}
fi

reporoot=$(./print_repo_root_location)
ORIGINAL_SCRIPT_RELATIVE_TO_ROOT=$(realpath --relative-to $reporoot "$original_testscript_abspath")

echo "ORIGINAL_SCRIPT_RELATIVE_TO_ROOT=[$ORIGINAL_SCRIPT_RELATIVE_TO_ROOT]"
INNER_MOUNT=/prc

: ${DOCKER:=docker}

# Start the container.
echo image="[$image]"
CONTAINER=$($DOCKER run -d -v $reporoot:$INNER_MOUNT:ro --rm $image)

# Wait for iRODS and database to start up.
TIME0=$(date +%s)
while :; do
[ `date +%s` -gt $((TIME0 + 30)) ] && { echo >&2 "Waited too long for DB and iRODS to start"; exit 124; }
sleep 1
$DOCKER exec $CONTAINER grep '(0)' /tmp/irods_status 2>/dev/null >/dev/null
[ $? -ne 0 ] && { echo -n . >&2; continue; }
break
done

$DOCKER exec ${RUN_AS_USER:+"-u$RUN_AS_USER"} \
${WORKDIR:+"-w$WORKDIR"} \
-e "ORIGINAL_SCRIPT_RELATIVE_TO_ROOT=$ORIGINAL_SCRIPT_RELATIVE_TO_ROOT" \
$CONTAINER \
$INNER_MOUNT/$(realpath --relative-to $reporoot "$testscript_abspath") \
$arglist
STATUS=$?

if [ $((0+KILL_TEST_CONTAINER)) -ne 0 ]; then
echo >&2 'Killed:' $($DOCKER stop --time=0 $CONTAINER)
fi

[ -n "$ECHO_CONTAINER" ] && echo $CONTAINER
exit $STATUS
Loading