Skip to content

Commit 829ff8f

Browse files
committed
add test to verify init reuse hvsock exntries for hyperv machines
Signed-off-by: lstocchi <[email protected]>
1 parent e0df1ac commit 829ff8f

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

pkg/machine/e2e/init_windows_test.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/Microsoft/go-winio/vhd"
1010
"github.com/containers/libhvee/pkg/hypervctl"
1111
"github.com/containers/podman/v5/pkg/machine/define"
12+
"github.com/containers/podman/v5/pkg/machine/hyperv/vsock"
1213
. "github.com/onsi/ginkgo/v2"
1314
. "github.com/onsi/gomega"
1415
. "github.com/onsi/gomega/gexec"
@@ -126,4 +127,56 @@ var _ = Describe("podman machine init - windows only", func() {
126127
Expect(err).ToNot(HaveOccurred())
127128
Expect(checkSession).To(Exit(125))
128129
})
130+
131+
It("init should create hvsock entries if they do not exist, otherwise should reuse existing ones", func() {
132+
skipIfNotVmtype(define.HyperVVirt, "HyperV test only")
133+
134+
name := randomString()
135+
136+
// Ensure no HVSock entries exist before we start
137+
networkHvSocks, err := vsock.LoadAllHVSockRegistryEntriesByPurpose(vsock.Network)
138+
Expect(err).ToNot(HaveOccurred())
139+
Expect(networkHvSocks).To(BeEmpty())
140+
141+
readySocks, err := vsock.LoadAllHVSockRegistryEntriesByPurpose(vsock.Events)
142+
Expect(err).ToNot(HaveOccurred())
143+
Expect(readySocks).To(BeEmpty())
144+
145+
// Execute init for the first machine. This should create new HVSock entries
146+
i := new(initMachine)
147+
session, err := mb.setName(name).setCmd(i.withImage(mb.imagePath)).run()
148+
Expect(err).ToNot(HaveOccurred())
149+
Expect(session).To(Exit(0))
150+
151+
// Check that the HVSock entries were created
152+
networkHvSocks, err = vsock.LoadAllHVSockRegistryEntriesByPurpose(vsock.Network)
153+
Expect(err).ToNot(HaveOccurred())
154+
fmt.Println(networkHvSocks)
155+
Expect(networkHvSocks).To(HaveLen(1))
156+
157+
readySocks, err = vsock.LoadAllHVSockRegistryEntriesByPurpose(vsock.Events)
158+
Expect(err).ToNot(HaveOccurred())
159+
Expect(readySocks).To(HaveLen(1))
160+
161+
// Execute init for another machine. This should reuse the existing HVSock entries created above
162+
otherName := randomString()
163+
i = new(initMachine)
164+
session, err = mb.setName(otherName).setCmd(i.withImage(mb.imagePath)).run()
165+
Expect(err).ToNot(HaveOccurred())
166+
Expect(session).To(Exit(0))
167+
168+
newNetworkHvSocks, err := vsock.LoadAllHVSockRegistryEntriesByPurpose(vsock.Network)
169+
Expect(err).ToNot(HaveOccurred())
170+
Expect(newNetworkHvSocks).To(HaveLen(1))
171+
Expect(newNetworkHvSocks[0].Port).To(Equal(networkHvSocks[0].Port))
172+
173+
newReadySocks, err := vsock.LoadAllHVSockRegistryEntriesByPurpose(vsock.Events)
174+
Expect(err).ToNot(HaveOccurred())
175+
Expect(newReadySocks).To(HaveLen(1))
176+
Expect(newReadySocks[0].Port).To(Equal(readySocks[0].Port))
177+
178+
// Clean up all hvsock entries created during the test
179+
err = vsock.RemoveAllHVSockRegistryEntries()
180+
Expect(err).ToNot(HaveOccurred())
181+
})
129182
})

0 commit comments

Comments
 (0)