github.com/equinix-metal/virtlet@v1.5.2-0.20191204181327-1659b8a48e9b/tests/e2e/9pfs_test.go (about) 1 /* 2 Copyright 2019 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 "path/filepath" 21 "time" 22 23 . "github.com/onsi/gomega" 24 25 "github.com/Mirantis/virtlet/tests/e2e/framework" 26 . "github.com/Mirantis/virtlet/tests/e2e/ginkgo-ext" 27 "k8s.io/api/core/v1" 28 ) 29 30 const ( 31 bbName = "busybox-9pfs" 32 ) 33 34 var _ = Describe("9pfs volumes [Heavy]", func() { 35 var busyboxPod *framework.PodInterface 36 var vm *framework.VMInterface 37 var ssh framework.Executor 38 39 AfterAll(func() { 40 if ssh != nil { 41 ssh.Close() 42 } 43 if vm != nil { 44 deleteVM(vm) 45 } 46 Expect(busyboxPod.Delete()).To(Succeed()) 47 }) 48 49 It("Should work with hostPath volumes", func() { 50 if UsingCirros() { 51 Skip("9pfs can't be tested using CirrOS at the moment") 52 } 53 54 By("Picking a Virtlet node") 55 nodeName, err := controller.VirtletNodeName() 56 Expect(err).NotTo(HaveOccurred()) 57 58 By("Starting a busybox pod") 59 busyboxPod, err = controller.RunPod( 60 bbName, framework.BusyboxImage, 61 framework.RunPodOptions{ 62 Command: []string{"/bin/sleep", "1200"}, 63 NodeName: nodeName, 64 HostPathMounts: []framework.HostPathMount{ 65 { 66 HostPath: "/tmp", 67 ContainerPath: "/tmp", 68 }, 69 }, 70 }) 71 Expect(err).NotTo(HaveOccurred()) 72 Expect(busyboxPod).NotTo(BeNil()) 73 bbExec, err := busyboxPod.Container(bbName) 74 Expect(err).NotTo(HaveOccurred()) 75 76 By("Creating a temp directory") 77 dir, err := framework.RunSimple(bbExec, "/bin/sh", "-c", "d=`mktemp -d`; echo foo >$d/bar; echo $d") 78 Expect(err).NotTo(HaveOccurred()) 79 Expect(dir).NotTo(BeEmpty()) 80 81 By("Creating a VM that has temp directory mounted via 9pfs") 82 vm = controller.VM("vm-9pfs") 83 podCustomization := func(pod *framework.PodInterface) { 84 pod.Pod.Spec.Volumes = append(pod.Pod.Spec.Volumes, v1.Volume{ 85 Name: "9pfs-vol", 86 VolumeSource: v1.VolumeSource{ 87 HostPath: &v1.HostPathVolumeSource{ 88 Path: dir, 89 }, 90 }, 91 }) 92 pod.Pod.Spec.Containers[0].VolumeMounts = append( 93 pod.Pod.Spec.Containers[0].VolumeMounts, 94 v1.VolumeMount{ 95 Name: "9pfs-vol", 96 MountPath: "/hostmount", 97 }) 98 } 99 Expect(vm.CreateAndWait(VMOptions{ 100 NodeName: nodeName, 101 }.ApplyDefaults(), time.Minute*5, podCustomization)).To(Succeed()) 102 _, err = vm.Pod() 103 Expect(err).NotTo(HaveOccurred()) 104 105 By("Wait for the volume to be mounted inside the VM") 106 ssh = waitSSH(vm) 107 Eventually(func() error { 108 _, err := framework.RunSimple(ssh, "sudo test -e /hostmount/bar") 109 return err 110 }, 60*5, 3).Should(Succeed()) 111 112 By("Make a copy of a file on the volume inside the VM") 113 _, err = framework.RunSimple(ssh, "sudo cp /hostmount/bar /hostmount/bar1") 114 Expect(err).NotTo(HaveOccurred()) 115 116 By("Verifying the new file contents inside the busybox pod") 117 content, err := framework.RunSimple(bbExec, "cat", filepath.Join(dir, "bar1")) 118 Expect(err).NotTo(HaveOccurred()) 119 Expect(content).To(Equal("foo")) 120 }) 121 })