github.com/Mirantis/virtlet@v1.5.2-0.20191204181327-1659b8a48e9b/tests/e2e/ceph_test.go (about) 1 /* 2 Copyright 2017 Mirantis 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package e2e 18 19 import ( 20 "regexp" 21 "time" 22 23 . "github.com/onsi/gomega" 24 "k8s.io/api/core/v1" 25 26 "github.com/Mirantis/virtlet/tests/e2e/framework" 27 . "github.com/Mirantis/virtlet/tests/e2e/ginkgo-ext" 28 ) 29 30 var _ = Describe("Ceph volumes tests", func() { 31 var ( 32 monitorIP string 33 secret string 34 ) 35 36 withCeph(&monitorIP, &secret, "") 37 38 Context("RBD volumes", func() { 39 var ( 40 vm *framework.VMInterface 41 ) 42 43 BeforeAll(func() { 44 vm = controller.VM("cirros-vm-rbd") 45 podCustomization := func(pod *framework.PodInterface) { 46 pod.Pod.Spec.Volumes = append(pod.Pod.Spec.Volumes, v1.Volume{ 47 Name: "test1", 48 VolumeSource: v1.VolumeSource{FlexVolume: cephVolumeSource("rbd-test-image1", monitorIP, secret)}, 49 }) 50 pod.Pod.Spec.Volumes = append(pod.Pod.Spec.Volumes, v1.Volume{ 51 Name: "test2", 52 VolumeSource: v1.VolumeSource{FlexVolume: cephVolumeSource("rbd-test-image2", monitorIP, secret)}, 53 }) 54 } 55 56 Expect(vm.CreateAndWait(VMOptions{}.ApplyDefaults(), time.Minute*5, podCustomization)).To(Succeed()) 57 var err error 58 _, err = vm.Pod() 59 Expect(err).NotTo(HaveOccurred()) 60 }) 61 62 AfterAll(func() { 63 deleteVM(vm) 64 }) 65 66 It("Must be attached to libvirt domain", func() { 67 out, err := vm.VirshCommand("domblklist", "<domain>") 68 Expect(err).NotTo(HaveOccurred()) 69 match := regexp.MustCompile("(?m:rbd-test-image[12]$)").FindAllString(out, -1) 70 Expect(match).To(HaveLen(2)) 71 }) 72 73 Context("Mounted volumes", func() { 74 var ssh framework.Executor 75 scheduleWaitSSH(&vm, &ssh) 76 77 It("Must be accessible from within OS", func() { 78 expectToBeUsableForFilesystem(ssh, "/dev/vdb") 79 }) 80 }) 81 }) 82 83 Context("RBD volumes defined with PV/PVC", func() { 84 var ( 85 vm *framework.VMInterface 86 ) 87 88 BeforeAll(func() { 89 vm = controller.VM("cirros-vm-rbd-pv") 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), 96 }, 97 }, 98 }.ApplyDefaults() 99 Expect(vm.CreateAndWait(opts, time.Minute*5, nil)).To(Succeed()) 100 _ = do(vm.Pod()).(*framework.PodInterface) 101 }) 102 103 AfterAll(func() { 104 deleteVM(vm) 105 }) 106 107 It("Must be attached to libvirt domain", func() { 108 out := do(vm.VirshCommand("domblklist", "<domain>")).(string) 109 Expect(regexp.MustCompile("(?m:rbd-test-image-pv$)").MatchString(out)).To(BeTrue()) 110 }) 111 112 It("Must be accessible from within the VM", func() { 113 ssh := waitSSH(vm) 114 expectToBeUsableForFilesystem(ssh, "/dev/vdb") 115 }) 116 }) 117 }) 118 119 func cephOptions(volume, monitorIP, secret string) map[string]string { 120 return map[string]string{ 121 "type": "ceph", 122 "monitor": monitorIP + ":6789", 123 "user": "admin", 124 "secret": secret, 125 "volume": volume, 126 "pool": "libvirt-pool", 127 } 128 } 129 130 func cephVolumeSource(volume, monitorIP, secret string) *v1.FlexVolumeSource { 131 return &v1.FlexVolumeSource{ 132 Driver: "virtlet/flexvolume_driver", 133 Options: cephOptions(volume, monitorIP, secret), 134 } 135 } 136 137 // TODO: use client.admin instead of client.libvirt