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 6, 2024
1 parent 206cd77 commit 68fc357
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 10 deletions.
2 changes: 1 addition & 1 deletion provider/server/machine_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
)

const (
osImage = "ghcr.io/ironcore-dev/ironcore-image/gardenlinux:rootfs-dev-20231206-v1"
osImage = "ghcr.io/ironcore-dev/ironcore-image/gardenlinux:squashfs-dev-20240123-v2"
emptyDiskSize = 1024 * 1024 * 1024
)

Expand Down
31 changes: 23 additions & 8 deletions provider/server/machine_volume_detach_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import (
"libvirt.org/go/libvirtxml"
)

var _ = Describe("DetachVolume", func() {
var _ = FDescribe("DetachVolume", func() {
const networkName = "default"
It("should correctly detach volume from machine", func(ctx SpecContext) {
By("creating a machine with two empty disks and single ceph volume")
createResp, err := machineClient.CreateMachine(ctx, &iri.CreateMachineRequest{
Expand All @@ -31,6 +32,12 @@ var _ = Describe("DetachVolume", func() {
Image: osImage,
},
Class: machineClassx3xlarge,
NetworkInterfaces: []*iri.NetworkInterface{
{
Name: "eth0",
NetworkId: networkName,
},
},
Volumes: []*iri.Volume{
{
Name: "disk-1",
Expand All @@ -46,7 +53,7 @@ var _ = Describe("DetachVolume", func() {
},
Device: "odb",
},
{
/*{
Name: "volume-1",
Device: "odc",
Connection: &iri.VolumeConnection{
Expand All @@ -61,7 +68,7 @@ var _ = Describe("DetachVolume", func() {
"userKey": []byte(cephUserkey),
},
},
},
},*/
},
},
},
Expand Down Expand Up @@ -121,11 +128,11 @@ var _ = Describe("DetachVolume", func() {
Handle: "libvirt-provider.ironcore.dev/empty-disk/disk-2",
State: iri.VolumeState_VOLUME_ATTACHED,
},
&iri.VolumeStatus{
/*&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)),
))

Expand All @@ -138,13 +145,21 @@ var _ = Describe("DetachVolume", func() {
Expect(domainXML.Unmarshal(domainXMLData)).Should(Succeed())
disks = domainXML.Devices.Disks
return len(disks)
}).Should(Equal(4))
}).Should(Equal(3))
Expect(disks[0].Serial).To(HavePrefix("oda"))
Expect(disks[1].Serial).To(HavePrefix("odb"))
Expect(disks[2].Serial).To(HavePrefix("odc"))
//Expect(disks[2].Serial).To(HavePrefix("odc"))

// wait to complete machine reconciliation
time.Sleep(20 * time.Second)
Eventually(func(g Gomega) {
domainXMLData, err := libvirtConn.DomainGetXMLDesc(domain, 0)
g.Expect(err).NotTo(HaveOccurred())
domainXML := &libvirtxml.Domain{}
g.Expect(domainXML.Unmarshal(domainXMLData)).Should(Succeed())
ip, err := getAnyDomainIPForNetwork(networkName, domainXML)
g.Expect(err).NotTo(HaveOccurred())
g.Expect(isSSHOpen(ip)).Should(BeTrue())
}).WithTimeout(2 * time.Minute).WithPolling(2 * time.Second).Should(Succeed())

By("detaching empty disk disk-1 from machine")
diskDetachResp, err := machineClient.DetachVolume(ctx, &iri.DetachVolumeRequest{
Expand Down
2 changes: 1 addition & 1 deletion provider/server/server_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ var _ = BeforeSuite(func() {
DeferCleanup(os.Remove, machineClassesFile.Name())

pluginOpts := networkinterfaceplugin.NewDefaultOptions()
pluginOpts.PluginName = "isolated"
pluginOpts.PluginName = "providernet"

tempDir = GinkgoT().TempDir()
Expect(os.Chmod(tempDir, 0730)).Should(Succeed())
Expand Down
50 changes: 50 additions & 0 deletions provider/server/testutils_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package server_test

import (
"fmt"
"net"
"time"

"libvirt.org/go/libvirtxml"
)

func getAnyDomainIPForNetwork(networkName string, domainDesc *libvirtxml.Domain) (string, error) {
ip := ""

MAIN:
for _, netIF := range domainDesc.Devices.Interfaces {
if isInterfaceInSpecificNetwork(netIF.Source, networkName) {
for index := range netIF.IP {
if netIF.IP[index].Address != "" {
ip = netIF.IP[index].Address
break MAIN
}
}
}
}

if ip == "" {
return "", fmt.Errorf("failed to find ip address for domain %s", domainDesc.Name)
}

return ip, nil
}

func isInterfaceInSpecificNetwork(source *libvirtxml.DomainInterfaceSource, networkName string) bool {
return source != nil && source.Network != nil && source.Network.Network == networkName
}

func isSSHOpen(ip string) bool {
timeout := time.Second
conn, err := net.DialTimeout("tcp", net.JoinHostPort(ip, "22"), timeout)
if err != nil {
return false
}

if conn != nil {
defer conn.Close()
return true
}

return false
}

0 comments on commit 68fc357

Please sign in to comment.