mirror of
https://github.com/moby/moby.git
synced 2025-12-03 07:41:01 +03:00
Emit events for docker daemon
This fix tries to cover the issue raised in #22463 by emitting events for docker daemon so that user could be notified by scenarios like config reload, etc. This fix adds the `daemon reload`, and events for docker daemon. Additional tests have been added to cover the changes in this fix. This fix fixes #22463. Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
"unicode"
|
||||
|
||||
@@ -366,3 +367,44 @@ func (s *DockerSuite) TestEventsFilterNetworkID(c *check.C) {
|
||||
c.Assert(events[0], checker.Contains, "test-event-network-local")
|
||||
c.Assert(events[0], checker.Contains, "type=bridge")
|
||||
}
|
||||
|
||||
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()
|
||||
c.Assert(s.d.Start(fmt.Sprintf("--config-file=%s", configFilePath)), check.IsNil)
|
||||
|
||||
// Get daemon ID
|
||||
out, err := s.d.Cmd("info")
|
||||
c.Assert(err, checker.IsNil)
|
||||
daemonID := ""
|
||||
for _, line := range strings.Split(out, "\n") {
|
||||
if strings.HasPrefix(line, "ID: ") {
|
||||
daemonID = strings.TrimPrefix(line, "ID: ")
|
||||
break
|
||||
}
|
||||
}
|
||||
c.Assert(daemonID, checker.Not(checker.Equals), "")
|
||||
|
||||
configFile, err = os.Create(configFilePath)
|
||||
c.Assert(err, checker.IsNil)
|
||||
daemonConfig = `{"labels":["bar=foo"]}`
|
||||
fmt.Fprintf(configFile, "%s", daemonConfig)
|
||||
configFile.Close()
|
||||
|
||||
syscall.Kill(s.d.cmd.Process.Pid, syscall.SIGHUP)
|
||||
|
||||
time.Sleep(3 * time.Second)
|
||||
|
||||
out, err = s.d.Cmd("events", "--since=0", "--until", daemonUnixTime(c))
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(out, checker.Contains, fmt.Sprintf("daemon reload %s (cluster-advertise=, cluster-store=, cluster-store-opts={}, debug=true, labels=[\"bar=foo\"])", daemonID))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user