Skip to content

Commit 12c7b76

Browse files
author
sivakami
committed
track nic usage.
1 parent 0d50247 commit 12c7b76

File tree

2 files changed

+44
-7
lines changed

2 files changed

+44
-7
lines changed

test/integration/swiftv2/longRunningCluster/datapath.go

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ type TestScenarios struct {
115115
PodImage string
116116
Scenarios []PodScenario
117117
VnetSubnetCache map[string]VnetSubnetInfo // Cache for vnet/subnet info
118+
NodeUsageTracker map[string]map[string]bool // Tracks which nodes are used per vnet/subnet: "vnet/subnet" -> map[nodeName]bool
118119
}
119120

120121
// VnetSubnetInfo holds network information for a vnet/subnet combination
@@ -336,16 +337,48 @@ func CreateScenarioResources(scenario PodScenario, testScenarios TestScenarios)
336337

337338
// Step 5: Select appropriate node based on scenario
338339
var targetNode string
340+
vnetSubnetKey := fmt.Sprintf("%s/%s", scenario.VnetName, scenario.SubnetName)
341+
342+
// Initialize node usage tracker for this vnet/subnet if not exists
343+
if testScenarios.NodeUsageTracker == nil {
344+
testScenarios.NodeUsageTracker = make(map[string]map[string]bool)
345+
}
346+
if testScenarios.NodeUsageTracker[vnetSubnetKey] == nil {
347+
testScenarios.NodeUsageTracker[vnetSubnetKey] = make(map[string]bool)
348+
}
349+
339350
if scenario.NodeSelector == "low-nic" {
340351
if len(nodeInfo.LowNicNodes) == 0 {
341352
return fmt.Errorf("scenario %s: no low-NIC nodes available", scenario.Name)
342353
}
343-
targetNode = nodeInfo.LowNicNodes[0]
354+
// Find first unused node in the pool
355+
targetNode = ""
356+
for _, node := range nodeInfo.LowNicNodes {
357+
if !testScenarios.NodeUsageTracker[vnetSubnetKey][node] {
358+
targetNode = node
359+
testScenarios.NodeUsageTracker[vnetSubnetKey][node] = true
360+
break
361+
}
362+
}
363+
if targetNode == "" {
364+
return fmt.Errorf("scenario %s: all low-NIC nodes already used for %s", scenario.Name, vnetSubnetKey)
365+
}
344366
} else { // "high-nic"
345367
if len(nodeInfo.HighNicNodes) == 0 {
346368
return fmt.Errorf("scenario %s: no high-NIC nodes available", scenario.Name)
347369
}
348-
targetNode = nodeInfo.HighNicNodes[0]
370+
// Find first unused node in the pool
371+
targetNode = ""
372+
for _, node := range nodeInfo.HighNicNodes {
373+
if !testScenarios.NodeUsageTracker[vnetSubnetKey][node] {
374+
targetNode = node
375+
testScenarios.NodeUsageTracker[vnetSubnetKey][node] = true
376+
break
377+
}
378+
}
379+
if targetNode == "" {
380+
return fmt.Errorf("scenario %s: all high-NIC nodes already used for %s", scenario.Name, vnetSubnetKey)
381+
}
349382
}
350383

351384
// Step 6: Create pod

test/integration/swiftv2/longRunningCluster/datapath_test.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,12 @@ var _ = ginkgo.Describe("Datapath Tests", func() {
9999

100100
// Initialize test scenarios with cache
101101
testScenarios := TestScenarios{
102-
ResourceGroup: rg,
103-
BuildID: buildId,
104-
PodImage: "weibeld/ubuntu-networking",
105-
Scenarios: scenarios,
106-
VnetSubnetCache: make(map[string]VnetSubnetInfo),
102+
ResourceGroup: rg,
103+
BuildID: buildId,
104+
PodImage: "weibeld/ubuntu-networking",
105+
Scenarios: scenarios,
106+
VnetSubnetCache: make(map[string]VnetSubnetInfo),
107+
NodeUsageTracker: make(map[string]map[string]bool),
107108
}
108109

109110
// Run indefinitely until test is cancelled
@@ -125,6 +126,9 @@ var _ = ginkgo.Describe("Datapath Tests", func() {
125126
ginkgo.By("Deleting all test scenarios")
126127
err = DeleteAllScenarios(testScenarios)
127128
gomega.Expect(err).To(gomega.BeNil(), "Failed to delete test scenarios")
129+
130+
// Clear node usage tracker for next iteration
131+
testScenarios.NodeUsageTracker = make(map[string]map[string]bool)
128132

129133
ginkgo.By(fmt.Sprintf("Completed iteration %d at %s", iteration, time.Now().Format(time.RFC3339)))
130134

0 commit comments

Comments
 (0)