Skip to content
Snippets Groups Projects
Select Git revision
1 result Searching

pfft.m

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    run_integration_test.sh 5.53 KiB
    #!/bin/bash -e
    
    # Usage function explains how parameters are parsed
    function usage {
        echo "./$(basename "$0")
          no arguments, builds and configures all docker containers and starts each
          stage of the integration test one after the other. Between each stage the
          dsconfig is updated accordingly."
        echo ""
        echo "./$(basename "$0") -h
          displays this help message"
        echo ""
        echo "./$(basename "$0") import-path.<class><function-name>
          A specific test can be defined by specifying the entire an import path
          and optionally extending this with a specific class and function. For
          instance tangostationcontrol.integration_test.observations.test_archiver.TestArchiver.test_get_multimember_devices"
        echo ""
    }
    
    # Configure the config database, restart containers and run a specific
    # integration module or even specific tests
    # integration_test module restarted_containers config_files specific_test
    function integration_test {
      IFS=" " read -r -a restarts <<< "${2}"
      IFS=" " read -r -a configs <<< "${3}"
      for config in "${configs[@]}"; do
        echo "Updating config ${config} ..."
        bash "${LOFAR20_DIR}"/sbin/update_ConfigDb.sh "${config}"
      done
      if [ -n "${2+x}" ]; then
        # shellcheck disable=SC2145
        echo "make restart ${restarts[@]} ..."
        make restart "${restarts[@]}"
        make await "${restarts[@]}"
      fi
    
      echo "make integration ${1} ..."
      make integration "${1}"
    }
    
    # list of arguments expected in the input
    optstring=":h"
    
    while getopts ${optstring} arg; do
      case ${arg} in
        h)
          usage
          exit 0
          ;;
        ?)
          echo "Invalid option: -${OPTARG}."
          exit 2
          ;;
      esac
    done
    
    if [ -z "$LOFAR20_DIR" ]; then
        # We assume we aren't in the PATH, so we can derive our path.
        # We need our parent directory.
        LOFAR20_DIR_RELATIVE=$(dirname "$0")/..
    
        # As an absolute path
        LOFAR20_DIR=$(readlink -f "${LOFAR20_DIR_RELATIVE}")
    fi
    
    cd "$LOFAR20_DIR/docker-compose" || exit 1
    
    
    
    # Start the database server first
    make build databaseds dsconfig
    make start databaseds dsconfig
    
    # Give dsconfig and databaseds time to start
    sleep 1 # dsconfig container must be up and running...
    # shellcheck disable=SC2016
    echo '/usr/local/bin/wait-for-it.sh ${TANGO_HOST} --strict --timeout=300 -- true' | make run dsconfig bash -
    
    # Devices list is used to explitly word split when supplied to commands, must
    # disable shellcheck SC2086 for each case.
    DEVICES=(device-boot device-apsct device-ccd device-apspu device-sdp device-recv device-bst device-sst device-unb2 device-xst device-beamlet device-digitalbeam device-tilebeam device-psoc device-pcon device-antennafield device-temperature-manager device-observation device-observation-control device-configuration)
    
    SIMULATORS=(sdptr-sim recv-sim unb2-sim apsct-sim apspu-sim ccd-sim)
    
    # Build only the required images, please do not build everything that makes CI
    # take really long to finish, especially grafana / jupyter / prometheus.
    # jupyter is physically large > 2.5gb and overlayfs is really slow.
    
    make build "${DEVICES[@]}" "${SIMULATORS[@]}"
    # make build elk integration-test   # L2SS-970: elk temporarily disabled
    make build logstash integration-test schemas
    make build archiver-timescale hdbppts-cm hdbppts-es
    
    # Start and stop sequence
    make stop schemas
    make stop "${DEVICES[@]}" "${SIMULATORS[@]}" hdbppts-es hdbppts-cm archiver-timescale
    make stop device-docker # this one does not test well in docker-in-docker
    # make stop elk  # L2SS-970: elk temporarily disabled
    make stop logstash schemas
    
    # Run dummy integration test to install pytango in tox virtualenv without
    # the memory pressure of the ELK stack.
    # Alternatively this step can be avoided if we use:
    # `tox --sitepackages -e integration` for the integration docker container,
    # however, that does require creating a container specific integration job.
    # TODO(L2SS-992): Remove me and above documentation
    integration_test dummy
    
    # make start elk # L2SS-970: elk temporarily disabled
    make start logstash schemas
    
    # Update the dsconfig
    # Do not remove `bash`, otherwise statement ignored by gitlab ci shell!
    bash "${LOFAR20_DIR}"/sbin/update_ConfigDb.sh "${LOFAR20_DIR}"/CDB/LOFAR_ConfigDb.json
    bash "${LOFAR20_DIR}"/sbin/update_ConfigDb.sh "${LOFAR20_DIR}"/CDB/test_environment_ConfigDb.json
    bash "${LOFAR20_DIR}"/sbin/update_ConfigDb.sh "${LOFAR20_DIR}"/CDB/tango-archiver-data/archiver-devices.json
    bash "${LOFAR20_DIR}"/sbin/update_ConfigDb.sh "${LOFAR20_DIR}"/CDB/stations/simulators_ConfigDb.json
    bash "${LOFAR20_DIR}"/sbin/update_ConfigDb.sh "${LOFAR20_DIR}"/CDB/stations/dummy_positions_ConfigDb.json
    
    cd "$LOFAR20_DIR/docker-compose" || exit 1
    make start "${SIMULATORS[@]}"
    
    # Give the simulators time to start
    sleep 5
    
    # shellcheck disable=SC2086
    make start "${DEVICES[@]}"
    # Archive devices: archive-timescale first
    make start archiver-timescale
    
    # Wait for archiver and devices to restart
    make await archiver-timescale "${DEVICES[@]}"
    
    # Give archiver-timescale time to start
    # shellcheck disable=SC2016
    echo '/usr/local/bin/wait-for-it.sh archiver-timescale:5432 --strict --timeout=300 -- true' | make run dsconfig bash -
    
    # Archive devices: Now that archiver-timescale is up we can start the CM and ES
    make start hdbppts-cm hdbppts-es
    
    # Start the integration test
    cd "$LOFAR20_DIR/docker-compose" || exit 1
    make up integration-test
    
    integration_test default
    
    integration_test recv_cluster "device-recv device-tilebeam device-antennafield" "${LOFAR20_DIR}/CDB/integrations/recvcluster_ConfigDb.json"
    
    integration_test observations "archiver-timescale hdbppts-cm hdbppts-es" "${LOFAR20_DIR}/CDB/integrations/multiobs_ConfigDb.json"