Skip to content

Commit

Permalink
changes for review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
so-sahu committed Mar 21, 2024
1 parent d9c981b commit 108db08
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 63 deletions.
96 changes: 48 additions & 48 deletions provider/server/machine_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ var _ = Describe("CreateMachine", Ordered, 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 @@ -43,18 +55,6 @@ var _ = Describe("CreateMachine", Ordered, 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 @@ -119,6 +119,18 @@ var _ = Describe("CreateMachine", Ordered, 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 @@ -141,18 +153,6 @@ var _ = Describe("CreateMachine", Ordered, 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 @@ -229,6 +229,18 @@ var _ = Describe("CreateMachine", Ordered, 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 @@ -252,18 +264,6 @@ var _ = Describe("CreateMachine", Ordered, 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 @@ -345,6 +345,18 @@ var _ = Describe("CreateMachine", Ordered, 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 Down Expand Up @@ -375,18 +387,6 @@ var _ = Describe("CreateMachine", Ordered, 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
2 changes: 1 addition & 1 deletion provider/server/machine_delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ var _ = Describe("DeleteMachine", Ordered, func() {
}).Should(Equal(iri.MachineState_MACHINE_RUNNING))

//allow some time for the vm to boot properly
time.Sleep(10 * time.Second)
time.Sleep(30 * time.Second)

By("deleting the machine")
_, err = machineClient.DeleteMachine(ctx, &iri.DeleteMachineRequest{
Expand Down
2 changes: 1 addition & 1 deletion provider/server/machine_networkinterface_attach_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var _ = Describe("AttachNetworkInterface", Ordered, func() {
Machine: &iri.Machine{
Metadata: &irimeta.ObjectMetadata{},
Spec: &iri.MachineSpec{
Class: machineClassx3xlarge,
Class: machineClassx2medium,
Image: &iri.ImageSpec{
Image: squashfsOSImage,
},
Expand Down
16 changes: 3 additions & 13 deletions provider/server/machine_networkinterface_detach_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,16 @@ var _ = Describe("DetachNetworkInterface", Ordered, func() {
Machine: &iri.Machine{
Metadata: &irimeta.ObjectMetadata{},
Spec: &iri.MachineSpec{
Class: machineClassx3xlarge,
Class: machineClassx2medium,
Image: &iri.ImageSpec{
Image: squashfsOSImage,
},
NetworkInterfaces: []*iri.NetworkInterface{
{
Name: "nic-1",
NetworkId: "nid-1",
Ips: []string{"192.168.1.1"},
Attributes: map[string]string{
"key1": "value1",
},
Name: "nic-1",
},
{
Name: "nic-2",
NetworkId: "nid-2",
Ips: []string{"192.168.1.2"},
Attributes: map[string]string{
"key2": "value2",
},
Name: "nic-2",
},
},
},
Expand Down
7 changes: 7 additions & 0 deletions provider/server/server_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ var _ = BeforeSuite(func() {
MemoryBytes: 8589934592,
},
},
{
Name: machineClassx2medium,
Capabilities: &iriv1alpha1.MachineClassCapabilities{
CpuMillis: 2000,
MemoryBytes: 2147483648,
},
},
}
machineClassData, err := json.Marshal(machineClasses)
Expect(err).NotTo(HaveOccurred())
Expand Down
10 changes: 10 additions & 0 deletions provider/server/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ var _ = Describe("Status", Ordered, func() {
},
Quantity: mcr.GetQuantity(&machineClasses[0], hostResources),
},
&iriv1alpha1.MachineClassStatus{
MachineClass: &iriv1alpha1.MachineClass{
Name: machineClasses[1].Name,
Capabilities: &iriv1alpha1.MachineClassCapabilities{
CpuMillis: machineClasses[1].Capabilities.CpuMillis,
MemoryBytes: machineClasses[1].Capabilities.MemoryBytes,
},
},
Quantity: mcr.GetQuantity(&machineClasses[1], hostResources),
},
))
})
})

0 comments on commit 108db08

Please sign in to comment.