@@ -71,14 +71,13 @@ func TestCreateInstanceWithNetwork(t *testing.T) {
7171 // Create instance with nginx:alpine and default network
7272 t .Log ("Creating instance with default network..." )
7373 inst , err := manager .CreateInstance (ctx , CreateInstanceRequest {
74- Name : "test-net-instance" ,
75- Image : integrationTestImageRef (t , "docker.io/library/nginx:alpine" ),
76- Size : 2 * 1024 * 1024 * 1024 , // 2GB (needs extra room for initrd with NVIDIA libs)
77- HotplugSize : 512 * 1024 * 1024 ,
78- OverlaySize : 5 * 1024 * 1024 * 1024 ,
79- Vcpus : 1 ,
80- NetworkEnabled : true ,
81- NetworkBandwidthUpload : 1024 * 1024 ,
74+ Name : "test-net-instance" ,
75+ Image : integrationTestImageRef (t , "docker.io/library/nginx:alpine" ),
76+ Size : 2 * 1024 * 1024 * 1024 , // 2GB (needs extra room for initrd with NVIDIA libs)
77+ HotplugSize : 512 * 1024 * 1024 ,
78+ OverlaySize : 5 * 1024 * 1024 * 1024 ,
79+ Vcpus : 1 ,
80+ NetworkEnabled : true ,
8281 HealthCheck : & healthcheck.Policy {
8382 Type : healthcheck .TypeHTTP ,
8483 Interval : "1s" ,
@@ -131,15 +130,15 @@ func TestCreateInstanceWithNetwork(t *testing.T) {
131130 bridgeName := master .Attrs ().Name
132131
133132 t .Log ("Verifying orphaned bridge tc cleanup preserves live TAP state..." )
134- liveFlowID := waitForUploadFlowID (t , ctx , manager , inst . Id , bridgeName )
135- require .True (t , bridgeClassExists (t , bridgeName , liveFlowID ), "live upload class should exist before cleanup" )
136- staleFlowID := createStaleBridgeTCForTest (t , bridgeName )
133+ liveFlowID := createBridgeTCForTest (t , bridgeName , tap . Attrs (). Index )
134+ require .True (t , bridgeClassExists (t , bridgeName , liveFlowID ), "live bridge tc class should exist before cleanup" )
135+ staleFlowID := createBridgeTCForTest (t , bridgeName , 1 )
137136 deletedTC := manager .networkManager .CleanupOrphanedClasses (ctx )
138137 require .GreaterOrEqual (t , deletedTC , 2 , "expected stale filter and class to be deleted" )
139- assert .True (t , bridgeFilterExistsForFlowID (t , bridgeName , liveFlowID ), "live upload filter should remain" )
140- assert .True (t , bridgeClassExists (t , bridgeName , liveFlowID ), "live upload class should remain" )
141- assert .False (t , bridgeFilterExistsForFlowID (t , bridgeName , staleFlowID ), "stale upload filter should be deleted" )
142- assert .False (t , bridgeClassExists (t , bridgeName , staleFlowID ), "stale upload class should be deleted" )
138+ assert .True (t , bridgeFilterExistsForFlowID (t , bridgeName , liveFlowID ), "live bridge tc filter should remain" )
139+ assert .True (t , bridgeClassExists (t , bridgeName , liveFlowID ), "live bridge tc class should remain" )
140+ assert .False (t , bridgeFilterExistsForFlowID (t , bridgeName , staleFlowID ), "stale bridge tc filter should be deleted" )
141+ assert .False (t , bridgeClassExists (t , bridgeName , staleFlowID ), "stale bridge tc class should be deleted" )
143142
144143 // Wait for nginx to start
145144 t .Log ("Waiting for nginx to start..." )
@@ -389,53 +388,39 @@ func bridgeFilterHandlesForFlowID(t *testing.T, bridgeName, flowID string) []str
389388 return handles
390389}
391390
392- func waitForUploadFlowID (t * testing.T , ctx context.Context , manager * manager , instanceID , bridgeName string ) string {
393- t .Helper ()
394- var flowID string
395- require .Eventually (t , func () bool {
396- alloc , err := manager .networkManager .GetAllocation (ctx , instanceID )
397- if err != nil || alloc == nil || alloc .ClassID == "" {
398- return false
399- }
400- flowID = "1:" + alloc .ClassID
401- return bridgeClassExists (t , bridgeName , flowID ) && bridgeFilterExistsForFlowID (t , bridgeName , flowID )
402- }, integrationTestTimeout (5 * time .Second ), 100 * time .Millisecond )
403- return flowID
404- }
405-
406- func createStaleBridgeTCForTest (t * testing.T , bridgeName string ) string {
391+ func createBridgeTCForTest (t * testing.T , bridgeName string , rtIif int ) string {
407392 t .Helper ()
408393 used := make (map [string ]bool )
409394 for _ , classID := range bridgeClassesForTest (t , bridgeName ) {
410395 used [classID ] = true
411396 }
412397
413- staleFlowID := ""
398+ flowID := ""
414399 for id := 0xff00 ; id <= 0xffff ; id ++ {
415400 candidate := fmt .Sprintf ("1:%04x" , id )
416401 if ! used [candidate ] {
417- staleFlowID = candidate
402+ flowID = candidate
418403 break
419404 }
420405 }
421- require .NotEmpty (t , staleFlowID , "expected an unused test class id" )
406+ require .NotEmpty (t , flowID , "expected an unused test class id" )
422407
423408 t .Cleanup (func () {
424- bestEffortDeleteBridgeFiltersForFlowID (t , bridgeName , staleFlowID )
425- _ = exec .Command (tcForTest (t ), "qdisc" , "del" , "dev" , bridgeName , "parent" , staleFlowID ).Run ()
426- _ = exec .Command (tcForTest (t ), "class" , "del" , "dev" , bridgeName , "classid" , staleFlowID ).Run ()
409+ bestEffortDeleteBridgeFiltersForFlowID (t , bridgeName , flowID )
410+ _ = exec .Command (tcForTest (t ), "qdisc" , "del" , "dev" , bridgeName , "parent" , flowID ).Run ()
411+ _ = exec .Command (tcForTest (t ), "class" , "del" , "dev" , bridgeName , "classid" , flowID ).Run ()
427412 })
428413
429414 runTCForTest (t , "class" , "add" , "dev" , bridgeName , "parent" , "1:1" ,
430- "classid" , staleFlowID , "htb" , "rate" , "1mbit" , "ceil" , "1mbit" )
431- runTCForTest (t , "qdisc" , "add" , "dev" , bridgeName , "parent" , staleFlowID , "fq_codel" )
415+ "classid" , flowID , "htb" , "rate" , "1mbit" , "ceil" , "1mbit" )
416+ runTCForTest (t , "qdisc" , "add" , "dev" , bridgeName , "parent" , flowID , "fq_codel" )
432417 runTCForTest (t , "filter" , "add" , "dev" , bridgeName , "parent" , "1:" ,
433418 "protocol" , "all" , "prio" , "1" , "basic" ,
434- "match" , "meta(rt_iif eq 1 )" , "flowid" , staleFlowID )
419+ "match" , fmt . Sprintf ( "meta(rt_iif eq %d )" , rtIif ), "flowid" , flowID )
435420
436- require .True (t , bridgeClassExists (t , bridgeName , staleFlowID ), "staged stale class should exist" )
437- require .True (t , bridgeFilterExistsForFlowID (t , bridgeName , staleFlowID ), "staged stale filter should exist" )
438- return staleFlowID
421+ require .True (t , bridgeClassExists (t , bridgeName , flowID ), "staged bridge tc class should exist" )
422+ require .True (t , bridgeFilterExistsForFlowID (t , bridgeName , flowID ), "staged bridge tc filter should exist" )
423+ return flowID
439424}
440425
441426func bestEffortDeleteBridgeFiltersForFlowID (t * testing.T , bridgeName , flowID string ) {
0 commit comments