github.com/containers/podman/v2@v2.2.2-0.20210501105131-c1e07d070c4c/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  die_unknown() {
    16      local var_name="$1"
    17      req_env_vars var_name
    18      local var_value="${!var_name}"
    19      die "Unknown/unsupported \$$var_name '$var_value'"
    20  }
    21  
    22  msg "************************************************************"
    23  msg "Setting up runtime environment"
    24  msg "************************************************************"
    25  show_env_vars
    26  
    27  req_env_vars USER HOME GOSRC SCRIPT_BASE TEST_FLAVOR TEST_ENVIRON \
    28               PODBIN_NAME PRIV_NAME DISTRO_NV
    29  
    30  # Verify basic dependencies
    31  for depbin in go rsync unzip sha256sum curl make python3 git
    32  do
    33      if ! type -P "$depbin" &> /dev/null
    34      then
    35          warn "$depbin binary not found in $PATH"
    36      fi
    37  done
    38  
    39  # Ensure that all lower-level contexts and child-processes have
    40  # ready access to higher level orchestration (e.g Cirrus-CI)
    41  # variables.
    42  echo -e "\n# Begin single-use VM global variables (${BASH_SOURCE[0]})" \
    43      > "/etc/ci_environment"
    44  (
    45      while read -r env_var_val; do
    46          echo "$env_var_val"
    47      done <<<"$(passthrough_envars)"
    48  ) >> "/etc/ci_environment"
    49  
    50  # This is a possible manual maintenance gaff, check to be sure everything matches.
    51  # shellcheck disable=SC2154
    52  [[ "$DISTRO_NV" == "$OS_REL_VER" ]] || \
    53      die "Automation spec. '$DISTRO_NV'; actual host '$OS_REL_VER'"
    54  
    55  # Only allow this script to execute once
    56  if ((${SETUP_ENVIRONMENT:-0})); then
    57      # Comes from automation library
    58      # shellcheck disable=SC2154
    59      warn "Not executing $SCRIPT_FILENAME again"
    60      exit 0
    61  fi
    62  
    63  cd "${GOSRC}/"
    64  
    65  # Defined by lib.sh: Does the host support cgroups v1 or v2
    66  case "$CG_FS_TYPE" in
    67      tmpfs)
    68          if ((CONTAINER==0)); then
    69              warn "Forcing testing with runc instead of crun"
    70              if [[ "$OS_RELEASE_ID" == "ubuntu" ]]; then
    71                  echo "OCI_RUNTIME=/usr/lib/cri-o-runc/sbin/runc" >> /etc/ci_environment
    72              else
    73                  echo "OCI_RUNTIME=runc" >> /etc/ci_environment
    74              fi
    75          fi
    76          ;;
    77      cgroup2fs)
    78          if ((CONTAINER==0)); then
    79              # This is necessary since we've built/installed from source,
    80              # which uses runc as the default.
    81              warn "Forcing testing with crun instead of runc"
    82              echo "OCI_RUNTIME=crun" >> /etc/ci_environment
    83          fi
    84          ;;
    85      *) die_unknown CG_FS_TYPE
    86  esac
    87  
    88  if ((CONTAINER==0)); then  # Not yet running inside a container
    89      # Discovered reemergence of BFQ scheduler bug in kernel 5.8.12-200
    90      # which causes a kernel panic when system is under heavy I/O load.
    91      # Previously discovered in F32beta and confirmed fixed. It's been
    92      # observed in F31 kernels as well.  Deploy workaround for all VMs
    93      # to ensure a more stable I/O scheduler (elevator).
    94      echo "mq-deadline" > /sys/block/sda/queue/scheduler
    95      warn "I/O scheduler: $(cat /sys/block/sda/queue/scheduler)"
    96  fi
    97  
    98  # Which distribution are we testing on.
    99  case "$OS_RELEASE_ID" in
   100      ubuntu*) ;;
   101      fedora*)
   102          if ((CONTAINER==0)); then
   103              msg "Configuring / Expanding host storage."
   104              # VM is setup to allow flexibility in testing alternate storage.
   105              # For general use, simply make use of all available space.
   106              bash "$SCRIPT_BASE/add_second_partition.sh"
   107              $SCRIPT_BASE/logcollector.sh df
   108  
   109              # All SELinux distros need this for systemd-in-a-container
   110              msg "Enabling container_manage_cgroup"
   111              setsebool container_manage_cgroup true
   112          fi
   113          ;;
   114      *) die_unknown OS_RELEASE_ID
   115  esac
   116  
   117  # Required to be defined by caller: The environment where primary testing happens
   118  # shellcheck disable=SC2154
   119  case "$TEST_ENVIRON" in
   120      host)
   121          if [[ "$OS_RELEASE_ID" == "fedora" ]]; then
   122              # The e2e tests wrongly guess `--cgroup-manager cgroupfs`
   123              warn "Forcing CGROUP_MANAGER=systemd"
   124              echo "CGROUP_MANAGER=systemd" >> /etc/ci_environment
   125          fi
   126          ;;
   127      container)
   128          if ((CONTAINER==0)); then  # not yet inside a container
   129              warn "Force loading iptables modules"
   130              # Since CRIU 3.11, uses iptables to lock and unlock
   131              # the network during checkpoint and restore.  Needs
   132              # the following two modules loaded on the host.
   133              modprobe ip6table_nat || :
   134              modprobe iptable_nat || :
   135          else
   136              # The e2e tests wrongly guess `--cgroup-manager systemd`
   137              warn "Forcing CGROUP_MANAGER=cgroupfs"
   138              echo "CGROUP_MANAGER=cgroupfs" >> /etc/ci_environment
   139          fi
   140          ;;
   141      *) die_unknown TEST_ENVIRON
   142  esac
   143  
   144  # Required to be defined by caller: Are we testing as root or a regular user
   145  # shellcheck disable=SC2154
   146  case "$PRIV_NAME" in
   147      root)
   148          if [[ "$TEST_ENVIRON" == "container" ]] && ((container)); then
   149              # There's no practical way to detect userns w/in a container
   150              # affected/related tests are sensitive to this variable.
   151              warn "Disabling usernamespace integration testing"
   152              echo "SKIP_USERNS=1" >> /etc/ci_environment
   153          fi
   154          ;;
   155      rootless)
   156          # Needs to exist for setup_rootless()
   157          ROOTLESS_USER="${ROOTLESS_USER:-some${RANDOM}dude}"
   158          echo "ROOTLESS_USER=$ROOTLESS_USER" >> /etc/ci_environment
   159          setup_rootless
   160          ;;
   161      *) die_unknown PRIV_NAME
   162  esac
   163  
   164  # Required to be defined by caller: Are we testing podman or podman-remote client
   165  # shellcheck disable=SC2154
   166  case "$PODBIN_NAME" in
   167      podman) ;;
   168      remote) ;;
   169      *) die_unknown PODBIN_NAME
   170  esac
   171  
   172  # Required to be defined by caller: The primary type of testing that will be performed
   173  # shellcheck disable=SC2154
   174  case "$TEST_FLAVOR" in
   175      ext_svc) ;;
   176      validate)
   177          # For some reason, this is also needed for validation
   178          make .install.pre-commit
   179          ;;
   180      automation) ;;
   181      altbuild)
   182          # Defined in .cirrus.yml
   183          # shellcheck disable=SC2154
   184          if [[ "$ALT_NAME" =~ RPM ]]; then
   185              bigto dnf install -y glibc-minimal-langpack rpm-build
   186          fi
   187          ;&
   188      docker-py) ;&
   189      build) make clean ;;
   190      unit) ;;
   191      apiv2) ;&  # use next item
   192      int) ;&
   193      sys) ;&
   194      bindings) ;&
   195      swagger) ;&
   196      endpoint)
   197          # Use existing host bits when testing is to happen inside a container
   198          # since this script will run again in that environment.
   199          # shellcheck disable=SC2154
   200          if ((CONTAINER==0)) && [[ "$TEST_ENVIRON" == "host" ]]; then
   201              remove_packaged_podman_files
   202              make install PREFIX=/usr ETCDIR=/etc
   203          fi
   204  
   205          install_test_configs
   206          ;;
   207      vendor) make clean ;;
   208      release) ;;
   209      *) die_unknown TEST_FLAVOR
   210  esac
   211  
   212  # Must be the very last command.  Prevents setup from running twice.
   213  echo 'SETUP_ENVIRONMENT=1' >> /etc/ci_environment
   214  echo -e "\n# End of global variable definitions" \
   215      >> /etc/ci_environment
   216  
   217  msg "Global CI Environment vars.:"
   218  grep -Ev '^#' /etc/ci_environment | sort | indent