|
9 | 9 | "github.com/Microsoft/go-winio/vhd"
|
10 | 10 | "github.com/containers/libhvee/pkg/hypervctl"
|
11 | 11 | "github.com/containers/podman/v5/pkg/machine/define"
|
| 12 | + "github.com/containers/podman/v5/pkg/machine/hyperv/vsock" |
12 | 13 | . "github.com/onsi/ginkgo/v2"
|
13 | 14 | . "github.com/onsi/gomega"
|
14 | 15 | . "github.com/onsi/gomega/gexec"
|
@@ -126,4 +127,56 @@ var _ = Describe("podman machine init - windows only", func() {
|
126 | 127 | Expect(err).ToNot(HaveOccurred())
|
127 | 128 | Expect(checkSession).To(Exit(125))
|
128 | 129 | })
|
| 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 | + }) |
129 | 182 | })
|
0 commit comments