-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathnodeserver_test.go
More file actions
179 lines (144 loc) · 6.05 KB
/
nodeserver_test.go
File metadata and controls
179 lines (144 loc) · 6.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
package blockstorage
import (
"context"
"github.com/container-storage-interface/spec/lib/go/csi"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
stackitconfig "github.com/stackitcloud/cloud-provider-stackit/pkg/stackit/config"
"go.uber.org/mock/gomock"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
mountutils "k8s.io/mount-utils"
sharedcsi "github.com/stackitcloud/cloud-provider-stackit/pkg/csi"
"github.com/stackitcloud/cloud-provider-stackit/pkg/csi/util/mount"
"github.com/stackitcloud/cloud-provider-stackit/pkg/stackit/metadata"
)
var _ = Describe("NodeServer", func() {
var (
ns *nodeServer
fakeEndpoint = "tcp://127.0.0.1:10000"
fakeCluster = "cluster"
req *csi.NodePublishVolumeRequest
mountMock *mount.MockIMount
metadataMock *metadata.MockIMetadata
)
BeforeEach(func() {
d := NewDriver(&DriverOpts{Endpoint: fakeEndpoint, ClusterID: fakeCluster})
ctrl := gomock.NewController(GinkgoT())
mountMock = mount.NewMockIMount(ctrl)
mount.MInstance = mountMock
metadataMock = metadata.NewMockIMetadata(ctrl)
metadata.MetadataService = metadataMock
ns = NewNodeServer(
d,
mountMock,
metadataMock,
stackitconfig.BlockStorageOpts{},
)
})
Describe("NodePublishVolume", func() {
BeforeEach(func() {
req = &csi.NodePublishVolumeRequest{
VolumeId: "volume-id",
TargetPath: "/target/path",
VolumeCapability: &csi.VolumeCapability{
AccessType: &csi.VolumeCapability_Mount{
Mount: &csi.VolumeCapability_MountVolume{
MountFlags: []string{"--foo"},
},
},
},
StagingTargetPath: "/staging/target/path",
}
})
It("should fail if the volumeID is empty", func() {
req.VolumeId = ""
_, err := ns.NodePublishVolume(context.Background(), req)
Expect(err).To(HaveOccurred())
Expect(status.Code(err)).To(Equal(codes.InvalidArgument))
Expect(err).To(MatchError(ContainSubstring("Volume ID must be provided")))
})
It("should fail if the targetPath is empty", func() {
req.TargetPath = ""
_, err := ns.NodePublishVolume(context.Background(), req)
Expect(err).To(HaveOccurred())
Expect(status.Code(err)).To(Equal(codes.InvalidArgument))
Expect(err).To(MatchError(ContainSubstring("Target Path must be provided")))
})
It("should fail if no volumeCapabilty is provided", func() {
req.VolumeCapability = nil
_, err := ns.NodePublishVolume(context.Background(), req)
Expect(err).To(HaveOccurred())
Expect(status.Code(err)).To(Equal(codes.InvalidArgument))
Expect(err).To(MatchError(ContainSubstring("Volume Capability must be provided")))
})
It("should fail if an ephemeral volume is requested", func() {
req.VolumeContext = map[string]string{
sharedcsi.VolEphemeralKey: "true",
}
_, err := ns.NodePublishVolume(context.Background(), req)
Expect(err).To(HaveOccurred())
Expect(status.Code(err)).To(Equal(codes.Unimplemented))
Expect(err).To(MatchError(ContainSubstring("CSI inline ephemeral volumes support is removed")))
})
It("should fail if staging target path is empty", func() {
req.StagingTargetPath = ""
_, err := ns.NodePublishVolume(context.Background(), req)
Expect(err).To(HaveOccurred())
Expect(status.Code(err)).To(Equal(codes.InvalidArgument))
Expect(err).To(MatchError(ContainSubstring("Staging Target Path must be provided")))
})
It("should mount successfully, if a mount volume is requests in the volume capabilities", func() {
mountPoints := make([]mountutils.MountPoint, 0)
mounter := mountutils.NewFakeMounter(mountPoints)
mountMock.EXPECT().IsLikelyNotMountPointAttach("/target/path").Return(true, nil)
mountMock.EXPECT().Mounter().Return(mountutils.NewSafeFormatAndMount(mounter, nil))
_, err := ns.NodePublishVolume(context.Background(), req)
Expect(err).NotTo(HaveOccurred())
Expect(mounter.MountPoints).To(HaveLen(1))
Expect(mounter.MountPoints[0].Path).To(Equal("/target/path"))
Expect(mounter.MountPoints[0].Type).To(Equal("ext4"))
})
It("should mount successfully, if a block volume is requests in the volume capabilities", func() {
req.VolumeCapability.AccessType = &csi.VolumeCapability_Block{
Block: &csi.VolumeCapability_BlockVolume{},
}
mountPoints := make([]mountutils.MountPoint, 0)
mounter := mountutils.NewFakeMounter(mountPoints)
mountMock.EXPECT().GetDevicePath("volume-id").Return("/dev/ice", nil)
mountMock.EXPECT().MakeDir("/target").Return(nil)
mountMock.EXPECT().MakeFile("/target/path").Return(nil)
mountMock.EXPECT().Mounter().Return(mountutils.NewSafeFormatAndMount(mounter, nil))
_, err := ns.NodePublishVolume(context.Background(), req)
Expect(err).NotTo(HaveOccurred())
Expect(mounter.MountPoints).To(HaveLen(1))
Expect(mounter.MountPoints[0].Path).To(Equal("/target/path"))
})
It("should mount rw by default", func() {
mountPoints := make([]mountutils.MountPoint, 0)
mounter := mountutils.NewFakeMounter(mountPoints)
mountMock.EXPECT().IsLikelyNotMountPointAttach("/target/path").Return(true, nil)
mountMock.EXPECT().Mounter().Return(mountutils.NewSafeFormatAndMount(mounter, nil))
_, err := ns.NodePublishVolume(context.Background(), req)
Expect(err).NotTo(HaveOccurred())
Expect(mounter.MountPoints[0].Opts).To(Equal([]string{"bind", "rw"}))
})
It("should mount ro if requested", func() {
req.Readonly = true
mountPoints := make([]mountutils.MountPoint, 0)
mounter := mountutils.NewFakeMounter(mountPoints)
mountMock.EXPECT().IsLikelyNotMountPointAttach("/target/path").Return(true, nil)
mountMock.EXPECT().Mounter().Return(mountutils.NewSafeFormatAndMount(mounter, nil))
_, err := ns.NodePublishVolume(context.Background(), req)
Expect(err).NotTo(HaveOccurred())
Expect(mounter.MountPoints[0].Opts).To(Equal([]string{"bind", "ro"}))
})
})
Describe("NodeUnpublishVolume", func() {})
Describe("NodeStageVolume", func() {})
Describe("NodeUnstageVolume", func() {})
Describe("NodeGetInfo", func() {})
Describe("NodeGetCapabilities", func() {})
Describe("NodeGetVolumeStats", func() {})
Describe("NodeExpandVolume", func() {})
})