Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check boot of vm with ssh connection #222

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
128 changes: 65 additions & 63 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 All @@ -37,6 +33,18 @@ var _ = Describe("CreateMachine", func() {
Expect(err).NotTo(HaveOccurred())
Expect(createResp).NotTo(BeNil())

DeferCleanup(func(ctx SpecContext) {
Eventually(func(g Gomega) bool {
_, err := machineClient.DeleteMachine(ctx, &iri.DeleteMachineRequest{MachineId: createResp.Machine.Metadata.Id})
g.Expect(err).To(SatisfyAny(
BeNil(),
MatchError(ContainSubstring("NotFound")),
))
_, err = libvirtConn.DomainLookupByUUID(libvirtutils.UUIDStringToBytes(createResp.Machine.Metadata.Id))
return libvirt.IsNotFound(err)
}).Should(BeTrue())
})

By("ensuring the correct creation response")
Expect(createResp).Should(SatisfyAll(
HaveField("Machine.Metadata.Id", Not(BeEmpty())),
Expand All @@ -53,18 +61,6 @@ var _ = Describe("CreateMachine", func() {
HaveField("Machine.Status.NetworkInterfaces", BeNil()),
))

DeferCleanup(func(ctx SpecContext) {
Eventually(func(g Gomega) bool {
_, err := machineClient.DeleteMachine(ctx, &iri.DeleteMachineRequest{MachineId: createResp.Machine.Metadata.Id})
g.Expect(err).To(SatisfyAny(
BeNil(),
MatchError(ContainSubstring("NotFound")),
))
_, err = libvirtConn.DomainLookupByUUID(libvirtutils.UUIDStringToBytes(createResp.Machine.Metadata.Id))
return libvirt.IsNotFound(err)
}).Should(BeTrue())
})

By("ensuring domain and domain XML is created for machine")
var domain libvirt.Domain
Eventually(func() error {
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 @@ -134,6 +131,18 @@ var _ = Describe("CreateMachine", func() {
Expect(err).NotTo(HaveOccurred())
Expect(createResp).NotTo(BeNil())

DeferCleanup(func(ctx SpecContext) {
Eventually(func(g Gomega) bool {
_, err := machineClient.DeleteMachine(ctx, &iri.DeleteMachineRequest{MachineId: createResp.Machine.Metadata.Id})
g.Expect(err).To(SatisfyAny(
BeNil(),
MatchError(ContainSubstring("NotFound")),
))
_, err = libvirtConn.DomainLookupByUUID(libvirtutils.UUIDStringToBytes(createResp.Machine.Metadata.Id))
return libvirt.IsNotFound(err)
}).Should(BeTrue())
})

By("ensuring the correct creation response")
Expect(createResp).Should(SatisfyAll(
HaveField("Machine.Metadata.Id", Not(BeEmpty())),
Expand All @@ -149,7 +158,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 All @@ -158,18 +168,6 @@ var _ = Describe("CreateMachine", func() {
HaveField("Machine.Status.NetworkInterfaces", BeNil()),
))

DeferCleanup(func(ctx SpecContext) {
Eventually(func(g Gomega) bool {
_, err := machineClient.DeleteMachine(ctx, &iri.DeleteMachineRequest{MachineId: createResp.Machine.Metadata.Id})
g.Expect(err).To(SatisfyAny(
BeNil(),
MatchError(ContainSubstring("NotFound")),
))
_, err = libvirtConn.DomainLookupByUUID(libvirtutils.UUIDStringToBytes(createResp.Machine.Metadata.Id))
return libvirt.IsNotFound(err)
}).Should(BeTrue())
})

By("ensuring domain and domain XML is created for machine")
var domain libvirt.Domain
Eventually(func() error {
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 @@ -251,11 +250,23 @@ var _ = Describe("CreateMachine", func() {
Expect(err).NotTo(HaveOccurred())
Expect(createResp).NotTo(BeNil())

DeferCleanup(func(ctx SpecContext) {
Eventually(func(g Gomega) bool {
_, err := machineClient.DeleteMachine(ctx, &iri.DeleteMachineRequest{MachineId: createResp.Machine.Metadata.Id})
g.Expect(err).To(SatisfyAny(
BeNil(),
MatchError(ContainSubstring("NotFound")),
))
_, err = libvirtConn.DomainLookupByUUID(libvirtutils.UUIDStringToBytes(createResp.Machine.Metadata.Id))
return libvirt.IsNotFound(err)
}).Should(BeTrue())
})

By("ensuring the correct creation response")
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 +277,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 All @@ -275,18 +287,6 @@ var _ = Describe("CreateMachine", func() {
HaveField("Machine.Status.NetworkInterfaces", BeNil()),
))

DeferCleanup(func(ctx SpecContext) {
Eventually(func(g Gomega) bool {
_, err := machineClient.DeleteMachine(ctx, &iri.DeleteMachineRequest{MachineId: createResp.Machine.Metadata.Id})
g.Expect(err).To(SatisfyAny(
BeNil(),
MatchError(ContainSubstring("NotFound")),
))
_, err = libvirtConn.DomainLookupByUUID(libvirtutils.UUIDStringToBytes(createResp.Machine.Metadata.Id))
return libvirt.IsNotFound(err)
}).Should(BeTrue())
})

By("ensuring domain and domain XML is created for machine")
var domain libvirt.Domain
Eventually(func() error {
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 @@ -374,11 +375,23 @@ var _ = Describe("CreateMachine", func() {
Expect(err).NotTo(HaveOccurred())
Expect(createResp).NotTo(BeNil())

DeferCleanup(func(ctx SpecContext) {
Eventually(func(g Gomega) bool {
_, err := machineClient.DeleteMachine(ctx, &iri.DeleteMachineRequest{MachineId: createResp.Machine.Metadata.Id})
g.Expect(err).To(SatisfyAny(
BeNil(),
MatchError(ContainSubstring("NotFound")),
))
_, err = libvirtConn.DomainLookupByUUID(libvirtutils.UUIDStringToBytes(createResp.Machine.Metadata.Id))
return libvirt.IsNotFound(err)
}).Should(BeTrue())
})

By("ensuring the correct creation response")
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 +410,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 All @@ -406,18 +420,6 @@ var _ = Describe("CreateMachine", func() {
HaveField("Machine.Status.NetworkInterfaces", BeNil()),
))

DeferCleanup(func(ctx SpecContext) {
Eventually(func(g Gomega) bool {
_, err := machineClient.DeleteMachine(ctx, &iri.DeleteMachineRequest{MachineId: createResp.Machine.Metadata.Id})
g.Expect(err).To(SatisfyAny(
BeNil(),
MatchError(ContainSubstring("NotFound")),
))
_, err = libvirtConn.DomainLookupByUUID(libvirtutils.UUIDStringToBytes(createResp.Machine.Metadata.Id))
return libvirt.IsNotFound(err)
}).Should(BeTrue())
})

By("ensuring domain and domain XML is created for machine")
var domain libvirt.Domain
Eventually(func() error {
Expand Down
46 changes: 15 additions & 31 deletions provider/server/machine_delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,24 @@ 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{
Machine: &iri.Machine{
Metadata: &irimeta.ObjectMetadata{
Labels: map[string]string{
"foo": "bar",
},
Labels: map[string]string{},
},
Spec: &iri.MachineSpec{
Power: iri.Power_POWER_ON,
Image: &iri.ImageSpec{
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 +70,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 +101,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 +118,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 +186,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
Loading
Loading