Skip to content

Commit

Permalink
changed server_suite_test.go
Browse files Browse the repository at this point in the history
  • Loading branch information
Parik Cmil committed Jul 8, 2024
1 parent 4b7b1fd commit 29a450f
Show file tree
Hide file tree
Showing 3 changed files with 335 additions and 335 deletions.
250 changes: 125 additions & 125 deletions tests/integration/machine_volume_attach_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,137 +3,137 @@

package server_test

// import (
// "time"
import (
"time"

// iri "github.com/ironcore-dev/ironcore/iri/apis/machine/v1alpha1"
// irimeta "github.com/ironcore-dev/ironcore/iri/apis/meta/v1alpha1"
// . "github.com/onsi/ginkgo/v2"
// . "github.com/onsi/gomega"
// "libvirt.org/go/libvirtxml"
// )
iri "github.com/ironcore-dev/ironcore/iri/apis/machine/v1alpha1"
irimeta "github.com/ironcore-dev/ironcore/iri/apis/meta/v1alpha1"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"libvirt.org/go/libvirtxml"
)

// var _ = Describe("AttachVolume", func() {
// It("should correctly attach volume to machine", func(ctx SpecContext) {
// By("creating a machine")
// createResp, err := machineClient.CreateMachine(ctx, &iri.CreateMachineRequest{
// Machine: &iri.Machine{
// Metadata: &irimeta.ObjectMetadata{
// Labels: map[string]string{
// "foo": "bar",
// },
// },
// Spec: &iri.MachineSpec{
// Power: iri.Power_POWER_ON,
// Class: machineClassx3xlarge,
// },
// },
// })
// Expect(err).NotTo(HaveOccurred())
// Expect(createResp).NotTo(BeNil())
var _ = Describe("AttachVolume", func() {
It("should correctly attach volume to machine", func(ctx SpecContext) {
By("creating a machine")
createResp, err := machineClient.CreateMachine(ctx, &iri.CreateMachineRequest{
Machine: &iri.Machine{
Metadata: &irimeta.ObjectMetadata{
Labels: map[string]string{
"foo": "bar",
},
},
Spec: &iri.MachineSpec{
Power: iri.Power_POWER_ON,
Class: machineClassx3xlarge,
},
},
})
Expect(err).NotTo(HaveOccurred())
Expect(createResp).NotTo(BeNil())

// DeferCleanup(machineClient.DeleteMachine, &iri.DeleteMachineRequest{
// MachineId: createResp.Machine.Metadata.Id,
// })
DeferCleanup(machineClient.DeleteMachine, &iri.DeleteMachineRequest{
MachineId: createResp.Machine.Metadata.Id,
})

// By("ensuring domain and domain XML is created and machine is running")
// domain := assertMachineIsRunning(createResp.Machine.Metadata.Id)
By("ensuring domain and domain XML is created and machine is running")
domain := assertMachineIsRunning(createResp.Machine.Metadata.Id)

// By("attaching empty disk to a machine")
// attachEmptyDiskResp, err := machineClient.AttachVolume(ctx, &iri.AttachVolumeRequest{
// MachineId: createResp.Machine.Metadata.Id,
// Volume: &iri.Volume{
// Name: "disk-1",
// EmptyDisk: &iri.EmptyDisk{
// SizeBytes: 5368709120,
// },
// Device: "oda",
// },
// })
// Expect(err).NotTo(HaveOccurred())
// Expect(attachEmptyDiskResp).NotTo(BeNil())
By("attaching empty disk to a machine")
attachEmptyDiskResp, err := machineClient.AttachVolume(ctx, &iri.AttachVolumeRequest{
MachineId: createResp.Machine.Metadata.Id,
Volume: &iri.Volume{
Name: "disk-1",
EmptyDisk: &iri.EmptyDisk{
SizeBytes: 5368709120,
},
Device: "oda",
},
})
Expect(err).NotTo(HaveOccurred())
Expect(attachEmptyDiskResp).NotTo(BeNil())

// By("ensuring attached empty disk have been updated in machine status field")
// Eventually(func(g Gomega) *iri.MachineStatus {
// listResp, err := machineClient.ListMachines(ctx, &iri.ListMachinesRequest{
// Filter: &iri.MachineFilter{
// Id: createResp.Machine.Metadata.Id,
// },
// })
// g.Expect(err).NotTo(HaveOccurred())
// g.Expect(listResp.Machines).NotTo(BeEmpty())
// g.Expect(listResp.Machines).Should(HaveLen(1))
// return listResp.Machines[0].Status
// }).Should(SatisfyAll(
// HaveField("Volumes", ContainElements(
// &iri.VolumeStatus{
// Name: "disk-1",
// Handle: "libvirt-provider.ironcore.dev/empty-disk/disk-1",
// State: iri.VolumeState_VOLUME_ATTACHED,
// })),
// HaveField("State", Equal(iri.MachineState_MACHINE_RUNNING)),
// ))
By("ensuring attached empty disk have been updated in machine status field")
Eventually(func(g Gomega) *iri.MachineStatus {
listResp, err := machineClient.ListMachines(ctx, &iri.ListMachinesRequest{
Filter: &iri.MachineFilter{
Id: createResp.Machine.Metadata.Id,
},
})
g.Expect(err).NotTo(HaveOccurred())
g.Expect(listResp.Machines).NotTo(BeEmpty())
g.Expect(listResp.Machines).Should(HaveLen(1))
return listResp.Machines[0].Status
}).Should(SatisfyAll(
HaveField("Volumes", ContainElements(
&iri.VolumeStatus{
Name: "disk-1",
Handle: "libvirt-provider.ironcore.dev/empty-disk/disk-1",
State: iri.VolumeState_VOLUME_ATTACHED,
})),
HaveField("State", Equal(iri.MachineState_MACHINE_RUNNING)),
))

// By("attaching volume with connection details to a machine")
// attachVolumeConnectionResp, err := machineClient.AttachVolume(ctx, &iri.AttachVolumeRequest{
// MachineId: createResp.Machine.Metadata.Id,
// Volume: &iri.Volume{
// Name: "volume-1",
// Device: "odb",
// Connection: &iri.VolumeConnection{
// Driver: "ceph",
// Handle: "dummy",
// Attributes: map[string]string{
// "image": cephImage,
// "monitors": cephMonitors,
// },
// SecretData: map[string][]byte{
// "userID": []byte(cephUsername),
// "userKey": []byte(cephUserkey),
// },
// },
// },
// })
// Expect(err).NotTo(HaveOccurred())
// Expect(attachVolumeConnectionResp).NotTo(BeNil())
By("attaching volume with connection details to a machine")
attachVolumeConnectionResp, err := machineClient.AttachVolume(ctx, &iri.AttachVolumeRequest{
MachineId: createResp.Machine.Metadata.Id,
Volume: &iri.Volume{
Name: "volume-1",
Device: "odb",
Connection: &iri.VolumeConnection{
Driver: "ceph",
Handle: "dummy",
Attributes: map[string]string{
"image": cephImage,
"monitors": cephMonitors,
},
SecretData: map[string][]byte{
"userID": []byte(cephUsername),
"userKey": []byte(cephUserkey),
},
},
},
})
Expect(err).NotTo(HaveOccurred())
Expect(attachVolumeConnectionResp).NotTo(BeNil())

// By("ensuring both the disks are attached to a machine domain")
// var disks []libvirtxml.DomainDisk
// Eventually(func(g Gomega) int {
// domainXMLData, err := libvirtConn.DomainGetXMLDesc(domain, 0)
// g.Expect(err).NotTo(HaveOccurred())
// domainXML := &libvirtxml.Domain{}
// g.Expect(domainXML.Unmarshal(domainXMLData)).Should(Succeed())
// disks = domainXML.Devices.Disks
// return len(disks)
// }).WithTimeout(2 * time.Minute).WithPolling(2 * time.Second).Should(Equal(2))
// Expect(disks[0].Serial).To(HavePrefix("oda"))
// Expect(disks[1].Serial).To(HavePrefix("odb"))
By("ensuring both the disks are attached to a machine domain")
var disks []libvirtxml.DomainDisk
Eventually(func(g Gomega) int {
domainXMLData, err := libvirtConn.DomainGetXMLDesc(domain, 0)
g.Expect(err).NotTo(HaveOccurred())
domainXML := &libvirtxml.Domain{}
g.Expect(domainXML.Unmarshal(domainXMLData)).Should(Succeed())
disks = domainXML.Devices.Disks
return len(disks)
}).WithTimeout(2 * time.Minute).WithPolling(2 * time.Second).Should(Equal(2))
Expect(disks[0].Serial).To(HavePrefix("oda"))
Expect(disks[1].Serial).To(HavePrefix("odb"))

// By("ensuring attached volume have been updated in machine status field")
// Eventually(func(g Gomega) *iri.MachineStatus {
// listResp, err := machineClient.ListMachines(ctx, &iri.ListMachinesRequest{
// Filter: &iri.MachineFilter{
// Id: createResp.Machine.Metadata.Id,
// },
// })
// g.Expect(err).NotTo(HaveOccurred())
// g.Expect(listResp.Machines).NotTo(BeEmpty())
// g.Expect(listResp.Machines).Should(HaveLen(1))
// return listResp.Machines[0].Status
// }).Should(SatisfyAll(
// HaveField("Volumes", ContainElements(
// &iri.VolumeStatus{
// Name: "disk-1",
// Handle: "libvirt-provider.ironcore.dev/empty-disk/disk-1",
// State: iri.VolumeState_VOLUME_ATTACHED,
// },
// &iri.VolumeStatus{
// Name: "volume-1",
// Handle: "libvirt-provider.ironcore.dev/ceph/libvirt-provider.ironcore.dev/ceph^dummy",
// State: iri.VolumeState_VOLUME_ATTACHED,
// })),
// HaveField("State", Equal(iri.MachineState_MACHINE_RUNNING)),
// ))
// })
// })
By("ensuring attached volume have been updated in machine status field")
Eventually(func(g Gomega) *iri.MachineStatus {
listResp, err := machineClient.ListMachines(ctx, &iri.ListMachinesRequest{
Filter: &iri.MachineFilter{
Id: createResp.Machine.Metadata.Id,
},
})
g.Expect(err).NotTo(HaveOccurred())
g.Expect(listResp.Machines).NotTo(BeEmpty())
g.Expect(listResp.Machines).Should(HaveLen(1))
return listResp.Machines[0].Status
}).Should(SatisfyAll(
HaveField("Volumes", ContainElements(
&iri.VolumeStatus{
Name: "disk-1",
Handle: "libvirt-provider.ironcore.dev/empty-disk/disk-1",
State: iri.VolumeState_VOLUME_ATTACHED,
},
&iri.VolumeStatus{
Name: "volume-1",
Handle: "libvirt-provider.ironcore.dev/ceph/libvirt-provider.ironcore.dev/ceph^dummy",
State: iri.VolumeState_VOLUME_ATTACHED,
})),
HaveField("State", Equal(iri.MachineState_MACHINE_RUNNING)),
))
})
})
Loading

0 comments on commit 29a450f

Please sign in to comment.