go.ligato.io/vpp-agent/v3@v3.5.0/scripts/test_examples.sh (about)

     1  #!/usr/bin/env bash
     2  
     3  TMP_FILE="/tmp/out"
     4  exitCode=0
     5  PREV_IFS="$IFS"
     6  
     7  # test whether output of the command contains expected lines
     8  # arguments
     9  # 1-st command to run
    10  # 2-nd array of expected strings in the
    11  
    12  function testOutput {
    13  IFS="${PREV_IFS}"
    14  
    15      #run the command
    16      $1 > ${TMP_FILE} 2>&1
    17  
    18  IFS="
    19  "
    20      echo "Testing $1"
    21      rv=0
    22      # loop through expected lines
    23      for i in $2
    24      do
    25          if grep "${i}" /tmp/out > /dev/null ; then
    26              echo "OK - '$i'"
    27          else
    28              echo "Not found - '$i'"
    29              rv=1
    30          fi
    31      done
    32  
    33      # if an error occurred print the output
    34      if [[ ! $rv -eq 0 ]] ; then
    35          cat ${TMP_FILE}
    36          exitCode=1
    37      fi
    38  
    39      echo "================================================================"
    40      rm ${TMP_FILE}
    41      return ${rv}
    42  }
    43  
    44  function startEtcd {
    45      docker run -p 2379:2379 --name etcd -d -e ETCDCTL_API=3 \
    46          quay.io/coreos/etcd:v3.1.0 /usr/local/bin/etcd \
    47               -advertise-client-urls http://0.0.0.0:2379 \
    48                   -listen-client-urls http://0.0.0.0:2379 > /dev/null
    49      # dump etcd content to make sure that etcd is ready
    50      docker exec etcd etcdctl get --prefix ""
    51  }
    52  
    53  function stopEtcd {
    54      docker stop etcd > /dev/null
    55      docker rm etcd > /dev/null
    56  }
    57  
    58  function startKafka {
    59      docker run -p 2181:2181 -p 9092:9092 --name kafka -d \
    60   --env ADVERTISED_HOST=0.0.0.0 --env ADVERTISED_PORT=9092 spotify/kafka > /dev/null
    61      # list kafka topics to ensure that kafka is ready
    62      docker exec kafka  /opt/kafka_2.11-0.10.1.0/bin/kafka-topics.sh --list --zookeeper localhost:2181 > /dev/null 2> /dev/null
    63  
    64  }
    65  
    66  function stopKafka {
    67      docker stop kafka > /dev/null
    68      docker rm kafka > /dev/null
    69  }
    70  
    71  function startVPP {
    72    /usr/bin/vpp "unix { nodaemon cli-listen 0.0.0.0:5002 cli-no-pager } plugins { plugin dpdk_plugin.so {disable}}" &
    73  }
    74  #### Local client #############################################################
    75  
    76  expected=("All plugins initialized successfully
    77  Successfully applied initial Linux&VPP configuration
    78  Successfully reconfigured Linux&VPP
    79  ")
    80  
    81  startVPP
    82  cmd="examples/localclient_linux/localclient_linux  "
    83  testOutput "${cmd}" "${expected}"
    84  
    85  
    86  ########################################################################
    87  
    88  exit ${exitCode}