Skip to content

Commit

Permalink
verify that filesystem can be passed through without having disk.img
Browse files Browse the repository at this point in the history
Signed-off-by: Vladik Romanovsky <[email protected]>
  • Loading branch information
vladikr committed Feb 11, 2021
1 parent 5bc93d4 commit 1fb1936
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 12 deletions.
12 changes: 0 additions & 12 deletions pkg/virt-launcher/virtwrap/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -875,12 +875,6 @@ func (l *LibvirtDomainManager) PrepareMigrationTarget(vmi *v1.VirtualMachineInst
isBlockDVMap := make(map[string]bool)
diskInfo := make(map[string]*containerdisk.DiskInfo)
for i, volume := range vmi.Spec.Volumes {
for i := range vmi.Spec.Domain.Devices.Filesystems {
if vmi.Spec.Domain.Devices.Filesystems[i].Name == volume.Name {
volume.VolumeSource.PersistentVolumeClaim = nil
break
}
}
if volume.VolumeSource.PersistentVolumeClaim != nil {
isBlockPVC, err := isBlockDeviceVolume(volume.Name)
if err != nil {
Expand Down Expand Up @@ -1241,12 +1235,6 @@ func (l *LibvirtDomainManager) SyncVMI(vmi *v1.VirtualMachineInstance, useEmulat
isBlockDVMap := make(map[string]bool)
diskInfo := make(map[string]*containerdisk.DiskInfo)
for i, volume := range vmi.Spec.Volumes {
for i := range vmi.Spec.Domain.Devices.Filesystems {
if vmi.Spec.Domain.Devices.Filesystems[i].Name == volume.Name {
volume.VolumeSource.PersistentVolumeClaim = nil
break
}
}
if volume.VolumeSource.PersistentVolumeClaim != nil {
isBlockPVC := false
if _, ok := hotplugVolumes[volume.Name]; ok {
Expand Down
54 changes: 54 additions & 0 deletions tests/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,60 @@ var _ = Describe("Storage", func() {
})

})
Context("VirtIO-FS with an empty PVC", func() {

var pvc = "empty-pvc1"

BeforeEach(func() {
tests.CreateHostPathPv(pvc, filepath.Join(tests.HostPathBase, pvc))
tests.CreateHostPathPVC(pvc, "1G")
}, 120)

AfterEach(func() {
tests.DeletePVC(pvc)
tests.DeletePV(pvc)
}, 120)

It("should be successfully started and virtiofs could be accessed", func() {
tests.SkipPVCTestIfRunnigOnKindInfra()

pvcName := fmt.Sprintf("disk-%s", pvc)
vmi := tests.NewRandomVMIWithPVCFS(pvcName)
vmi.Spec.Domain.Resources.Requests[k8sv1.ResourceMemory] = resource.MustParse("512Mi")
vmi.Spec.Domain.Devices.Rng = &v1.Rng{}

// add userdata for guest agent and mount virtio-fs
fs := vmi.Spec.Domain.Devices.Filesystems[0]
virtiofsMountPath := fmt.Sprintf("/mnt/virtiof_%s", fs.Name)
virtiofsTestFile := fmt.Sprintf("%s/virtiofs_test", virtiofsMountPath)
mountVirtiofsCommands := fmt.Sprintf(`
mkdir %s
mount -t virtiofs %s %s
touch %s
`, virtiofsMountPath, fs.Name, virtiofsMountPath, virtiofsTestFile)
userData := fmt.Sprintf("%s\n%s", tests.GetGuestAgentUserData(), mountVirtiofsCommands)
tests.AddUserData(vmi, "cloud-init", userData)

vmi = tests.RunVMIAndExpectLaunchIgnoreWarnings(vmi, 300)

// Wait for cloud init to finish and start the agent inside the vmi.
tests.WaitAgentConnected(virtClient, vmi)

By("Checking that the VirtualMachineInstance console has expected output")
Expect(libnet.WithIPv6(console.LoginToFedora)(vmi)).To(Succeed(), "Should be able to login to the Fedora VM")

virtioFsFileTestCmd := fmt.Sprintf("test -f /run/kubevirt-private/vmi-disks/%s/virtiofs_test && echo exist", fs.Name)
pod := tests.GetRunningPodByVirtualMachineInstance(vmi, tests.NamespaceTestDefault)
podVirtioFsFileExist, err := tests.ExecuteCommandOnPod(
virtClient,
pod,
"compute",
[]string{"/usr/bin/bash", "-c", virtioFsFileTestCmd},
)
Expect(err).ToNot(HaveOccurred())
Expect(strings.Trim(podVirtioFsFileExist, "\n")).To(Equal("exist"))
})
})
Context("Run a VMI with VirtIO-FS and a datavolume", func() {
var dataVolume *cdiv1.DataVolume
BeforeEach(func() {
Expand Down

0 comments on commit 1fb1936

Please sign in to comment.