Skip to content

Commit 356e249

Browse files
kola/tests/iso: simplify iso.pxe* networking initialization
Simplify PXE test network setup by using QemuBuilder's built-in methods (SetNetbootP, SetNetbootIndex, EnableUsermodeNetworking) instead of manually constructing QEMU network device arguments.
1 parent e81a64e commit 356e249

1 file changed

Lines changed: 15 additions & 23 deletions

File tree

mantle/kola/tests/iso/live-pxe.go

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -159,20 +159,17 @@ func testPXE(c cluster.TestCluster, opts IsoTestOpts) {
159159
}
160160

161161
setupNet := func(o platform.MachineOptions, builder *platform.QemuBuilder) error {
162-
netdev := fmt.Sprintf("%s,netdev=mynet0,mac=52:54:00:12:34:56", pxe.networkdevice)
163-
if pxe.bootindex == "" {
164-
builder.Append("-boot", "once=n")
165-
} else {
166-
netdev += fmt.Sprintf(",bootindex=%s", pxe.bootindex)
167-
}
168-
builder.Append("-device", netdev)
169-
usernetdev := fmt.Sprintf("user,id=mynet0,tftp=%s,bootfile=%s", pxe.tftpdir, pxe.bootfile)
162+
usernetdev := ""
170163
if pxe.tftpipaddr != "10.0.2.2" {
171-
usernetdev += ",net=192.168.76.0/24,dhcpstart=192.168.76.9"
164+
usernetdev = "192.168.76.0/24,dhcpstart=192.168.76.9"
172165
}
173-
builder.Append("-netdev", usernetdev)
174-
// for SSH access
175-
return qc.SetupDefaultNetwork(o, builder)
166+
h := []platform.HostForwardPort{
167+
{Service: "ssh", HostPort: 0, GuestPort: 22},
168+
}
169+
builder.SetNetbootP(pxe.bootfile, pxe.tftpdir)
170+
builder.SetNetbootIndex(pxe.bootindex)
171+
builder.EnableUsermodeNetworking(h, usernetdev)
172+
return nil
176173
}
177174

178175
errchan := make(chan error)
@@ -286,13 +283,12 @@ func getPXEConfig(insecure bool, offline bool) (*conf.Conf, error) {
286283
}
287284

288285
type PXE struct {
289-
tftpdir string
290-
tftpipaddr string
291-
boottype string
292-
networkdevice string
293-
bootindex string
294-
pxeimagepath string
295-
bootfile string
286+
tftpdir string
287+
tftpipaddr string
288+
boottype string
289+
bootindex string
290+
pxeimagepath string
291+
bootfile string
296292
}
297293

298294
func createPXE(tempdir string, opts IsoTestOpts) (*PXE, *http.Server, error) {
@@ -380,7 +376,6 @@ func (pxe *PXE) setupArchDefaults(opts IsoTestOpts) error {
380376
pxe.tftpipaddr = "192.168.76.2"
381377
switch coreosarch.CurrentRpmArch() {
382378
case "x86_64":
383-
pxe.networkdevice = "e1000"
384379
if opts.firmware == "uefi" {
385380
pxe.boottype = "grub"
386381
pxe.bootfile = "/boot/grub2/grubx64.efi"
@@ -394,17 +389,14 @@ func (pxe *PXE) setupArchDefaults(opts IsoTestOpts) error {
394389
}
395390
case "aarch64":
396391
pxe.boottype = "grub"
397-
pxe.networkdevice = "virtio-net-pci"
398392
pxe.bootfile = "/boot/grub2/grubaa64.efi"
399393
pxe.pxeimagepath = "/boot/efi/EFI/fedora/grubaa64.efi"
400394
pxe.bootindex = "1"
401395
case "ppc64le":
402396
pxe.boottype = "grub"
403-
pxe.networkdevice = "virtio-net-pci"
404397
pxe.bootfile = "/boot/grub2/powerpc-ieee1275/core.elf"
405398
case "s390x":
406399
pxe.boottype = "pxe"
407-
pxe.networkdevice = "virtio-net-ccw"
408400
pxe.bootindex = "1"
409401
pxe.tftpipaddr = "10.0.2.2"
410402
default:

0 commit comments

Comments
 (0)