Skip to content

Commit f56f15b

Browse files
committed
system deployment tests: fix port collisions
Two groups on the same job cannot both have a static port assignment, but this ends up getting configured in the update block test for system deployments. This test setup bug has complicated landing the fix in #26953.
1 parent c607929 commit f56f15b

File tree

1 file changed

+35
-5
lines changed

1 file changed

+35
-5
lines changed

scheduler/scheduler_system_test.go

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3383,8 +3383,8 @@ func TestEvictAndPlace(t *testing.T) {
33833383

33843384
}
33853385

3386-
// TestSystemScheduler_UpdateBlock tests various permutations of the update block
3387-
func TestSystemScheduler_UpdateBlock(t *testing.T) {
3386+
// TestSystemSched_UpdateBlock tests various permutations of the update block
3387+
func TestSystemSched_UpdateBlock(t *testing.T) {
33883388
ci.Parallel(t)
33893389

33903390
collect := func(planned map[string][]*structs.Allocation) map[string]int {
@@ -3799,6 +3799,15 @@ func TestSystemScheduler_UpdateBlock(t *testing.T) {
37993799
taskGroup2.Name = tg2
38003800
oldJob.TaskGroups = append(oldJob.TaskGroups, taskGroup2)
38013801

3802+
// make sure tg1 network matches AllocForNode
3803+
taskGroup1 := oldJob.TaskGroups[0]
3804+
taskGroup1.Networks = []*structs.NetworkResource{{
3805+
ReservedPorts: []structs.Port{{
3806+
Label: "admin", Value: 5000, HostNetwork: "default"}},
3807+
DynamicPorts: []structs.Port{{
3808+
Label: "http", Value: 9876, HostNetwork: "default"}},
3809+
}}
3810+
38023811
must.NoError(t, h.State.UpsertJob(
38033812
structs.MsgTypeTestSetup, h.NextIndex(), nil, oldJob))
38043813

@@ -3829,7 +3838,14 @@ func TestSystemScheduler_UpdateBlock(t *testing.T) {
38293838
for _, tg := range []string{tg1, tg2} {
38303839
nodesToAllocs := map[string]string{}
38313840
for _, nodeIdx := range tc.existingPrevious[tg] {
3832-
alloc := mock.AllocForNode(nodes[nodeIdx])
3841+
var alloc *structs.Allocation
3842+
if tg == tg2 {
3843+
alloc = mock.AllocForNodeWithoutReservedPort(nodes[nodeIdx])
3844+
} else {
3845+
// make sure alloc matches tg1.Networks
3846+
alloc = mock.AllocForNode(nodes[nodeIdx])
3847+
alloc.TaskResources["web"].Networks = nil
3848+
}
38333849
alloc.Job = oldJob
38343850
alloc.JobID = job.ID
38353851
alloc.TaskGroup = tg
@@ -3839,7 +3855,14 @@ func TestSystemScheduler_UpdateBlock(t *testing.T) {
38393855
existAllocs = append(existAllocs, alloc)
38403856
}
38413857
for _, nodeIdx := range tc.existingRunning[tg] {
3842-
alloc := mock.AllocForNode(nodes[nodeIdx])
3858+
var alloc *structs.Allocation
3859+
if tg == tg2 {
3860+
alloc = mock.AllocForNodeWithoutReservedPort(nodes[nodeIdx])
3861+
} else {
3862+
// make sure alloc matches tg1.Networks
3863+
alloc = mock.AllocForNode(nodes[nodeIdx])
3864+
alloc.TaskResources["web"].Networks = nil
3865+
}
38433866
alloc.Job = job
38443867
alloc.JobID = job.ID
38453868
alloc.TaskGroup = tg
@@ -3861,7 +3884,14 @@ func TestSystemScheduler_UpdateBlock(t *testing.T) {
38613884
existAllocs = append(existAllocs, alloc)
38623885
}
38633886
for _, nodeIdx := range tc.existingFailed[tg] {
3864-
alloc := mock.AllocForNode(nodes[nodeIdx])
3887+
var alloc *structs.Allocation
3888+
if tg == tg2 {
3889+
alloc = mock.AllocForNodeWithoutReservedPort(nodes[nodeIdx])
3890+
} else {
3891+
// make sure alloc matches tg1.Networks
3892+
alloc = mock.AllocForNode(nodes[nodeIdx])
3893+
alloc.TaskResources["web"].Networks = nil
3894+
}
38653895
alloc.Job = job
38663896
alloc.JobID = job.ID
38673897
alloc.TaskGroup = tg

0 commit comments

Comments
 (0)