aoh

A tool for running Ansible playbooks with `curl <url> | python` commands
git clone https://git.ashermorgan.net/aoh/
Log | Files | Refs | README

run.sh (3931B)


      1 #!/bin/bash
      2 
      3 set -e
      4 
      5 cd $(dirname $0)
      6 
      7 DOCKER=${DOCKER:-docker} # Set DOCKER=podman to use podman instead of docker
      8 
      9 function on_exit() {
     10     echo 'Cleaning up...'
     11     if [ $($DOCKER ps --filter name=aoh-test-client | wc -l) -gt 1 ]; then
     12         $DOCKER stop aoh-test-client
     13     fi
     14     if [ $($DOCKER ps --filter name=aoh-test-server | wc -l) -gt 1 ]; then
     15         $DOCKER stop aoh-test-server
     16     fi
     17 }
     18 trap on_exit EXIT
     19 
     20 $DOCKER build -t aoh-test-client -f client.Dockerfile .
     21 $DOCKER build -t aoh-test-server ../../
     22 if [ $($DOCKER network ls --filter name=aoh-test | wc -l) -eq 1 ]; then
     23     $DOCKER network create aoh-test
     24 fi
     25 
     26 for i in {1..6}; do
     27     echo ================================
     28     echo Running test$i.yml...
     29     echo ================================
     30 
     31     if [ "$i" -eq 6 ]; then
     32         # Test 6 is different: start a long-running playbook, kill the client,
     33         # and then check to make sure that server cleans everything up
     34         $DOCKER run --rm --network aoh-test --detach -h aoh-test-server \
     35             --name aoh-test-server -v ./:/aoh \
     36             -e AOH_GC_INTERVAL=1 -e AOH_GC_THRESHOLD=1 aoh-test-server
     37         sleep 1
     38         $DOCKER run --rm --network aoh-test --detach --name aoh-test-client \
     39             aoh-test-client bash -c \
     40             "curl http://aoh-test-server:8000/run | python3 - test$i.yml"
     41 
     42         for j in {1..10}; do
     43             if $DOCKER exec aoh-test-server sh -c \
     44                 'find /tmp -maxdepth 1 -type d -name "aoh-*" -print -quit | \
     45                 grep -q . && ps -eo comm | grep -qx ansible-playboo'
     46             then
     47                 break
     48             elif [ "$j" -eq 10 ]; then
     49                 echo Timed out waiting for server to start runner
     50                 $DOCKER exec aoh-test-server sh -c \
     51                     'find /tmp -maxdepth 1 -type d -name "aoh-*" -print -quit; \
     52                     ps -eo comm'
     53                 echo ================================
     54                 echo test$i.yml failed.
     55                 echo ================================
     56                 exit 1
     57             else
     58                 sleep 1
     59             fi
     60         done
     61 
     62         sleep 1
     63         $DOCKER stop aoh-test-client
     64 
     65         for j in {1..10}; do
     66             if $DOCKER exec aoh-test-server sh -c \
     67                 '! find /tmp -maxdepth 1 -type d -name "aoh-*" -print -quit | \
     68                 grep -q . && ! ps -eo comm | grep -qx ansible-playboo'
     69             then
     70                 echo ================================
     71                 echo test$i.yml passed.
     72                 echo ================================
     73                 break
     74             elif [ "$j" -eq 10 ]; then
     75                 echo Timed out waiting for server to clean up runner
     76                 $DOCKER exec aoh-test-server sh -c \
     77                     'find /tmp -maxdepth 1 -type d -name "aoh-*" -print -quit; \
     78                     ps -eo comm'
     79                 echo ================================
     80                 echo test$i.yml failed.
     81                 echo ================================
     82                 exit 1
     83             else
     84                 sleep 1
     85             fi
     86         done
     87 
     88         $DOCKER stop aoh-test-server
     89         sleep 1
     90 
     91         continue
     92     fi
     93 
     94     $DOCKER run --rm --network aoh-test --detach -h aoh-test-server \
     95         --name aoh-test-server -v ./:/aoh aoh-test-server
     96     sleep 1
     97 
     98     if $DOCKER run --rm --network aoh-test --tty aoh-test-client bash -c \
     99         "curl http://aoh-test-server:8000/run | python3 - test$i.yml"
    100     then
    101         echo ================================
    102         echo test$i.yml passed.
    103         echo ================================
    104         echo
    105     else
    106         echo ================================
    107         echo test$i.yml failed.
    108         echo ================================
    109         exit 1
    110     fi
    111 
    112     $DOCKER stop aoh-test-server
    113     sleep 1
    114 done
    115 
    116 echo ================================
    117 echo All tests passed.
    118 echo ================================