зеркало из https://github.com/microsoft/docker.git
Check for plugin state before enable and disable.
This prevents unnecessary API call to containerd. Signed-off-by: Anusha Ragunathan <anusha@docker.com>
This commit is contained in:
Родитель
8f11896a45
Коммит
b867f6c6e1
|
@ -68,3 +68,24 @@ func (s *DockerSuite) TestPluginInstallImage(c *check.C) {
|
|||
c.Assert(err, checker.NotNil)
|
||||
c.Assert(out, checker.Contains, "content is not a plugin")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestPluginEnableDisableNegative(c *check.C) {
|
||||
testRequires(c, DaemonIsLinux, ExperimentalDaemon)
|
||||
out, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", pName)
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(strings.TrimSpace(out), checker.Contains, pName)
|
||||
|
||||
out, _, err = dockerCmdWithError("plugin", "enable", pName)
|
||||
c.Assert(err, checker.NotNil)
|
||||
c.Assert(strings.TrimSpace(out), checker.Contains, "already enabled")
|
||||
|
||||
_, _, err = dockerCmdWithError("plugin", "disable", pName)
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
out, _, err = dockerCmdWithError("plugin", "disable", pName)
|
||||
c.Assert(err, checker.NotNil)
|
||||
c.Assert(strings.TrimSpace(out), checker.Contains, "already disabled")
|
||||
|
||||
_, _, err = dockerCmdWithError("plugin", "remove", pName)
|
||||
c.Assert(err, checker.IsNil)
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
package plugin
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"syscall"
|
||||
|
@ -20,6 +21,9 @@ import (
|
|||
)
|
||||
|
||||
func (pm *Manager) enable(p *plugin) error {
|
||||
if p.P.Active {
|
||||
return fmt.Errorf("plugin %s is already enabled", p.Name())
|
||||
}
|
||||
spec, err := pm.initSpec(p)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -27,12 +31,18 @@ func (pm *Manager) enable(p *plugin) error {
|
|||
|
||||
p.restartManager = restartmanager.New(container.RestartPolicy{Name: "always"}, 0)
|
||||
if err := pm.containerdClient.Create(p.P.ID, libcontainerd.Spec(*spec), libcontainerd.WithRestartManager(p.restartManager)); err != nil { // POC-only
|
||||
if err := p.restartManager.Cancel(); err != nil {
|
||||
logrus.Errorf("enable: restartManager.Cancel failed due to %v", err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
socket := p.P.Manifest.Interface.Socket
|
||||
p.client, err = plugins.NewClient("unix://"+filepath.Join(p.runtimeSourcePath, socket), nil)
|
||||
if err != nil {
|
||||
if err := p.restartManager.Cancel(); err != nil {
|
||||
logrus.Errorf("enable: restartManager.Cancel failed due to %v", err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -114,6 +124,9 @@ func (pm *Manager) initSpec(p *plugin) (*specs.Spec, error) {
|
|||
}
|
||||
|
||||
func (pm *Manager) disable(p *plugin) error {
|
||||
if !p.P.Active {
|
||||
return fmt.Errorf("plugin %s is already disabled", p.Name())
|
||||
}
|
||||
if err := p.restartManager.Cancel(); err != nil {
|
||||
logrus.Error(err)
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче