From 612fb1793eff62e9926f4aa656b83daccc311731 Mon Sep 17 00:00:00 2001 From: Jan Safranek Date: Fri, 4 Oct 2019 13:59:44 +0200 Subject: [PATCH] Test global block directory in reconstruction tests --- test/e2e/storage/testsuites/disruptive.go | 14 ++++++------ test/e2e/storage/utils/utils.go | 26 +++++++++++++++++------ 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/test/e2e/storage/testsuites/disruptive.go b/test/e2e/storage/testsuites/disruptive.go index 7201944d8bb..540628401ea 100644 --- a/test/e2e/storage/testsuites/disruptive.go +++ b/test/e2e/storage/testsuites/disruptive.go @@ -140,8 +140,9 @@ func (s *disruptiveTestSuite) defineTests(driver TestDriver, pattern testpattern } for _, test := range disruptiveTestTable { - if test.runTestFile != nil { - func(t disruptiveTest) { + func(t disruptiveTest) { + if (pattern.VolMode == v1.PersistentVolumeBlock && t.runTestBlock != nil) || + (pattern.VolMode == v1.PersistentVolumeFilesystem && t.runTestFile != nil) { ginkgo.It(t.testItStmt, func() { init() defer cleanup() @@ -158,13 +159,14 @@ func (s *disruptiveTestSuite) defineTests(driver TestDriver, pattern testpattern l.pod, err = e2epod.CreateSecPodWithNodeSelection(l.cs, l.ns.Name, pvcs, inlineSources, false, "", false, false, e2epv.SELinuxLabel, nil, e2epod.NodeSelection{Name: l.config.ClientNodeName}, framework.PodStartTimeout) framework.ExpectNoError(err, "While creating pods for kubelet restart test") - if pattern.VolMode == v1.PersistentVolumeBlock { + if pattern.VolMode == v1.PersistentVolumeBlock && t.runTestBlock != nil { t.runTestBlock(l.cs, l.config.Framework, l.pod) - } else { + } + if pattern.VolMode == v1.PersistentVolumeFilesystem && t.runTestFile != nil { t.runTestFile(l.cs, l.config.Framework, l.pod) } }) - }(test) - } + } + }(test) } } diff --git a/test/e2e/storage/utils/utils.go b/test/e2e/storage/utils/utils.go index 7239763b667..a02aafb45d5 100644 --- a/test/e2e/storage/utils/utils.go +++ b/test/e2e/storage/utils/utils.go @@ -318,18 +318,28 @@ func TestVolumeUnmapsFromDeletedPodWithForceOption(c clientset.Interface, f *fra nodeIP = nodeIP + ":22" // Creating command to check whether path exists - command := fmt.Sprintf("ls /var/lib/kubelet/pods/%s/volumeDevices/*/ | grep '.'", clientPod.UID) + podDirectoryCmd := fmt.Sprintf("ls /var/lib/kubelet/pods/%s/volumeDevices/*/ | grep '.'", clientPod.UID) if isSudoPresent(nodeIP, framework.TestContext.Provider) { - command = fmt.Sprintf("sudo sh -c \"%s\"", command) + podDirectoryCmd = fmt.Sprintf("sudo sh -c \"%s\"", podDirectoryCmd) + } + // Directories in the global directory have unpredictable names, however, device symlinks + // have the same name as pod.UID. So just find anything with pod.UID name. + globalBlockDirectoryCmd := fmt.Sprintf("find /var/lib/kubelet/plugins -name %s", clientPod.UID) + if isSudoPresent(nodeIP, framework.TestContext.Provider) { + globalBlockDirectoryCmd = fmt.Sprintf("sudo sh -c \"%s\"", globalBlockDirectoryCmd) } ginkgo.By("Expecting the symlinks from PodDeviceMapPath to be found.") - result, err := e2essh.SSH(command, nodeIP, framework.TestContext.Provider) + result, err := e2essh.SSH(podDirectoryCmd, nodeIP, framework.TestContext.Provider) e2essh.LogResult(result) framework.ExpectNoError(err, "Encountered SSH error.") framework.ExpectEqual(result.Code, 0, fmt.Sprintf("Expected grep exit code of 0, got %d", result.Code)) - // TODO: Needs to check GetGlobalMapPath and descriptor lock, as well. + ginkgo.By("Expecting the symlinks from global map path to be found.") + result, err = e2essh.SSH(globalBlockDirectoryCmd, nodeIP, framework.TestContext.Provider) + e2essh.LogResult(result) + framework.ExpectNoError(err, "Encountered SSH error.") + framework.ExpectEqual(result.Code, 0, fmt.Sprintf("Expected find exit code of 0, got %d", result.Code)) // This command is to make sure kubelet is started after test finishes no matter it fails or not. defer func() { @@ -358,12 +368,16 @@ func TestVolumeUnmapsFromDeletedPodWithForceOption(c clientset.Interface, f *fra } ginkgo.By("Expecting the symlink from PodDeviceMapPath not to be found.") - result, err = e2essh.SSH(command, nodeIP, framework.TestContext.Provider) + result, err = e2essh.SSH(podDirectoryCmd, nodeIP, framework.TestContext.Provider) e2essh.LogResult(result) framework.ExpectNoError(err, "Encountered SSH error.") gomega.Expect(result.Stdout).To(gomega.BeEmpty(), "Expected grep stdout to be empty.") - // TODO: Needs to check GetGlobalMapPath and descriptor lock, as well. + ginkgo.By("Expecting the symlinks from global map path not to be found.") + result, err = e2essh.SSH(globalBlockDirectoryCmd, nodeIP, framework.TestContext.Provider) + e2essh.LogResult(result) + framework.ExpectNoError(err, "Encountered SSH error.") + gomega.Expect(result.Stdout).To(gomega.BeEmpty(), "Expected find stdout to be empty.") framework.Logf("Volume unmaped on node %s", clientPod.Spec.NodeName) }