Skip to content

Commit d9a4231

Browse files
authored
Merge pull request #2327 from kevpar/compat-ws2025
osversion: Add new versions, fix compat bug, improve tests
2 parents f234e83 + bacda39 commit d9a4231

File tree

3 files changed

+81
-49
lines changed

3 files changed

+81
-49
lines changed

osversion/platform_compat_windows.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ package osversion
33
// List of stable ABI compliant ltsc releases
44
// Note: List must be sorted in ascending order
55
var compatLTSCReleases = []uint16{
6-
V21H2Server,
6+
LTSC2022,
7+
LTSC2025,
78
}
89

910
// CheckHostAndContainerCompat checks if given host and container
@@ -20,16 +21,25 @@ func CheckHostAndContainerCompat(host, ctr OSVersion) bool {
2021
}
2122

2223
// If host is < WS 2022, exact version match is required
23-
if host.Build < V21H2Server {
24+
if host.Build < LTSC2022 {
2425
return host.Build == ctr.Build
2526
}
2627

27-
var supportedLtscRelease uint16
28+
// Find the latest LTSC version that is earlier than the host version.
29+
// This is the earliest version of container that the host can run.
30+
//
31+
// If the host version is an LTSC, then it supports compatibility with
32+
// everything from the previous LTSC up to itself, so we want supportedLTSCRelease
33+
// to be the previous entry.
34+
//
35+
// If no match is found, then we know that the host is LTSC2022 exactly,
36+
// since we already checked that it's not less than LTSC2022.
37+
var supportedLTSCRelease uint16 = LTSC2022
2838
for i := len(compatLTSCReleases) - 1; i >= 0; i-- {
29-
if host.Build >= compatLTSCReleases[i] {
30-
supportedLtscRelease = compatLTSCReleases[i]
39+
if host.Build > compatLTSCReleases[i] {
40+
supportedLTSCRelease = compatLTSCReleases[i]
3141
break
3242
}
3343
}
34-
return ctr.Build >= supportedLtscRelease && ctr.Build <= host.Build
44+
return supportedLTSCRelease <= ctr.Build && ctr.Build <= host.Build
3545
}
Lines changed: 61 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,86 @@
11
package osversion
22

33
import (
4+
"fmt"
45
"testing"
56
)
67

7-
// Test the platform compatibility of the different
8-
// OS Versions considering two ltsc container image
9-
// versions (ltsc2019, ltsc2022)
8+
// Test the platform compatibility of the different OS Versions
109
func Test_PlatformCompat(t *testing.T) {
11-
for testName, tc := range map[string]struct {
12-
hostOs uint16
13-
ctrOs uint16
10+
for _, tc := range []struct {
11+
hostOS uint16
12+
ctrOS uint16
1413
shouldRun bool
1514
}{
16-
"RS5Host_ltsc2019": {
17-
hostOs: RS5,
18-
ctrOs: RS5,
15+
{
16+
hostOS: LTSC2019,
17+
ctrOS: LTSC2019,
1918
shouldRun: true,
2019
},
21-
"RS5Host_ltsc2022": {
22-
hostOs: RS5,
23-
ctrOs: V21H2Server,
20+
{
21+
hostOS: LTSC2019,
22+
ctrOS: LTSC2022,
2423
shouldRun: false,
2524
},
26-
"WS2022Host_ltsc2019": {
27-
hostOs: V21H2Server,
28-
ctrOs: RS5,
25+
{
26+
hostOS: LTSC2022,
27+
ctrOS: LTSC2019,
2928
shouldRun: false,
3029
},
31-
"WS2022Host_ltsc2022": {
32-
hostOs: V21H2Server,
33-
ctrOs: V21H2Server,
30+
{
31+
hostOS: LTSC2022,
32+
ctrOS: LTSC2022,
3433
shouldRun: true,
3534
},
36-
"Wind11Host_ltsc2019": {
37-
hostOs: V22H2Win11,
38-
ctrOs: RS5,
35+
{
36+
hostOS: V22H2Win11,
37+
ctrOS: LTSC2019,
3938
shouldRun: false,
4039
},
41-
"Wind11Host_ltsc2022": {
42-
hostOs: V22H2Win11,
43-
ctrOs: V21H2Server,
40+
{
41+
hostOS: V22H2Win11,
42+
ctrOS: LTSC2022,
43+
shouldRun: true,
44+
},
45+
{
46+
hostOS: LTSC2025,
47+
ctrOS: LTSC2022,
48+
shouldRun: true,
49+
},
50+
{
51+
hostOS: LTSC2022,
52+
ctrOS: LTSC2025,
53+
shouldRun: false,
54+
},
55+
{
56+
hostOS: LTSC2022,
57+
ctrOS: V22H2Win11,
58+
shouldRun: false,
59+
},
60+
{
61+
hostOS: LTSC2025,
62+
ctrOS: V22H2Win11,
4463
shouldRun: true,
4564
},
4665
} {
47-
// Check if ltsc2019/ltsc2022 guest images are compatible on
48-
// the given host OS versions
49-
//
50-
hostOSVersion := OSVersion{
51-
MajorVersion: 10,
52-
MinorVersion: 0,
53-
Build: tc.hostOs,
54-
}
55-
ctrOSVersion := OSVersion{
56-
MajorVersion: 10,
57-
MinorVersion: 0,
58-
Build: tc.ctrOs,
59-
}
60-
if CheckHostAndContainerCompat(hostOSVersion, ctrOSVersion) != tc.shouldRun {
61-
var expectedResultStr string
62-
if !tc.shouldRun {
63-
expectedResultStr = " NOT"
66+
t.Run(fmt.Sprintf("Host_%d_Ctr_%d", tc.hostOS, tc.ctrOS), func(t *testing.T) {
67+
hostOSVersion := OSVersion{
68+
MajorVersion: 10,
69+
MinorVersion: 0,
70+
Build: tc.hostOS,
71+
}
72+
ctrOSVersion := OSVersion{
73+
MajorVersion: 10,
74+
MinorVersion: 0,
75+
Build: tc.ctrOS,
76+
}
77+
if CheckHostAndContainerCompat(hostOSVersion, ctrOSVersion) != tc.shouldRun {
78+
var expectedResultStr string
79+
if !tc.shouldRun {
80+
expectedResultStr = " NOT"
81+
}
82+
t.Fatalf("host %v should%s be able to run guest %v", tc.hostOS, expectedResultStr, tc.ctrOS)
6483
}
65-
t.Fatalf("Failed %v: host %v should%s be able to run guest %v", testName, tc.hostOs, expectedResultStr, tc.ctrOs)
66-
}
84+
})
6785
}
6886
}

osversion/windowsbuilds.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ const (
8282
// V22H2Win11 corresponds to Windows 11 (2022 Update).
8383
V22H2Win11 = 22621
8484

85+
// V23H2 is the 23H2 release in the Windows Server annual channel.
86+
V23H2 = 25398
87+
8588
// Windows Server 2025 build 26100
8689
V25H1Server = 26100
90+
LTSC2025 = V25H1Server
8791
)

0 commit comments

Comments
 (0)