|
| 1 | +#!/usr/bin/env bats |
| 2 | + |
| 3 | +load ./common |
| 4 | + |
| 5 | +function setup() { |
| 6 | + enroot_cleanup env-test env-test2 || true |
| 7 | +} |
| 8 | + |
| 9 | +function teardown() { |
| 10 | + enroot_cleanup env-test env-test2 || true |
| 11 | +} |
| 12 | + |
| 13 | +@test "PYXIS_CONTAINER_IMAGE environment variable" { |
| 14 | + PYXIS_CONTAINER_IMAGE=ubuntu:22.04 run_srun grep 'Ubuntu 22.04' /etc/os-release |
| 15 | +} |
| 16 | + |
| 17 | +@test "PYXIS_CONTAINER_IMAGE: command line precedence" { |
| 18 | + PYXIS_CONTAINER_IMAGE=ubuntu:22.04 run_srun --container-image=ubuntu:24.04 grep 'Ubuntu 24.04' /etc/os-release |
| 19 | +} |
| 20 | + |
| 21 | +@test "PYXIS_CONTAINER_MOUNTS environment variable" { |
| 22 | + PYXIS_CONTAINER_MOUNTS=/home:/test-mnt run_srun --container-image=ubuntu:24.04 findmnt /test-mnt |
| 23 | +} |
| 24 | + |
| 25 | +@test "PYXIS_CONTAINER_MOUNTS: command line precedence" { |
| 26 | + PYXIS_CONTAINER_MOUNTS=/home:/mnt-env run_srun --container-image=ubuntu:24.04 --container-mounts=/tmp:/mnt-cli bash -c 'findmnt /mnt-cli && ! findmnt /mnt-env' |
| 27 | +} |
| 28 | + |
| 29 | +@test "PYXIS_CONTAINER_WORKDIR environment variable" { |
| 30 | + PYXIS_CONTAINER_WORKDIR=/usr/local/bin run_srun --container-image=ubuntu:24.04 pwd |
| 31 | + [ "${lines[-1]}" == "/usr/local/bin" ] |
| 32 | +} |
| 33 | + |
| 34 | +@test "PYXIS_CONTAINER_WORKDIR: command line precedence" { |
| 35 | + PYXIS_CONTAINER_WORKDIR=/usr/local/bin run_srun --container-image=ubuntu:24.04 --container-workdir=/tmp pwd |
| 36 | + [ "${lines[-1]}" == "/tmp" ] |
| 37 | +} |
| 38 | + |
| 39 | +@test "PYXIS_CONTAINER_NAME environment variable" { |
| 40 | + PYXIS_CONTAINER_NAME=env-test run_srun --container-image=ubuntu:24.04 --container-remap-root bash -c 'apt-get update && apt-get install -y --no-install-recommends file' |
| 41 | + run_srun --container-name=env-test which file |
| 42 | +} |
| 43 | + |
| 44 | +@test "PYXIS_CONTAINER_NAME: command line precedence" { |
| 45 | + PYXIS_CONTAINER_NAME=env-test run_srun --container-image=ubuntu:24.04 --container-name=env-test2 --container-remap-root bash -c 'apt-get update && apt-get install -y --no-install-recommends make' |
| 46 | + run_srun --container-name=env-test2 which make |
| 47 | + run_srun_unchecked --container-name=env-test which make |
| 48 | + [ "${status}" -ne 0 ] |
| 49 | +} |
| 50 | + |
| 51 | +@test "PYXIS_CONTAINER_SAVE environment variable" { |
| 52 | + readonly image="./env-test.sqsh" |
| 53 | + rm -f "${image}" |
| 54 | + PYXIS_CONTAINER_SAVE=${image} run_srun --container-image=ubuntu:24.04 sh -c 'echo pyxis > /test' |
| 55 | + sleep 1s |
| 56 | + run_srun --container-image=${image} cat /test |
| 57 | + [ "${lines[-1]}" == "pyxis" ] |
| 58 | + rm -f "${image}" |
| 59 | +} |
| 60 | + |
| 61 | +@test "PYXIS_CONTAINER_SAVE: command line precedence" { |
| 62 | + readonly env_image="./env-test.sqsh" |
| 63 | + readonly cli_image="./cli-test.sqsh" |
| 64 | + rm -f "${env_image}" "${cli_image}" |
| 65 | + PYXIS_CONTAINER_SAVE=${env_image} run_srun --container-image=ubuntu:24.04 --container-save=${cli_image} sh -c 'echo pyxis > /test' |
| 66 | + sleep 1s |
| 67 | + run_srun --container-image=${cli_image} cat /test |
| 68 | + [ "${lines[-1]}" == "pyxis" ] |
| 69 | + [ ! -f "${env_image}" ] |
| 70 | + rm -f "${cli_image}" |
| 71 | +} |
| 72 | + |
| 73 | +@test "PYXIS_CONTAINER_MOUNT_HOME=1 environment variable" { |
| 74 | + PYXIS_CONTAINER_MOUNT_HOME=1 run_srun --container-remap-root --container-image=ubuntu:24.04 findmnt /root |
| 75 | +} |
| 76 | + |
| 77 | +@test "PYXIS_CONTAINER_MOUNT_HOME=0 environment variable" { |
| 78 | + PYXIS_CONTAINER_MOUNT_HOME=0 run_srun --container-remap-root --container-image=ubuntu:24.04 bash -c '! findmnt /root' |
| 79 | +} |
| 80 | + |
| 81 | +@test "PYXIS_CONTAINER_MOUNT_HOME: command line precedence" { |
| 82 | + PYXIS_CONTAINER_MOUNT_HOME=1 run_srun --no-container-mount-home --container-remap-root --container-image=ubuntu:24.04 bash -c '! findmnt /root' |
| 83 | +} |
| 84 | + |
| 85 | +@test "PYXIS_CONTAINER_REMAP_ROOT=1 environment variable" { |
| 86 | + PYXIS_CONTAINER_REMAP_ROOT=1 run_srun --container-image=ubuntu:24.04 bash -c 'cat /proc/self/uid_map' |
| 87 | + uidmap=(${lines[-1]}) |
| 88 | + [ "${uidmap[0]}" -eq 0 ] |
| 89 | + [ "${uidmap[1]}" -eq $(id -u) ] |
| 90 | + [ "${uidmap[2]}" -eq 1 ] |
| 91 | +} |
| 92 | + |
| 93 | +@test "PYXIS_CONTAINER_REMAP_ROOT=0 environment variable" { |
| 94 | + PYXIS_CONTAINER_REMAP_ROOT=0 run_srun --container-image=ubuntu:24.04 bash -c 'cat /proc/self/uid_map' |
| 95 | + uidmap=(${lines[-1]}) |
| 96 | + [ "${uidmap[0]}" -eq $(id -u) ] |
| 97 | + [ "${uidmap[1]}" -eq $(id -u) ] |
| 98 | + [ "${uidmap[2]}" -eq 1 ] |
| 99 | +} |
| 100 | + |
| 101 | +@test "PYXIS_CONTAINER_REMAP_ROOT: command line precedence" { |
| 102 | + PYXIS_CONTAINER_REMAP_ROOT=1 run_srun --no-container-remap-root --container-image=ubuntu:24.04 bash -c 'cat /proc/self/uid_map' |
| 103 | + uidmap=(${lines[-1]}) |
| 104 | + [ "${uidmap[0]}" -eq $(id -u) ] |
| 105 | + [ "${uidmap[1]}" -eq $(id -u) ] |
| 106 | + [ "${uidmap[2]}" -eq 1 ] |
| 107 | +} |
| 108 | + |
| 109 | +@test "PYXIS_CONTAINER_ENTRYPOINT=1 environment variable" { |
| 110 | + if srun bash -c '[ -f /etc/enroot/entrypoint ]'; then |
| 111 | + skip "entrypoint disabled by enroot" |
| 112 | + fi |
| 113 | + |
| 114 | + PYXIS_CONTAINER_ENTRYPOINT=1 run_srun --container-image=docker:26.1.0-dind-rootless sh -c '[ -n "${DOCKER_HOST}" ]' |
| 115 | +} |
| 116 | + |
| 117 | +@test "PYXIS_CONTAINER_ENTRYPOINT=0 environment variable" { |
| 118 | + PYXIS_CONTAINER_ENTRYPOINT=0 run_srun --container-image=docker:26.1.0-dind-rootless sh -c '[ -z "${DOCKER_HOST}" ]' |
| 119 | +} |
| 120 | + |
| 121 | +@test "PYXIS_CONTAINER_ENTRYPOINT: command line precedence" { |
| 122 | + if srun bash -c '[ -f /etc/enroot/entrypoint ]'; then |
| 123 | + skip "entrypoint disabled by enroot" |
| 124 | + fi |
| 125 | + |
| 126 | + PYXIS_CONTAINER_ENTRYPOINT=0 run_srun --container-entrypoint --container-image=docker:26.1.0-dind-rootless sh -c '[ -n "${DOCKER_HOST}" ]' |
| 127 | +} |
| 128 | + |
| 129 | +@test "PYXIS_CONTAINER_ENTRYPOINT_LOG=1 environment variable" { |
| 130 | + if srun bash -c '[ -f /etc/enroot/entrypoint ]'; then |
| 131 | + skip "entrypoint disabled by enroot" |
| 132 | + fi |
| 133 | + |
| 134 | + PYXIS_CONTAINER_ENTRYPOINT_LOG=1 run_srun --container-entrypoint --container-image=nvidia/cuda:12.9.1-runtime-ubuntu24.04 true |
| 135 | + grep -q "== CUDA ==" <<< "${output}" |
| 136 | +} |
| 137 | + |
| 138 | +@test "PYXIS_CONTAINER_ENTRYPOINT_LOG=0 environment variable" { |
| 139 | + if srun bash -c '[ -f /etc/enroot/entrypoint ]'; then |
| 140 | + skip "entrypoint disabled by enroot" |
| 141 | + fi |
| 142 | + |
| 143 | + PYXIS_CONTAINER_ENTRYPOINT_LOG=0 run_srun --container-entrypoint --container-image=nvidia/cuda:12.9.1-runtime-ubuntu24.04 true |
| 144 | + ! grep -q "== CUDA ==" <<< "${output}" |
| 145 | +} |
| 146 | + |
| 147 | +@test "PYXIS_CONTAINER_WRITABLE=1 environment variable" { |
| 148 | + PYXIS_CONTAINER_WRITABLE=1 run_srun --container-image=ubuntu:24.04 touch /newfile |
| 149 | +} |
| 150 | + |
| 151 | +@test "PYXIS_CONTAINER_WRITABLE=0 environment variable" { |
| 152 | + PYXIS_CONTAINER_WRITABLE=0 run_srun_unchecked --container-image=ubuntu:24.04 touch /newfile |
| 153 | + [ "${status}" -ne 0 ] |
| 154 | + grep -q 'Read-only file system' <<< "${output}" |
| 155 | +} |
| 156 | + |
| 157 | +@test "PYXIS_CONTAINER_WRITABLE: command line precedence" { |
| 158 | + PYXIS_CONTAINER_WRITABLE=1 run_srun_unchecked --container-readonly --container-image=ubuntu:24.04 touch /newfile |
| 159 | + [ "${status}" -ne 0 ] |
| 160 | + grep -q 'Read-only file system' <<< "${output}" |
| 161 | +} |
| 162 | + |
| 163 | +@test "PYXIS_CONTAINER_READONLY=1 environment variable" { |
| 164 | + PYXIS_CONTAINER_READONLY=1 run_srun_unchecked --container-image=ubuntu:24.04 touch /newfile |
| 165 | + [ "${status}" -ne 0 ] |
| 166 | + grep -q 'Read-only file system' <<< "${output}" |
| 167 | +} |
| 168 | + |
| 169 | +@test "PYXIS_CONTAINER_READONLY=0 environment variable" { |
| 170 | + PYXIS_CONTAINER_READONLY=0 run_srun_unchecked --container-image=ubuntu:24.04 touch /newfile |
| 171 | +} |
| 172 | + |
| 173 | +@test "PYXIS_CONTAINER_READONLY: command line precedence" { |
| 174 | + PYXIS_CONTAINER_READONLY=0 run_srun_unchecked --container-readonly --container-image=ubuntu:24.04 touch /newfile |
| 175 | + [ "${status}" -ne 0 ] |
| 176 | + grep -q 'Read-only file system' <<< "${output}" |
| 177 | +} |
| 178 | + |
| 179 | +@test "PYXIS_CONTAINER_ENV environment variable" { |
| 180 | + export CUDA_VERSION=11.0.0 |
| 181 | + PYXIS_CONTAINER_ENV=CUDA_VERSION run_srun --no-container-mount-home --container-image=nvidia/cuda:12.9.1-base-ubuntu24.04 sh -c 'echo $CUDA_VERSION' |
| 182 | + [ "${lines[-1]}" == "11.0.0" ] |
| 183 | +} |
| 184 | + |
| 185 | +@test "PYXIS_CONTAINER_ENV: command line precedence" { |
| 186 | + export CUDA_VERSION=12.0.0 |
| 187 | + export LD_LIBRARY_PATH=/usr/local/cuda/lib64 |
| 188 | + PYXIS_CONTAINER_ENV=CUDA_VERSION run_srun --no-container-mount-home --container-image=nvidia/cuda:12.9.1-base-ubuntu24.04 --container-env=LD_LIBRARY_PATH sh -c 'echo $CUDA_VERSION $LD_LIBRARY_PATH' |
| 189 | + [[ "${lines[-1]}" == "12.9.1 /usr/local/cuda/lib64" ]] |
| 190 | +} |
0 commit comments