Skip to content

Commit

Permalink
upgrade to consul ~0.7.0 (#248)
Browse files Browse the repository at this point in the history
  • Loading branch information
flyinprogrammer authored and tgross committed Nov 21, 2016
1 parent 936a5ac commit d93c156
Show file tree
Hide file tree
Showing 21 changed files with 138 additions and 46 deletions.
12 changes: 9 additions & 3 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion glide.yaml
Expand Up @@ -21,7 +21,7 @@ import:
subpackages:
- proto
- package: github.com/hashicorp/consul
version: 158eabdd6f2408067c1d7656fa10e49434f96480
version: ~0.7.0
subpackages:
- api
- package: github.com/matttproud/golang_protobuf_extensions
Expand Down
7 changes: 3 additions & 4 deletions integration_tests/README.md
Expand Up @@ -4,15 +4,15 @@

- To run integration tests:

`make integration` or `./test.sh test`
`make integration` or `./scripts/test.sh test`

- To run a single integration test:

`./test.sh test test_name`
`./scripts/test.sh test test_name`

- To clean fixtures. Next time tests are run they will be rebuilt.

`make clean` or `./test.sh clean`
`make clean` or `./scripts/test.sh clean`

## Making Tests

Expand Down Expand Up @@ -41,7 +41,6 @@ This script can make some assumptions:
- Following environment variables are set:
- `COMPOSE_FILE`
- `COMPOSE_PROJECT_NAME` - The name of the test folder
- `DOCKER_IP` - The IP of docker on the host machine
- `CONTAINERPILOT_BIN` - Absolute path to containerpilot binary on the host.
- all fixtures in `integration_tests/fixtures` are created and are available as images

Expand Down
4 changes: 2 additions & 2 deletions integration_tests/fixtures/consul/Dockerfile
@@ -1,3 +1,3 @@
FROM progrium/consul:latest
FROM consul:latest

EXPOSE 53 8300 8301 8302 8400 8500 8600
CMD ["agent","-dev","-client","0.0.0.0","-bind","0.0.0.0"]
8 changes: 0 additions & 8 deletions integration_tests/fixtures/consul/config/server.json

This file was deleted.

34 changes: 22 additions & 12 deletions integration_tests/fixtures/test_probe/src/consul.go
Expand Up @@ -2,15 +2,17 @@ package main

import (
"fmt"
consul "github.com/hashicorp/consul/api"
"time"

consul "github.com/hashicorp/consul/api"
)

const consulAddress = "consul:8500"

// ConsulProbe is a test probe for consul
type ConsulProbe interface {
WaitForServices(service string, tag string, count int) error
WaitForLeader() error
}

type consulClient struct {
Expand All @@ -37,20 +39,11 @@ func (c consulClient) WaitForServices(service string, tag string, count int) err
retry := 0
var err error

// we need to wait for Consul to start and self-elect
for ; retry < maxRetry; retry++ {
if retry > 0 {
time.Sleep(1 * time.Second)
}
if leader, err := c.Client.Status().Leader(); err == nil && leader != "" {
break
}
}
err = c.WaitForLeader()
if err != nil {
return err
return fmt.Errorf("Consul could not elect leader")
}

retry = 0
for ; retry < maxRetry; retry++ {
if retry > 0 {
time.Sleep(1 * time.Second)
Expand All @@ -65,3 +58,20 @@ func (c consulClient) WaitForServices(service string, tag string, count int) err
}
return fmt.Errorf("Service %s (tag:%s) count != %d", service, tag, count)
}

func (c consulClient) WaitForLeader() error {
maxRetry := 30
retry := 0
var err error

// we need to wait for Consul to start and self-elect
for ; retry < maxRetry; retry++ {
if retry > 0 {
time.Sleep(1 * time.Second)
}
if leader, err := c.Client.Status().Leader(); err == nil && leader != "" {
break
}
}
return err
}
7 changes: 4 additions & 3 deletions integration_tests/fixtures/test_probe/src/main.go
Expand Up @@ -14,11 +14,12 @@ var AllTests map[string]TestCommand
func runTest(testName string, args []string) {
// Register Tests
AllTests = map[string]TestCommand{
"test_sigterm": TestSigterm,
"test_consul": TestConsul,
"test_discovery": TestDiscovery,
"test_sighup_deadlock": TestSighupDeadlock,
"test_sigusr1_prestart": TestSigUsr1Prestart,
"test_sighup_prestart": TestSigHupPrestart,
"test_discovery": TestDiscovery,
"test_sigterm": TestSigterm,
"test_sigusr1_prestart": TestSigUsr1Prestart,
}

if test := AllTests[testName]; test != nil {
Expand Down
19 changes: 19 additions & 0 deletions integration_tests/fixtures/test_probe/src/test_consul.go
@@ -0,0 +1,19 @@
package main

import "log"

// TestConsul test that consul has elected a leader
func TestConsul(args []string) bool {
consul, err := NewConsulProbe()
if err != nil {
log.Printf("Expected to be able to create consul client before the test starts: %s\n", err)
return false
}

err = consul.WaitForLeader()
if err != nil {
log.Printf("Expected consul to elect leader before the test starts: %s\n", err)
return false
}
return true
}
9 changes: 9 additions & 0 deletions integration_tests/tests/test_coprocess/docker-compose.yml
Expand Up @@ -14,3 +14,12 @@ app:
- '${CONTAINERPILOT_BIN}:/bin/containerpilot:ro'
- './containerpilot.json:/etc/containerpilot.json'
- './coprocess.sh:/bin/coprocess.sh'

test:
image: "cpfix_test_probe"
mem_limit: 128m
links:
- consul:consul
- app:app
volumes:
- '/var/run/docker.sock:/var/run/docker.sock'
4 changes: 4 additions & 0 deletions integration_tests/tests/test_coprocess/run.sh
Expand Up @@ -16,6 +16,10 @@ trap finish EXIT

docker-compose up -d

# Wait for consul to elect a leader
docker-compose run --no-deps test /go/bin/test_probe test_consul > /dev/null 2>&1
if [ ! $? -eq 0 ] ; then exit 1 ; fi

ID=$(docker ps -l -f "ancestor=cpfix_app" --format="{{.ID}}")

# verify the coprocess is running
Expand Down
6 changes: 5 additions & 1 deletion integration_tests/tests/test_discovery_consul/run.sh
Expand Up @@ -3,7 +3,11 @@
# start up consul, app, nginx and then wait
# this can take a while to converge
docker-compose up -d consul
sleep 2

# Wait for consul to elect a leader
docker-compose run --no-deps test /go/bin/test_probe test_consul > /dev/null 2>&1
if [ ! $? -eq 0 ] ; then exit 1 ; fi

docker-compose up -d app nginx > /dev/null 2>&1
sleep 5

Expand Down
9 changes: 9 additions & 0 deletions integration_tests/tests/test_reap_zombies/docker-compose.yml
Expand Up @@ -10,3 +10,12 @@ app:
- consul:consul
volumes:
- '${CONTAINERPILOT_BIN}:/bin/containerpilot:ro'

test:
image: "cpfix_test_probe"
mem_limit: 128m
links:
- consul:consul
- app:app
volumes:
- '/var/run/docker.sock:/var/run/docker.sock'
5 changes: 5 additions & 0 deletions integration_tests/tests/test_reap_zombies/run.sh
Expand Up @@ -6,6 +6,11 @@
# reparenting mechanism.

docker-compose up -d consul app > /dev/null 2>&1

# Wait for consul to elect a leader
docker-compose run --no-deps test /go/bin/test_probe test_consul > /dev/null 2>&1
if [ ! $? -eq 0 ] ; then exit 1 ; fi

APP_ID="$(docker-compose ps -q app)"
sleep 6

Expand Down
5 changes: 5 additions & 0 deletions integration_tests/tests/test_sighup_deadlock/run.sh
@@ -1,6 +1,11 @@
#!/bin/bash

docker-compose up -d consul app

# Wait for consul to elect a leader
docker-compose run --no-deps test /go/bin/test_probe test_consul > /dev/null 2>&1
if [ ! $? -eq 0 ] ; then exit 1 ; fi

APP_ID="$(docker-compose ps -q app)"
docker-compose run --no-deps test /go/bin/test_probe test_sighup_deadlock $APP_ID > /dev/null 2>&1
result=$?
Expand Down
5 changes: 5 additions & 0 deletions integration_tests/tests/test_sighup_prestart/run.sh
@@ -1,6 +1,11 @@
#!/bin/bash

docker-compose up -d consul app

# Wait for consul to elect a leader
docker-compose run --no-deps test /go/bin/test_probe test_consul > /dev/null 2>&1
if [ ! $? -eq 0 ] ; then exit 1 ; fi

APP_ID="$(docker-compose ps -q app)"
docker-compose run --no-deps test /go/bin/test_probe test_sighup_prestart $APP_ID > /dev/null 2>&1
result=$?
Expand Down
5 changes: 5 additions & 0 deletions integration_tests/tests/test_sigterm/run.sh
@@ -1,6 +1,11 @@
#!/bin/bash

docker-compose up -d consul app > /dev/null 2>&1

# Wait for consul to elect a leader
docker-compose run --no-deps test /go/bin/test_probe test_consul > /dev/null 2>&1
if [ ! $? -eq 0 ] ; then exit 1 ; fi

APP_ID="$(docker-compose ps -q app)"
docker-compose run --no-deps test /go/bin/test_probe test_sigterm $APP_ID > /dev/null 2>&1
result=$?
Expand Down
9 changes: 9 additions & 0 deletions integration_tests/tests/test_tasks/docker-compose.yml
Expand Up @@ -12,3 +12,12 @@ app:
- 9090:9090
volumes:
- '${CONTAINERPILOT_BIN}:/bin/containerpilot:ro'

test:
image: "cpfix_test_probe"
mem_limit: 128m
links:
- consul:consul
- app:app
volumes:
- '/var/run/docker.sock:/var/run/docker.sock'
6 changes: 5 additions & 1 deletion integration_tests/tests/test_tasks/run.sh
Expand Up @@ -2,7 +2,11 @@

# start up consul and app
docker-compose up -d consul
sleep 2

# Wait for consul to elect a leader
docker-compose run --no-deps test /go/bin/test_probe test_consul > /dev/null 2>&1
if [ ! $? -eq 0 ] ; then exit 1 ; fi

docker-compose up -d app

APP_ID="$(docker-compose ps -q app)"
Expand Down
9 changes: 9 additions & 0 deletions integration_tests/tests/test_telemetry/docker-compose.yml
Expand Up @@ -12,3 +12,12 @@ app:
- 9090:9090
volumes:
- '${CONTAINERPILOT_BIN}:/bin/containerpilot:ro'

test:
image: "cpfix_test_probe"
mem_limit: 128m
links:
- consul:consul
- app:app
volumes:
- '/var/run/docker.sock:/var/run/docker.sock'
6 changes: 5 additions & 1 deletion integration_tests/tests/test_telemetry/run.sh
Expand Up @@ -11,7 +11,11 @@ trap finish EXIT

# start up consul and app
docker-compose up -d consul
sleep 2

# Wait for consul to elect a leader
docker-compose run --no-deps test /go/bin/test_probe test_consul > /dev/null 2>&1
if [ ! $? -eq 0 ] ; then exit 1 ; fi

docker-compose up -d app

APP_ID="$(docker-compose ps -q app)"
Expand Down
13 changes: 3 additions & 10 deletions scripts/test.sh
Expand Up @@ -37,16 +37,6 @@ docker_running() {
if [ ! -d $FIXTURE_DIR ]; then die "Unable to find fixtures: $FIXTURE_DIR"; fi
if [ ! -d $TESTS_DIR ]; then die "Unable to find tests: $TESTS_DIR"; fi

DOCKER_IP=127.0.0.1
if which docker-machine > /dev/null; then
DOCKER_MACHINE_ACTIVE=$(docker-machine active)
DOCKER_IP=$(docker-machine ip $DOCKER_MACHINE_ACTIVE)
fi

## Log settings
export DOCKER_IP
debug "DOCKER_IP=$DOCKER_IP"

export FIXTURE_PREFIX=${FIXTURE_PREFIX:-"cpfix_"}
debug "FIXTURE_PREFIX=$FIXTURE_PREFIX"

Expand Down Expand Up @@ -159,6 +149,9 @@ clean_tests() {
COMMAND=${1:-"test"}
shift
case $COMMAND in
create_test_fixtures)
create_test_fixtures
;;
test)
create_test_fixtures
run_tests "$1"
Expand Down

0 comments on commit d93c156

Please sign in to comment.