@@ -22,30 +22,18 @@ import (
22
22
23
23
. "github.com/onsi/gomega"
24
24
"k8s.io/api/core/v1"
25
- "k8s.io/apimachinery/pkg/api/resource"
26
- metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
27
25
28
26
"github.com/Mirantis/virtlet/tests/e2e/framework"
29
27
. "github.com/Mirantis/virtlet/tests/e2e/ginkgo-ext"
30
28
)
31
29
32
- const cephContainerName = "ceph_cluster"
33
-
34
30
var _ = Describe ("Ceph volumes tests" , func () {
35
31
var (
36
32
monitorIP string
37
33
secret string
38
34
)
39
35
40
- BeforeAll (func () {
41
- monitorIP , secret = setupCeph ()
42
- })
43
-
44
- AfterAll (func () {
45
- container , err := controller .DockerContainer (cephContainerName )
46
- Expect (err ).NotTo (HaveOccurred ())
47
- container .Delete ()
48
- })
36
+ withCeph (& monitorIP , & secret , "" )
49
37
50
38
Context ("RBD volumes" , func () {
51
39
var (
@@ -87,7 +75,7 @@ var _ = Describe("Ceph volumes tests", func() {
87
75
scheduleWaitSSH (& vm , & ssh )
88
76
89
77
It ("Must be accessible from within OS" , func () {
90
- checkFilesystemAccess (ssh )
78
+ expectToBeUsableForFilesystem (ssh , "/dev/vdb" )
91
79
})
92
80
})
93
81
})
@@ -98,147 +86,41 @@ var _ = Describe("Ceph volumes tests", func() {
98
86
)
99
87
100
88
BeforeAll (func () {
101
- pv := & v1.PersistentVolume {
102
- ObjectMeta : metav1.ObjectMeta {
103
- Name : "rbd-pv-virtlet" ,
104
- },
105
- Spec : v1.PersistentVolumeSpec {
106
- Capacity : v1.ResourceList {
107
- v1 .ResourceStorage : resource .MustParse ("10M" ),
108
- },
109
- AccessModes : []v1.PersistentVolumeAccessMode {v1 .ReadWriteOnce },
110
- PersistentVolumeSource : v1.PersistentVolumeSource {
111
- FlexVolume : cephPersistentVolumeSource ("rbd-test-image-pv" , monitorIP , secret ),
112
- },
113
- },
114
- }
115
- do (controller .PersistentVolumesClient ().Create (pv ))
116
-
117
- pvc := & v1.PersistentVolumeClaim {
118
- ObjectMeta : metav1.ObjectMeta {
119
- Name : "rbd-claim" ,
120
- },
121
- Spec : v1.PersistentVolumeClaimSpec {
122
- AccessModes : []v1.PersistentVolumeAccessMode {v1 .ReadWriteOnce },
123
- Resources : v1.ResourceRequirements {
124
- Requests : v1.ResourceList {
125
- v1 .ResourceStorage : resource .MustParse ("10M" ),
126
- },
127
- },
128
- },
129
- }
130
- do (controller .PersistentVolumeClaimsClient ().Create (pvc ))
131
-
132
89
vm = controller .VM ("cirros-vm-rbd-pv" )
133
- podCustomization := func (pod * framework.PodInterface ) {
134
- pod .Pod .Spec .Volumes = append (pod .Pod .Spec .Volumes , v1.Volume {
135
- Name : "test" ,
136
- VolumeSource : v1.VolumeSource {
137
- PersistentVolumeClaim : & v1.PersistentVolumeClaimVolumeSource {
138
- ClaimName : "rbd-claim" ,
139
- },
90
+ opts := VMOptions {
91
+ PVCs : []framework.PVCSpec {
92
+ {
93
+ Name : "rbd-pv-virtlet" ,
94
+ Size : "10M" ,
95
+ FlexVolumeOptions : cephOptions ("rbd-test-image-pv" , monitorIP , secret ),
140
96
},
141
- })
142
- }
143
-
144
- Expect (vm .CreateAndWait (VMOptions {}.ApplyDefaults (), time .Minute * 5 , podCustomization )).To (Succeed ())
97
+ },
98
+ }.ApplyDefaults ()
99
+ Expect (vm .CreateAndWait (opts , time .Minute * 5 , nil )).To (Succeed ())
145
100
_ = do (vm .Pod ()).(* framework.PodInterface )
146
101
})
147
102
148
103
AfterAll (func () {
149
104
deleteVM (vm )
150
- controller .PersistentVolumeClaimsClient ().Delete ("rbd-claim" , nil )
151
- controller .PersistentVolumesClient ().Delete ("rbd-pv-virtlet" , nil )
152
105
})
153
106
154
107
It ("Must be attached to libvirt domain" , func () {
155
108
out := do (vm .VirshCommand ("domblklist" , "<domain>" )).(string )
156
109
Expect (regexp .MustCompile ("(?m:rbd-test-image-pv$)" ).MatchString (out )).To (BeTrue ())
157
110
})
158
111
159
- Context ("Mounted volumes" , func () {
160
- var ssh framework.Executor
161
- scheduleWaitSSH (& vm , & ssh )
162
-
163
- It ("Must be accessible from within OS" , func () {
164
- checkFilesystemAccess (ssh )
165
- })
112
+ It ("Must be accessible from within the VM" , func () {
113
+ ssh := waitSSH (vm )
114
+ expectToBeUsableForFilesystem (ssh , "/dev/vdb" )
166
115
})
167
116
})
168
117
})
169
118
170
- func checkFilesystemAccess (ssh framework.Executor ) {
171
- do (framework .RunSimple (ssh , "sudo /usr/sbin/mkfs.ext2 /dev/vdb" ))
172
- do (framework .RunSimple (ssh , "sudo mount /dev/vdb /mnt" ))
173
- out := do (framework .RunSimple (ssh , "ls -l /mnt" )).(string )
174
- Expect (out ).To (ContainSubstring ("lost+found" ))
175
- }
176
-
177
- func setupCeph () (string , string ) {
178
- nodeExecutor , err := controller .DinDNodeExecutor ("kube-master" )
179
- Expect (err ).NotTo (HaveOccurred ())
180
-
181
- route , err := framework .RunSimple (nodeExecutor , "route" , "-n" )
182
- Expect (err ).NotTo (HaveOccurred ())
183
-
184
- match := regexp .MustCompile (`(?:default|0\.0\.0\.0)\s+([\d.]+)` ).FindStringSubmatch (route )
185
- Expect (match ).To (HaveLen (2 ))
186
-
187
- monIP := match [1 ]
188
- cephPublicNetwork := monIP + "/16"
189
-
190
- container , err := controller .DockerContainer (cephContainerName )
191
- Expect (err ).NotTo (HaveOccurred ())
192
-
193
- container .Delete ()
194
- Expect (container .PullImage ("docker.io/ceph/daemon:v3.1.0-stable-3.1-mimic-centos-7" )).To (Succeed ())
195
- Expect (container .Run ("docker.io/ceph/daemon:v3.1.0-stable-3.1-mimic-centos-7" ,
196
- map [string ]string {
197
- "MON_IP" : monIP ,
198
- "CEPH_PUBLIC_NETWORK" : cephPublicNetwork ,
199
- "CEPH_DEMO_UID" : "foo" ,
200
- "CEPH_DEMO_ACCESS_KEY" : "foo" ,
201
- "CEPH_DEMO_SECRET_KEY" : "foo" ,
202
- "CEPH_DEMO_BUCKET" : "foo" ,
203
- "DEMO_DAEMONS" : "osd mds" ,
204
- },
205
- "host" , nil , false , "demo" )).To (Succeed ())
206
-
207
- cephContainerExecutor := container .Executor (false , "" )
208
- By ("Waiting for ceph cluster" )
209
- Eventually (func () error {
210
- _ , err := framework .RunSimple (cephContainerExecutor , "ceph" , "-s" )
211
- return err
212
- }).Should (Succeed ())
213
- By ("Ceph cluster started" )
214
-
215
- var out string
216
- commands := []string {
217
- // Adjust ceph configs
218
- `echo -e "rbd default features = 1\nrbd default format = 2" >> /etc/ceph/ceph.conf` ,
219
-
220
- // Add rbd pool and volume
221
- `ceph osd pool create libvirt-pool 8 8` ,
222
- `rbd create rbd-test-image1 --size 10M --pool libvirt-pool --image-feature layering` ,
223
- `rbd create rbd-test-image2 --size 10M --pool libvirt-pool --image-feature layering` ,
224
- `rbd create rbd-test-image-pv --size 10M --pool libvirt-pool --image-feature layering` ,
225
-
226
- // Add user for virtlet
227
- `ceph auth get-or-create client.libvirt` ,
228
- `ceph auth caps client.libvirt mon "allow *" osd "allow *"` ,
229
- `ceph auth get-key client.libvirt` ,
230
- }
231
- for _ , cmd := range commands {
232
- out = do (framework .RunSimple (cephContainerExecutor , "/bin/bash" , "-c" , cmd )).(string )
233
- }
234
- return monIP , out
235
- }
236
-
237
119
func cephOptions (volume , monitorIP , secret string ) map [string ]string {
238
120
return map [string ]string {
239
121
"type" : "ceph" ,
240
122
"monitor" : monitorIP + ":6789" ,
241
- "user" : "libvirt " ,
123
+ "user" : "admin " ,
242
124
"secret" : secret ,
243
125
"volume" : volume ,
244
126
"pool" : "libvirt-pool" ,
@@ -252,9 +134,4 @@ func cephVolumeSource(volume, monitorIP, secret string) *v1.FlexVolumeSource {
252
134
}
253
135
}
254
136
255
- func cephPersistentVolumeSource (volume , monitorIP , secret string ) * v1.FlexPersistentVolumeSource {
256
- return & v1.FlexPersistentVolumeSource {
257
- Driver : "virtlet/flexvolume_driver" ,
258
- Options : cephOptions (volume , monitorIP , secret ),
259
- }
260
- }
137
+ // TODO: use client.admin instead of client.libvirt
0 commit comments