github.com/containers/podman/v4@v4.9.4/contrib/cirrus/setup_environment.sh (about) 1 #!/usr/bin/env bash 2 3 # This script is intended to be executed early by automation before 4 # performing other substantial operations. It relies heavily on 5 # desired setup information being passed in environment variables 6 # from Cirrus-CI and/or other orchestration tooling. To that end, 7 # VM's must always be considered single-purpose, single-use, 8 # disposable entities. i.e. One setup, one test, then always discarded. 9 10 set -e 11 12 # shellcheck source=./contrib/cirrus/lib.sh 13 source $(dirname $0)/lib.sh 14 15 showrun echo "starting" 16 17 die_unknown() { 18 local var_name="$1" 19 req_env_vars var_name 20 local var_value="${!var_name}" 21 die "Unknown/unsupported \$$var_name '$var_value'" 22 } 23 24 msg "************************************************************" 25 msg "Setting up runtime environment" 26 msg "************************************************************" 27 show_env_vars 28 29 req_env_vars USER HOME GOSRC SCRIPT_BASE TEST_FLAVOR TEST_ENVIRON \ 30 PODBIN_NAME PRIV_NAME DISTRO_NV DEST_BRANCH 31 32 # Verify basic dependencies 33 for depbin in go rsync unzip sha256sum curl make python3 git 34 do 35 if ! type -P "$depbin" &> /dev/null 36 then 37 warn "$depbin binary not found in $PATH" 38 fi 39 done 40 41 cp hack/podman-registry /bin 42 43 # Some test operations & checks require a git "identity" 44 _gc='git config --file /root/.gitconfig' 45 showrun $_gc user.email "TMcTestFace@example.com" 46 showrun $_gc user.name "Testy McTestface" 47 # Bypass git safety/security checks when operating in a throwaway environment 48 showrun git config --system --add safe.directory $GOSRC 49 50 # Ensure that all lower-level contexts and child-processes have 51 # ready access to higher level orchestration (e.g Cirrus-CI) 52 # variables. 53 echo -e "\n# Begin single-use VM global variables (${BASH_SOURCE[0]})" \ 54 > "/etc/ci_environment" 55 ( 56 while read -r env_var; do 57 printf -- "%s=%q\n" "${env_var}" "${!env_var}" 58 done <<<"$(passthrough_envars)" 59 ) >> "/etc/ci_environment" 60 61 # This is a possible manual maintenance gaff, i.e. forgetting to update a 62 # *_NAME variable in .cirrus.yml. check to be sure at least one comparison 63 # matches the actual OS being run. Ignore details, such as debian point-release 64 # number and/or '-aarch64' suffix. 65 # shellcheck disable=SC2154 66 grep -q "$DISTRO_NV" <<<"$OS_REL_VER" || \ 67 grep -q "$OS_REL_VER" <<<"$DISTRO_NV" || \ 68 grep -q "rawhide" <<<"$DISTRO_NV" || \ 69 die "Automation spec. '$DISTRO_NV'; actual host '$OS_REL_VER'" 70 71 # Only allow this script to execute once 72 if ((${SETUP_ENVIRONMENT:-0})); then 73 # Comes from automation library 74 # shellcheck disable=SC2154 75 warn "Not executing $SCRIPT_FILENAME again" 76 exit 0 77 fi 78 79 cd "${GOSRC}/" 80 81 mkdir -p /etc/containers/containers.conf.d 82 83 # Defined by lib.sh: Does the host support cgroups v1 or v2? Use runc or crun 84 # respectively. 85 # **IMPORTANT**: $OCI_RUNTIME is a fakeout! It is used only in e2e tests. 86 # For actual podman, as in system tests, we force runtime in containers.conf 87 showrun echo "conditional check: CG_FS_TYPE [=$CG_FS_TYPE]" 88 case "$CG_FS_TYPE" in 89 tmpfs) 90 if ((CONTAINER==0)); then 91 warn "Forcing testing with runc instead of crun" 92 echo "OCI_RUNTIME=runc" >> /etc/ci_environment 93 printf "[engine]\nruntime=\"runc\"\n" > /etc/containers/containers.conf.d/90-runtime.conf 94 fi 95 ;; 96 cgroup2fs) 97 # Nothing to do: podman defaults to crun 98 ;; 99 *) die_unknown CG_FS_TYPE 100 esac 101 102 # Force the requested database backend without having to use command-line args 103 # As of #20318 (2023-10-10) sqlite is the default, but for complicated reasons 104 # we still (2023-11-01) have to explicitly create a containers.conf. See 105 # comments in #20559. 106 # FIXME: some day, when new CI VMs are in place with podman >= 4.8 installed 107 # from RPM, un-comment the 'if' below. That will confirm that sqlite is default. 108 # shellcheck disable=SC2154 109 #if [[ "${CI_DESIRED_DATABASE:-sqlite}" != "sqlite" ]]; then 110 printf "[engine]\ndatabase_backend=\"$CI_DESIRED_DATABASE\"\n" > /etc/containers/containers.conf.d/92-db.conf 111 112 if ((CONTAINER==0)); then # Not yet running inside a container 113 showrun echo "conditional setup for CONTAINER == 0" 114 # Discovered reemergence of BFQ scheduler bug in kernel 5.8.12-200 115 # which causes a kernel panic when system is under heavy I/O load. 116 # Disable the I/O scheduler (a.k.a. elevator) for all environments, 117 # leaving optimization up to underlying storage infrastructure. 118 testfs="/" # mountpoint that experiences the most I/O during testing 119 msg "Querying block device owning partition hosting the '$testfs' filesystem" 120 # Need --nofsroot b/c btrfs appends subvolume label to `source` name 121 testdev=$(findmnt --canonicalize --noheadings --nofsroot \ 122 --output source --mountpoint $testfs) 123 msg " found partition: '$testdev'" 124 testdisk=$(lsblk --noheadings --output pkname --paths $testdev) 125 msg " found block dev: '$testdisk'" 126 testsched="/sys/block/$(basename $testdisk)/queue/scheduler" 127 if [[ -n "$testdev" ]] && [[ -n "$testdisk" ]] && [[ -e "$testsched" ]]; then 128 msg " Found active I/O scheduler: $(cat $testsched)" 129 if [[ ! "$(<$testsched)" =~ \[none\] ]]; then 130 msg " Disabling elevator for '$testsched'" 131 echo "none" > "$testsched" 132 else 133 msg " Elevator already disabled" 134 fi 135 else 136 warn "Sys node for elevator doesn't exist: '$testsched'" 137 fi 138 fi 139 140 # Which distribution are we testing on. 141 case "$OS_RELEASE_ID" in 142 debian) 143 showrun echo "more conditional setup for debian" 144 # FIXME 2023-04-11: workaround for runc regression causing failure 145 # in system tests: "skipping device /dev/char/10:200 for systemd" 146 # (Checked on 2023-08-08 and it's still too old: 1.1.5) 147 # FIXME: please remove this once runc >= 1.2 makes it into debian. 148 showrun modprobe tun 149 ;; 150 fedora) 151 showrun echo "conditional setup for fedora" 152 if ((CONTAINER==0)); then 153 # All SELinux distros need this for systemd-in-a-container 154 msg "Enabling container_manage_cgroup" 155 showrun setsebool container_manage_cgroup true 156 fi 157 ;; 158 *) die_unknown OS_RELEASE_ID 159 esac 160 161 # Networking: force CNI or Netavark as requested in .cirrus.yml 162 # (this variable is mandatory). 163 # shellcheck disable=SC2154 164 showrun echo "about to set up for CI_DESIRED_NETWORK [=$CI_DESIRED_NETWORK]" 165 case "$CI_DESIRED_NETWORK" in 166 netavark) use_netavark ;; 167 cni) use_cni ;; 168 *) die_unknown CI_DESIRED_NETWORK ;; 169 esac 170 171 # Database: force SQLite or BoltDB as requested in .cirrus.yml. 172 # If unset, will default to SQLite. 173 # shellcheck disable=SC2154 174 showrun echo "about to set up for CI_DESIRED_DATABASE [=$CI_DESIRED_DATABASE]" 175 case "$CI_DESIRED_DATABASE" in 176 sqlite) 177 warn "Forcing PODMAN_DB=sqlite" 178 echo "PODMAN_DB=sqlite" >> /etc/ci_environment 179 ;; 180 boltdb) 181 warn "Forcing PODMAN_DB=boltdb" 182 echo "PODMAN_DB=boltdb" >> /etc/ci_environment 183 ;; 184 "") 185 warn "Using default Podman database" 186 ;; 187 *) 188 die_unknown CI_DESIRED_DATABASE 189 ;; 190 esac 191 192 # Force the requested storage driver for both system and e2e tests. 193 # This is (sigh) different because e2e tests have their own special way 194 # of ignoring system defaults. 195 # shellcheck disable=SC2154 196 showrun echo "Setting CI_DESIRED_STORAGE [=$CI_DESIRED_STORAGE] for *system* tests" 197 conf=/etc/containers/storage.conf 198 if [[ -e $conf ]]; then 199 die "FATAL! INTERNAL ERROR! Cannot override $conf" 200 fi 201 cat <<EOF >$conf 202 [storage] 203 driver = "$CI_DESIRED_STORAGE" 204 runroot = "/run/containers/storage" 205 graphroot = "/var/lib/containers/storage" 206 EOF 207 208 # shellcheck disable=SC2154 209 showrun echo "Setting CI_DESIRED_STORAGE [=$CI_DESIRED_STORAGE] for *e2e* tests" 210 echo "STORAGE_FS=$CI_DESIRED_STORAGE" >>/etc/ci_environment 211 212 # Required to be defined by caller: The environment where primary testing happens 213 # shellcheck disable=SC2154 214 showrun echo "about to set up for TEST_ENVIRON [=$TEST_ENVIRON]" 215 case "$TEST_ENVIRON" in 216 host) 217 # The e2e tests wrongly guess `--cgroup-manager` option 218 # shellcheck disable=SC2154 219 if [[ "$CG_FS_TYPE" == "cgroup2fs" ]] || [[ "$PRIV_NAME" == "root" ]] 220 then 221 warn "Forcing CGROUP_MANAGER=systemd" 222 echo "CGROUP_MANAGER=systemd" >> /etc/ci_environment 223 else 224 warn "Forcing CGROUP_MANAGER=cgroupfs" 225 echo "CGROUP_MANAGER=cgroupfs" >> /etc/ci_environment 226 fi 227 ;; 228 container) 229 if ((CONTAINER==0)); then # not yet inside a container 230 warn "Force loading iptables modules" 231 # Since CRIU 3.11, uses iptables to lock and unlock 232 # the network during checkpoint and restore. Needs 233 # the following two modules loaded on the host. 234 modprobe ip6table_nat || : 235 modprobe iptable_nat || : 236 else 237 warn "Forcing CGROUP_MANAGER=cgroupfs" 238 echo "CGROUP_MANAGER=cgroupfs" >> /etc/ci_environment 239 240 # There's no practical way to detect userns w/in a container 241 # affected/related tests are sensitive to this variable. 242 warn "Disabling usernamespace integration testing" 243 echo "SKIP_USERNS=1" >> /etc/ci_environment 244 245 # In F35 the hard-coded default 246 # (from containers-common-1-32.fc35.noarch) is 'journald' despite 247 # the upstream repository having this line commented-out. 248 # Containerized integration tests cannot run with 'journald' 249 # as there is no daemon/process there to receive them. 250 cconf="/usr/share/containers/containers.conf" 251 note="- commented-out by setup_environment.sh" 252 if grep -Eq '^log_driver.+journald' "$cconf"; then 253 warn "Patching out $cconf journald log_driver" 254 sed -r -i -e "s/^log_driver(.*)/# log_driver\1 $note/" "$cconf" 255 fi 256 fi 257 ;; 258 *) die_unknown TEST_ENVIRON 259 esac 260 261 # Required to be defined by caller: Are we testing as root or a regular user 262 showrun echo "about to set up for PRIV_NAME [=$PRIV_NAME]" 263 case "$PRIV_NAME" in 264 root) 265 # shellcheck disable=SC2154 266 if [[ "$TEST_FLAVOR" = "sys" || "$TEST_FLAVOR" = "apiv2" ]]; then 267 # Used in local image-scp testing 268 setup_rootless 269 echo "PODMAN_ROOTLESS_USER=$ROOTLESS_USER" >> /etc/ci_environment 270 echo "PODMAN_ROOTLESS_UID=$ROOTLESS_UID" >> /etc/ci_environment 271 fi 272 ;; 273 rootless) 274 # load kernel modules since the rootless user has no permission to do so 275 modprobe ip6_tables || : 276 modprobe ip6table_nat || : 277 setup_rootless 278 ;; 279 *) die_unknown PRIV_NAME 280 esac 281 282 # FIXME! experimental workaround for #16973, the "lookup cdn03.quay.io" flake. 283 # 284 # If you are reading this on or after April 2023: 285 # * If we're NOT seeing the cdn03 flake any more, well, someone 286 # should probably figure out how to fix systemd-resolved, then 287 # remove this workaround. 288 # 289 # * If we're STILL seeing the cdn03 flake, well, this "fix" 290 # didn't work and should be removed. 291 # 292 # Either way, this block of code should be removed after March 31 2023 293 # because it creates a system that is not representative of real-world Fedora. 294 if ((CONTAINER==0)); then 295 nsswitch=/etc/authselect/nsswitch.conf 296 if [[ -e $nsswitch ]]; then 297 if grep -q -E 'hosts:.*resolve' $nsswitch; then 298 showrun echo "Disabling systemd-resolved" 299 sed -i -e 's/^\(hosts: *\).*/\1files dns myhostname/' $nsswitch 300 systemctl stop systemd-resolved 301 rm -f /etc/resolv.conf 302 303 # NetworkManager may already be running, or it may not.... 304 systemctl start NetworkManager 305 sleep 1 306 systemctl restart NetworkManager 307 308 # ...and it may create resolv.conf upon start/restart, or it 309 # may not. Keep restarting until it does. (Yes, I realize 310 # this is cargocult thinking. Don't care. Not worth the effort 311 # to diagnose and solve properly.) 312 retries=10 313 while ! test -e /etc/resolv.conf;do 314 retries=$((retries - 1)) 315 if [[ $retries -eq 0 ]]; then 316 die "Timed out waiting for resolv.conf" 317 fi 318 systemctl restart NetworkManager 319 sleep 5 320 done 321 fi 322 fi 323 fi 324 325 # Required to be defined by caller: Are we testing podman or podman-remote client 326 # shellcheck disable=SC2154 327 case "$PODBIN_NAME" in 328 podman) ;; 329 remote) ;; 330 *) die_unknown PODBIN_NAME 331 esac 332 333 # Required to be defined by caller: The primary type of testing that will be performed 334 # shellcheck disable=SC2154 335 showrun echo "about to set up for TEST_FLAVOR [=$TEST_FLAVOR]" 336 case "$TEST_FLAVOR" in 337 validate) 338 showrun dnf install -y $PACKAGE_DOWNLOAD_DIR/python3*.rpm 339 # For some reason, this is also needed for validation 340 showrun make .install.pre-commit .install.gitvalidation 341 ;; 342 altbuild) 343 # Defined in .cirrus.yml 344 # shellcheck disable=SC2154 345 if [[ "$ALT_NAME" =~ RPM ]]; then 346 showrun bigto dnf install -y glibc-minimal-langpack go-rpm-macros rpkg rpm-build shadow-utils-subid-devel 347 fi 348 ;; 349 docker-py) 350 remove_packaged_podman_files 351 showrun make install PREFIX=/usr ETCDIR=/etc 352 353 msg "Installing previously downloaded/cached packages" 354 showrun dnf install -y $PACKAGE_DOWNLOAD_DIR/python3*.rpm 355 virtualenv .venv/docker-py 356 source .venv/docker-py/bin/activate 357 showrun pip install --upgrade pip 358 showrun pip install --requirement $GOSRC/test/python/requirements.txt 359 ;; 360 build) make clean ;; 361 unit) 362 showrun make .install.ginkgo 363 ;; 364 compose_v2) 365 showrun dnf -y remove docker-compose 366 showrun curl -SL https://github.com/docker/compose/releases/download/v2.2.3/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose 367 showrun chmod +x /usr/local/bin/docker-compose 368 ;& # Continue with next item 369 apiv2) 370 msg "Installing previously downloaded/cached packages" 371 showrun dnf install -y $PACKAGE_DOWNLOAD_DIR/python3*.rpm 372 virtualenv .venv/requests 373 source .venv/requests/bin/activate 374 showrun pip install --upgrade pip 375 showrun pip install --requirement $GOSRC/test/apiv2/python/requirements.txt 376 ;& # continue with next item 377 compose) 378 showrun make install.tools 379 showrun dnf remove -y gvisor-tap-vsock 380 showrun dnf install -y podman-docker* 381 ;& # continue with next item 382 int) 383 showrun make .install.ginkgo 384 ;& 385 sys) ;& 386 upgrade_test) ;& 387 bud) ;& 388 bindings) ;& 389 endpoint) 390 showrun echo "Entering shared endpoint setup" 391 # Use existing host bits when testing is to happen inside a container 392 # since this script will run again in that environment. 393 # shellcheck disable=SC2154 394 if [[ "$TEST_ENVIRON" =~ host ]]; then 395 if ((CONTAINER)); then 396 die "Refusing to config. host-test in container"; 397 fi 398 remove_packaged_podman_files 399 make install PREFIX=/usr ETCDIR=/etc 400 elif [[ "$TEST_ENVIRON" == "container" ]]; then 401 if ((CONTAINER)); then 402 remove_packaged_podman_files 403 make install PREFIX=/usr ETCDIR=/etc 404 fi 405 else 406 die "Invalid value for \$TEST_ENVIRON=$TEST_ENVIRON" 407 fi 408 409 install_test_configs 410 ;; 411 farm) 412 showrun loginctl enable-linger $ROOTLESS_USER 413 showrun ssh $ROOTLESS_USER@localhost systemctl --user enable --now podman.socket 414 remove_packaged_podman_files 415 showrun make install PREFIX=/usr ETCDIR=/etc 416 install_test_configs 417 ;; 418 minikube) 419 showrun dnf install -y $PACKAGE_DOWNLOAD_DIR/minikube-latest* 420 remove_packaged_podman_files 421 showrun make install.tools 422 showrun make install PREFIX=/usr ETCDIR=/etc 423 showrun minikube config set driver podman 424 install_test_configs 425 ;; 426 machine-linux) 427 showrun dnf install -y podman-gvproxy* 428 remove_packaged_podman_files 429 showrun make install PREFIX=/usr ETCDIR=/etc 430 install_test_configs 431 ;; 432 swagger) 433 showrun make .install.swagger 434 ;; 435 release) ;; 436 *) die_unknown TEST_FLAVOR 437 esac 438 439 # See ./contrib/cirrus/CIModes.md. 440 # Vars defined by cirrus-ci 441 # shellcheck disable=SC2154 442 if [[ ! "$OS_RELEASE_ID" =~ "debian" ]] && \ 443 [[ "$CIRRUS_CHANGE_TITLE" =~ CI:NEXT ]] 444 then 445 showrun echo "Entering setup for CI:NEXT" 446 # shellcheck disable=SC2154 447 if [[ "$CIRRUS_PR_DRAFT" != "true" ]]; then 448 die "Magic 'CI:NEXT' string can only be used on DRAFT PRs" 449 fi 450 451 showrun dnf copr enable rhcontainerbot/podman-next -y 452 453 # DNF ignores repos that don't exist. For example, updates-testing is not 454 # enabled on Fedora N-1 CI VMs. Don't updated everything, isolate just the 455 # podman-next COPR updates. 456 showrun dnf update -y \ 457 "--enablerepo=copr:copr.fedorainfracloud.org:rhcontainerbot:podman-next" \ 458 "--disablerepo=copr:copr.fedorainfracloud.org:sbrivio:passt" \ 459 "--disablerepo=fedora*" "--disablerepo=updates*" 460 fi 461 462 # Must be the very last command. Prevents setup from running twice. 463 echo 'SETUP_ENVIRONMENT=1' >> /etc/ci_environment 464 echo -e "\n# End of global variable definitions" \ 465 >> /etc/ci_environment 466 467 msg "Global CI Environment vars.:" 468 grep -Ev '^#' /etc/ci_environment | sort | indent 469 470 showrun echo "finished"