add events to mesos and a few tests

Signed-off-by: Victor Vieux <vieux@docker.com>
This commit is contained in:
Victor Vieux 2015-07-14 14:20:17 -07:00
parent 6ecab7f5b7
commit f00e6aa967
11 changed files with 187 additions and 53 deletions

View File

@ -137,6 +137,17 @@ func NewCluster(scheduler *scheduler.Scheduler, store *state.Store, TLSConfig *t
return cluster, nil
}
// Handle callbacks for the events
func (c *Cluster) Handle(e *cluster.Event) error {
if c.eventHandler == nil {
return nil
}
if err := c.eventHandler.Handle(e); err != nil {
log.Error(err)
}
return nil
}
// RegisterEventHandler registers an event handler.
func (c *Cluster) RegisterEventHandler(h cluster.EventHandler) error {
if c.eventHandler != nil {

View File

@ -49,6 +49,9 @@ func (c *Cluster) ResourceOffers(_ mesosscheduler.SchedulerDriver, offers []*mes
} else {
s = newSlave(slaveID, engine)
c.slaves[slaveID] = s
if err := s.engine.RegisterEventHandler(c); err != nil {
log.Error(err)
}
}
}
c.addOffer(offer)

View File

@ -7,17 +7,4 @@ function teardown() {
stop_docker
}
@test "docker build" {
start_docker 2
swarm_manage
run docker_swarm images -q
[ "$status" -eq 0 ]
[ "${#lines[@]}" -eq 0 ]
docker_swarm build -t test $TESTDATA/build
run docker_swarm images -q
[ "$status" -eq 0 ]
[ "${#lines[@]}" -eq 1 ]
}

View File

@ -8,10 +8,10 @@ function teardown() {
}
@test "docker info" {
start_docker 1 --label foo=bar
start_docker 2 --label foo=bar
swarm_manage
run docker_swarm info
[ "$status" -eq 0 ]
[[ "${output}" == *"Nodes: 1"* ]]
[[ "${output}" == *"Nodes: 2"* ]]
[[ "${output}" == *"└ Labels:"*"foo=bar"* ]]
}

View File

@ -1,37 +0,0 @@
#!/usr/bin/env bats
load mesos_helpers
function teardown() {
swarm_manage_cleanup
stop_mesos
stop_docker
}
@test "docker info" {
start_docker 2
start_mesos
swarm_manage_mesos
run docker_swarm info
[ "$status" -eq 0 ]
[[ "${output}" == *'Offers: 2'* ]]
}
@test "docker run no resources" {
start_docker 1
start_mesos
swarm_manage_mesos
run docker_swarm run -d busybox ls
[ "$status" -ne 0 ]
[[ "${output}" == *'resources constraints (-c and/or -m) are required by mesos'* ]]
}
@test "docker run" {
start_docker_with_busybox 1
start_mesos
swarm_manage_mesos
docker_swarm run -d -m 20m busybox ls
docker_swarm run -d -m 20m busybox ls
}

View File

@ -0,0 +1,25 @@
#!/usr/bin/env bats
load ../mesos_helpers
function teardown() {
swarm_manage_cleanup
stop_mesos
stop_docker
}
@test "mesos - docker build" {
start_docker 2
start_mesos
swarm_manage_mesos
run docker_swarm images -q
[ "$status" -eq 0 ]
[ "${#lines[@]}" -eq 0 ]
docker_swarm build -t test $TESTDATA/build
run docker_swarm images -q
[ "$status" -eq 0 ]
[ "${#lines[@]}" -eq 1 ]
}

View File

@ -0,0 +1,35 @@
#!/usr/bin/env bats
load ../mesos_helpers
function teardown() {
swarm_manage_cleanup
stop_mesos
stop_docker
}
@test "mesos - docker commit" {
start_docker_with_busybox 2
start_mesos
swarm_manage_mesos
docker_swarm run -d -m 20m --name test_container busybox sleep 500
# make sure container exists
run docker_swarm ps -l
[ "${#lines[@]}" -eq 2 ]
[[ "${lines[1]}" == *"test_container"* ]]
# no comming name before commit
run docker_swarm images
[ "$status" -eq 0 ]
[[ "${output}" != *"commit_image_busybox"* ]]
# commit container
docker_swarm commit test_container commit_image_busybox
# verify after commit
run docker_swarm images
[ "$status" -eq 0 ]
[[ "${output}" == *"commit_image_busybox"* ]]
}

View File

@ -0,0 +1,40 @@
#!/usr/bin/env bats
load ../mesos_helpers
function teardown() {
swarm_manage_cleanup
stop_mesos
stop_docker
}
@test "docker events" {
start_docker_with_busybox 2
start_mesos
swarm_manage_mesos
# start events, report real time events to $log_file
local log_file=$(mktemp)
docker_swarm events > "$log_file" &
local events_pid="$!"
# This should emit 3 events: create, start, die.
docker_swarm run -m 20m --name test_container -e constraint:node==node-0 busybox true
# events might take a little big to show up, wait until we get the last one.
retry 5 0.5 grep -q "die" "$log_file"
# clean up `docker events`
kill "$events_pid"
# verify
run cat "$log_file"
[ "$status" -eq 0 ]
[[ "${output}" == *"node:node-0"* ]]
[[ "${output}" == *"create"* ]]
[[ "${output}" == *"start"* ]]
[[ "${output}" == *"die"* ]]
# after ok, remove the log file
rm -f "$log_file"
}

View File

@ -0,0 +1,18 @@
#!/usr/bin/env bats
load ../mesos_helpers
function teardown() {
swarm_manage_cleanup
stop_mesos
stop_docker
}
@test "mesos - docker info" {
start_docker 2
start_mesos
swarm_manage_mesos
run docker_swarm info
[ "$status" -eq 0 ]
[[ "${output}" == *'Offers: 2'* ]]
}

View File

@ -0,0 +1,52 @@
#!/usr/bin/env bats
load ../mesos_helpers
function teardown() {
swarm_manage_cleanup
stop_mesos
stop_docker
}
@test "mesos - docker run" {
start_docker_with_busybox 2
start_mesos
swarm_manage_mesos
# make sure no container exist
run docker_swarm ps -qa
[ "${#lines[@]}" -eq 0 ]
# run
docker_swarm run -m 20m -d --name test_container busybox sleep 100
# verify, container is running
[ -n $(docker_swarm ps -q --filter=name=test_container --filter=status=running) ]
# error check
run docker_swarm run -m 20m -d 4e8aa3148a132f19ec560952231c4d39522043994df7d2dc239942c0f9424ebd
[[ "${output}" == *"cannot specify 64-byte hexadecimal strings"* ]]
}
@test "mesos - docker run no resources" {
start_docker 1
start_mesos
swarm_manage_mesos
run docker_swarm run -d busybox ls
[ "$status" -ne 0 ]
[[ "${output}" == *'resources constraints (-c and/or -m) are required by mesos'* ]]
}
@test "mesos - docker run big" {
start_docker_with_busybox 3
start_mesos
swarm_manage_mesos
for i in `seq 1 100`; do
docker_swarm run -d -m 20m busybox echo $i
done
run docker_swarm ps -aq
[ "${#lines[@]}" -eq 100 ]
}

View File

@ -1,6 +1,6 @@
#!/bin/bash
load ../helpers
load ../../helpers
MESOS_IMAGE=jimenez/mesos-dev:clang
MESOS_MASTER_PORT=$(( ( RANDOM % 1000 ) + 10000 ))