docker_cli_daemon_experimental_test.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. // +build linux, experimental
  2. package main
  3. import (
  4. "github.com/docker/docker/pkg/integration/checker"
  5. "github.com/go-check/check"
  6. "os"
  7. "os/exec"
  8. "time"
  9. )
  10. var pluginName = "tiborvass/no-remove"
  11. // TestDaemonRestartWithPluginEnabled tests state restore for an enabled plugin
  12. func (s *DockerDaemonSuite) TestDaemonRestartWithPluginEnabled(c *check.C) {
  13. if err := s.d.Start(); err != nil {
  14. c.Fatalf("Could not start daemon: %v", err)
  15. }
  16. if out, err := s.d.Cmd("plugin", "install", "--grant-all-permissions", pluginName); err != nil {
  17. c.Fatalf("Could not install plugin: %v %s", err, out)
  18. }
  19. defer func() {
  20. if out, err := s.d.Cmd("plugin", "disable", pluginName); err != nil {
  21. c.Fatalf("Could not disable plugin: %v %s", err, out)
  22. }
  23. if out, err := s.d.Cmd("plugin", "remove", pluginName); err != nil {
  24. c.Fatalf("Could not remove plugin: %v %s", err, out)
  25. }
  26. }()
  27. if err := s.d.Restart(); err != nil {
  28. c.Fatalf("Could not restart daemon: %v", err)
  29. }
  30. out, err := s.d.Cmd("plugin", "ls")
  31. if err != nil {
  32. c.Fatalf("Could not list plugins: %v %s", err, out)
  33. }
  34. c.Assert(out, checker.Contains, pluginName)
  35. c.Assert(out, checker.Contains, "true")
  36. }
  37. // TestDaemonRestartWithPluginEnabled tests state restore for a disabled plugin
  38. func (s *DockerDaemonSuite) TestDaemonRestartWithPluginDisabled(c *check.C) {
  39. if err := s.d.Start(); err != nil {
  40. c.Fatalf("Could not start daemon: %v", err)
  41. }
  42. if out, err := s.d.Cmd("plugin", "install", "--grant-all-permissions", pluginName, "--disable"); err != nil {
  43. c.Fatalf("Could not install plugin: %v %s", err, out)
  44. }
  45. defer func() {
  46. if out, err := s.d.Cmd("plugin", "remove", pluginName); err != nil {
  47. c.Fatalf("Could not remove plugin: %v %s", err, out)
  48. }
  49. }()
  50. if err := s.d.Restart(); err != nil {
  51. c.Fatalf("Could not restart daemon: %v", err)
  52. }
  53. out, err := s.d.Cmd("plugin", "ls")
  54. if err != nil {
  55. c.Fatalf("Could not list plugins: %v %s", err, out)
  56. }
  57. c.Assert(out, checker.Contains, pluginName)
  58. c.Assert(out, checker.Contains, "false")
  59. }
  60. // TestDaemonShutdownLiveRestoreWithPlugins leaves plugin running.
  61. func (s *DockerDaemonSuite) TestDaemonShutdownLiveRestoreWithPlugins(c *check.C) {
  62. if err := s.d.Start("--live-restore"); err != nil {
  63. c.Fatalf("Could not start daemon: %v", err)
  64. }
  65. if out, err := s.d.Cmd("plugin", "install", "--grant-all-permissions", pluginName); err != nil {
  66. c.Fatalf("Could not install plugin: %v %s", err, out)
  67. }
  68. defer func() {
  69. if err := s.d.Restart("--live-restore"); err != nil {
  70. c.Fatalf("Could not restart daemon: %v", err)
  71. }
  72. if out, err := s.d.Cmd("plugin", "disable", pluginName); err != nil {
  73. c.Fatalf("Could not disable plugin: %v %s", err, out)
  74. }
  75. if out, err := s.d.Cmd("plugin", "remove", pluginName); err != nil {
  76. c.Fatalf("Could not remove plugin: %v %s", err, out)
  77. }
  78. }()
  79. if err := s.d.Kill(); err != nil {
  80. c.Fatalf("Could not kill daemon: %v", err)
  81. }
  82. cmd := exec.Command("pgrep", "-f", "plugin-no-remove")
  83. if out, ec, err := runCommandWithOutput(cmd); ec != 0 {
  84. c.Fatalf("Expected exit code '0', got %d err: %v output: %s ", ec, err, out)
  85. }
  86. }
  87. // TestDaemonShutdownWithPlugins shuts down running plugins.
  88. func (s *DockerDaemonSuite) TestDaemonShutdownWithPlugins(c *check.C) {
  89. if err := s.d.Start(); err != nil {
  90. c.Fatalf("Could not start daemon: %v", err)
  91. }
  92. if out, err := s.d.Cmd("plugin", "install", "--grant-all-permissions", pluginName); err != nil {
  93. c.Fatalf("Could not install plugin: %v %s", err, out)
  94. }
  95. defer func() {
  96. if err := s.d.Restart(); err != nil {
  97. c.Fatalf("Could not restart daemon: %v", err)
  98. }
  99. if out, err := s.d.Cmd("plugin", "disable", pluginName); err != nil {
  100. c.Fatalf("Could not disable plugin: %v %s", err, out)
  101. }
  102. if out, err := s.d.Cmd("plugin", "remove", pluginName); err != nil {
  103. c.Fatalf("Could not remove plugin: %v %s", err, out)
  104. }
  105. }()
  106. if err := s.d.cmd.Process.Signal(os.Interrupt); err != nil {
  107. c.Fatalf("Could not kill daemon: %v", err)
  108. }
  109. time.Sleep(5 * time.Second)
  110. cmd := exec.Command("pgrep", "-f", "plugin-no-remove")
  111. if out, ec, err := runCommandWithOutput(cmd); ec != 1 {
  112. c.Fatalf("Expected exit code '1', got %d err: %v output: %s ", ec, err, out)
  113. }
  114. }