11package iso
22
33import (
4+ "context"
45 _ "embed"
56 "fmt"
7+ "log"
68 "net"
79 "net/http"
810 "os"
@@ -203,17 +205,6 @@ func isoLiveInstall(c cluster.TestCluster, opts IsoTestOpts) {
203205 c .Fatal ("Cannot use `--add-nm-keyfile` with offline mode" )
204206 }
205207
206- qc , ok := c .Cluster .(* qemu.Cluster )
207- if ! ok {
208- c .Fatalf ("Unsupported cluster type" )
209- }
210- if opts .enable4k {
211- qc .EnforceNative4k ()
212- }
213- if opts .enableMultipath {
214- qc .EnforceMultipath ()
215- }
216-
217208 tempdir , err := os .MkdirTemp ("/var/tmp" , "iso" )
218209 if err != nil {
219210 c .Fatal (err )
@@ -222,12 +213,22 @@ func isoLiveInstall(c cluster.TestCluster, opts IsoTestOpts) {
222213 os .RemoveAll (tempdir )
223214 }()
224215
225- if err := isoRunTest (qc , opts , tempdir ); err != nil {
216+ if err := isoRunTest (c , opts , tempdir ); err != nil {
226217 c .Fatal (err )
227218 }
228219}
229220
230- func isoRunTest (qc * qemu.Cluster , opts IsoTestOpts , tempdir string ) error {
221+ func isoRunTest (c cluster.TestCluster , opts IsoTestOpts , tempdir string ) error {
222+ qc , ok := c .Cluster .(* qemu.Cluster )
223+ if ! ok {
224+ return errors .Errorf ("Unsupported cluster type" )
225+ }
226+ if opts .enable4k {
227+ qc .EnforceNative4k ()
228+ }
229+ if opts .enableMultipath {
230+ qc .EnforceMultipath ()
231+ }
231232 targetConfig , err := conf .EmptyIgnition ().Render (conf .FailWarnings )
232233 if err != nil {
233234 return err
@@ -315,11 +316,21 @@ func isoRunTest(qc *qemu.Cluster, opts IsoTestOpts, tempdir string) error {
315316 targetConfig .AddConfigSource (baseurl + "/target.ign" )
316317 serializedTargetConfig = targetConfig .String ()
317318
318- //nolint // Yeah this leaks
319+ ctx := c .Context ()
320+ mux := http .NewServeMux ()
321+ mux .Handle ("/" , http .FileServer (http .Dir (tempdir )))
322+ srv := & http.Server {Handler : mux }
323+
324+ go func () {
325+ if err := srv .Serve (listener ); err != nil && ! errors .Is (err , http .ErrServerClosed ) {
326+ log .Printf ("http serve: %v" , err )
327+ }
328+ }()
329+
330+ // stop server when ctx is canceled
319331 go func () {
320- mux := http .NewServeMux ()
321- mux .Handle ("/" , http .FileServer (http .Dir (tempdir )))
322- http .Serve (listener , mux )
332+ <- ctx .Done ()
333+ _ = srv .Shutdown (context .Background ())
323334 }()
324335 }
325336
0 commit comments