From a174fffcfebe779f2c473618854d7ec27d4c629d Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 9 Jul 2018 19:40:34 +0200 Subject: [PATCH 1/4] Fix ineffassign linting Signed-off-by: Sebastiaan van Stijn Upstream-commit: ddd8a6572d36a6d0db2aa21d697018f419a7b424 Component: engine --- .../docker_api_containers_test.go | 2 ++ .../integration-cli/docker_cli_build_test.go | 8 ++----- .../integration-cli/docker_cli_commit_test.go | 3 +-- .../docker_cli_config_create_test.go | 3 +++ .../integration-cli/docker_cli_cp_test.go | 3 +++ .../integration-cli/docker_cli_daemon_test.go | 13 ++++++---- .../integration-cli/docker_cli_health_test.go | 2 +- .../integration-cli/docker_cli_logs_test.go | 6 ++--- .../docker_cli_network_unix_test.go | 6 ++--- .../docker_cli_plugins_test.go | 16 ++++++------- .../integration-cli/docker_cli_ps_test.go | 13 ++++------ .../docker_cli_restart_test.go | 1 + .../integration-cli/docker_cli_run_test.go | 1 + .../docker_cli_secret_create_test.go | 3 +++ .../docker_cli_service_scale_test.go | 8 +++---- .../integration-cli/docker_cli_swarm_test.go | 19 +++++++++------ .../docker_cli_swarm_unix_test.go | 1 + .../docker_cli_update_unix_test.go | 2 +- .../integration-cli/docker_cli_userns_test.go | 4 ++-- .../integration-cli/docker_cli_volume_test.go | 24 +++++++++---------- 20 files changed, 74 insertions(+), 64 deletions(-) diff --git a/components/engine/integration-cli/docker_api_containers_test.go b/components/engine/integration-cli/docker_api_containers_test.go index e8e47bd8b1..ca90e152f6 100644 --- a/components/engine/integration-cli/docker_api_containers_test.go +++ b/components/engine/integration-cli/docker_api_containers_test.go @@ -1265,6 +1265,7 @@ func (s *DockerSuite) TestContainerAPIDeleteRemoveVolume(c *check.C) { c.Assert(waitRun(id), checker.IsNil) source, err := inspectMountSourceField(id, vol) + c.Assert(err, checker.IsNil) _, err = os.Stat(source) c.Assert(err, checker.IsNil) @@ -2201,6 +2202,7 @@ func (s *DockerSuite) TestContainerKillCustomStopSignal(c *check.C) { defer res.Body.Close() b, err := ioutil.ReadAll(res.Body) + c.Assert(err, checker.IsNil) c.Assert(res.StatusCode, checker.Equals, http.StatusNoContent, check.Commentf(string(b))) err = waitInspect(id, "{{.State.Running}} {{.State.Restarting}}", "false false", 30*time.Second) c.Assert(err, checker.IsNil) diff --git a/components/engine/integration-cli/docker_cli_build_test.go b/components/engine/integration-cli/docker_cli_build_test.go index 1e88b1ba39..f6d5fe23f3 100644 --- a/components/engine/integration-cli/docker_cli_build_test.go +++ b/components/engine/integration-cli/docker_cli_build_test.go @@ -1012,10 +1012,6 @@ func (s *DockerSuite) TestBuildAddBadLinksVolume(c *check.C) { ADD foo.txt /x/` targetFile = "foo.txt" ) - var ( - name = "test-link-absolute-volume" - dockerfile = "" - ) tempDir, err := ioutil.TempDir("", "test-link-absolute-volume-temp-") if err != nil { @@ -1023,7 +1019,7 @@ func (s *DockerSuite) TestBuildAddBadLinksVolume(c *check.C) { } defer os.RemoveAll(tempDir) - dockerfile = fmt.Sprintf(dockerfileTemplate, tempDir) + dockerfile := fmt.Sprintf(dockerfileTemplate, tempDir) nonExistingFile := filepath.Join(tempDir, targetFile) ctx := fakecontext.New(c, "", fakecontext.WithDockerfile(dockerfile)) @@ -1040,7 +1036,7 @@ func (s *DockerSuite) TestBuildAddBadLinksVolume(c *check.C) { c.Fatal(err) } - buildImageSuccessfully(c, name, build.WithExternalBuildContext(ctx)) + buildImageSuccessfully(c, "test-link-absolute-volume", build.WithExternalBuildContext(ctx)) if _, err := os.Stat(nonExistingFile); err == nil || err != nil && !os.IsNotExist(err) { c.Fatalf("%s shouldn't have been written and it shouldn't exist", nonExistingFile) } diff --git a/components/engine/integration-cli/docker_cli_commit_test.go b/components/engine/integration-cli/docker_cli_commit_test.go index 79c5f73156..d9f6e6875c 100644 --- a/components/engine/integration-cli/docker_cli_commit_test.go +++ b/components/engine/integration-cli/docker_cli_commit_test.go @@ -46,8 +46,7 @@ func (s *DockerSuite) TestCommitPausedContainer(c *check.C) { cleanedContainerID := strings.TrimSpace(out) dockerCmd(c, "pause", cleanedContainerID) - - out, _ = dockerCmd(c, "commit", cleanedContainerID) + dockerCmd(c, "commit", cleanedContainerID) out = inspectField(c, cleanedContainerID, "State.Paused") // commit should not unpause a paused container diff --git a/components/engine/integration-cli/docker_cli_config_create_test.go b/components/engine/integration-cli/docker_cli_config_create_test.go index b823254874..9bc108a587 100644 --- a/components/engine/integration-cli/docker_cli_config_create_test.go +++ b/components/engine/integration-cli/docker_cli_config_create_test.go @@ -78,6 +78,7 @@ func (s *DockerSwarmSuite) TestConfigCreateResolve(c *check.C) { c.Assert(out, checker.Contains, fake) out, err = d.Cmd("config", "rm", id) + c.Assert(err, checker.IsNil) c.Assert(out, checker.Contains, id) // Fake one will remain @@ -93,6 +94,7 @@ func (s *DockerSwarmSuite) TestConfigCreateResolve(c *check.C) { // - Full Name // - Partial ID (prefix) out, err = d.Cmd("config", "rm", id[:5]) + c.Assert(err, checker.Not(checker.IsNil)) c.Assert(out, checker.Not(checker.Contains), id) out, err = d.Cmd("config", "ls") c.Assert(err, checker.IsNil) @@ -101,6 +103,7 @@ func (s *DockerSwarmSuite) TestConfigCreateResolve(c *check.C) { // Remove based on ID prefix of the fake one should succeed out, err = d.Cmd("config", "rm", fake[:5]) + c.Assert(err, checker.IsNil) c.Assert(out, checker.Contains, fake[:5]) out, err = d.Cmd("config", "ls") c.Assert(err, checker.IsNil) diff --git a/components/engine/integration-cli/docker_cli_cp_test.go b/components/engine/integration-cli/docker_cli_cp_test.go index ec53712fab..a1997335b1 100644 --- a/components/engine/integration-cli/docker_cli_cp_test.go +++ b/components/engine/integration-cli/docker_cli_cp_test.go @@ -423,6 +423,7 @@ func (s *DockerSuite) TestCpSpecialFiles(c *check.C) { expected := readContainerFile(c, containerID, "resolv.conf") actual, err := ioutil.ReadFile(outDir + "/resolv.conf") + c.Assert(err, checker.IsNil) // Expected copied file to be duplicate of the container resolvconf c.Assert(bytes.Equal(actual, expected), checker.True) @@ -432,6 +433,7 @@ func (s *DockerSuite) TestCpSpecialFiles(c *check.C) { expected = readContainerFile(c, containerID, "hosts") actual, err = ioutil.ReadFile(outDir + "/hosts") + c.Assert(err, checker.IsNil) // Expected copied file to be duplicate of the container hosts c.Assert(bytes.Equal(actual, expected), checker.True) @@ -639,6 +641,7 @@ func (s *DockerSuite) TestCpSymlinkFromConToHostFollowSymlink(c *check.C) { expected := []byte(cpContainerContents) actual, err := ioutil.ReadFile(expectedPath) + c.Assert(err, checker.IsNil) if !bytes.Equal(actual, expected) { c.Fatalf("Expected copied file to be duplicate of the container symbol link target") diff --git a/components/engine/integration-cli/docker_cli_daemon_test.go b/components/engine/integration-cli/docker_cli_daemon_test.go index bd5f6d56c8..9fc96c56ae 100644 --- a/components/engine/integration-cli/docker_cli_daemon_test.go +++ b/components/engine/integration-cli/docker_cli_daemon_test.go @@ -448,10 +448,10 @@ func (s *DockerDaemonSuite) TestDaemonIPv6FixedCIDRAndMac(c *check.C) { s.d.StartWithBusybox(c, "--ipv6", "--fixed-cidr-v6=2001:db8:1::/64") - out, err := s.d.Cmd("run", "-itd", "--name=ipv6test", "--mac-address", "AA:BB:CC:DD:EE:FF", "busybox") + _, err := s.d.Cmd("run", "-itd", "--name=ipv6test", "--mac-address", "AA:BB:CC:DD:EE:FF", "busybox") c.Assert(err, checker.IsNil) - out, err = s.d.Cmd("inspect", "--format", "{{.NetworkSettings.Networks.bridge.GlobalIPv6Address}}", "ipv6test") + out, err := s.d.Cmd("inspect", "--format", "{{.NetworkSettings.Networks.bridge.GlobalIPv6Address}}", "ipv6test") c.Assert(err, checker.IsNil) c.Assert(strings.Trim(out, " \r\n'"), checker.Equals, "2001:db8:1::aabb:ccdd:eeff") } @@ -742,6 +742,7 @@ func (s *DockerDaemonSuite) TestDaemonBridgeFixedCidr2(c *check.C) { defer d.Cmd("stop", "bb") out, err = d.Cmd("exec", "bb", "/bin/sh", "-c", "ifconfig eth0 | awk '/inet addr/{print substr($2,6)}'") + c.Assert(err, check.IsNil) c.Assert(out, checker.Equals, "10.2.2.0\n") out, err = d.Cmd("run", "--rm", "busybox", "/bin/sh", "-c", "ifconfig eth0 | awk '/inet addr/{print substr($2,6)}'") @@ -1944,11 +1945,12 @@ func (s *DockerDaemonSuite) TestDaemonRestartWithNames(c *check.C) { test2ID := strings.TrimSpace(out) out, err = s.d.Cmd("run", "-d", "--name=test3", "--link", "test2:abc", "busybox", "top") + c.Assert(err, check.IsNil) test3ID := strings.TrimSpace(out) s.d.Restart(c) - out, err = s.d.Cmd("create", "--name=test", "busybox") + _, err = s.d.Cmd("create", "--name=test", "busybox") c.Assert(err, check.NotNil, check.Commentf("expected error trying to create container with duplicate name")) // this one is no longer needed, removing simplifies the remainder of the test out, err = s.d.Cmd("rm", "-f", "test") @@ -2615,6 +2617,7 @@ func (s *DockerDaemonSuite) TestDaemonRestartWithAutoRemoveContainer(c *check.C) c.Assert(err, checker.IsNil, check.Commentf("run top2: %v", out)) out, err = s.d.Cmd("ps") + c.Assert(err, checker.IsNil) c.Assert(out, checker.Contains, "top1", check.Commentf("top1 should be running")) c.Assert(out, checker.Contains, "top2", check.Commentf("top2 should be running")) @@ -2639,11 +2642,11 @@ func (s *DockerDaemonSuite) TestDaemonRestartSaveContainerExitCode(c *check.C) { // captured, so `.State.Error` is empty. // See the discussion on https://github.com/docker/docker/pull/30227#issuecomment-274161426, // and https://github.com/docker/docker/pull/26061#r78054578 for more information. - out, err := s.d.Cmd("run", "--name", containerName, "--init=false", "busybox", "toto") + _, err := s.d.Cmd("run", "--name", containerName, "--init=false", "busybox", "toto") c.Assert(err, checker.NotNil) // Check that those values were saved on disk - out, err = s.d.Cmd("inspect", "-f", "{{.State.ExitCode}}", containerName) + out, err := s.d.Cmd("inspect", "-f", "{{.State.ExitCode}}", containerName) out = strings.TrimSpace(out) c.Assert(err, checker.IsNil) c.Assert(out, checker.Equals, "127") diff --git a/components/engine/integration-cli/docker_cli_health_test.go b/components/engine/integration-cli/docker_cli_health_test.go index a06b6c8830..4fb63994bb 100644 --- a/components/engine/integration-cli/docker_cli_health_test.go +++ b/components/engine/integration-cli/docker_cli_health_test.go @@ -81,7 +81,7 @@ func (s *DockerSuite) TestHealth(c *check.C) { dockerCmd(c, "rm", "-f", name) // Disable the check from the CLI - out, _ = dockerCmd(c, "create", "--name=noh", "--no-healthcheck", imageName) + dockerCmd(c, "create", "--name=noh", "--no-healthcheck", imageName) out, _ = dockerCmd(c, "inspect", "--format={{.Config.Healthcheck.Test}}", "noh") c.Check(out, checker.Equals, "[NONE]\n") dockerCmd(c, "rm", "noh") diff --git a/components/engine/integration-cli/docker_cli_logs_test.go b/components/engine/integration-cli/docker_cli_logs_test.go index 17ee5deaad..60ea333815 100644 --- a/components/engine/integration-cli/docker_cli_logs_test.go +++ b/components/engine/integration-cli/docker_cli_logs_test.go @@ -181,14 +181,14 @@ func (s *DockerSuite) TestLogsSinceFutureFollow(c *check.C) { // TODO Windows TP5 - Figure out why this test is so flakey. Disabled for now. testRequires(c, DaemonIsLinux) name := "testlogssincefuturefollow" - out, _ := dockerCmd(c, "run", "-d", "--name", name, "busybox", "/bin/sh", "-c", `for i in $(seq 1 5); do echo log$i; sleep 1; done`) + dockerCmd(c, "run", "-d", "--name", name, "busybox", "/bin/sh", "-c", `for i in $(seq 1 5); do echo log$i; sleep 1; done`) // Extract one timestamp from the log file to give us a starting point for // our `--since` argument. Because the log producer runs in the background, // we need to check repeatedly for some output to be produced. var timestamp string for i := 0; i != 100 && timestamp == ""; i++ { - if out, _ = dockerCmd(c, "logs", "-t", name); out == "" { + if out, _ := dockerCmd(c, "logs", "-t", name); out == "" { time.Sleep(time.Millisecond * 100) // Retry } else { timestamp = strings.Split(strings.Split(out, "\n")[0], " ")[0] @@ -200,7 +200,7 @@ func (s *DockerSuite) TestLogsSinceFutureFollow(c *check.C) { c.Assert(err, check.IsNil) since := t.Unix() + 2 - out, _ = dockerCmd(c, "logs", "-t", "-f", fmt.Sprintf("--since=%v", since), name) + out, _ := dockerCmd(c, "logs", "-t", "-f", fmt.Sprintf("--since=%v", since), name) c.Assert(out, checker.Not(checker.HasLen), 0, check.Commentf("cannot read from empty log")) lines := strings.Split(strings.TrimSpace(out), "\n") for _, v := range lines { diff --git a/components/engine/integration-cli/docker_cli_network_unix_test.go b/components/engine/integration-cli/docker_cli_network_unix_test.go index a0abb6798a..d4167f6620 100644 --- a/components/engine/integration-cli/docker_cli_network_unix_test.go +++ b/components/engine/integration-cli/docker_cli_network_unix_test.go @@ -348,7 +348,7 @@ func (s *DockerNetworkSuite) TestDockerNetworkLsFilter(c *check.C) { out, _ = dockerCmd(c, "network", "ls", "-f", "type=custom", "-f", "type=builtin") assertNwList(c, out, []string{"bridge", "dev", "host", "none"}) - out, _ = dockerCmd(c, "network", "create", "--label", testLabel+"="+testValue, testNet) + dockerCmd(c, "network", "create", "--label", testLabel+"="+testValue, testNet) assertNwIsAvailable(c, testNet) out, _ = dockerCmd(c, "network", "ls", "-f", "label="+testLabel) @@ -880,8 +880,6 @@ func (s *DockerNetworkSuite) TestDockerNetworkAnonymousEndpoint(c *check.C) { out, _ = dockerCmd(c, "run", "-d", "--net", cstmBridgeNw, "busybox", "top") cid2 := strings.TrimSpace(out) - hosts2 := readContainerFileWithExec(c, cid2, hostsFile) - // verify first container etc/hosts file has not changed hosts1post := readContainerFileWithExec(c, cid1, hostsFile) c.Assert(string(hosts1), checker.Equals, string(hosts1post), @@ -894,7 +892,7 @@ func (s *DockerNetworkSuite) TestDockerNetworkAnonymousEndpoint(c *check.C) { dockerCmd(c, "network", "connect", cstmBridgeNw1, cid2) - hosts2 = readContainerFileWithExec(c, cid2, hostsFile) + hosts2 := readContainerFileWithExec(c, cid2, hostsFile) hosts1post = readContainerFileWithExec(c, cid1, hostsFile) c.Assert(string(hosts1), checker.Equals, string(hosts1post), check.Commentf("Unexpected %s change on container connect", hostsFile)) diff --git a/components/engine/integration-cli/docker_cli_plugins_test.go b/components/engine/integration-cli/docker_cli_plugins_test.go index 391c74aa5d..3692b6cb70 100644 --- a/components/engine/integration-cli/docker_cli_plugins_test.go +++ b/components/engine/integration-cli/docker_cli_plugins_test.go @@ -62,10 +62,10 @@ func (ps *DockerPluginSuite) TestPluginBasicOps(c *check.C) { func (ps *DockerPluginSuite) TestPluginForceRemove(c *check.C) { pNameWithTag := ps.getPluginRepoWithTag() - out, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", pNameWithTag) + _, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", pNameWithTag) c.Assert(err, checker.IsNil) - out, _, err = dockerCmdWithError("plugin", "remove", pNameWithTag) + out, _, _ := dockerCmdWithError("plugin", "remove", pNameWithTag) c.Assert(out, checker.Contains, "is enabled") out, _, err = dockerCmdWithError("plugin", "remove", "--force", pNameWithTag) @@ -82,7 +82,7 @@ func (s *DockerSuite) TestPluginActive(c *check.C) { _, _, err = dockerCmdWithError("volume", "create", "-d", pNameWithTag, "--name", "testvol1") c.Assert(err, checker.IsNil) - out, _, err := dockerCmdWithError("plugin", "disable", pNameWithTag) + out, _, _ := dockerCmdWithError("plugin", "disable", pNameWithTag) c.Assert(out, checker.Contains, "in use") _, _, err = dockerCmdWithError("volume", "rm", "testvol1") @@ -98,21 +98,21 @@ func (s *DockerSuite) TestPluginActive(c *check.C) { func (s *DockerSuite) TestPluginActiveNetwork(c *check.C) { testRequires(c, DaemonIsLinux, IsAmd64, Network) - out, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", npNameWithTag) + _, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", npNameWithTag) c.Assert(err, checker.IsNil) - out, _, err = dockerCmdWithError("network", "create", "-d", npNameWithTag, "test") + out, _, err := dockerCmdWithError("network", "create", "-d", npNameWithTag, "test") c.Assert(err, checker.IsNil) nID := strings.TrimSpace(out) - out, _, err = dockerCmdWithError("plugin", "remove", npNameWithTag) + out, _, _ = dockerCmdWithError("plugin", "remove", npNameWithTag) c.Assert(out, checker.Contains, "is in use") _, _, err = dockerCmdWithError("network", "rm", nID) c.Assert(err, checker.IsNil) - out, _, err = dockerCmdWithError("plugin", "remove", npNameWithTag) + out, _, _ = dockerCmdWithError("plugin", "remove", npNameWithTag) c.Assert(out, checker.Contains, "is enabled") _, _, err = dockerCmdWithError("plugin", "disable", npNameWithTag) @@ -400,7 +400,7 @@ func (ps *DockerPluginSuite) TestPluginIDPrefix(c *check.C) { c.Assert(out, checker.Contains, "false") // Remove - out, _, err = dockerCmdWithError("plugin", "remove", id[:5]) + _, _, err = dockerCmdWithError("plugin", "remove", id[:5]) c.Assert(err, checker.IsNil) // List returns none out, _, err = dockerCmdWithError("plugin", "ls") diff --git a/components/engine/integration-cli/docker_cli_ps_test.go b/components/engine/integration-cli/docker_cli_ps_test.go index a975bc3542..824ca683ba 100644 --- a/components/engine/integration-cli/docker_cli_ps_test.go +++ b/components/engine/integration-cli/docker_cli_ps_test.go @@ -792,19 +792,14 @@ func (s *DockerSuite) TestPsListContainersFilterNetwork(c *check.C) { } func (s *DockerSuite) TestPsByOrder(c *check.C) { - name1 := "xyz-abc" - out := runSleepingContainer(c, "--name", name1) + out := runSleepingContainer(c, "--name", "xyz-abc") container1 := strings.TrimSpace(out) - name2 := "xyz-123" - out = runSleepingContainer(c, "--name", name2) + out = runSleepingContainer(c, "--name", "xyz-123") container2 := strings.TrimSpace(out) - name3 := "789-abc" - out = runSleepingContainer(c, "--name", name3) - - name4 := "789-123" - out = runSleepingContainer(c, "--name", name4) + runSleepingContainer(c, "--name", "789-abc") + runSleepingContainer(c, "--name", "789-123") // Run multiple time should have the same result out = cli.DockerCmd(c, "ps", "--no-trunc", "-q", "-f", "name=xyz").Combined() diff --git a/components/engine/integration-cli/docker_cli_restart_test.go b/components/engine/integration-cli/docker_cli_restart_test.go index 1b4c928b9a..02d4254c35 100644 --- a/components/engine/integration-cli/docker_cli_restart_test.go +++ b/components/engine/integration-cli/docker_cli_restart_test.go @@ -224,6 +224,7 @@ func (s *DockerSuite) TestRestartWithPolicyUserDefinedNetwork(c *check.C) { c.Assert(err, check.IsNil) err = waitInspect("second", "{{.State.Status}}", "running", 5*time.Second) + c.Assert(err, check.IsNil) // ping to first and its alias foo must still succeed _, _, err = dockerCmdWithError("exec", "second", "ping", "-c", "1", "first") diff --git a/components/engine/integration-cli/docker_cli_run_test.go b/components/engine/integration-cli/docker_cli_run_test.go index aaaa7174d3..22c610fe79 100644 --- a/components/engine/integration-cli/docker_cli_run_test.go +++ b/components/engine/integration-cli/docker_cli_run_test.go @@ -623,6 +623,7 @@ func (s *DockerSuite) TestRunCreateVolumeWithSymlink(c *check.C) { // Cannot run on Windows as relies on Linux-specific functionality (sh -c mount...) testRequires(c, DaemonIsLinux) workingDirectory, err := ioutil.TempDir("", "TestRunCreateVolumeWithSymlink") + c.Assert(err, checker.IsNil) image := "docker-test-createvolumewithsymlink" buildCmd := exec.Command(dockerBinary, "build", "-t", image, "-") diff --git a/components/engine/integration-cli/docker_cli_secret_create_test.go b/components/engine/integration-cli/docker_cli_secret_create_test.go index a807e4e7e7..738db3b9e5 100644 --- a/components/engine/integration-cli/docker_cli_secret_create_test.go +++ b/components/engine/integration-cli/docker_cli_secret_create_test.go @@ -39,6 +39,7 @@ func (s *DockerSwarmSuite) TestSecretCreateResolve(c *check.C) { c.Assert(out, checker.Contains, fake) out, err = d.Cmd("secret", "rm", id) + c.Assert(err, checker.IsNil) c.Assert(out, checker.Contains, id) // Fake one will remain @@ -54,6 +55,7 @@ func (s *DockerSwarmSuite) TestSecretCreateResolve(c *check.C) { // - Full Name // - Partial ID (prefix) out, err = d.Cmd("secret", "rm", id[:5]) + c.Assert(err, checker.Not(checker.IsNil)) c.Assert(out, checker.Not(checker.Contains), id) out, err = d.Cmd("secret", "ls") c.Assert(err, checker.IsNil) @@ -62,6 +64,7 @@ func (s *DockerSwarmSuite) TestSecretCreateResolve(c *check.C) { // Remove based on ID prefix of the fake one should succeed out, err = d.Cmd("secret", "rm", fake[:5]) + c.Assert(err, checker.IsNil) c.Assert(out, checker.Contains, fake[:5]) out, err = d.Cmd("secret", "ls") c.Assert(err, checker.IsNil) diff --git a/components/engine/integration-cli/docker_cli_service_scale_test.go b/components/engine/integration-cli/docker_cli_service_scale_test.go index 41b49d64aa..ad045ee570 100644 --- a/components/engine/integration-cli/docker_cli_service_scale_test.go +++ b/components/engine/integration-cli/docker_cli_service_scale_test.go @@ -21,16 +21,16 @@ func (s *DockerSwarmSuite) TestServiceScale(c *check.C) { service2Args := append([]string{"service", "create", "--detach", "--no-resolve-image", "--name", service2Name, "--mode=global", defaultSleepImage}, sleepCommandForDaemonPlatform()...) // Create services - out, err := d.Cmd(service1Args...) + _, err := d.Cmd(service1Args...) c.Assert(err, checker.IsNil) - out, err = d.Cmd(service2Args...) + _, err = d.Cmd(service2Args...) c.Assert(err, checker.IsNil) - out, err = d.Cmd("service", "scale", "TestService1=2") + _, err = d.Cmd("service", "scale", "TestService1=2") c.Assert(err, checker.IsNil) - out, err = d.Cmd("service", "scale", "TestService1=foobar") + out, err := d.Cmd("service", "scale", "TestService1=foobar") c.Assert(err, checker.NotNil) str := fmt.Sprintf("%s: invalid replicas value %s", service1Name, "foobar") diff --git a/components/engine/integration-cli/docker_cli_swarm_test.go b/components/engine/integration-cli/docker_cli_swarm_test.go index 057c0d94c8..ae9fb3e8dd 100644 --- a/components/engine/integration-cli/docker_cli_swarm_test.go +++ b/components/engine/integration-cli/docker_cli_swarm_test.go @@ -279,13 +279,13 @@ func (s *DockerSwarmSuite) TestSwarmPublishAdd(c *check.C) { c.Assert(err, checker.IsNil) c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), "") - out, err = d.Cmd("service", "update", "--detach", "--publish-add", "80:80", name) + _, err = d.Cmd("service", "update", "--detach", "--publish-add", "80:80", name) c.Assert(err, checker.IsNil) - out, err = d.Cmd("service", "update", "--detach", "--publish-add", "80:80", name) + _, err = d.Cmd("service", "update", "--detach", "--publish-add", "80:80", name) c.Assert(err, checker.IsNil) - out, err = d.Cmd("service", "update", "--detach", "--publish-add", "80:80", "--publish-add", "80:20", name) + _, err = d.Cmd("service", "update", "--detach", "--publish-add", "80:80", "--publish-add", "80:20", name) c.Assert(err, checker.NotNil) out, err = d.Cmd("service", "inspect", "--format", "{{ .Spec.EndpointSpec.Ports }}", name) @@ -841,14 +841,14 @@ func (s *DockerSwarmSuite) TestSwarmServiceTTY(c *check.C) { // Without --tty expectedOutput := "none" - out, err := d.Cmd("service", "create", "--detach", "--no-resolve-image", "--name", name, "busybox", "sh", "-c", ttyCheck) + _, err := d.Cmd("service", "create", "--detach", "--no-resolve-image", "--name", name, "busybox", "sh", "-c", ttyCheck) c.Assert(err, checker.IsNil) // Make sure task has been deployed. waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, 1) // We need to get the container id. - out, err = d.Cmd("ps", "-q", "--no-trunc") + out, err := d.Cmd("ps", "-q", "--no-trunc") c.Assert(err, checker.IsNil) id := strings.TrimSpace(out) @@ -857,14 +857,14 @@ func (s *DockerSwarmSuite) TestSwarmServiceTTY(c *check.C) { c.Assert(out, checker.Contains, expectedOutput, check.Commentf("Expected '%s', but got %q", expectedOutput, out)) // Remove service - out, err = d.Cmd("service", "rm", name) + _, err = d.Cmd("service", "rm", name) c.Assert(err, checker.IsNil) // Make sure container has been destroyed. waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, 0) // With --tty expectedOutput = "TTY" - out, err = d.Cmd("service", "create", "--detach", "--no-resolve-image", "--name", name, "--tty", "busybox", "sh", "-c", ttyCheck) + _, err = d.Cmd("service", "create", "--detach", "--no-resolve-image", "--name", name, "--tty", "busybox", "sh", "-c", ttyCheck) c.Assert(err, checker.IsNil) // Make sure task has been deployed. @@ -1069,6 +1069,7 @@ func (s *DockerSwarmSuite) TestSwarmInitLocked(c *check.C) { c.Assert(unlockKey, checker.Not(checker.Equals), "") outs, err = d.Cmd("swarm", "unlock-key", "-q") + c.Assert(err, checker.IsNil) c.Assert(outs, checker.Equals, unlockKey+"\n") c.Assert(getNodeStatus(c, d), checker.Equals, swarm.LocalNodeStateActive) @@ -1168,6 +1169,7 @@ func (s *DockerSwarmSuite) TestSwarmLockUnlockCluster(c *check.C) { c.Assert(unlockKey, checker.Not(checker.Equals), "") outs, err = d1.Cmd("swarm", "unlock-key", "-q") + c.Assert(err, checker.IsNil) c.Assert(outs, checker.Equals, unlockKey+"\n") // The ones that got the cluster update should be set to locked @@ -1234,6 +1236,7 @@ func (s *DockerSwarmSuite) TestSwarmJoinPromoteLocked(c *check.C) { c.Assert(unlockKey, checker.Not(checker.Equals), "") outs, err = d1.Cmd("swarm", "unlock-key", "-q") + c.Assert(err, checker.IsNil) c.Assert(outs, checker.Equals, unlockKey+"\n") // joined workers start off unlocked @@ -1306,6 +1309,7 @@ func (s *DockerSwarmSuite) TestSwarmRotateUnlockKey(c *check.C) { c.Assert(unlockKey, checker.Not(checker.Equals), "") outs, err = d.Cmd("swarm", "unlock-key", "-q") + c.Assert(err, checker.IsNil) c.Assert(outs, checker.Equals, unlockKey+"\n") // Rotate multiple times @@ -1390,6 +1394,7 @@ func (s *DockerSwarmSuite) TestSwarmClusterRotateUnlockKey(c *check.C) { c.Assert(unlockKey, checker.Not(checker.Equals), "") outs, err = d1.Cmd("swarm", "unlock-key", "-q") + c.Assert(err, checker.IsNil) c.Assert(outs, checker.Equals, unlockKey+"\n") // Rotate multiple times diff --git a/components/engine/integration-cli/docker_cli_swarm_unix_test.go b/components/engine/integration-cli/docker_cli_swarm_unix_test.go index 3b890bcc69..f491a0da60 100644 --- a/components/engine/integration-cli/docker_cli_swarm_unix_test.go +++ b/components/engine/integration-cli/docker_cli_swarm_unix_test.go @@ -26,6 +26,7 @@ func (s *DockerSwarmSuite) TestSwarmVolumePlugin(c *check.C) { // create a dummy volume to trigger lazy loading of the plugin out, err = d.Cmd("volume", "create", "-d", "customvolumedriver", "hello") + c.Assert(err, checker.IsNil, check.Commentf(out)) // TODO(aaronl): It will take about 15 seconds for swarm to realize the // plugin was loaded. Switching the test over to plugin v2 would avoid diff --git a/components/engine/integration-cli/docker_cli_update_unix_test.go b/components/engine/integration-cli/docker_cli_update_unix_test.go index 564c50f32f..1fb30f04d6 100644 --- a/components/engine/integration-cli/docker_cli_update_unix_test.go +++ b/components/engine/integration-cli/docker_cli_update_unix_test.go @@ -324,7 +324,7 @@ func (s *DockerSuite) TestUpdateWithNanoCPUs(c *check.C) { c.Assert(err, checker.NotNil) c.Assert(out, checker.Contains, "Conflicting options: CPU Quota cannot be updated as NanoCPUs has already been set") - out, _ = dockerCmd(c, "update", "--cpus", "0.8", "top") + dockerCmd(c, "update", "--cpus", "0.8", "top") inspect, err = clt.ContainerInspect(context.Background(), "top") c.Assert(err, checker.IsNil) c.Assert(inspect.HostConfig.NanoCPUs, checker.Equals, int64(800000000)) diff --git a/components/engine/integration-cli/docker_cli_userns_test.go b/components/engine/integration-cli/docker_cli_userns_test.go index 54cfdd179c..13d1f56dc6 100644 --- a/components/engine/integration-cli/docker_cli_userns_test.go +++ b/components/engine/integration-cli/docker_cli_userns_test.go @@ -61,12 +61,12 @@ func (s *DockerDaemonSuite) TestDaemonUserNamespaceRootSetting(c *check.C) { c.Assert(err, checker.IsNil, check.Commentf("Could not inspect running container: out: %q", pid)) // check the uid and gid maps for the PID to ensure root is remapped // (cmd = cat /proc//uid_map | grep -E '0\s+9999\s+1') - out, err = RunCommandPipelineWithOutput( + _, err = RunCommandPipelineWithOutput( exec.Command("cat", "/proc/"+strings.TrimSpace(pid)+"/uid_map"), exec.Command("grep", "-E", fmt.Sprintf("0[[:space:]]+%d[[:space:]]+", uid))) c.Assert(err, check.IsNil) - out, err = RunCommandPipelineWithOutput( + _, err = RunCommandPipelineWithOutput( exec.Command("cat", "/proc/"+strings.TrimSpace(pid)+"/gid_map"), exec.Command("grep", "-E", fmt.Sprintf("0[[:space:]]+%d[[:space:]]+", gid))) c.Assert(err, check.IsNil) diff --git a/components/engine/integration-cli/docker_cli_volume_test.go b/components/engine/integration-cli/docker_cli_volume_test.go index 340bdfe254..257ac89701 100644 --- a/components/engine/integration-cli/docker_cli_volume_test.go +++ b/components/engine/integration-cli/docker_cli_volume_test.go @@ -300,10 +300,10 @@ func (s *DockerSuite) TestVolumeCLICreateLabel(c *check.C) { testLabel := "foo" testValue := "bar" - out, _, err := dockerCmdWithError("volume", "create", "--label", testLabel+"="+testValue, testVol) + _, _, err := dockerCmdWithError("volume", "create", "--label", testLabel+"="+testValue, testVol) c.Assert(err, check.IsNil) - out, _ = dockerCmd(c, "volume", "inspect", "--format={{ .Labels."+testLabel+" }}", testVol) + out, _ := dockerCmd(c, "volume", "inspect", "--format={{ .Labels."+testLabel+" }}", testVol) c.Assert(strings.TrimSpace(out), check.Equals, testValue) } @@ -325,25 +325,25 @@ func (s *DockerSuite) TestVolumeCLICreateLabelMultiple(c *check.C) { args = append(args, "--label", k+"="+v) } - out, _, err := dockerCmdWithError(args...) + _, _, err := dockerCmdWithError(args...) c.Assert(err, check.IsNil) for k, v := range testLabels { - out, _ = dockerCmd(c, "volume", "inspect", "--format={{ .Labels."+k+" }}", testVol) + out, _ := dockerCmd(c, "volume", "inspect", "--format={{ .Labels."+k+" }}", testVol) c.Assert(strings.TrimSpace(out), check.Equals, v) } } func (s *DockerSuite) TestVolumeCLILsFilterLabels(c *check.C) { testVol1 := "testvolcreatelabel-1" - out, _, err := dockerCmdWithError("volume", "create", "--label", "foo=bar1", testVol1) + _, _, err := dockerCmdWithError("volume", "create", "--label", "foo=bar1", testVol1) c.Assert(err, check.IsNil) testVol2 := "testvolcreatelabel-2" - out, _, err = dockerCmdWithError("volume", "create", "--label", "foo=bar2", testVol2) + _, _, err = dockerCmdWithError("volume", "create", "--label", "foo=bar2", testVol2) c.Assert(err, check.IsNil) - out, _ = dockerCmd(c, "volume", "ls", "--filter", "label=foo") + out, _ := dockerCmd(c, "volume", "ls", "--filter", "label=foo") // filter with label=key c.Assert(out, checker.Contains, "testvolcreatelabel-1\n", check.Commentf("expected volume 'testvolcreatelabel-1' in output")) @@ -367,15 +367,15 @@ func (s *DockerSuite) TestVolumeCLILsFilterLabels(c *check.C) { func (s *DockerSuite) TestVolumeCLILsFilterDrivers(c *check.C) { // using default volume driver local to create volumes testVol1 := "testvol-1" - out, _, err := dockerCmdWithError("volume", "create", testVol1) + _, _, err := dockerCmdWithError("volume", "create", testVol1) c.Assert(err, check.IsNil) testVol2 := "testvol-2" - out, _, err = dockerCmdWithError("volume", "create", testVol2) + _, _, err = dockerCmdWithError("volume", "create", testVol2) c.Assert(err, check.IsNil) // filter with driver=local - out, _ = dockerCmd(c, "volume", "ls", "--filter", "driver=local") + out, _ := dockerCmd(c, "volume", "ls", "--filter", "driver=local") c.Assert(out, checker.Contains, "testvol-1\n", check.Commentf("expected volume 'testvol-1' in output")) c.Assert(out, checker.Contains, "testvol-2\n", check.Commentf("expected volume 'testvol-2' in output")) @@ -434,7 +434,7 @@ func (s *DockerSuite) TestVolumeCLIRmForceInUse(c *check.C) { c.Assert(id, checker.Equals, name) prefix, slash := getPrefixAndSlashFromDaemonPlatform() - out, e := dockerCmd(c, "create", "-v", "testvolume:"+prefix+slash+"foo", "busybox") + out, _ = dockerCmd(c, "create", "-v", "testvolume:"+prefix+slash+"foo", "busybox") cid := strings.TrimSpace(out) _, _, err := dockerCmdWithError("volume", "rm", "-f", name) @@ -454,7 +454,7 @@ func (s *DockerSuite) TestVolumeCLIRmForceInUse(c *check.C) { c.Assert(out, checker.Contains, name) // Verify removing the volume after the container is removed works - _, e = dockerCmd(c, "rm", cid) + _, e := dockerCmd(c, "rm", cid) c.Assert(e, check.Equals, 0) _, e = dockerCmd(c, "volume", "rm", "-f", name) From d799a9b46d3411ccec59437dc9266d0c9daab662 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 9 Jul 2018 19:51:13 +0200 Subject: [PATCH 2/4] Fix golint issues Signed-off-by: Sebastiaan van Stijn Upstream-commit: 35f7e7c50a131494c9d530800e80bf2da42fb89c Component: engine --- .../builder-next/adapters/snapshot/snapshot.go | 18 ++++-------------- .../internal/container/container.go | 2 ++ .../integration/internal/network/network.go | 1 + .../plugin/graphdriver/external_test.go | 1 + 4 files changed, 8 insertions(+), 14 deletions(-) diff --git a/components/engine/builder/builder-next/adapters/snapshot/snapshot.go b/components/engine/builder/builder-next/adapters/snapshot/snapshot.go index 5b2c583a17..e1a12a4563 100644 --- a/components/engine/builder/builder-next/adapters/snapshot/snapshot.go +++ b/components/engine/builder/builder-next/adapters/snapshot/snapshot.go @@ -90,20 +90,13 @@ func (s *snapshotter) Prepare(ctx context.Context, key, parent string, opts ...s if err := s.opt.GraphDriver.Create(key, parent, nil); err != nil { return err } - if err := s.db.Update(func(tx *bolt.Tx) error { + return s.db.Update(func(tx *bolt.Tx) error { b, err := tx.CreateBucketIfNotExists([]byte(key)) if err != nil { return err } - - if err := b.Put(keyParent, []byte(origParent)); err != nil { - return err - } - return nil - }); err != nil { - return err - } - return nil + return b.Put(keyParent, []byte(origParent)) + }) } func (s *snapshotter) chainID(key string) (layer.ChainID, bool) { @@ -332,10 +325,7 @@ func (s *snapshotter) Commit(ctx context.Context, name, key string, opts ...snap if err != nil { return err } - if err := b.Put(keyCommitted, []byte(key)); err != nil { - return err - } - return nil + return b.Put(keyCommitted, []byte(key)) }) } diff --git a/components/engine/integration/internal/container/container.go b/components/engine/integration/internal/container/container.go index 489e07154a..20ad774242 100644 --- a/components/engine/integration/internal/container/container.go +++ b/components/engine/integration/internal/container/container.go @@ -21,6 +21,7 @@ type TestContainerConfig struct { } // Create creates a container with the specified options +// nolint: golint func Create(t *testing.T, ctx context.Context, client client.APIClient, ops ...func(*TestContainerConfig)) string { // nolint: golint t.Helper() config := &TestContainerConfig{ @@ -43,6 +44,7 @@ func Create(t *testing.T, ctx context.Context, client client.APIClient, ops ...f } // Run creates and start a container with the specified options +// nolint: golint func Run(t *testing.T, ctx context.Context, client client.APIClient, ops ...func(*TestContainerConfig)) string { // nolint: golint t.Helper() id := Create(t, ctx, client, ops...) diff --git a/components/engine/integration/internal/network/network.go b/components/engine/integration/internal/network/network.go index 9c13114f92..07d366433b 100644 --- a/components/engine/integration/internal/network/network.go +++ b/components/engine/integration/internal/network/network.go @@ -26,6 +26,7 @@ func Create(ctx context.Context, client client.APIClient, name string, ops ...fu } // CreateNoError creates a network with the specified options and verifies there were no errors +// nolint: golint func CreateNoError(t *testing.T, ctx context.Context, client client.APIClient, name string, ops ...func(*types.NetworkCreate)) string { // nolint: golint t.Helper() diff --git a/components/engine/integration/plugin/graphdriver/external_test.go b/components/engine/integration/plugin/graphdriver/external_test.go index 3596056a84..2aabc21df3 100644 --- a/components/engine/integration/plugin/graphdriver/external_test.go +++ b/components/engine/integration/plugin/graphdriver/external_test.go @@ -437,6 +437,7 @@ func TestGraphdriverPluginV2(t *testing.T) { testGraphDriver(t, client, ctx, plugin, nil) } +// nolint: golint func testGraphDriver(t *testing.T, c client.APIClient, ctx context.Context, driverName string, afterContainerRunFn func(*testing.T)) { //nolint: golint id := container.Run(t, ctx, c, container.WithCmd("sh", "-c", "echo hello > /hello")) From 8a9efc106f3a6de9250425ab744eb532876af3af Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Wed, 11 Jul 2018 16:44:58 -0700 Subject: [PATCH 3/4] lcow: fix debug in startServiceVMIfNotRunning() When go-1.11beta1 is used for building, the following error is reported: > 14:56:20 daemon\graphdriver\lcow\lcow.go:236: Debugf format %s reads > arg #2, but call has 1 arg While fixing this, let's also fix a few other things in this very function (startServiceVMIfNotRunning): 1. Do not use fmt.Printf when not required. 2. Use `title` whenever possible. 3. Don't add `id` to messages as `title` already has it. 4. Remove duplicated colons. 5. Try to unify style of messages. 6. s/startservicevmifnotrunning/startServiceVMIfNotRunning/ ... In general, logging/debugging here is a mess and requires much more love than I can give it at the moment. Areas for improvement: 1. Add a global var logger = logrus.WithField("storage-driver", "lcow") and use it everywhere else in the code. 2. Use logger.WithField("id", id) whenever possible (same for "context" and other similar fields). 3. Revise all the errors returned to be uniform. 4. Make use of errors.Wrap[f] whenever possible. Signed-off-by: Kir Kolyshkin Upstream-commit: b7a95a3ce4c731c0fca204435be758ea89d6050f Component: engine --- .../engine/daemon/graphdriver/lcow/lcow.go | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/components/engine/daemon/graphdriver/lcow/lcow.go b/components/engine/daemon/graphdriver/lcow/lcow.go index 649beccdc6..242aa8016e 100644 --- a/components/engine/daemon/graphdriver/lcow/lcow.go +++ b/components/engine/daemon/graphdriver/lcow/lcow.go @@ -219,21 +219,21 @@ func (d *Driver) startServiceVMIfNotRunning(id string, mvdToAdd []hcsshim.Mapped // Use the global ID if in global mode id = d.getVMID(id) - title := fmt.Sprintf("lcowdriver: startservicevmifnotrunning %s:", id) + title := "lcowdriver: startServiceVMIfNotRunning " + id // Attempt to add ID to the service vm map - logrus.Debugf("%s: Adding entry to service vm map", title) + logrus.Debugf("%s: adding entry to service vm map", title) svm, exists, err := d.serviceVms.add(id) if err != nil && err == errVMisTerminating { // VM is in the process of terminating. Wait until it's done and and then try again - logrus.Debugf("%s: VM with current ID still in the process of terminating: %s", title, id) + logrus.Debugf("%s: VM with current ID still in the process of terminating", title) if err := svm.getStopError(); err != nil { - logrus.Debugf("%s: VM %s did not stop successfully: %s", title, id, err) + logrus.Debugf("%s: VM did not stop successfully: %s", title, err) return nil, err } return d.startServiceVMIfNotRunning(id, mvdToAdd, context) } else if err != nil { - logrus.Debugf("%s: failed to add service vm to map: %s", err) + logrus.Debugf("%s: failed to add service vm to map: %s", title, err) return nil, fmt.Errorf("%s: failed to add to service vm map: %s", title, err) } @@ -248,7 +248,7 @@ func (d *Driver) startServiceVMIfNotRunning(id string, mvdToAdd []hcsshim.Mapped } // We are the first service for this id, so we need to start it - logrus.Debugf("%s: service vm doesn't exist. Now starting it up: %s", title, id) + logrus.Debugf("%s: service vm doesn't exist. Now starting it up", title) defer func() { // Signal that start has finished, passing in the error if any. @@ -261,7 +261,7 @@ func (d *Driver) startServiceVMIfNotRunning(id string, mvdToAdd []hcsshim.Mapped // Generate a default configuration if err := svm.config.GenerateDefault(d.options); err != nil { - return nil, fmt.Errorf("%s failed to generate default gogcs configuration for global svm (%s): %s", title, context, err) + return nil, fmt.Errorf("%s: failed to generate default gogcs configuration for global svm (%s): %s", title, context, err) } // For the name, we deliberately suffix if safe-mode to ensure that it doesn't @@ -277,19 +277,19 @@ func (d *Driver) startServiceVMIfNotRunning(id string, mvdToAdd []hcsshim.Mapped // and not in the process of being created by another thread. scratchTargetFile := filepath.Join(d.dataRoot, scratchDirectory, fmt.Sprintf("%s.vhdx", id)) - logrus.Debugf("%s locking cachedScratchMutex", title) + logrus.Debugf("%s: locking cachedScratchMutex", title) d.cachedScratchMutex.Lock() if _, err := os.Stat(d.cachedScratchFile); err == nil { // Make a copy of cached scratch to the scratch directory - logrus.Debugf("lcowdriver: startServiceVmIfNotRunning: (%s) cloning cached scratch for mvd", context) + logrus.Debugf("%s: (%s) cloning cached scratch for mvd", title, context) if err := client.CopyFile(d.cachedScratchFile, scratchTargetFile, true); err != nil { - logrus.Debugf("%s releasing cachedScratchMutex on err: %s", title, err) + logrus.Debugf("%s: releasing cachedScratchMutex on err: %s", title, err) d.cachedScratchMutex.Unlock() return nil, err } // Add the cached clone as a mapped virtual disk - logrus.Debugf("lcowdriver: startServiceVmIfNotRunning: (%s) adding cloned scratch as mvd", context) + logrus.Debugf("%s: (%s) adding cloned scratch as mvd", title, context) mvd := hcsshim.MappedVirtualDisk{ HostPath: scratchTargetFile, ContainerPath: toolsScratchPath, @@ -299,7 +299,7 @@ func (d *Driver) startServiceVMIfNotRunning(id string, mvdToAdd []hcsshim.Mapped svm.scratchAttached = true } - logrus.Debugf("%s releasing cachedScratchMutex", title) + logrus.Debugf("%s: releasing cachedScratchMutex", title) d.cachedScratchMutex.Unlock() // If requested to start it with a mapped virtual disk, add it now. @@ -309,7 +309,7 @@ func (d *Driver) startServiceVMIfNotRunning(id string, mvdToAdd []hcsshim.Mapped } // Start it. - logrus.Debugf("lcowdriver: startServiceVmIfNotRunning: (%s) starting %s", context, svm.config.Name) + logrus.Debugf("%s: (%s) starting %s", title, context, svm.config.Name) if err := svm.config.StartUtilityVM(); err != nil { return nil, fmt.Errorf("failed to start service utility VM (%s): %s", context, err) } @@ -317,31 +317,31 @@ func (d *Driver) startServiceVMIfNotRunning(id string, mvdToAdd []hcsshim.Mapped // defer function to terminate the VM if the next steps fail defer func() { if err != nil { - waitTerminate(svm, fmt.Sprintf("startServiceVmIfNotRunning: %s (%s)", id, context)) + waitTerminate(svm, fmt.Sprintf("%s: (%s)", title, context)) } }() // Now we have a running service VM, we can create the cached scratch file if it doesn't exist. - logrus.Debugf("%s locking cachedScratchMutex", title) + logrus.Debugf("%s: locking cachedScratchMutex", title) d.cachedScratchMutex.Lock() if _, err := os.Stat(d.cachedScratchFile); err != nil { - logrus.Debugf("%s (%s): creating an SVM scratch", title, context) + logrus.Debugf("%s: (%s) creating an SVM scratch", title, context) // Don't use svm.CreateExt4Vhdx since that only works when the service vm is setup, // but we're still in that process right now. if err := svm.config.CreateExt4Vhdx(scratchTargetFile, client.DefaultVhdxSizeGB, d.cachedScratchFile); err != nil { - logrus.Debugf("%s (%s): releasing cachedScratchMutex on error path", title, context) + logrus.Debugf("%s: (%s) releasing cachedScratchMutex on error path", title, context) d.cachedScratchMutex.Unlock() logrus.Debugf("%s: failed to create vm scratch %s: %s", title, scratchTargetFile, err) return nil, fmt.Errorf("failed to create SVM scratch VHDX (%s): %s", context, err) } } - logrus.Debugf("%s (%s): releasing cachedScratchMutex", title, context) + logrus.Debugf("%s: (%s) releasing cachedScratchMutex", title, context) d.cachedScratchMutex.Unlock() // Hot-add the scratch-space if not already attached if !svm.scratchAttached { - logrus.Debugf("lcowdriver: startServiceVmIfNotRunning: (%s) hot-adding scratch %s", context, scratchTargetFile) + logrus.Debugf("%s: (%s) hot-adding scratch %s", title, context, scratchTargetFile) if err := svm.hotAddVHDsAtStart(hcsshim.MappedVirtualDisk{ HostPath: scratchTargetFile, ContainerPath: toolsScratchPath, @@ -353,7 +353,7 @@ func (d *Driver) startServiceVMIfNotRunning(id string, mvdToAdd []hcsshim.Mapped svm.scratchAttached = true } - logrus.Debugf("lcowdriver: startServiceVmIfNotRunning: (%s) success", context) + logrus.Debugf("%s: (%s) success", title, context) return svm, nil } From 1efda2126ed386a46e1f217916a5a11c237dd31e Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Thu, 12 Jul 2018 13:29:37 -0700 Subject: [PATCH 4/4] vendor: update continuity to 0377f7d767206 This is to include the Go 1.11 fix (https://github.com/containerd/continuity/pull/120). Signed-off-by: Kir Kolyshkin Upstream-commit: c64a2448d1f2b7ba680dcb017cd46dcb8ac359c4 Component: engine --- components/engine/vendor.conf | 2 +- .../continuity/driver/driver_unix.go | 13 ---------- .../continuity/driver/lchmod_linux.go | 19 ++++++++++++++ .../continuity/driver/lchmod_unix.go | 14 +++++++++++ .../github.com/containerd/continuity/fs/du.go | 4 +-- .../containerd/continuity/fs/du_unix.go | 8 +++++- .../containerd/continuity/fs/du_windows.go | 8 +++++- .../continuity/sysx/chmod_darwin.go | 18 ------------- .../continuity/sysx/chmod_darwin_386.go | 25 ------------------- .../continuity/sysx/chmod_darwin_amd64.go | 25 ------------------- .../continuity/sysx/chmod_freebsd.go | 17 ------------- .../continuity/sysx/chmod_freebsd_amd64.go | 25 ------------------- .../containerd/continuity/sysx/chmod_linux.go | 12 --------- .../continuity/sysx/chmod_solaris.go | 11 -------- .../continuity/sysx/xattr_darwin.go | 1 - 15 files changed, 50 insertions(+), 152 deletions(-) create mode 100644 components/engine/vendor/github.com/containerd/continuity/driver/lchmod_linux.go create mode 100644 components/engine/vendor/github.com/containerd/continuity/driver/lchmod_unix.go delete mode 100644 components/engine/vendor/github.com/containerd/continuity/sysx/chmod_darwin.go delete mode 100644 components/engine/vendor/github.com/containerd/continuity/sysx/chmod_darwin_386.go delete mode 100644 components/engine/vendor/github.com/containerd/continuity/sysx/chmod_darwin_amd64.go delete mode 100644 components/engine/vendor/github.com/containerd/continuity/sysx/chmod_freebsd.go delete mode 100644 components/engine/vendor/github.com/containerd/continuity/sysx/chmod_freebsd_amd64.go delete mode 100644 components/engine/vendor/github.com/containerd/continuity/sysx/chmod_linux.go delete mode 100644 components/engine/vendor/github.com/containerd/continuity/sysx/chmod_solaris.go diff --git a/components/engine/vendor.conf b/components/engine/vendor.conf index 8c191e5e60..d6c1f52704 100644 --- a/components/engine/vendor.conf +++ b/components/engine/vendor.conf @@ -116,7 +116,7 @@ google.golang.org/genproto 694d95ba50e67b2e363f3483057db5d4910c18f9 # containerd github.com/containerd/containerd b41633746ed4833f52c3c071e8edcfa2713e5677 github.com/containerd/fifo 3d5202aec260678c48179c56f40e6f38a095738c -github.com/containerd/continuity d3c23511c1bf5851696cba83143d9cbcd666869b +github.com/containerd/continuity 0377f7d767206f3a9e8881d0f02267b0d89c7a62 github.com/containerd/cgroups fe281dd265766145e943a034aa41086474ea6130 github.com/containerd/console 5d1b48d6114b8c9666f0c8b916f871af97b0a761 github.com/containerd/go-runc f271fa2021de855d4d918dbef83c5fe19db1bdd diff --git a/components/engine/vendor/github.com/containerd/continuity/driver/driver_unix.go b/components/engine/vendor/github.com/containerd/continuity/driver/driver_unix.go index 67493ade08..c7d4e6ba15 100644 --- a/components/engine/vendor/github.com/containerd/continuity/driver/driver_unix.go +++ b/components/engine/vendor/github.com/containerd/continuity/driver/driver_unix.go @@ -6,7 +6,6 @@ import ( "errors" "fmt" "os" - "path/filepath" "sort" "github.com/containerd/continuity/devices" @@ -26,18 +25,6 @@ func (d *driver) Mkfifo(path string, mode os.FileMode) error { return devices.Mknod(path, mode, 0, 0) } -// Lchmod changes the mode of an file not following symlinks. -func (d *driver) Lchmod(path string, mode os.FileMode) (err error) { - if !filepath.IsAbs(path) { - path, err = filepath.Abs(path) - if err != nil { - return - } - } - - return sysx.Fchmodat(0, path, uint32(mode), sysx.AtSymlinkNofollow) -} - // Getxattr returns all of the extended attributes for the file at path p. func (d *driver) Getxattr(p string) (map[string][]byte, error) { xattrs, err := sysx.Listxattr(p) diff --git a/components/engine/vendor/github.com/containerd/continuity/driver/lchmod_linux.go b/components/engine/vendor/github.com/containerd/continuity/driver/lchmod_linux.go new file mode 100644 index 0000000000..39ffe9cc32 --- /dev/null +++ b/components/engine/vendor/github.com/containerd/continuity/driver/lchmod_linux.go @@ -0,0 +1,19 @@ +package driver + +import ( + "os" + + "golang.org/x/sys/unix" +) + +// Lchmod changes the mode of a file not following symlinks. +func (d *driver) Lchmod(path string, mode os.FileMode) error { + // On Linux, file mode is not supported for symlinks, + // and fchmodat() does not support AT_SYMLINK_NOFOLLOW, + // so symlinks need to be skipped entirely. + if st, err := os.Stat(path); err == nil && st.Mode()&os.ModeSymlink != 0 { + return nil + } + + return unix.Fchmodat(unix.AT_FDCWD, path, uint32(mode), 0) +} diff --git a/components/engine/vendor/github.com/containerd/continuity/driver/lchmod_unix.go b/components/engine/vendor/github.com/containerd/continuity/driver/lchmod_unix.go new file mode 100644 index 0000000000..1b539f78e3 --- /dev/null +++ b/components/engine/vendor/github.com/containerd/continuity/driver/lchmod_unix.go @@ -0,0 +1,14 @@ +// +build darwin freebsd solaris + +package driver + +import ( + "os" + + "golang.org/x/sys/unix" +) + +// Lchmod changes the mode of a file not following symlinks. +func (d *driver) Lchmod(path string, mode os.FileMode) error { + return unix.Fchmodat(unix.AT_FDCWD, path, uint32(mode), unix.AT_SYMLINK_NOFOLLOW) +} diff --git a/components/engine/vendor/github.com/containerd/continuity/fs/du.go b/components/engine/vendor/github.com/containerd/continuity/fs/du.go index 26f5333154..f8fc9a9946 100644 --- a/components/engine/vendor/github.com/containerd/continuity/fs/du.go +++ b/components/engine/vendor/github.com/containerd/continuity/fs/du.go @@ -10,8 +10,8 @@ type Usage struct { // DiskUsage counts the number of inodes and disk usage for the resources under // path. -func DiskUsage(roots ...string) (Usage, error) { - return diskUsage(roots...) +func DiskUsage(ctx context.Context, roots ...string) (Usage, error) { + return diskUsage(ctx, roots...) } // DiffUsage counts the numbers of inodes and disk usage in the diff --git a/components/engine/vendor/github.com/containerd/continuity/fs/du_unix.go b/components/engine/vendor/github.com/containerd/continuity/fs/du_unix.go index fe3426d278..9f6bc55fd9 100644 --- a/components/engine/vendor/github.com/containerd/continuity/fs/du_unix.go +++ b/components/engine/vendor/github.com/containerd/continuity/fs/du_unix.go @@ -24,7 +24,7 @@ func newInode(stat *syscall.Stat_t) inode { } } -func diskUsage(roots ...string) (Usage, error) { +func diskUsage(ctx context.Context, roots ...string) (Usage, error) { var ( size int64 @@ -37,6 +37,12 @@ func diskUsage(roots ...string) (Usage, error) { return err } + select { + case <-ctx.Done(): + return ctx.Err() + default: + } + inoKey := newInode(fi.Sys().(*syscall.Stat_t)) if _, ok := inodes[inoKey]; !ok { inodes[inoKey] = struct{}{} diff --git a/components/engine/vendor/github.com/containerd/continuity/fs/du_windows.go b/components/engine/vendor/github.com/containerd/continuity/fs/du_windows.go index 3f852fc15e..faa443feda 100644 --- a/components/engine/vendor/github.com/containerd/continuity/fs/du_windows.go +++ b/components/engine/vendor/github.com/containerd/continuity/fs/du_windows.go @@ -8,7 +8,7 @@ import ( "path/filepath" ) -func diskUsage(roots ...string) (Usage, error) { +func diskUsage(ctx context.Context, roots ...string) (Usage, error) { var ( size int64 ) @@ -21,6 +21,12 @@ func diskUsage(roots ...string) (Usage, error) { return err } + select { + case <-ctx.Done(): + return ctx.Err() + default: + } + size += fi.Size() return nil }); err != nil { diff --git a/components/engine/vendor/github.com/containerd/continuity/sysx/chmod_darwin.go b/components/engine/vendor/github.com/containerd/continuity/sysx/chmod_darwin.go deleted file mode 100644 index e3ae2b7bbf..0000000000 --- a/components/engine/vendor/github.com/containerd/continuity/sysx/chmod_darwin.go +++ /dev/null @@ -1,18 +0,0 @@ -package sysx - -const ( - // AtSymlinkNoFollow defined from AT_SYMLINK_NOFOLLOW in - AtSymlinkNofollow = 0x20 -) - -const ( - - // SYS_FCHMODAT defined from golang.org/sys/unix - SYS_FCHMODAT = 467 -) - -// These functions will be generated by generate.sh -// $ GOOS=darwin GOARCH=386 ./generate.sh chmod -// $ GOOS=darwin GOARCH=amd64 ./generate.sh chmod - -//sys Fchmodat(dirfd int, path string, mode uint32, flags int) (err error) diff --git a/components/engine/vendor/github.com/containerd/continuity/sysx/chmod_darwin_386.go b/components/engine/vendor/github.com/containerd/continuity/sysx/chmod_darwin_386.go deleted file mode 100644 index 5a8cf5b57d..0000000000 --- a/components/engine/vendor/github.com/containerd/continuity/sysx/chmod_darwin_386.go +++ /dev/null @@ -1,25 +0,0 @@ -// mksyscall.pl -l32 chmod_darwin.go -// MACHINE GENERATED BY THE COMMAND ABOVE; DO NOT EDIT - -package sysx - -import ( - "syscall" - "unsafe" -) - -// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT - -func Fchmodat(dirfd int, path string, mode uint32, flags int) (err error) { - var _p0 *byte - _p0, err = syscall.BytePtrFromString(path) - if err != nil { - return - } - _, _, e1 := syscall.Syscall6(SYS_FCHMODAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(flags), 0, 0) - use(unsafe.Pointer(_p0)) - if e1 != 0 { - err = errnoErr(e1) - } - return -} diff --git a/components/engine/vendor/github.com/containerd/continuity/sysx/chmod_darwin_amd64.go b/components/engine/vendor/github.com/containerd/continuity/sysx/chmod_darwin_amd64.go deleted file mode 100644 index 3287d1d579..0000000000 --- a/components/engine/vendor/github.com/containerd/continuity/sysx/chmod_darwin_amd64.go +++ /dev/null @@ -1,25 +0,0 @@ -// mksyscall.pl chmod_darwin.go -// MACHINE GENERATED BY THE COMMAND ABOVE; DO NOT EDIT - -package sysx - -import ( - "syscall" - "unsafe" -) - -// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT - -func Fchmodat(dirfd int, path string, mode uint32, flags int) (err error) { - var _p0 *byte - _p0, err = syscall.BytePtrFromString(path) - if err != nil { - return - } - _, _, e1 := syscall.Syscall6(SYS_FCHMODAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(flags), 0, 0) - use(unsafe.Pointer(_p0)) - if e1 != 0 { - err = errnoErr(e1) - } - return -} diff --git a/components/engine/vendor/github.com/containerd/continuity/sysx/chmod_freebsd.go b/components/engine/vendor/github.com/containerd/continuity/sysx/chmod_freebsd.go deleted file mode 100644 index b64a708be1..0000000000 --- a/components/engine/vendor/github.com/containerd/continuity/sysx/chmod_freebsd.go +++ /dev/null @@ -1,17 +0,0 @@ -package sysx - -const ( - // AtSymlinkNoFollow defined from AT_SYMLINK_NOFOLLOW in - AtSymlinkNofollow = 0x200 -) - -const ( - - // SYS_FCHMODAT defined from golang.org/sys/unix - SYS_FCHMODAT = 490 -) - -// These functions will be generated by generate.sh -// $ GOOS=freebsd GOARCH=amd64 ./generate.sh chmod - -//sys Fchmodat(dirfd int, path string, mode uint32, flags int) (err error) diff --git a/components/engine/vendor/github.com/containerd/continuity/sysx/chmod_freebsd_amd64.go b/components/engine/vendor/github.com/containerd/continuity/sysx/chmod_freebsd_amd64.go deleted file mode 100644 index 5a271abb1e..0000000000 --- a/components/engine/vendor/github.com/containerd/continuity/sysx/chmod_freebsd_amd64.go +++ /dev/null @@ -1,25 +0,0 @@ -// mksyscall.pl chmod_freebsd.go -// MACHINE GENERATED BY THE COMMAND ABOVE; DO NOT EDIT - -package sysx - -import ( - "syscall" - "unsafe" -) - -// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT - -func Fchmodat(dirfd int, path string, mode uint32, flags int) (err error) { - var _p0 *byte - _p0, err = syscall.BytePtrFromString(path) - if err != nil { - return - } - _, _, e1 := syscall.Syscall6(SYS_FCHMODAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(flags), 0, 0) - use(unsafe.Pointer(_p0)) - if e1 != 0 { - err = errnoErr(e1) - } - return -} diff --git a/components/engine/vendor/github.com/containerd/continuity/sysx/chmod_linux.go b/components/engine/vendor/github.com/containerd/continuity/sysx/chmod_linux.go deleted file mode 100644 index 89df6d38ef..0000000000 --- a/components/engine/vendor/github.com/containerd/continuity/sysx/chmod_linux.go +++ /dev/null @@ -1,12 +0,0 @@ -package sysx - -import "syscall" - -const ( - // AtSymlinkNoFollow defined from AT_SYMLINK_NOFOLLOW in /usr/include/linux/fcntl.h - AtSymlinkNofollow = 0x100 -) - -func Fchmodat(dirfd int, path string, mode uint32, flags int) error { - return syscall.Fchmodat(dirfd, path, mode, flags) -} diff --git a/components/engine/vendor/github.com/containerd/continuity/sysx/chmod_solaris.go b/components/engine/vendor/github.com/containerd/continuity/sysx/chmod_solaris.go deleted file mode 100644 index 3ba6e5edc8..0000000000 --- a/components/engine/vendor/github.com/containerd/continuity/sysx/chmod_solaris.go +++ /dev/null @@ -1,11 +0,0 @@ -package sysx - -import "golang.org/x/sys/unix" - -const ( - AtSymlinkNofollow = unix.AT_SYMLINK_NOFOLLOW -) - -func Fchmodat(dirfd int, path string, mode uint32, flags int) error { - return unix.Fchmodat(dirfd, path, mode, flags) -} diff --git a/components/engine/vendor/github.com/containerd/continuity/sysx/xattr_darwin.go b/components/engine/vendor/github.com/containerd/continuity/sysx/xattr_darwin.go index 1164a7d11c..58da430706 100644 --- a/components/engine/vendor/github.com/containerd/continuity/sysx/xattr_darwin.go +++ b/components/engine/vendor/github.com/containerd/continuity/sysx/xattr_darwin.go @@ -8,7 +8,6 @@ package sysx //sys setxattr(path string, attr string, data []byte, flags int) (err error) //sys removexattr(path string, attr string, options int) (err error) //sys listxattr(path string, dest []byte, options int) (sz int, err error) -//sys Fchmodat(dirfd int, path string, mode uint32, flags int) (err error) const ( xattrNoFollow = 0x01