github.com/vvnotw/moby@v1.13.1/integration-cli/docker_cli_swarm_unix_test.go (about)

     1  // +build !windows
     2  
     3  package main
     4  
     5  import (
     6  	"encoding/json"
     7  	"strings"
     8  
     9  	"github.com/docker/docker/api/types/swarm"
    10  	"github.com/docker/docker/pkg/integration/checker"
    11  	"github.com/go-check/check"
    12  )
    13  
    14  func (s *DockerSwarmSuite) TestSwarmVolumePlugin(c *check.C) {
    15  	d := s.AddDaemon(c, true, true)
    16  
    17  	out, err := d.Cmd("service", "create", "--mount", "type=volume,source=my-volume,destination=/foo,volume-driver=customvolumedriver", "--name", "top", "busybox", "top")
    18  	c.Assert(err, checker.IsNil, check.Commentf(out))
    19  
    20  	// Make sure task stays pending before plugin is available
    21  	waitAndAssert(c, defaultReconciliationTimeout, d.checkServiceTasksInState("top", swarm.TaskStatePending, "missing plugin on 1 node"), checker.Equals, 1)
    22  
    23  	plugin := newVolumePlugin(c, "customvolumedriver")
    24  	defer plugin.Close()
    25  
    26  	// create a dummy volume to trigger lazy loading of the plugin
    27  	out, err = d.Cmd("volume", "create", "-d", "customvolumedriver", "hello")
    28  
    29  	// TODO(aaronl): It will take about 15 seconds for swarm to realize the
    30  	// plugin was loaded. Switching the test over to plugin v2 would avoid
    31  	// this long delay.
    32  
    33  	// make sure task has been deployed.
    34  	waitAndAssert(c, defaultReconciliationTimeout, d.checkActiveContainerCount, checker.Equals, 1)
    35  
    36  	out, err = d.Cmd("ps", "-q")
    37  	c.Assert(err, checker.IsNil)
    38  	containerID := strings.TrimSpace(out)
    39  
    40  	out, err = d.Cmd("inspect", "-f", "{{json .Mounts}}", containerID)
    41  	c.Assert(err, checker.IsNil)
    42  
    43  	var mounts []struct {
    44  		Name   string
    45  		Driver string
    46  	}
    47  
    48  	c.Assert(json.NewDecoder(strings.NewReader(out)).Decode(&mounts), checker.IsNil)
    49  	c.Assert(len(mounts), checker.Equals, 1, check.Commentf(out))
    50  	c.Assert(mounts[0].Name, checker.Equals, "my-volume")
    51  	c.Assert(mounts[0].Driver, checker.Equals, "customvolumedriver")
    52  }