Skip to content

Commit 24b5e4b

Browse files
Guest OS Imagescopybara-github
authored andcommitted
networkconfig: support switching config expectations on kernel version
Add min_kernel_version and max_kernel_version to SystemConfig in config_expectations.proto to allow switching expectations based on the kernel version of the VM under test. Update expectedConfigForMachine to compare the VM's kernel version against any specified min_kernel_version and max_kernel_version bounds. Add an expectation for n2-highcpu-32 with single GVNIC on kernels >= 6.8 where the GVE driver includes NUMA-locality awareness in default IRQ affinity assignment. PiperOrigin-RevId: 954709834
1 parent d6e8416 commit 24b5e4b

5 files changed

Lines changed: 463 additions & 72 deletions

File tree

test_suites/networkconfig/config_expectations/config_expectations.proto

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,17 @@ message SystemConfig {
3535
// The GCE machine type e.g. "n2d-standard-2".
3636
string machine_type = 2;
3737

38+
// The minimum kernel version (inclusive) required for this expectation to
39+
// apply, e.g. "6.8.0" or "6.8".
40+
string min_kernel_version = 3;
41+
3842
// NICs in the VM. This includes any device expected to be created by the
3943
// GCE stack, but not any created by the user (e.g. not `lo` or `docker0`).
4044
repeated NicExpectation nics = 4;
45+
46+
// The maximum kernel version (exclusive) required for this expectation to
47+
// apply, e.g. "6.8.0" or "6.8".
48+
string max_kernel_version = 5;
4149
}
4250

4351
message NicExpectation {

test_suites/networkconfig/config_expectations/config_expectations.textproto

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,8 +630,9 @@ config_expectations: {
630630
}
631631
}
632632
config_expectations: {
633-
description: "n2-32 with single GVNIC"
633+
description: "n2-32 with single GVNIC (kernel < 6.8)"
634634
machine_type: "n2-highcpu-32"
635+
max_kernel_version: "6.8"
635636
nics: {
636637
type: "GVNIC"
637638
tx_queues: { index: 0 irq_cpulist: "0" xps_cpulist: "0" }
@@ -668,6 +669,46 @@ config_expectations: {
668669
rx_queues: { index: 15 irq_cpulist: "15" }
669670
}
670671
}
672+
config_expectations: {
673+
description: "n2-32 with single GVNIC (kernel >= 6.8)"
674+
machine_type: "n2-highcpu-32"
675+
min_kernel_version: "6.8"
676+
nics: {
677+
type: "GVNIC"
678+
tx_queues: { index: 0 irq_cpulist: "0" xps_cpulist: "0" }
679+
tx_queues: { index: 1 irq_cpulist: "1" xps_cpulist: "1" }
680+
tx_queues: { index: 2 irq_cpulist: "2" xps_cpulist: "2" }
681+
tx_queues: { index: 3 irq_cpulist: "3" xps_cpulist: "3" }
682+
tx_queues: { index: 4 irq_cpulist: "4" xps_cpulist: "4" }
683+
tx_queues: { index: 5 irq_cpulist: "5" xps_cpulist: "5" }
684+
tx_queues: { index: 6 irq_cpulist: "6" xps_cpulist: "6" }
685+
tx_queues: { index: 7 irq_cpulist: "7" xps_cpulist: "7" }
686+
tx_queues: { index: 8 irq_cpulist: "16" xps_cpulist: "8" }
687+
tx_queues: { index: 9 irq_cpulist: "17" xps_cpulist: "9" }
688+
tx_queues: { index: 10 irq_cpulist: "18" xps_cpulist: "10" }
689+
tx_queues: { index: 11 irq_cpulist: "19" xps_cpulist: "11" }
690+
tx_queues: { index: 12 irq_cpulist: "20" xps_cpulist: "12" }
691+
tx_queues: { index: 13 irq_cpulist: "21" xps_cpulist: "13" }
692+
tx_queues: { index: 14 irq_cpulist: "22" xps_cpulist: "14" }
693+
tx_queues: { index: 15 irq_cpulist: "23" xps_cpulist: "15" }
694+
rx_queues: { index: 0 irq_cpulist: "0" }
695+
rx_queues: { index: 1 irq_cpulist: "1" }
696+
rx_queues: { index: 2 irq_cpulist: "2" }
697+
rx_queues: { index: 3 irq_cpulist: "3" }
698+
rx_queues: { index: 4 irq_cpulist: "4" }
699+
rx_queues: { index: 5 irq_cpulist: "5" }
700+
rx_queues: { index: 6 irq_cpulist: "6" }
701+
rx_queues: { index: 7 irq_cpulist: "7" }
702+
rx_queues: { index: 8 irq_cpulist: "16" }
703+
rx_queues: { index: 9 irq_cpulist: "17" }
704+
rx_queues: { index: 10 irq_cpulist: "18" }
705+
rx_queues: { index: 11 irq_cpulist: "19" }
706+
rx_queues: { index: 12 irq_cpulist: "20" }
707+
rx_queues: { index: 13 irq_cpulist: "21" }
708+
rx_queues: { index: 14 irq_cpulist: "22" }
709+
rx_queues: { index: 15 irq_cpulist: "23" }
710+
}
711+
}
671712
config_expectations: {
672713
description: "n2-32 with two GVNICs"
673714
machine_type: "n2-highcpu-32"

test_suites/networkconfig/config_expectations/config_expectations_test.go

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
_ "embed"
66
"fmt"
77
"sort"
8+
"strconv"
9+
"strings"
810
"testing"
911

1012
pb "github.com/GoogleCloudPlatform/cloud-image-tests/test_suites/networkconfig/config_expectations_proto"
@@ -146,3 +148,87 @@ func TestRingSizes(t *testing.T) {
146148
})
147149
}
148150
}
151+
152+
func TestKernelVersionFormat(t *testing.T) {
153+
c := proto()
154+
for _, config := range c.GetConfigExpectations() {
155+
t.Run(config.GetDescription(), func(t *testing.T) {
156+
if minVer := config.GetMinKernelVersion(); minVer != "" {
157+
if len(minVer) == 0 {
158+
t.Errorf("Empty min_kernel_version string")
159+
}
160+
}
161+
if maxVer := config.GetMaxKernelVersion(); maxVer != "" {
162+
if len(maxVer) == 0 {
163+
t.Errorf("Empty max_kernel_version string")
164+
}
165+
}
166+
})
167+
}
168+
}
169+
170+
func parseKernelVersion(v string) []int {
171+
var nums []int
172+
for _, part := range strings.FieldsFunc(v, func(r rune) bool {
173+
return r < '0' || r > '9'
174+
}) {
175+
if part == "" {
176+
continue
177+
}
178+
n, err := strconv.Atoi(part)
179+
if err == nil {
180+
nums = append(nums, n)
181+
}
182+
}
183+
return nums
184+
}
185+
186+
func compareKernelVersion(v1, v2 string) int {
187+
n1 := parseKernelVersion(v1)
188+
n2 := parseKernelVersion(v2)
189+
maxLen := len(n1)
190+
if len(n2) > maxLen {
191+
maxLen = len(n2)
192+
}
193+
for i := 0; i < maxLen; i++ {
194+
var x1, x2 int
195+
if i < len(n1) {
196+
x1 = n1[i]
197+
}
198+
if i < len(n2) {
199+
x2 = n2[i]
200+
}
201+
if x1 < x2 {
202+
return -1
203+
}
204+
if x1 > x2 {
205+
return 1
206+
}
207+
}
208+
return 0
209+
}
210+
211+
func TestCompareKernelVersion(t *testing.T) {
212+
tests := []struct {
213+
v1 string
214+
v2 string
215+
want int
216+
}{
217+
{"6.8.0-1006-gcp", "6.8.0", 1},
218+
{"6.8.0-1006-gcp", "6.8", 1},
219+
{"6.8.0", "6.8.0", 0},
220+
{"6.8", "6.8.0", 0},
221+
{"6.6.0-1006-gcp", "6.8.0", -1},
222+
{"6.6.0-1006-gcp", "6.8", -1},
223+
{"6.8.1-gcp", "6.8.0", 1},
224+
{"6.8.0", "6.8.1", -1},
225+
{"5.15.0-1040-gcp", "6.8", -1},
226+
}
227+
228+
for _, tc := range tests {
229+
got := compareKernelVersion(tc.v1, tc.v2)
230+
if got != tc.want {
231+
t.Errorf("compareKernelVersion(%q, %q) = %d, want %d", tc.v1, tc.v2, got, tc.want)
232+
}
233+
}
234+
}

0 commit comments

Comments
 (0)