2014-11-20 00:19:16 -05:00
// +build !windows
package main
import (
"bufio"
2016-08-25 13:29:10 -04:00
"bytes"
2014-11-20 00:19:16 -05:00
"fmt"
"io/ioutil"
"os"
"os/exec"
2015-09-11 06:01:47 -04:00
"strings"
"time"
2014-11-20 00:19:16 -05:00
"unicode"
2016-12-30 12:23:00 -05:00
"github.com/docker/docker/integration-cli/checker"
2017-03-23 13:35:22 -04:00
"github.com/docker/docker/integration-cli/cli/build"
2015-04-18 12:46:47 -04:00
"github.com/go-check/check"
2014-11-20 00:19:16 -05:00
"github.com/kr/pty"
2017-05-23 10:22:32 -04:00
"golang.org/x/sys/unix"
2014-11-20 00:19:16 -05:00
)
// #5979
2015-04-18 12:46:47 -04:00
func ( s * DockerSuite ) TestEventsRedirectStdout ( c * check . C ) {
2016-04-11 14:52:34 -04:00
since := daemonUnixTime ( c )
2015-04-18 12:46:47 -04:00
dockerCmd ( c , "run" , "busybox" , "true" )
2014-11-20 00:19:16 -05:00
file , err := ioutil . TempFile ( "" , "" )
2015-10-19 19:15:24 -04:00
c . Assert ( err , checker . IsNil , check . Commentf ( "could not create temp file" ) )
2014-11-20 00:19:16 -05:00
defer os . Remove ( file . Name ( ) )
2016-04-11 14:52:34 -04:00
command := fmt . Sprintf ( "%s events --since=%s --until=%s > %s" , dockerBinary , since , daemonUnixTime ( c ) , file . Name ( ) )
2014-11-20 00:19:16 -05:00
_ , tty , err := pty . Open ( )
2015-10-19 19:15:24 -04:00
c . Assert ( err , checker . IsNil , check . Commentf ( "Could not open pty" ) )
2014-11-20 00:19:16 -05:00
cmd := exec . Command ( "sh" , "-c" , command )
cmd . Stdin = tty
cmd . Stdout = tty
cmd . Stderr = tty
2015-10-19 19:15:24 -04:00
c . Assert ( cmd . Run ( ) , checker . IsNil , check . Commentf ( "run err for command %q" , command ) )
2014-11-20 00:19:16 -05:00
scanner := bufio . NewScanner ( file )
for scanner . Scan ( ) {
2015-04-18 12:46:47 -04:00
for _ , ch := range scanner . Text ( ) {
2015-10-19 19:15:24 -04:00
c . Assert ( unicode . IsControl ( ch ) , checker . False , check . Commentf ( "found control character %v" , [ ] byte ( string ( ch ) ) ) )
2014-11-20 00:19:16 -05:00
}
}
2015-10-19 19:15:24 -04:00
c . Assert ( scanner . Err ( ) , checker . IsNil , check . Commentf ( "Scan err for command %q" , command ) )
2014-11-20 00:19:16 -05:00
}
2015-09-11 06:01:47 -04:00
func ( s * DockerSuite ) TestEventsOOMDisableFalse ( c * check . C ) {
2016-08-24 06:09:35 -04:00
testRequires ( c , DaemonIsLinux , oomControl , memoryLimitSupport , swapMemorySupport )
2015-09-11 06:01:47 -04:00
errChan := make ( chan error )
go func ( ) {
defer close ( errChan )
out , exitCode , _ := dockerCmdWithError ( "run" , "--name" , "oomFalse" , "-m" , "10MB" , "busybox" , "sh" , "-c" , "x=a; while true; do x=$x$x$x$x; done" )
if expected := 137 ; exitCode != expected {
errChan <- fmt . Errorf ( "wrong exit code for OOM container: expected %d, got %d (output: %q)" , expected , exitCode , out )
}
} ( )
select {
case err := <- errChan :
2015-10-19 19:15:24 -04:00
c . Assert ( err , checker . IsNil )
2015-09-11 06:01:47 -04:00
case <- time . After ( 30 * time . Second ) :
c . Fatal ( "Timeout waiting for container to die on OOM" )
}
2016-04-11 14:52:34 -04:00
out , _ := dockerCmd ( c , "events" , "--since=0" , "-f" , "container=oomFalse" , "--until" , daemonUnixTime ( c ) )
2015-09-11 06:01:47 -04:00
events := strings . Split ( strings . TrimSuffix ( out , "\n" ) , "\n" )
2015-12-21 17:55:23 -05:00
nEvents := len ( events )
c . Assert ( nEvents , checker . GreaterOrEqualThan , 5 ) //Missing expected event
c . Assert ( parseEventAction ( c , events [ nEvents - 5 ] ) , checker . Equals , "create" )
c . Assert ( parseEventAction ( c , events [ nEvents - 4 ] ) , checker . Equals , "attach" )
c . Assert ( parseEventAction ( c , events [ nEvents - 3 ] ) , checker . Equals , "start" )
c . Assert ( parseEventAction ( c , events [ nEvents - 2 ] ) , checker . Equals , "oom" )
c . Assert ( parseEventAction ( c , events [ nEvents - 1 ] ) , checker . Equals , "die" )
2015-09-11 06:01:47 -04:00
}
func ( s * DockerSuite ) TestEventsOOMDisableTrue ( c * check . C ) {
2016-08-24 06:09:35 -04:00
testRequires ( c , DaemonIsLinux , oomControl , memoryLimitSupport , NotArm , swapMemorySupport )
2015-09-11 06:01:47 -04:00
errChan := make ( chan error )
2016-01-23 22:27:39 -05:00
observer , err := newEventObserver ( c )
c . Assert ( err , checker . IsNil )
err = observer . Start ( )
c . Assert ( err , checker . IsNil )
defer observer . Stop ( )
2015-09-11 06:01:47 -04:00
go func ( ) {
defer close ( errChan )
out , exitCode , _ := dockerCmdWithError ( "run" , "--oom-kill-disable=true" , "--name" , "oomTrue" , "-m" , "10MB" , "busybox" , "sh" , "-c" , "x=a; while true; do x=$x$x$x$x; done" )
if expected := 137 ; exitCode != expected {
errChan <- fmt . Errorf ( "wrong exit code for OOM container: expected %d, got %d (output: %q)" , expected , exitCode , out )
}
} ( )
2016-01-23 22:27:39 -05:00
c . Assert ( waitRun ( "oomTrue" ) , checker . IsNil )
2017-09-05 11:19:57 -04:00
defer dockerCmdWithResult ( "kill" , "oomTrue" )
2016-01-28 09:19:25 -05:00
containerID := inspectField ( c , "oomTrue" , "Id" )
2015-09-11 06:01:47 -04:00
2016-01-23 22:27:39 -05:00
testActions := map [ string ] chan bool {
"oom" : make ( chan bool ) ,
}
2015-09-11 06:01:47 -04:00
2016-01-23 22:27:39 -05:00
matcher := matchEventLine ( containerID , "container" , testActions )
processor := processEventMatch ( testActions )
go observer . Match ( matcher , processor )
select {
case <- time . After ( 20 * time . Second ) :
observer . CheckEventError ( c , containerID , "oom" , matcher )
case <- testActions [ "oom" ] :
2017-03-23 13:35:22 -04:00
// ignore, done
2016-01-23 22:27:39 -05:00
case errRun := <- errChan :
if errRun != nil {
c . Fatalf ( "%v" , errRun )
} else {
c . Fatalf ( "container should be still running but it's not" )
}
2015-09-11 06:01:47 -04:00
}
2016-01-23 22:27:39 -05:00
2016-01-28 09:19:25 -05:00
status := inspectField ( c , "oomTrue" , "State.Status" )
2016-01-23 22:27:39 -05:00
c . Assert ( strings . TrimSpace ( status ) , checker . Equals , "running" , check . Commentf ( "container should be still running" ) )
2015-09-11 06:01:47 -04:00
}
2015-12-07 08:33:16 -05:00
// #18453
2015-12-21 17:55:23 -05:00
func ( s * DockerSuite ) TestEventsContainerFilterByName ( c * check . C ) {
2015-12-07 08:33:16 -05:00
testRequires ( c , DaemonIsLinux )
2015-12-21 17:55:23 -05:00
cOut , _ := dockerCmd ( c , "run" , "--name=foo" , "-d" , "busybox" , "top" )
c1 := strings . TrimSpace ( cOut )
waitRun ( "foo" )
cOut , _ = dockerCmd ( c , "run" , "--name=bar" , "-d" , "busybox" , "top" )
c2 := strings . TrimSpace ( cOut )
waitRun ( "bar" )
2016-04-11 14:52:34 -04:00
out , _ := dockerCmd ( c , "events" , "-f" , "container=foo" , "--since=0" , "--until" , daemonUnixTime ( c ) )
2015-12-21 17:55:23 -05:00
c . Assert ( out , checker . Contains , c1 , check . Commentf ( out ) )
c . Assert ( out , checker . Not ( checker . Contains ) , c2 , check . Commentf ( out ) )
2015-12-07 08:33:16 -05:00
}
// #18453
func ( s * DockerSuite ) TestEventsContainerFilterBeforeCreate ( c * check . C ) {
testRequires ( c , DaemonIsLinux )
2016-08-25 13:29:10 -04:00
buf := & bytes . Buffer { }
cmd := exec . Command ( dockerBinary , "events" , "-f" , "container=foo" , "--since=0" )
cmd . Stdout = buf
c . Assert ( cmd . Start ( ) , check . IsNil )
defer cmd . Wait ( )
defer cmd . Process . Kill ( )
// Sleep for a second to make sure we are testing the case where events are listened before container starts.
time . Sleep ( time . Second )
id , _ := dockerCmd ( c , "run" , "--name=foo" , "-d" , "busybox" , "top" )
2015-12-07 08:33:16 -05:00
cID := strings . TrimSpace ( id )
2016-08-25 13:29:10 -04:00
for i := 0 ; ; i ++ {
out := buf . String ( )
if strings . Contains ( out , cID ) {
break
}
if i > 30 {
c . Fatalf ( "Missing event of container (foo, %v), got %q" , cID , out )
}
time . Sleep ( 500 * time . Millisecond )
}
2015-12-07 08:33:16 -05:00
}
2015-12-21 19:45:31 -05:00
func ( s * DockerSuite ) TestVolumeEvents ( c * check . C ) {
testRequires ( c , DaemonIsLinux )
2016-04-11 14:52:34 -04:00
since := daemonUnixTime ( c )
2015-12-21 19:45:31 -05:00
// Observe create/mount volume actions
2016-06-14 18:42:30 -04:00
dockerCmd ( c , "volume" , "create" , "test-event-volume-local" )
2015-12-21 19:45:31 -05:00
dockerCmd ( c , "run" , "--name" , "test-volume-container" , "--volume" , "test-event-volume-local:/foo" , "-d" , "busybox" , "true" )
waitRun ( "test-volume-container" )
// Observe unmount/destroy volume actions
dockerCmd ( c , "rm" , "-f" , "test-volume-container" )
dockerCmd ( c , "volume" , "rm" , "test-event-volume-local" )
2016-04-11 14:52:34 -04:00
until := daemonUnixTime ( c )
out , _ := dockerCmd ( c , "events" , "--since" , since , "--until" , until )
2015-12-21 19:45:31 -05:00
events := strings . Split ( strings . TrimSpace ( out ) , "\n" )
c . Assert ( len ( events ) , checker . GreaterThan , 4 )
volumeEvents := eventActionsByIDAndType ( c , events , "test-event-volume-local" , "volume" )
c . Assert ( volumeEvents , checker . HasLen , 4 )
c . Assert ( volumeEvents [ 0 ] , checker . Equals , "create" )
c . Assert ( volumeEvents [ 1 ] , checker . Equals , "mount" )
c . Assert ( volumeEvents [ 2 ] , checker . Equals , "unmount" )
c . Assert ( volumeEvents [ 3 ] , checker . Equals , "destroy" )
}
2015-12-21 23:35:30 -05:00
func ( s * DockerSuite ) TestNetworkEvents ( c * check . C ) {
testRequires ( c , DaemonIsLinux )
2016-04-11 14:52:34 -04:00
since := daemonUnixTime ( c )
2015-12-21 23:35:30 -05:00
// Observe create/connect network actions
dockerCmd ( c , "network" , "create" , "test-event-network-local" )
dockerCmd ( c , "run" , "--name" , "test-network-container" , "--net" , "test-event-network-local" , "-d" , "busybox" , "true" )
waitRun ( "test-network-container" )
// Observe disconnect/destroy network actions
dockerCmd ( c , "rm" , "-f" , "test-network-container" )
dockerCmd ( c , "network" , "rm" , "test-event-network-local" )
2016-04-11 14:52:34 -04:00
until := daemonUnixTime ( c )
out , _ := dockerCmd ( c , "events" , "--since" , since , "--until" , until )
2015-12-21 23:35:30 -05:00
events := strings . Split ( strings . TrimSpace ( out ) , "\n" )
c . Assert ( len ( events ) , checker . GreaterThan , 4 )
netEvents := eventActionsByIDAndType ( c , events , "test-event-network-local" , "network" )
c . Assert ( netEvents , checker . HasLen , 4 )
c . Assert ( netEvents [ 0 ] , checker . Equals , "create" )
c . Assert ( netEvents [ 1 ] , checker . Equals , "connect" )
c . Assert ( netEvents [ 2 ] , checker . Equals , "disconnect" )
c . Assert ( netEvents [ 3 ] , checker . Equals , "destroy" )
}
2015-12-28 15:15:34 -05:00
2016-06-08 10:36:42 -04:00
func ( s * DockerSuite ) TestEventsContainerWithMultiNetwork ( c * check . C ) {
testRequires ( c , DaemonIsLinux )
// Observe create/connect network actions
dockerCmd ( c , "network" , "create" , "test-event-network-local-1" )
dockerCmd ( c , "network" , "create" , "test-event-network-local-2" )
dockerCmd ( c , "run" , "--name" , "test-network-container" , "--net" , "test-event-network-local-1" , "-td" , "busybox" , "sh" )
waitRun ( "test-network-container" )
dockerCmd ( c , "network" , "connect" , "test-event-network-local-2" , "test-network-container" )
since := daemonUnixTime ( c )
dockerCmd ( c , "stop" , "-t" , "1" , "test-network-container" )
until := daemonUnixTime ( c )
out , _ := dockerCmd ( c , "events" , "--since" , since , "--until" , until , "-f" , "type=network" )
netEvents := strings . Split ( strings . TrimSpace ( out ) , "\n" )
2016-06-11 02:51:09 -04:00
// received two network disconnect events
2016-06-08 10:36:42 -04:00
c . Assert ( len ( netEvents ) , checker . Equals , 2 )
c . Assert ( netEvents [ 0 ] , checker . Contains , "disconnect" )
c . Assert ( netEvents [ 1 ] , checker . Contains , "disconnect" )
2016-06-11 02:51:09 -04:00
//both networks appeared in the network event output
c . Assert ( out , checker . Contains , "test-event-network-local-1" )
c . Assert ( out , checker . Contains , "test-event-network-local-2" )
2016-06-08 10:36:42 -04:00
}
2015-12-28 15:15:34 -05:00
func ( s * DockerSuite ) TestEventsStreaming ( c * check . C ) {
testRequires ( c , DaemonIsLinux )
observer , err := newEventObserver ( c )
c . Assert ( err , checker . IsNil )
err = observer . Start ( )
c . Assert ( err , checker . IsNil )
defer observer . Stop ( )
out , _ := dockerCmd ( c , "run" , "-d" , "busybox:latest" , "true" )
containerID := strings . TrimSpace ( out )
testActions := map [ string ] chan bool {
2016-02-18 16:10:29 -05:00
"create" : make ( chan bool , 1 ) ,
"start" : make ( chan bool , 1 ) ,
"die" : make ( chan bool , 1 ) ,
"destroy" : make ( chan bool , 1 ) ,
2015-12-28 15:15:34 -05:00
}
matcher := matchEventLine ( containerID , "container" , testActions )
2016-01-20 17:36:39 -05:00
processor := processEventMatch ( testActions )
go observer . Match ( matcher , processor )
2015-12-28 15:15:34 -05:00
select {
case <- time . After ( 5 * time . Second ) :
observer . CheckEventError ( c , containerID , "create" , matcher )
case <- testActions [ "create" ] :
// ignore, done
}
select {
case <- time . After ( 5 * time . Second ) :
observer . CheckEventError ( c , containerID , "start" , matcher )
case <- testActions [ "start" ] :
// ignore, done
}
select {
case <- time . After ( 5 * time . Second ) :
observer . CheckEventError ( c , containerID , "die" , matcher )
case <- testActions [ "die" ] :
// ignore, done
}
dockerCmd ( c , "rm" , containerID )
select {
case <- time . After ( 5 * time . Second ) :
observer . CheckEventError ( c , containerID , "destroy" , matcher )
case <- testActions [ "destroy" ] :
// ignore, done
}
}
func ( s * DockerSuite ) TestEventsImageUntagDelete ( c * check . C ) {
testRequires ( c , DaemonIsLinux )
observer , err := newEventObserver ( c )
c . Assert ( err , checker . IsNil )
err = observer . Start ( )
c . Assert ( err , checker . IsNil )
defer observer . Stop ( )
name := "testimageevents"
2017-03-23 13:35:22 -04:00
buildImageSuccessfully ( c , name , build . WithDockerfile ( ` FROM scratch
2017-01-16 05:30:14 -05:00
MAINTAINER "docker" ` ) )
imageID := getIDByName ( c , name )
2015-12-28 15:15:34 -05:00
c . Assert ( deleteImages ( name ) , checker . IsNil )
testActions := map [ string ] chan bool {
2016-02-18 16:10:29 -05:00
"untag" : make ( chan bool , 1 ) ,
"delete" : make ( chan bool , 1 ) ,
2015-12-28 15:15:34 -05:00
}
matcher := matchEventLine ( imageID , "image" , testActions )
2016-01-20 17:36:39 -05:00
processor := processEventMatch ( testActions )
go observer . Match ( matcher , processor )
2015-12-28 15:15:34 -05:00
select {
case <- time . After ( 10 * time . Second ) :
observer . CheckEventError ( c , imageID , "untag" , matcher )
case <- testActions [ "untag" ] :
// ignore, done
}
select {
case <- time . After ( 10 * time . Second ) :
observer . CheckEventError ( c , imageID , "delete" , matcher )
case <- testActions [ "delete" ] :
// ignore, done
}
}
func ( s * DockerSuite ) TestEventsFilterVolumeAndNetworkType ( c * check . C ) {
testRequires ( c , DaemonIsLinux )
2016-04-11 14:52:34 -04:00
since := daemonUnixTime ( c )
2015-12-28 15:15:34 -05:00
dockerCmd ( c , "network" , "create" , "test-event-network-type" )
2016-06-14 18:42:30 -04:00
dockerCmd ( c , "volume" , "create" , "test-event-volume-type" )
2015-12-28 15:15:34 -05:00
2016-04-11 14:52:34 -04:00
out , _ := dockerCmd ( c , "events" , "--filter" , "type=volume" , "--filter" , "type=network" , "--since" , since , "--until" , daemonUnixTime ( c ) )
2015-12-28 15:15:34 -05:00
events := strings . Split ( strings . TrimSpace ( out ) , "\n" )
c . Assert ( len ( events ) , checker . GreaterOrEqualThan , 2 , check . Commentf ( out ) )
networkActions := eventActionsByIDAndType ( c , events , "test-event-network-type" , "network" )
volumeActions := eventActionsByIDAndType ( c , events , "test-event-volume-type" , "volume" )
c . Assert ( volumeActions [ 0 ] , checker . Equals , "create" )
c . Assert ( networkActions [ 0 ] , checker . Equals , "create" )
}
func ( s * DockerSuite ) TestEventsFilterVolumeID ( c * check . C ) {
testRequires ( c , DaemonIsLinux )
2016-04-11 14:52:34 -04:00
since := daemonUnixTime ( c )
2015-12-28 15:15:34 -05:00
2016-06-14 18:42:30 -04:00
dockerCmd ( c , "volume" , "create" , "test-event-volume-id" )
2016-04-11 14:52:34 -04:00
out , _ := dockerCmd ( c , "events" , "--filter" , "volume=test-event-volume-id" , "--since" , since , "--until" , daemonUnixTime ( c ) )
2015-12-28 15:15:34 -05:00
events := strings . Split ( strings . TrimSpace ( out ) , "\n" )
c . Assert ( events , checker . HasLen , 1 )
c . Assert ( events [ 0 ] , checker . Contains , "test-event-volume-id" )
c . Assert ( events [ 0 ] , checker . Contains , "driver=local" )
}
func ( s * DockerSuite ) TestEventsFilterNetworkID ( c * check . C ) {
testRequires ( c , DaemonIsLinux )
2016-04-11 14:52:34 -04:00
since := daemonUnixTime ( c )
2015-12-28 15:15:34 -05:00
dockerCmd ( c , "network" , "create" , "test-event-network-local" )
2016-04-11 14:52:34 -04:00
out , _ := dockerCmd ( c , "events" , "--filter" , "network=test-event-network-local" , "--since" , since , "--until" , daemonUnixTime ( c ) )
2015-12-28 15:15:34 -05:00
events := strings . Split ( strings . TrimSpace ( out ) , "\n" )
c . Assert ( events , checker . HasLen , 1 )
c . Assert ( events [ 0 ] , checker . Contains , "test-event-network-local" )
c . Assert ( events [ 0 ] , checker . Contains , "type=bridge" )
}
2016-05-08 19:11:34 -04:00
func ( s * DockerDaemonSuite ) TestDaemonEvents ( c * check . C ) {
testRequires ( c , SameHostDaemon , DaemonIsLinux )
// daemon config file
configFilePath := "test.json"
configFile , err := os . Create ( configFilePath )
c . Assert ( err , checker . IsNil )
defer os . Remove ( configFilePath )
daemonConfig := ` { "labels":["foo=bar"]} `
fmt . Fprintf ( configFile , "%s" , daemonConfig )
configFile . Close ( )
2016-12-09 17:20:14 -05:00
s . d . Start ( c , fmt . Sprintf ( "--config-file=%s" , configFilePath ) )
2016-05-08 19:11:34 -04:00
// Get daemon ID
out , err := s . d . Cmd ( "info" )
c . Assert ( err , checker . IsNil )
daemonID := ""
2016-05-08 19:15:33 -04:00
daemonName := ""
2016-05-08 19:11:34 -04:00
for _ , line := range strings . Split ( out , "\n" ) {
if strings . HasPrefix ( line , "ID: " ) {
daemonID = strings . TrimPrefix ( line , "ID: " )
2016-05-08 19:15:33 -04:00
} else if strings . HasPrefix ( line , "Name: " ) {
daemonName = strings . TrimPrefix ( line , "Name: " )
2016-05-08 19:11:34 -04:00
}
}
c . Assert ( daemonID , checker . Not ( checker . Equals ) , "" )
configFile , err = os . Create ( configFilePath )
c . Assert ( err , checker . IsNil )
2016-05-26 17:07:30 -04:00
daemonConfig = ` { "max-concurrent-downloads":1,"labels":["bar=foo"], "shutdown-timeout": 10} `
2016-05-08 19:11:34 -04:00
fmt . Fprintf ( configFile , "%s" , daemonConfig )
configFile . Close ( )
2017-05-23 10:22:32 -04:00
c . Assert ( s . d . Signal ( unix . SIGHUP ) , checker . IsNil )
2016-05-08 19:11:34 -04:00
time . Sleep ( 3 * time . Second )
out , err = s . d . Cmd ( "events" , "--since=0" , "--until" , daemonUnixTime ( c ) )
c . Assert ( err , checker . IsNil )
2016-05-23 17:49:50 -04:00
2017-07-19 14:24:54 -04:00
// only check for values known (daemon ID/name) or explicitly set above,
// otherwise just check for names being present.
expectedSubstrings := [ ] string {
" daemon reload " + daemonID + " " ,
"(allow-nondistributable-artifacts=[" ,
" cluster-advertise=, " ,
" cluster-store=, " ,
" cluster-store-opts={" ,
" debug=true, " ,
" default-ipc-mode=" ,
" default-runtime=" ,
" default-shm-size=" ,
" insecure-registries=[" ,
" labels=[\"bar=foo\"], " ,
" live-restore=" ,
" max-concurrent-downloads=1, " ,
" max-concurrent-uploads=5, " ,
" name=" + daemonName ,
" registry-mirrors=[" ,
" runtimes=" ,
" shutdown-timeout=10)" ,
}
for _ , s := range expectedSubstrings {
c . Assert ( out , checker . Contains , s )
}
2016-05-08 19:15:33 -04:00
}
func ( s * DockerDaemonSuite ) TestDaemonEventsWithFilters ( c * check . C ) {
testRequires ( c , SameHostDaemon , DaemonIsLinux )
// daemon config file
configFilePath := "test.json"
configFile , err := os . Create ( configFilePath )
c . Assert ( err , checker . IsNil )
defer os . Remove ( configFilePath )
daemonConfig := ` { "labels":["foo=bar"]} `
fmt . Fprintf ( configFile , "%s" , daemonConfig )
configFile . Close ( )
2016-12-09 17:20:14 -05:00
s . d . Start ( c , fmt . Sprintf ( "--config-file=%s" , configFilePath ) )
2016-05-08 19:15:33 -04:00
// Get daemon ID
out , err := s . d . Cmd ( "info" )
c . Assert ( err , checker . IsNil )
daemonID := ""
daemonName := ""
for _ , line := range strings . Split ( out , "\n" ) {
if strings . HasPrefix ( line , "ID: " ) {
daemonID = strings . TrimPrefix ( line , "ID: " )
} else if strings . HasPrefix ( line , "Name: " ) {
daemonName = strings . TrimPrefix ( line , "Name: " )
}
}
c . Assert ( daemonID , checker . Not ( checker . Equals ) , "" )
2017-05-23 10:22:32 -04:00
c . Assert ( s . d . Signal ( unix . SIGHUP ) , checker . IsNil )
2016-05-08 19:15:33 -04:00
time . Sleep ( 3 * time . Second )
out , err = s . d . Cmd ( "events" , "--since=0" , "--until" , daemonUnixTime ( c ) , "--filter" , fmt . Sprintf ( "daemon=%s" , daemonID ) )
c . Assert ( err , checker . IsNil )
c . Assert ( out , checker . Contains , fmt . Sprintf ( "daemon reload %s" , daemonID ) )
out , err = s . d . Cmd ( "events" , "--since=0" , "--until" , daemonUnixTime ( c ) , "--filter" , fmt . Sprintf ( "daemon=%s" , daemonName ) )
c . Assert ( err , checker . IsNil )
c . Assert ( out , checker . Contains , fmt . Sprintf ( "daemon reload %s" , daemonID ) )
out , err = s . d . Cmd ( "events" , "--since=0" , "--until" , daemonUnixTime ( c ) , "--filter" , "daemon=foo" )
c . Assert ( err , checker . IsNil )
c . Assert ( out , checker . Not ( checker . Contains ) , fmt . Sprintf ( "daemon reload %s" , daemonID ) )
out , err = s . d . Cmd ( "events" , "--since=0" , "--until" , daemonUnixTime ( c ) , "--filter" , "type=daemon" )
c . Assert ( err , checker . IsNil )
c . Assert ( out , checker . Contains , fmt . Sprintf ( "daemon reload %s" , daemonID ) )
out , err = s . d . Cmd ( "events" , "--since=0" , "--until" , daemonUnixTime ( c ) , "--filter" , "type=container" )
c . Assert ( err , checker . IsNil )
c . Assert ( out , checker . Not ( checker . Contains ) , fmt . Sprintf ( "daemon reload %s" , daemonID ) )
2016-05-08 19:11:34 -04:00
}