Skip to content

Commit 640a560

Browse files
authored
Add support for platform compatibility check for windows (#1821)
Signed-off-by: Kirtana Ashok <kiashok@microsoft.com>
1 parent 6eea50b commit 640a560

File tree

2 files changed

+103
-0
lines changed

2 files changed

+103
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package osversion
2+
3+
// List of stable ABI compliant ltsc releases
4+
// Note: List must be sorted in ascending order
5+
var compatLTSCReleases = []uint16{
6+
V21H2Server,
7+
}
8+
9+
// CheckHostAndContainerCompat checks if given host and container
10+
// OS versions are compatible.
11+
// It includes support for stable ABI compliant versions as well.
12+
// Every release after WS 2022 will support the previous ltsc
13+
// container image. Stable ABI is in preview mode for windows 11 client.
14+
// Refer: https://learn.microsoft.com/en-us/virtualization/windowscontainers/deploy-containers/version-compatibility?tabs=windows-server-2022%2Cwindows-10#windows-server-host-os-compatibility
15+
func CheckHostAndContainerCompat(host, ctr OSVersion) bool {
16+
// check major minor versions of host and guest
17+
if host.MajorVersion != ctr.MajorVersion ||
18+
host.MinorVersion != ctr.MinorVersion {
19+
return false
20+
}
21+
22+
// If host is < WS 2022, exact version match is required
23+
if host.Build < V21H2Server {
24+
return host.Build == ctr.Build
25+
}
26+
27+
var supportedLtscRelease uint16
28+
for i := len(compatLTSCReleases) - 1; i >= 0; i-- {
29+
if host.Build >= compatLTSCReleases[i] {
30+
supportedLtscRelease = compatLTSCReleases[i]
31+
break
32+
}
33+
}
34+
return ctr.Build >= supportedLtscRelease && ctr.Build <= host.Build
35+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package osversion
2+
3+
import (
4+
"testing"
5+
)
6+
7+
// Test the platform compatibility of the different
8+
// OS Versions considering two ltsc container image
9+
// versions (ltsc2019, ltsc2022)
10+
func Test_PlatformCompat(t *testing.T) {
11+
for testName, tc := range map[string]struct {
12+
hostOs uint16
13+
ctrOs uint16
14+
shouldRun bool
15+
}{
16+
"RS5Host_ltsc2019": {
17+
hostOs: RS5,
18+
ctrOs: RS5,
19+
shouldRun: true,
20+
},
21+
"RS5Host_ltsc2022": {
22+
hostOs: RS5,
23+
ctrOs: V21H2Server,
24+
shouldRun: false,
25+
},
26+
"WS2022Host_ltsc2019": {
27+
hostOs: V21H2Server,
28+
ctrOs: RS5,
29+
shouldRun: false,
30+
},
31+
"WS2022Host_ltsc2022": {
32+
hostOs: V21H2Server,
33+
ctrOs: V21H2Server,
34+
shouldRun: true,
35+
},
36+
"Wind11Host_ltsc2019": {
37+
hostOs: V22H2Win11,
38+
ctrOs: RS5,
39+
shouldRun: false,
40+
},
41+
"Wind11Host_ltsc2022": {
42+
hostOs: V22H2Win11,
43+
ctrOs: V21H2Server,
44+
shouldRun: true,
45+
},
46+
} {
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"
64+
}
65+
t.Fatalf("Failed %v: host %v should%s be able to run guest %v", testName, tc.hostOs, expectedResultStr, tc.ctrOs)
66+
}
67+
}
68+
}

0 commit comments

Comments
 (0)