Skip to content

Commit

Permalink
check boot of vm with ssh connection
Browse files Browse the repository at this point in the history
  • Loading branch information
lukas016 committed Mar 16, 2024
1 parent 615412e commit 8dc4a00
Show file tree
Hide file tree
Showing 13 changed files with 254 additions and 88 deletions.
3 changes: 1 addition & 2 deletions provider/server/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ import (
"k8s.io/kubectl/pkg/util/term"
)

var _ = Describe("Exec", func() {

var _ = Describe("Exec", Ordered, func() {
It("should verify an exec-url with a token", func(ctx SpecContext) {
By("creating the test machine")
createResp, err := machineClient.CreateMachine(ctx, &iri.CreateMachineRequest{
Expand Down
2 changes: 1 addition & 1 deletion provider/server/machine_annotations_update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
. "github.com/onsi/gomega"
)

var _ = Describe("UpdateMachineAnnotations", func() {
var _ = Describe("UpdateMachineAnnotations", Ordered, func() {
It("should update machine annotations", func(ctx SpecContext) {
ignitionData := []byte("urjhikmnbdjfkknhhdddeee")
By("creating a machine")
Expand Down
32 changes: 17 additions & 15 deletions provider/server/machine_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ import (
. "github.com/onsi/gomega"
)

const (
osImage = "ghcr.io/ironcore-dev/ironcore-image/gardenlinux:rootfs-dev-20231206-v1"
)

var _ = Describe("CreateMachine", func() {
var _ = Describe("CreateMachine", Ordered, func() {
It("should create a machine without boot image, volume and network interface", func(ctx SpecContext) {
By("creating a machine without boot image, volume and network interface")
createResp, err := machineClient.CreateMachine(ctx, &iri.CreateMachineRequest{
Expand Down Expand Up @@ -125,7 +121,8 @@ var _ = Describe("CreateMachine", func() {
},
NetworkInterfaces: []*iri.NetworkInterface{
{
Name: "nic-1",
Name: "nic-1",
NetworkId: networkID.Name,
},
},
},
Expand All @@ -149,7 +146,8 @@ var _ = Describe("CreateMachine", func() {
Device: "oda",
})),
HaveField("Machine.Spec.NetworkInterfaces", ContainElement(&iri.NetworkInterface{
Name: "nic-1",
Name: "nic-1",
NetworkId: networkID.Name,
})),
HaveField("Machine.Status.ObservedGeneration", BeZero()),
HaveField("Machine.Status.State", Equal(iri.MachineState_MACHINE_PENDING)),
Expand Down Expand Up @@ -227,7 +225,7 @@ var _ = Describe("CreateMachine", func() {
Spec: &iri.MachineSpec{
Power: iri.Power_POWER_ON,
Image: &iri.ImageSpec{
Image: osImage,
Image: squashfsOSImage,
},
Class: machineClassx3xlarge,
IgnitionData: ignitionData,
Expand All @@ -242,7 +240,8 @@ var _ = Describe("CreateMachine", func() {
},
NetworkInterfaces: []*iri.NetworkInterface{
{
Name: "nic-1",
Name: "nic-1",
NetworkId: networkID.Name,
},
},
},
Expand All @@ -255,7 +254,7 @@ var _ = Describe("CreateMachine", func() {
Expect(createResp).Should(SatisfyAll(
HaveField("Machine.Metadata.Id", Not(BeEmpty())),
HaveField("Machine.Spec.Power", iri.Power_POWER_ON),
HaveField("Machine.Spec.Image.Image", Equal(osImage)),
HaveField("Machine.Spec.Image.Image", Equal(squashfsOSImage)),
HaveField("Machine.Spec.Class", machineClassx3xlarge),
HaveField("Machine.Spec.IgnitionData", Equal(ignitionData)),
HaveField("Machine.Spec.Volumes", ContainElement(&iri.Volume{
Expand All @@ -266,7 +265,8 @@ var _ = Describe("CreateMachine", func() {
},
})),
HaveField("Machine.Spec.NetworkInterfaces", ContainElement(&iri.NetworkInterface{
Name: "nic-1",
Name: "nic-1",
NetworkId: networkID.Name,
})),
HaveField("Machine.Status.ObservedGeneration", BeZero()),
HaveField("Machine.Status.State", Equal(iri.MachineState_MACHINE_PENDING)),
Expand Down Expand Up @@ -343,7 +343,7 @@ var _ = Describe("CreateMachine", func() {
Spec: &iri.MachineSpec{
Power: iri.Power_POWER_ON,
Image: &iri.ImageSpec{
Image: osImage,
Image: squashfsOSImage,
},
Class: machineClassx3xlarge,
IgnitionData: ignitionData,
Expand All @@ -365,7 +365,8 @@ var _ = Describe("CreateMachine", func() {
},
NetworkInterfaces: []*iri.NetworkInterface{
{
Name: "nic-1",
Name: "nic-1",
NetworkId: networkID.Name,
},
},
},
Expand All @@ -378,7 +379,7 @@ var _ = Describe("CreateMachine", func() {
Expect(createResp).Should(SatisfyAll(
HaveField("Machine.Metadata.Id", Not(BeEmpty())),
HaveField("Machine.Spec.Power", iri.Power_POWER_ON),
HaveField("Machine.Spec.Image.Image", Equal(osImage)),
HaveField("Machine.Spec.Image.Image", Equal(squashfsOSImage)),
HaveField("Machine.Spec.Class", machineClassx3xlarge),
HaveField("Machine.Spec.IgnitionData", Equal(ignitionData)),
HaveField("Machine.Spec.Volumes", ContainElements(
Expand All @@ -397,7 +398,8 @@ var _ = Describe("CreateMachine", func() {
},
})),
HaveField("Machine.Spec.NetworkInterfaces", ContainElement(&iri.NetworkInterface{
Name: "nic-1",
Name: "nic-1",
NetworkId: networkID.Name,
})),
HaveField("Machine.Status.ObservedGeneration", BeZero()),
HaveField("Machine.Status.State", Equal(iri.MachineState_MACHINE_PENDING)),
Expand Down
42 changes: 14 additions & 28 deletions provider/server/machine_delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ import (
. "github.com/onsi/gomega"
)

var _ = Describe("DeleteMachine", func() {

var _ = Describe("DeleteMachine", Ordered, func() {
It("should delete a machine with graceful shutdown", func(ctx SpecContext) {
By("creating a machine using squashfs os image")
createResp, err := machineClient.CreateMachine(ctx, &iri.CreateMachineRequest{
Expand All @@ -32,13 +31,10 @@ var _ = Describe("DeleteMachine", func() {
Image: squashfsOSImage,
},
Class: machineClassx3xlarge,
Volumes: []*iri.Volume{
NetworkInterfaces: []*iri.NetworkInterface{
{
Name: "disk-1",
EmptyDisk: &iri.EmptyDisk{
SizeBytes: emptyDiskSize,
},
Device: "oda",
Name: "eth0",
NetworkId: networkID.Name,
},
},
},
Expand Down Expand Up @@ -76,8 +72,9 @@ var _ = Describe("DeleteMachine", func() {
return listResp.Machines[0].Status.State
}).Should(Equal(iri.MachineState_MACHINE_RUNNING))

//allow some time for the vm to boot properly
time.Sleep(30 * time.Second)
Eventually(func(g Gomega) {
isDomainVMUpAndRunning(g, libvirtConn, &domain, &networkID)
}).WithTimeout(5 * time.Minute).WithPolling(5 * time.Second).Should(Succeed())

By("deleting the machine")
_, err = machineClient.DeleteMachine(ctx, &iri.DeleteMachineRequest{
Expand Down Expand Up @@ -106,7 +103,7 @@ var _ = Describe("DeleteMachine", func() {
})
g.Expect(err).NotTo(HaveOccurred())
g.Expect(listResp.Machines).To(BeEmpty())
}).Within(gracefulShutdownTimeout).ProbeEvery(probeEveryInterval).Should(Succeed()) // ProbeEvery has to be ideally less than or equal to half of ResyncIntervalGarbageCollector
}).WithTimeout(gracefulShutdownTimeout).WithPolling(pollingIntervalDeletion).Should(Succeed())

By("ensuring domain and domain XML is deleted for machine")
domain, err = libvirtConn.DomainLookupByUUID(libvirtutils.UUIDStringToBytes(createResp.Machine.Metadata.Id))
Expand All @@ -123,23 +120,11 @@ var _ = Describe("DeleteMachine", func() {
By("creating a machine which may not boot properly")
createResp, err := machineClient.CreateMachine(ctx, &iri.CreateMachineRequest{
Machine: &iri.Machine{
Metadata: &irimeta.ObjectMetadata{
Labels: map[string]string{
"foo": "bar",
},
},
Metadata: &irimeta.ObjectMetadata{},
Spec: &iri.MachineSpec{
Power: iri.Power_POWER_ON,
Class: machineClassx3xlarge,
Volumes: []*iri.Volume{
{
Name: "disk-1",
EmptyDisk: &iri.EmptyDisk{
SizeBytes: emptyDiskSize,
},
Device: "oda",
},
},
Power: iri.Power_POWER_ON,
Class: machineClassx3xlarge,
Volumes: nil,
NetworkInterfaces: nil,
},
},
Expand Down Expand Up @@ -203,7 +188,8 @@ var _ = Describe("DeleteMachine", func() {
})
g.Expect(err).NotTo(HaveOccurred())
g.Expect(listResp.Machines).Should(HaveLen(1))
}).WithTimeout(gracefulShutdownTimeout).WithPolling(probeEveryInterval).Should(Succeed())
g.Expect(listResp.Machines[0].Status.State).Should(Equal(iri.MachineState_MACHINE_TERMINATING))
}).WithTimeout(gracefulShutdownTimeout).WithPolling(pollingIntervalDeletion).Should(Succeed())

By("ensuring machine is deleted after gracefulShutdownTimeout")
Eventually(func(g Gomega) {
Expand Down
12 changes: 1 addition & 11 deletions provider/server/machine_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
. "github.com/onsi/gomega"
)

var _ = Describe("ListMachine", func() {
var _ = Describe("ListMachine", Ordered, func() {
It("should list machines", func(ctx SpecContext) {
By("creating a machine")
createResp, err := machineClient.CreateMachine(ctx, &iri.CreateMachineRequest{
Expand All @@ -25,16 +25,6 @@ var _ = Describe("ListMachine", func() {
Spec: &iri.MachineSpec{
Power: iri.Power_POWER_ON,
Class: machineClassx3xlarge,
Volumes: []*iri.Volume{
{
Name: "disk-1",
EmptyDisk: &iri.EmptyDisk{
SizeBytes: 5368709120,
},
Device: "oda",
},
},
NetworkInterfaces: nil,
},
},
})
Expand Down
7 changes: 4 additions & 3 deletions provider/server/machine_networkinterface_attach_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"libvirt.org/go/libvirtxml"
)

var _ = Describe("AttachNetworkInterface", func() {
var _ = Describe("AttachNetworkInterface", Ordered, func() {
It("should attach a network interface to the machine", func(ctx SpecContext) {
By("creating a machine")
createResp, err := machineClient.CreateMachine(ctx, &iri.CreateMachineRequest{
Expand All @@ -31,7 +31,7 @@ var _ = Describe("AttachNetworkInterface", func() {
Power: iri.Power_POWER_ON,
Class: machineClassx2medium,
Image: &iri.ImageSpec{
Image: osImage,
Image: squashfsOSImage,
},
},
},
Expand Down Expand Up @@ -72,7 +72,8 @@ var _ = Describe("AttachNetworkInterface", func() {
attachNetworkResp, err := machineClient.AttachNetworkInterface(ctx, &iri.AttachNetworkInterfaceRequest{
MachineId: createResp.Machine.Metadata.Id,
NetworkInterface: &iri.NetworkInterface{
Name: "nic-1",
Name: "nic-1",
NetworkId: networkID.Name,
},
})
Expect(err).NotTo(HaveOccurred())
Expand Down
16 changes: 4 additions & 12 deletions provider/server/machine_networkinterface_detach_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"libvirt.org/go/libvirtxml"
)

var _ = Describe("DetachNetworkInterface", func() {
var _ = Describe("DetachNetworkInterface", Ordered, func() {
It("should detach a network interface from the machine", func(ctx SpecContext) {
By("creating a machine")
createResp, err := machineClient.CreateMachine(ctx, &iri.CreateMachineRequest{
Expand All @@ -31,24 +31,16 @@ var _ = Describe("DetachNetworkInterface", func() {
Power: iri.Power_POWER_ON,
Class: machineClassx2medium,
Image: &iri.ImageSpec{
Image: osImage,
Image: squashfsOSImage,
},
NetworkInterfaces: []*iri.NetworkInterface{
{
Name: "nic-1",
NetworkId: "nid-1",
Ips: []string{"192.168.1.1"},
Attributes: map[string]string{
"key1": "value1",
},
NetworkId: networkID.Name,
},
{
Name: "nic-2",
NetworkId: "nid-2",
Ips: []string{"192.168.1.2"},
Attributes: map[string]string{
"key2": "value2",
},
NetworkId: networkID.Name,
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion provider/server/machine_powerstate_update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

// TODO: This test will require update after implementation of: https://github.com/ironcore-dev/libvirt-provider/issues/106
var _ = Describe("UpdateMachinePower", func() {
var _ = Describe("UpdateMachinePower", Ordered, func() {
It("should update machine power state", func(ctx SpecContext) {
ignitionData := []byte("urjhikmnbdjfkknhhdddeee")
By("creating a machine")
Expand Down
17 changes: 13 additions & 4 deletions provider/server/machine_volume_attach_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"libvirt.org/go/libvirtxml"
)

var _ = Describe("AttachVolume", func() {
var _ = Describe("AttachVolume", Ordered, func() {
It("should correctly attach volume to machine", func(ctx SpecContext) {
By("creating a machine")
createResp, err := machineClient.CreateMachine(ctx, &iri.CreateMachineRequest{
Expand All @@ -26,6 +26,9 @@ var _ = Describe("AttachVolume", func() {
},
},
Spec: &iri.MachineSpec{
Image: &iri.ImageSpec{
Image: squashfsOSImage,
},
Power: iri.Power_POWER_ON,
Class: machineClassx3xlarge,
},
Expand Down Expand Up @@ -63,6 +66,10 @@ var _ = Describe("AttachVolume", func() {
return libvirt.DomainState(domainState)
}).Should(Equal(libvirt.DomainRunning))

Eventually(func(g Gomega) {
isDomainVMUpAndRunning(g, libvirtConn, &domain, &networkID)
}).WithTimeout(5 * time.Minute).WithPolling(5 * time.Second).Should(Succeed())

By("attaching empty disk to a machine")
attachEmptyDiskResp, err := machineClient.AttachVolume(ctx, &iri.AttachVolumeRequest{
MachineId: createResp.Machine.Metadata.Id,
Expand Down Expand Up @@ -130,9 +137,11 @@ var _ = Describe("AttachVolume", func() {
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"))
}).WithTimeout(2 * time.Minute).WithPolling(2 * time.Second).Should(Equal(3))
for index := range disks {
Expect(disks[index].Serial).To(
SatisfyAny(HavePrefix("oda"), HavePrefix("odb"), HavePrefix("machineboot")))
}

By("ensuring attached volume have been updated in machine status field")
Eventually(func(g Gomega) *iri.MachineStatus {
Expand Down
Loading

0 comments on commit 8dc4a00

Please sign in to comment.