|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +set -o errexit |
| 4 | +set -o nounset |
| 5 | + |
| 6 | +HERE="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
| 7 | +cd "$HERE/.." |
| 8 | + |
| 9 | + |
| 10 | +TEST_DIR=$(pwd)/container-test |
| 11 | +DOCKER_IMAGE="${DOCKER_IMAGE:-infrakit/devbundle}" |
| 12 | +DOCKER_TAG="${DOCKER_TAG:-dev}" |
| 13 | + |
| 14 | +cleanup() { |
| 15 | + docker ps | grep devbundle | awk '{print $1}' | xargs docker stop |
| 16 | + rm -rf $TEST_DIR |
| 17 | +} |
| 18 | +trap cleanup EXIT |
| 19 | + |
| 20 | +mkdir -p $TEST_DIR/plugins |
| 21 | +mkdir -p $TEST_DIR/tutorial |
| 22 | + |
| 23 | +volumes="-v $TEST_DIR:/root -v $PWD/docs:/root/docs" |
| 24 | + |
| 25 | +# set the environment variable to use a shorter path so we don't have |
| 26 | +# problems with Docker for Mac. See https://github.com/docker/docker/issues/23545 |
| 27 | +envs="-e INFRAKIT_PLUGINS_DIR=/root" |
| 28 | + |
| 29 | +server() { |
| 30 | + docker run -d --rm --name $1 $envs $volumes $DOCKER_IMAGE:$DOCKER_TAG $@ |
| 31 | +} |
| 32 | + |
| 33 | +run() { |
| 34 | + docker run --rm $envs $volumes $DOCKER_IMAGE:$DOCKER_TAG $@ |
| 35 | +} |
| 36 | + |
| 37 | +server infrakit-instance-file --dir /root/tutorial/ |
| 38 | +server infrakit-group-default --poll-interval 500ms |
| 39 | +server infrakit-flavor-vanilla |
| 40 | + |
| 41 | +sleep 1 |
| 42 | + |
| 43 | +expect_exact_output() { |
| 44 | + message=$1 |
| 45 | + cmd=$2 |
| 46 | + expected_output=$3 |
| 47 | + |
| 48 | + actual_output="$($2)" |
| 49 | + echo -n "--> $message: " |
| 50 | + if [ "$actual_output" = "$3" ] |
| 51 | + then |
| 52 | + echo 'PASS' |
| 53 | + else |
| 54 | + echo 'FAIL' |
| 55 | + echo "Expected output: $expected_output" |
| 56 | + echo "Actual output: $actual_output" |
| 57 | + exit 1 |
| 58 | + fi |
| 59 | +} |
| 60 | + |
| 61 | +expect_output_lines() { |
| 62 | + message=$1 |
| 63 | + cmd=$2 |
| 64 | + expected_lines=$3 |
| 65 | + |
| 66 | + actual_line_count=$($2 | wc -l) |
| 67 | + echo -n "--> $message: " |
| 68 | + if [ "$actual_line_count" -eq "$3" ] |
| 69 | + then |
| 70 | + echo 'PASS' |
| 71 | + else |
| 72 | + echo 'FAIL' |
| 73 | + echo "Expected line count: $expected_lines" |
| 74 | + echo "Actual line count: $actual_line_count" |
| 75 | + exit 1 |
| 76 | + fi |
| 77 | +} |
| 78 | + |
| 79 | +expect_output_lines "3 plugins should be discoverable" "run infrakit plugin ls -q" "3" |
| 80 | + |
| 81 | +expect_output_lines "0 instances should exist" "run infrakit instance describe -q --name instance-file" "0" |
| 82 | + |
| 83 | +run infrakit group commit /root/docs/cattle.json |
| 84 | + |
| 85 | +echo 'Waiting for group to be provisioned' |
| 86 | +sleep 2 |
| 87 | + |
| 88 | +expect_output_lines "5 instances should exist in group" "run infrakit group describe cattle -q" "5" |
| 89 | +expect_output_lines "5 instances should exist" "run infrakit instance describe -q --name instance-file" "5" |
| 90 | + |
| 91 | +run infrakit group free cattle |
| 92 | +run infrakit group commit /root/docs/cattle.json |
| 93 | + |
| 94 | +expect_exact_output "Should be watching one group" "run infrakit group ls -q" "cattle" |
| 95 | + |
| 96 | +expect_exact_output \ |
| 97 | + "Update should roll 5 and scale group to 10" \ |
| 98 | + "run infrakit group commit /root/docs/cattle2.json --pretend" \ |
| 99 | + "Committing cattle would involve: Performing a rolling update on 5 instances, then adding 5 instances to increase the group size to 10" |
| 100 | + |
| 101 | +run infrakit group commit /root/docs/cattle2.json |
| 102 | + |
| 103 | +sleep 5 |
| 104 | + |
| 105 | +expect_output_lines "10 instances should exist in group" "run infrakit group describe cattle -q" "10" |
| 106 | + |
| 107 | +# Terminate 3 instances. |
| 108 | +pushd $TEST_DIR/tutorial |
| 109 | + rm $(ls | head -3) |
| 110 | +popd |
| 111 | + |
| 112 | +sleep 5 |
| 113 | + |
| 114 | +expect_output_lines "10 instances should exist in group" "run infrakit group describe cattle -q" "10" |
| 115 | + |
| 116 | +run infrakit group destroy cattle |
| 117 | +expect_output_lines "0 instances should exist" "run infrakit instance describe -q --name instance-file" "0" |
| 118 | + |
| 119 | +echo 'ALL TESTS PASSED' |
0 commit comments