github.com/dmaizel/tests@v0.0.0-20210728163746-cae6a2d9cee8/integration/stability/agent_stability_test.sh (about)

     1  #!/bin/bash
     2  #
     3  # Copyright (c) 2018-2021 Intel Corporation
     4  #
     5  # SPDX-License-Identifier: Apache-2.0
     6  #
     7  # This test will perform several execs to a
     8  # running container, the main purpose of this
     9  # test is to stress the agent
    10  
    11  set -e -x
    12  
    13  cidir=$(dirname "$0")
    14  
    15  source "${cidir}/../../metrics/lib/common.bash"
    16  
    17  # Environment variables
    18  IMAGE="${IMAGE:-quay.io/prometheus/busybox:latest}"
    19  CONTAINER_NAME="${CONTAINER_NAME:-test}"
    20  PAYLOAD_ARGS="${PAYLOAD_ARGS:-tail -f /dev/null}"
    21  
    22  
    23  # Timeout is the duration of this test (seconds)
    24  # We want to stress the agent for a significant
    25  # time (approximately running for two days)
    26  timeout=186400
    27  start_time=$(date +%s)
    28  end_time=$((start_time+timeout))
    29  
    30  function setup {
    31  	sudo systemctl restart containerd
    32  	clean_env_ctr
    33  	sudo ctr image pull $IMAGE
    34  	sudo ctr run --runtime=$CONTAINERD_RUNTIME -d $IMAGE $CONTAINER_NAME sh -c $PAYLOAD_ARGS
    35  }
    36  
    37  function exec_loop {
    38  	cmd="sudo ctr t exec --exec-id 1 $CONTAINER_NAME sh -c"
    39  	$cmd "echo 'hello world' > file"
    40  	$cmd "rm -rf /file"
    41  	$cmd "touch /tmp/execWorks"
    42  	$cmd "ls /tmp | grep execWorks"
    43  	$cmd "rm -rf /tmp/execWorks"
    44  	$cmd "ls /etc/foo" || echo "Fail expected"
    45  	$cmd "cat /tmp/one" || echo "Fail expected"
    46  	$cmd "exit 42" || echo "Fail expected"
    47  }
    48  
    49  function teardown {
    50  	clean_env_ctr
    51  }
    52  
    53  echo "Starting stability test"
    54  setup
    55  
    56  echo "Running stability test"
    57  while [[ $end_time > $(date +%s) ]]; do
    58  	exec_loop
    59  done
    60  
    61  echo "Ending stability test"
    62  teardown