Skip to content

Commit 68fc357

Browse files
committed
check boot of vm with ssh connection
1 parent 206cd77 commit 68fc357

File tree

4 files changed

+75
-10
lines changed

4 files changed

+75
-10
lines changed

provider/server/machine_create_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
)
1616

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

provider/server/machine_volume_detach_test.go

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ import (
1515
"libvirt.org/go/libvirtxml"
1616
)
1717

18-
var _ = Describe("DetachVolume", func() {
18+
var _ = FDescribe("DetachVolume", func() {
19+
const networkName = "default"
1920
It("should correctly detach volume from machine", func(ctx SpecContext) {
2021
By("creating a machine with two empty disks and single ceph volume")
2122
createResp, err := machineClient.CreateMachine(ctx, &iri.CreateMachineRequest{
@@ -31,6 +32,12 @@ var _ = Describe("DetachVolume", func() {
3132
Image: osImage,
3233
},
3334
Class: machineClassx3xlarge,
35+
NetworkInterfaces: []*iri.NetworkInterface{
36+
{
37+
Name: "eth0",
38+
NetworkId: networkName,
39+
},
40+
},
3441
Volumes: []*iri.Volume{
3542
{
3643
Name: "disk-1",
@@ -46,7 +53,7 @@ var _ = Describe("DetachVolume", func() {
4653
},
4754
Device: "odb",
4855
},
49-
{
56+
/*{
5057
Name: "volume-1",
5158
Device: "odc",
5259
Connection: &iri.VolumeConnection{
@@ -61,7 +68,7 @@ var _ = Describe("DetachVolume", func() {
6168
"userKey": []byte(cephUserkey),
6269
},
6370
},
64-
},
71+
},*/
6572
},
6673
},
6774
},
@@ -121,11 +128,11 @@ var _ = Describe("DetachVolume", func() {
121128
Handle: "libvirt-provider.ironcore.dev/empty-disk/disk-2",
122129
State: iri.VolumeState_VOLUME_ATTACHED,
123130
},
124-
&iri.VolumeStatus{
131+
/*&iri.VolumeStatus{
125132
Name: "volume-1",
126133
Handle: "libvirt-provider.ironcore.dev/ceph/libvirt-provider.ironcore.dev/ceph^dummy",
127134
State: iri.VolumeState_VOLUME_ATTACHED,
128-
})),
135+
}*/)),
129136
HaveField("State", Equal(iri.MachineState_MACHINE_RUNNING)),
130137
))
131138

@@ -138,13 +145,21 @@ var _ = Describe("DetachVolume", func() {
138145
Expect(domainXML.Unmarshal(domainXMLData)).Should(Succeed())
139146
disks = domainXML.Devices.Disks
140147
return len(disks)
141-
}).Should(Equal(4))
148+
}).Should(Equal(3))
142149
Expect(disks[0].Serial).To(HavePrefix("oda"))
143150
Expect(disks[1].Serial).To(HavePrefix("odb"))
144-
Expect(disks[2].Serial).To(HavePrefix("odc"))
151+
//Expect(disks[2].Serial).To(HavePrefix("odc"))
145152

146153
// wait to complete machine reconciliation
147-
time.Sleep(20 * time.Second)
154+
Eventually(func(g Gomega) {
155+
domainXMLData, err := libvirtConn.DomainGetXMLDesc(domain, 0)
156+
g.Expect(err).NotTo(HaveOccurred())
157+
domainXML := &libvirtxml.Domain{}
158+
g.Expect(domainXML.Unmarshal(domainXMLData)).Should(Succeed())
159+
ip, err := getAnyDomainIPForNetwork(networkName, domainXML)
160+
g.Expect(err).NotTo(HaveOccurred())
161+
g.Expect(isSSHOpen(ip)).Should(BeTrue())
162+
}).WithTimeout(2 * time.Minute).WithPolling(2 * time.Second).Should(Succeed())
148163

149164
By("detaching empty disk disk-1 from machine")
150165
diskDetachResp, err := machineClient.DetachVolume(ctx, &iri.DetachVolumeRequest{

provider/server/server_suite_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ var _ = BeforeSuite(func() {
8888
DeferCleanup(os.Remove, machineClassesFile.Name())
8989

9090
pluginOpts := networkinterfaceplugin.NewDefaultOptions()
91-
pluginOpts.PluginName = "isolated"
91+
pluginOpts.PluginName = "providernet"
9292

9393
tempDir = GinkgoT().TempDir()
9494
Expect(os.Chmod(tempDir, 0730)).Should(Succeed())

provider/server/testutils_test.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package server_test
2+
3+
import (
4+
"fmt"
5+
"net"
6+
"time"
7+
8+
"libvirt.org/go/libvirtxml"
9+
)
10+
11+
func getAnyDomainIPForNetwork(networkName string, domainDesc *libvirtxml.Domain) (string, error) {
12+
ip := ""
13+
14+
MAIN:
15+
for _, netIF := range domainDesc.Devices.Interfaces {
16+
if isInterfaceInSpecificNetwork(netIF.Source, networkName) {
17+
for index := range netIF.IP {
18+
if netIF.IP[index].Address != "" {
19+
ip = netIF.IP[index].Address
20+
break MAIN
21+
}
22+
}
23+
}
24+
}
25+
26+
if ip == "" {
27+
return "", fmt.Errorf("failed to find ip address for domain %s", domainDesc.Name)
28+
}
29+
30+
return ip, nil
31+
}
32+
33+
func isInterfaceInSpecificNetwork(source *libvirtxml.DomainInterfaceSource, networkName string) bool {
34+
return source != nil && source.Network != nil && source.Network.Network == networkName
35+
}
36+
37+
func isSSHOpen(ip string) bool {
38+
timeout := time.Second
39+
conn, err := net.DialTimeout("tcp", net.JoinHostPort(ip, "22"), timeout)
40+
if err != nil {
41+
return false
42+
}
43+
44+
if conn != nil {
45+
defer conn.Close()
46+
return true
47+
}
48+
49+
return false
50+
}

0 commit comments

Comments
 (0)