github.com/endophage/docker@v1.4.2-0.20161027011718-242853499895/integration-cli/docker_cli_daemon_experimental_test.go (about) 1 // +build linux 2 3 package main 4 5 import ( 6 "os" 7 "os/exec" 8 "path/filepath" 9 "strings" 10 "syscall" 11 12 "github.com/docker/docker/pkg/integration/checker" 13 "github.com/go-check/check" 14 ) 15 16 var pluginName = "tiborvass/no-remove" 17 18 // TestDaemonRestartWithPluginEnabled tests state restore for an enabled plugin 19 func (s *DockerDaemonSuite) TestDaemonRestartWithPluginEnabled(c *check.C) { 20 testRequires(c, Network, ExperimentalDaemon) 21 22 if err := s.d.Start(); err != nil { 23 c.Fatalf("Could not start daemon: %v", err) 24 } 25 26 if out, err := s.d.Cmd("plugin", "install", "--grant-all-permissions", pluginName); err != nil { 27 c.Fatalf("Could not install plugin: %v %s", err, out) 28 } 29 30 defer func() { 31 if out, err := s.d.Cmd("plugin", "disable", pluginName); err != nil { 32 c.Fatalf("Could not disable plugin: %v %s", err, out) 33 } 34 if out, err := s.d.Cmd("plugin", "remove", pluginName); err != nil { 35 c.Fatalf("Could not remove plugin: %v %s", err, out) 36 } 37 }() 38 39 if err := s.d.Restart(); err != nil { 40 c.Fatalf("Could not restart daemon: %v", err) 41 } 42 43 out, err := s.d.Cmd("plugin", "ls") 44 if err != nil { 45 c.Fatalf("Could not list plugins: %v %s", err, out) 46 } 47 c.Assert(out, checker.Contains, pluginName) 48 c.Assert(out, checker.Contains, "true") 49 } 50 51 // TestDaemonRestartWithPluginDisabled tests state restore for a disabled plugin 52 func (s *DockerDaemonSuite) TestDaemonRestartWithPluginDisabled(c *check.C) { 53 testRequires(c, Network, ExperimentalDaemon) 54 55 if err := s.d.Start(); err != nil { 56 c.Fatalf("Could not start daemon: %v", err) 57 } 58 59 if out, err := s.d.Cmd("plugin", "install", "--grant-all-permissions", pluginName, "--disable"); err != nil { 60 c.Fatalf("Could not install plugin: %v %s", err, out) 61 } 62 63 defer func() { 64 if out, err := s.d.Cmd("plugin", "remove", pluginName); err != nil { 65 c.Fatalf("Could not remove plugin: %v %s", err, out) 66 } 67 }() 68 69 if err := s.d.Restart(); err != nil { 70 c.Fatalf("Could not restart daemon: %v", err) 71 } 72 73 out, err := s.d.Cmd("plugin", "ls") 74 if err != nil { 75 c.Fatalf("Could not list plugins: %v %s", err, out) 76 } 77 c.Assert(out, checker.Contains, pluginName) 78 c.Assert(out, checker.Contains, "false") 79 } 80 81 // TestDaemonKillLiveRestoreWithPlugins SIGKILLs daemon started with --live-restore. 82 // Plugins should continue to run. 83 func (s *DockerDaemonSuite) TestDaemonKillLiveRestoreWithPlugins(c *check.C) { 84 testRequires(c, Network, ExperimentalDaemon) 85 86 if err := s.d.Start("--live-restore"); err != nil { 87 c.Fatalf("Could not start daemon: %v", err) 88 } 89 if out, err := s.d.Cmd("plugin", "install", "--grant-all-permissions", pluginName); err != nil { 90 c.Fatalf("Could not install plugin: %v %s", err, out) 91 } 92 defer func() { 93 if err := s.d.Restart("--live-restore"); err != nil { 94 c.Fatalf("Could not restart daemon: %v", err) 95 } 96 if out, err := s.d.Cmd("plugin", "disable", pluginName); err != nil { 97 c.Fatalf("Could not disable plugin: %v %s", err, out) 98 } 99 if out, err := s.d.Cmd("plugin", "remove", pluginName); err != nil { 100 c.Fatalf("Could not remove plugin: %v %s", err, out) 101 } 102 }() 103 104 if err := s.d.Kill(); err != nil { 105 c.Fatalf("Could not kill daemon: %v", err) 106 } 107 108 cmd := exec.Command("pgrep", "-f", "plugin-no-remove") 109 if out, ec, err := runCommandWithOutput(cmd); ec != 0 { 110 c.Fatalf("Expected exit code '0', got %d err: %v output: %s ", ec, err, out) 111 } 112 } 113 114 // TestDaemonShutdownLiveRestoreWithPlugins SIGTERMs daemon started with --live-restore. 115 // Plugins should continue to run. 116 func (s *DockerDaemonSuite) TestDaemonShutdownLiveRestoreWithPlugins(c *check.C) { 117 testRequires(c, Network, ExperimentalDaemon) 118 119 if err := s.d.Start("--live-restore"); err != nil { 120 c.Fatalf("Could not start daemon: %v", err) 121 } 122 if out, err := s.d.Cmd("plugin", "install", "--grant-all-permissions", pluginName); err != nil { 123 c.Fatalf("Could not install plugin: %v %s", err, out) 124 } 125 defer func() { 126 if err := s.d.Restart("--live-restore"); err != nil { 127 c.Fatalf("Could not restart daemon: %v", err) 128 } 129 if out, err := s.d.Cmd("plugin", "disable", pluginName); err != nil { 130 c.Fatalf("Could not disable plugin: %v %s", err, out) 131 } 132 if out, err := s.d.Cmd("plugin", "remove", pluginName); err != nil { 133 c.Fatalf("Could not remove plugin: %v %s", err, out) 134 } 135 }() 136 137 if err := s.d.cmd.Process.Signal(os.Interrupt); err != nil { 138 c.Fatalf("Could not kill daemon: %v", err) 139 } 140 141 cmd := exec.Command("pgrep", "-f", "plugin-no-remove") 142 if out, ec, err := runCommandWithOutput(cmd); ec != 0 { 143 c.Fatalf("Expected exit code '0', got %d err: %v output: %s ", ec, err, out) 144 } 145 } 146 147 // TestDaemonShutdownWithPlugins shuts down running plugins. 148 func (s *DockerDaemonSuite) TestDaemonShutdownWithPlugins(c *check.C) { 149 testRequires(c, Network, ExperimentalDaemon) 150 151 if err := s.d.Start(); err != nil { 152 c.Fatalf("Could not start daemon: %v", err) 153 } 154 if out, err := s.d.Cmd("plugin", "install", "--grant-all-permissions", pluginName); err != nil { 155 c.Fatalf("Could not install plugin: %v %s", err, out) 156 } 157 158 defer func() { 159 if err := s.d.Restart(); err != nil { 160 c.Fatalf("Could not restart daemon: %v", err) 161 } 162 if out, err := s.d.Cmd("plugin", "disable", pluginName); err != nil { 163 c.Fatalf("Could not disable plugin: %v %s", err, out) 164 } 165 if out, err := s.d.Cmd("plugin", "remove", pluginName); err != nil { 166 c.Fatalf("Could not remove plugin: %v %s", err, out) 167 } 168 }() 169 170 if err := s.d.cmd.Process.Signal(os.Interrupt); err != nil { 171 c.Fatalf("Could not kill daemon: %v", err) 172 } 173 174 for { 175 if err := syscall.Kill(s.d.cmd.Process.Pid, 0); err == syscall.ESRCH { 176 break 177 } 178 } 179 180 cmd := exec.Command("pgrep", "-f", "plugin-no-remove") 181 if out, ec, err := runCommandWithOutput(cmd); ec != 1 { 182 c.Fatalf("Expected exit code '1', got %d err: %v output: %s ", ec, err, out) 183 } 184 } 185 186 // TestVolumePlugin tests volume creation using a plugin. 187 func (s *DockerDaemonSuite) TestVolumePlugin(c *check.C) { 188 testRequires(c, Network, ExperimentalDaemon) 189 190 volName := "plugin-volume" 191 volRoot := "/data" 192 destDir := "/tmp/data/" 193 destFile := "foo" 194 195 if err := s.d.Start(); err != nil { 196 c.Fatalf("Could not start daemon: %v", err) 197 } 198 out, err := s.d.Cmd("plugin", "install", pluginName, "--grant-all-permissions") 199 if err != nil { 200 c.Fatalf("Could not install plugin: %v %s", err, out) 201 } 202 defer func() { 203 if out, err := s.d.Cmd("plugin", "disable", pluginName); err != nil { 204 c.Fatalf("Could not disable plugin: %v %s", err, out) 205 } 206 if out, err := s.d.Cmd("plugin", "remove", pluginName); err != nil { 207 c.Fatalf("Could not remove plugin: %v %s", err, out) 208 } 209 }() 210 211 out, err = s.d.Cmd("volume", "create", "-d", pluginName, volName) 212 if err != nil { 213 c.Fatalf("Could not create volume: %v %s", err, out) 214 } 215 defer func() { 216 if out, err := s.d.Cmd("volume", "remove", volName); err != nil { 217 c.Fatalf("Could not remove volume: %v %s", err, out) 218 } 219 }() 220 221 out, err = s.d.Cmd("volume", "ls") 222 if err != nil { 223 c.Fatalf("Could not list volume: %v %s", err, out) 224 } 225 c.Assert(out, checker.Contains, volName) 226 c.Assert(out, checker.Contains, pluginName) 227 228 mountPoint, err := s.d.Cmd("volume", "inspect", volName, "--format", "{{.Mountpoint}}") 229 if err != nil { 230 c.Fatalf("Could not inspect volume: %v %s", err, mountPoint) 231 } 232 mountPoint = strings.TrimSpace(mountPoint) 233 234 out, err = s.d.Cmd("run", "--rm", "-v", volName+":"+destDir, "busybox", "touch", destDir+destFile) 235 c.Assert(err, checker.IsNil, check.Commentf(out)) 236 path := filepath.Join(mountPoint, destFile) 237 _, err = os.Lstat(path) 238 c.Assert(err, checker.IsNil) 239 240 // tiborvass/no-remove is a volume plugin that persists data on disk at /data, 241 // even after the volume is removed. So perform an explicit filesystem cleanup. 242 os.RemoveAll(volRoot) 243 }