github.com/sbuss/deis@v1.6.1/tests/bin/test-integration-ec2.sh (about)

     1  #!/bin/bash
     2  #
     3  # Preps a test environment and runs `make test-integration`
     4  # against artifacts produced from the current source tree
     5  #
     6  
     7  # fail on any command exiting non-zero
     8  set -eo pipefail
     9  
    10  # absolute path to current directory
    11  export THIS_DIR=$(cd $(dirname $0); pwd)
    12  
    13  # setup the test environment
    14  source $THIS_DIR/test-setup.sh
    15  
    16  # AWS credentials required for aws cli and boto
    17  export AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID?}
    18  export AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY?}
    19  
    20  # install python requirements for this script
    21  pip install awscli boto docopt
    22  
    23  function cleanup_ec2 {
    24      log_phase "Cleaning up"
    25      aws cloudformation delete-stack --stack-name $STACK_NAME
    26      python $DEIS_ROOT/contrib/ec2/route53-wildcard.py delete $DEIS_TEST_DOMAIN $ELB_DNS_NAME
    27  }
    28  
    29  # setup callbacks on process exit and error
    30  trap cleanup_ec2 EXIT
    31  trap dump_logs ERR
    32  
    33  log_phase "Running style tests"
    34  
    35  make test-style
    36  
    37  log_phase "Running documentation tests"
    38  
    39  # test building documentation
    40  make -C docs/ test
    41  
    42  log_phase "Running unit tests"
    43  
    44  make test-unit
    45  
    46  log_phase "Building from current source tree"
    47  
    48  # build all docker images and client binaries
    49  make build
    50  
    51  # use the built client binaries
    52  export PATH=$DEIS_ROOT/deisctl:$DEIS_ROOT/client/dist:$PATH
    53  
    54  log_phase "Running functional tests"
    55  
    56  make test-functional
    57  
    58  export DEIS_NUM_INSTANCES=3
    59  log_phase "Provisioning $DEIS_NUM_INSTANCES-node CoreOS"
    60  
    61  # TODO: don't hardcode --key-names
    62  if ! aws ec2 describe-key-pairs --key-names "deis" >/dev/null ; then
    63      echo "Importing $DEIS_TEST_AUTH_KEY keypair to EC2"
    64      aws ec2 import-key-pair --key-name deis \
    65          --public-key-material file://~/.ssh/$DEIS_TEST_AUTH_KEY.pub \
    66          --output text
    67  fi
    68  
    69  make discovery-url
    70  
    71  # customize cloudformation.json to use m3.medium instances
    72  cat > $DEIS_ROOT/contrib/ec2/cloudformation.json <<EOF
    73  [
    74      {
    75          "ParameterKey":     "KeyPair",
    76          "ParameterValue":   "deis"
    77      },
    78      {
    79          "ParameterKey":     "InstanceType",
    80          "ParameterValue":   "m3.medium"
    81      }
    82  ]
    83  EOF
    84  
    85  # add random characters after STACK_TAG to avoid collisions
    86  STACK_TAG=${STACK_TAG:-test}-$DEIS_TEST_ID
    87  STACK_NAME=deis-$STACK_TAG
    88  echo "Creating CloudFormation stack $STACK_NAME"
    89  $DEIS_ROOT/contrib/ec2/provision-ec2-cluster.sh $STACK_NAME
    90  
    91  # discard changes to cloudformation.json
    92  git checkout -- $DEIS_ROOT/contrib/ec2/cloudformation.json
    93  
    94  # use the first cluster node for now
    95  INSTANCE_IDS=$(aws ec2 describe-instances \
    96      --filters Name=tag:aws:cloudformation:stack-name,Values=$STACK_NAME Name=instance-state-name,Values=running \
    97      --query 'Reservations[].Instances[].[ InstanceId ]' \
    98      --output text)
    99  export INSTANCE_ID=$(cut -d " " -f1 <<< $INSTANCE_IDS)
   100  export DEISCTL_TUNNEL=$(aws ec2 describe-instances \
   101      --instance-ids=$INSTANCE_ID \
   102      --filters Name=tag:aws:cloudformation:stack-name,Values=$STACK_NAME Name=instance-state-name,Values=running \
   103      --query 'Reservations[].Instances[].[ PublicDnsName ]' \
   104      --output text)
   105  
   106  log_phase "Waiting for etcd/fleet at $DEISCTL_TUNNEL"
   107  
   108  # wait for etcd up to 5 minutes
   109  WAIT_TIME=1
   110  until deisctl --request-timeout=1 list >/dev/null 2>&1; do
   111     (( WAIT_TIME += 1 ))
   112     if [ $WAIT_TIME -gt 300 ]; then
   113      log_phase "Timeout waiting for etcd/fleet"
   114      # run deisctl one last time without eating the error, so we can see what's up
   115      deisctl --request-timeout=1 list
   116      exit 1;
   117    fi
   118  done
   119  
   120  log_phase "etcd available after $WAIT_TIME seconds"
   121  
   122  log_phase "Publishing release from source tree"
   123  
   124  # TODO: detect where IMAGE_PREFIX=deis/ and DEV_REGISTRY=registry.hub.docker.com
   125  # and disallow it so we can't pollute the production account.
   126  make dev-release
   127  
   128  log_phase "Provisioning Deis"
   129  
   130  export DEIS_TEST_DOMAIN=$STACK_TAG.$DEIS_TEST_DOMAIN
   131  
   132  # configure platform settings
   133  deisctl config platform set domain=$DEIS_TEST_DOMAIN
   134  deisctl config platform set sshPrivateKey=$DEIS_TEST_SSH_KEY
   135  
   136  time deisctl install platform
   137  time deisctl start platform
   138  
   139  # get ELB public DNS name through cloudformation
   140  # TODO: is "first output value" going to be reliable enough?
   141  ELB_DNS_NAME=$(aws cloudformation describe-stacks \
   142      --stack-name $STACK_NAME \
   143      --max-items 1 \
   144      --query 'Stacks[].[ Outputs[0].[ OutputValue ] ]' \
   145      --output=text)
   146  
   147  # get ELB friendly name through aws elb
   148  ELB_NAME=$(aws elb describe-load-balancers \
   149      --query 'LoadBalancerDescriptions[].[ DNSName,LoadBalancerName ]' \
   150      --output=text | grep -F $ELB_DNS_NAME | head -n1 | cut -f2)
   151  echo "Using ELB $ELB_NAME"
   152  
   153  # add or update a route53 alias record set to route queries to the ELB
   154  # this python script won't return until the wildcard domain is accessible
   155  python $DEIS_ROOT/contrib/ec2/route53-wildcard.py create $DEIS_TEST_DOMAIN $ELB_DNS_NAME
   156  
   157  # loop until at least one instance is "in service" with the ELB
   158  ATTEMPTS=45
   159  SLEEPTIME=10
   160  COUNTER=1
   161  IN_SERVICE=0
   162  until [ $IN_SERVICE -ge 1 ]; do
   163      if [ $COUNTER -gt $ATTEMPTS ]; then exit 1; fi  # timeout after 7 1/2 minutes
   164      if [ $COUNTER -ne 1 ]; then sleep $SLEEPTIME; fi
   165      echo "Waiting for ELB to see an instance in service..."
   166      IN_SERVICE=$(aws elb describe-instance-health \
   167          --load-balancer-name $ELB_NAME \
   168          --query 'InstanceStates[].State' \
   169          | grep InService | wc -l)
   170  done
   171  
   172  log_phase "Running integration suite"
   173  
   174  time make test-integration