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