From 0bd2e629c73cb3b32364bb82fad7875fde3f8a43 Mon Sep 17 00:00:00 2001 From: Jan Safranek Date: Thu, 13 Feb 2020 11:26:54 +0100 Subject: [PATCH] Fix unit tests --- pkg/volume/csi/csi_block.go | 2 +- pkg/volume/csi/csi_block_test.go | 13 ++++++------- pkg/volume/csi/fake/fake_client.go | 2 +- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/pkg/volume/csi/csi_block.go b/pkg/volume/csi/csi_block.go index 38004d9210d..20cd9791790 100644 --- a/pkg/volume/csi/csi_block.go +++ b/pkg/volume/csi/csi_block.go @@ -466,7 +466,7 @@ func (m *csiBlockMapper) cleanupOrphanDeviceFiles() error { publishDir = publishPath } if err := os.Remove(publishDir); err != nil && !os.IsNotExist(err) { - return errors.New(log("failed to publish directory [%s]: %v", publishDir, err)) + return errors.New(log("failed to remove publish directory [%s]: %v", publishDir, err)) } // Remove artifacts of NodeStage. diff --git a/pkg/volume/csi/csi_block_test.go b/pkg/volume/csi/csi_block_test.go index 762e74e003b..e856da79427 100644 --- a/pkg/volume/csi/csi_block_test.go +++ b/pkg/volume/csi/csi_block_test.go @@ -304,7 +304,7 @@ func TestBlockMapperSetupDeviceError(t *testing.T) { attachID := getAttachmentName(csiMapper.volumeID, string(csiMapper.driverName), string(nodeName)) attachment := makeTestAttachment(attachID, nodeName, pvName) attachment.Status.Attached = true - _, err = csiMapper.k8s.StorageV1().VolumeAttachments().Create(context.TODO(), attachment, metav1.CreateOptions{}) + _, err = csiMapper.k8s.StorageV1().VolumeAttachments().Create(context.Background(), attachment, metav1.CreateOptions{}) if err != nil { t.Fatalf("failed to setup VolumeAttachment: %v", err) } @@ -347,10 +347,10 @@ func TestBlockMapperMapPodDevice(t *testing.T) { csiMapper.csiClient = setupClient(t, true) - attachID := getAttachmentName(csiMapper.volumeID, string(csiMapper.driverName), string(nodeName)) + attachID := getAttachmentName(csiMapper.volumeID, string(csiMapper.driverName), nodeName) attachment := makeTestAttachment(attachID, nodeName, pvName) attachment.Status.Attached = true - _, err = csiMapper.k8s.StorageV1().VolumeAttachments().Create(context.TODO(), attachment, metav1.CreateOptions{}) + _, err = csiMapper.k8s.StorageV1().VolumeAttachments().Create(context.Background(), attachment, metav1.CreateOptions{}) if err != nil { t.Fatalf("failed to setup VolumeAttachment: %v", err) } @@ -483,6 +483,9 @@ func TestBlockMapperTearDownDevice(t *testing.T) { func TestVolumeSetupTeardown(t *testing.T) { defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.CSIBlockVolume, true)() + // Follow volume setup + teardown sequences at top of cs_block.go and set up / clean up one CSI block device. + // Focus on testing that there were no leftover files present after the cleanup. + plug, tmpDir := newTestPlugin(t, nil) defer os.RemoveAll(tmpDir) @@ -505,7 +508,6 @@ func TestVolumeSetupTeardown(t *testing.T) { } t.Log("created attachement ", attachID) - // SetupDevice err = csiMapper.SetUpDevice() if err != nil { t.Fatalf("mapper failed to SetupDevice: %v", err) @@ -521,7 +523,6 @@ func TestVolumeSetupTeardown(t *testing.T) { t.Errorf("csi server expected device path %s, got %s", stagingPath, svol.Path) } - // MapPodDevice path, err := csiMapper.MapPodDevice() if err != nil { t.Fatalf("mapper failed to GetGlobalMapPath: %v", err) @@ -552,7 +553,6 @@ func TestVolumeSetupTeardown(t *testing.T) { t.Fatalf("unmapper failed to GetGlobalMapPath: %v", err) } - // UnmapDevice err = csiUnmapper.UnmapPodDevice() if err != nil { t.Errorf("unmapper failed to call UnmapPodDevice: %v", err) @@ -566,7 +566,6 @@ func TestVolumeSetupTeardown(t *testing.T) { csiUnmapper = unmapper.(*csiBlockMapper) csiUnmapper.csiClient = csiMapper.csiClient - // TearDownDevice err = csiUnmapper.TearDownDevice(globalMapPath, "/dev/test") if err != nil { t.Fatal(err) diff --git a/pkg/volume/csi/fake/fake_client.go b/pkg/volume/csi/fake/fake_client.go index 463683894b9..0c9c446fba1 100644 --- a/pkg/volume/csi/fake/fake_client.go +++ b/pkg/volume/csi/fake/fake_client.go @@ -192,9 +192,9 @@ func (f *NodeClient) NodePublishVolume(ctx context.Context, req *csipb.NodePubli Path: req.GetTargetPath(), DeviceMountPath: req.GetStagingTargetPath(), VolumeContext: req.GetVolumeContext(), - FSType: req.GetVolumeCapability().GetMount().GetFsType(), } if req.GetVolumeCapability().GetMount() != nil { + publishedVolume.FSType = req.GetVolumeCapability().GetMount().FsType publishedVolume.MountFlags = req.GetVolumeCapability().GetMount().MountFlags } f.nodePublishedVolumes[req.GetVolumeId()] = publishedVolume