mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-14 06:15:45 +00:00
test: add csi raw block mode wiht podinfo ut
This commit is contained in:
parent
31aa15284f
commit
0017b602be
@ -21,6 +21,7 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"google.golang.org/grpc/codes"
|
||||
@ -40,7 +41,7 @@ func prepareBlockMapperTest(plug *csiPlugin, specVolumeName string, t *testing.T
|
||||
spec := volume.NewSpecFromPersistentVolume(pv, pv.Spec.PersistentVolumeSource.CSI.ReadOnly)
|
||||
mapper, err := plug.NewBlockVolumeMapper(
|
||||
spec,
|
||||
&api.Pod{ObjectMeta: meta.ObjectMeta{UID: testPodUID, Namespace: testns}},
|
||||
&api.Pod{ObjectMeta: meta.ObjectMeta{UID: testPodUID, Namespace: testns, Name: testPod}},
|
||||
volume.VolumeOptions{},
|
||||
)
|
||||
if err != nil {
|
||||
@ -367,6 +368,52 @@ func TestBlockMapperMapPodDeviceNotSupportAttach(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBlockMapperMapPodDeviceWithPodInfo(t *testing.T) {
|
||||
fakeClient := fakeclient.NewSimpleClientset()
|
||||
attachRequired := false
|
||||
podInfo := true
|
||||
fakeDriver := &storagev1.CSIDriver{
|
||||
ObjectMeta: meta.ObjectMeta{
|
||||
Name: testDriver,
|
||||
},
|
||||
Spec: storagev1.CSIDriverSpec{
|
||||
PodInfoOnMount: &podInfo,
|
||||
AttachRequired: &attachRequired,
|
||||
},
|
||||
}
|
||||
_, err := fakeClient.StorageV1().CSIDrivers().Create(context.TODO(), fakeDriver, metav1.CreateOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create a fakeDriver: %v", err)
|
||||
}
|
||||
|
||||
// after the driver is created, create the plugin. newTestPlugin waits for the informer to sync,
|
||||
// such that csiMapper.SetUpDevice below sees the VolumeAttachment object in the lister.
|
||||
|
||||
plug, tmpDir := newTestPlugin(t, fakeClient)
|
||||
defer os.RemoveAll(tmpDir)
|
||||
|
||||
csiMapper, _, _, err := prepareBlockMapperTest(plug, "test-pv", t)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to make a new Mapper: %v", err)
|
||||
}
|
||||
csiMapper.csiClient = setupClient(t, true)
|
||||
|
||||
// Map device to global and pod device map path
|
||||
_, err = csiMapper.MapPodDevice()
|
||||
if err != nil {
|
||||
t.Fatalf("mapper failed to GetGlobalMapPath: %v", err)
|
||||
}
|
||||
pvols := csiMapper.csiClient.(*fakeCsiDriverClient).nodeClient.GetNodePublishedVolumes()
|
||||
pvol, ok := pvols[csiMapper.volumeID]
|
||||
if !ok {
|
||||
t.Error("csi server may not have received NodePublishVolume call")
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(pvol.VolumeContext, map[string]string{"csi.storage.k8s.io/pod.uid": "test-pod", "csi.storage.k8s.io/serviceAccount.name": "", "csi.storage.k8s.io/pod.name": "test-pod", "csi.storage.k8s.io/pod.namespace": "test-ns", "csi.storage.k8s.io/ephemeral": "false"}) {
|
||||
t.Error("csi mapper check pod info failed")
|
||||
}
|
||||
}
|
||||
|
||||
func TestBlockMapperTearDownDevice(t *testing.T) {
|
||||
plug, tmpDir := newTestPlugin(t, nil)
|
||||
defer os.RemoveAll(tmpDir)
|
||||
|
Loading…
Reference in New Issue
Block a user