Skip to content

Commit

Permalink
PR: refactor, updated image names in cri tests
Browse files Browse the repository at this point in the history
Signed-off-by: Hamza El-Saawy <hamzaelsaawy@microsoft.com>
  • Loading branch information
helsaawy committed Aug 4, 2022
1 parent bf3434f commit 3dc4f6a
Show file tree
Hide file tree
Showing 15 changed files with 103 additions and 110 deletions.
65 changes: 15 additions & 50 deletions test/cri-containerd/main_test.go
Expand Up @@ -25,6 +25,7 @@ import (
"google.golang.org/grpc"
runtime "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"

"github.com/Microsoft/hcsshim/test/internal/constants"
_ "github.com/Microsoft/hcsshim/test/internal/manifest"
)

Expand Down Expand Up @@ -73,12 +74,12 @@ const (
var (
imageWindowsNanoserver = getWindowsNanoserverImage(osversion.Build())
imageWindowsServercore = getWindowsServerCoreImage(osversion.Build())
imageWindowsNanoserver17763 = getWindowsNanoserverImage(osversion.RS5)
imageWindowsNanoserver18362 = getWindowsNanoserverImage(osversion.V19H1)
imageWindowsNanoserver19041 = getWindowsNanoserverImage(osversion.V20H1)
imageWindowsServercore17763 = getWindowsServerCoreImage(osversion.RS5)
imageWindowsServercore18362 = getWindowsServerCoreImage(osversion.V19H1)
imageWindowsServercore19041 = getWindowsServerCoreImage(osversion.V20H1)
imageWindowsNanoserver17763 = constants.ImageWindowsNanoserver1809
imageWindowsNanoserver18362 = constants.ImageWindowsNanoserver1903
imageWindowsNanoserver19041 = constants.ImageWindowsNanoserver2004
imageWindowsServercore17763 = constants.ImageWindowsServercore1809
imageWindowsServercore18362 = constants.ImageWindowsServercore1903
imageWindowsServercore19041 = constants.ImageWindowsServercore2004
)

// Flags
Expand Down Expand Up @@ -162,55 +163,19 @@ func requireBinary(t *testing.T, binary string) string {
}

func getWindowsNanoserverImage(build uint16) string {
switch build {
case osversion.RS5:
return "mcr.microsoft.com/windows/nanoserver:1809"
case osversion.V19H1:
return "mcr.microsoft.com/windows/nanoserver:1903"
case osversion.V19H2:
return "mcr.microsoft.com/windows/nanoserver:1909"
case osversion.V20H1:
return "mcr.microsoft.com/windows/nanoserver:2004"
case osversion.V20H2:
return "mcr.microsoft.com/windows/nanoserver:2009"
case osversion.V21H2Server:
return "mcr.microsoft.com/windows/nanoserver:ltsc2022"
default:
// Due to some efforts in improving down-level compatibility for Windows containers (see
// https://techcommunity.microsoft.com/t5/containers/windows-server-2022-and-beyond-for-containers/ba-p/2712487)
// the ltsc2022 image should continue to work on builds ws2022 and onwards. With this in mind,
// if there's no mapping for the host build, just use the Windows Server 2022 image.
if build > osversion.V21H2Server {
return "mcr.microsoft.com/windows/nanoserver:ltsc2022"
}
panic("unsupported build")
tag, err := constants.ImageFromBuild(build)
if err != nil {
panic(err)
}
return constants.NanoserverImage(tag)
}

func getWindowsServerCoreImage(build uint16) string {
switch build {
case osversion.RS5:
return "mcr.microsoft.com/windows/servercore:1809"
case osversion.V19H1:
return "mcr.microsoft.com/windows/servercore:1903"
case osversion.V19H2:
return "mcr.microsoft.com/windows/servercore:1909"
case osversion.V20H1:
return "mcr.microsoft.com/windows/servercore:2004"
case osversion.V20H2:
return "mcr.microsoft.com/windows/servercore:2009"
case osversion.V21H2Server:
return "mcr.microsoft.com/windows/servercore:ltsc2022"
default:
// Due to some efforts in improving down-level compatibility for Windows containers (see
// https://techcommunity.microsoft.com/t5/containers/windows-server-2022-and-beyond-for-containers/ba-p/2712487)
// the ltsc2022 image should continue to work on builds ws2022 and onwards. With this in mind,
// if there's no mapping for the host build, just use the Windows Server 2022 image.
if build > osversion.V21H2Server {
return "mcr.microsoft.com/windows/servercore:ltsc2022"
}
panic("unsupported build")
tag, err := constants.ImageFromBuild(build)
if err != nil {
panic(err)
}
return constants.ServercoreImage(tag)
}

func createGRPCConn(ctx context.Context) (*grpc.ClientConn, error) {
Expand Down
8 changes: 4 additions & 4 deletions test/functional/lcow_bench_test.go
Expand Up @@ -22,7 +22,7 @@ func BenchmarkLCOW_UVM_Create(b *testing.B) {
b.StopTimer()
b.ResetTimer()
for i := 0; i < b.N; i++ {
opts := defaultLCOWOptions(b, b.Name())
opts := defaultLCOWOptions(b)

b.StartTimer()
vm := uvm.CreateLCOW(ctx, b, opts)
Expand All @@ -43,7 +43,7 @@ func BenchmarkLCOW_UVM_Start(b *testing.B) {
b.StopTimer()
b.ResetTimer()
for i := 0; i < b.N; i++ {
vm := uvm.CreateLCOW(ctx, b, defaultLCOWOptions(b, b.Name()))
vm := uvm.CreateLCOW(ctx, b, defaultLCOWOptions(b))

b.StartTimer()
if err := vm.Start(ctx); err != nil {
Expand All @@ -64,7 +64,7 @@ func BenchmarkLCOW_UVM_Kill(b *testing.B) {
b.StopTimer()
b.ResetTimer()
for i := 0; i < b.N; i++ {
vm := uvm.CreateLCOW(ctx, b, defaultLCOWOptions(b, b.Name()))
vm := uvm.CreateLCOW(ctx, b, defaultLCOWOptions(b))
cleanup := uvm.Start(ctx, b, vm)

b.StartTimer()
Expand All @@ -87,7 +87,7 @@ func BenchmarkLCOW_UVM_Close(b *testing.B) {
b.StopTimer()
b.ResetTimer()
for i := 0; i < b.N; i++ {
vm := uvm.CreateLCOW(ctx, b, defaultLCOWOptions(b, b.Name()))
vm := uvm.CreateLCOW(ctx, b, defaultLCOWOptions(b))
cleanup := uvm.Start(ctx, b, vm)

b.StartTimer()
Expand Down
36 changes: 12 additions & 24 deletions test/functional/lcow_container_bench_test.go
Expand Up @@ -5,7 +5,6 @@ package functional

import (
"context"
"strings"
"testing"

ctrdoci "github.com/containerd/containerd/oci"
Expand All @@ -18,7 +17,6 @@ import (
"github.com/Microsoft/hcsshim/test/internal/cmd"
"github.com/Microsoft/hcsshim/test/internal/constants"
"github.com/Microsoft/hcsshim/test/internal/container"
"github.com/Microsoft/hcsshim/test/internal/containerd"
"github.com/Microsoft/hcsshim/test/internal/layers"
"github.com/Microsoft/hcsshim/test/internal/oci"
"github.com/Microsoft/hcsshim/test/internal/require"
Expand All @@ -30,17 +28,15 @@ func BenchmarkLCOW_Container(b *testing.B) {
require.Build(b, osversion.RS5)

ctx, _, client := newContainerdClient(context.Background(), b)
chainID := containerd.PullImage(ctx, b, client, constants.ImageLinuxAlpineLatest, constants.PlatformLinux)
ls := layers.FromChainID(ctx, b, client, chainID, constants.SnapshotterLinux)
ls := layers.FromImage(ctx, b, client, constants.ImageLinuxAlpineLatest,
constants.PlatformLinux, constants.SnapshotterLinux)

// Create a new uvm per benchmark in case any left over state lingers

b.Run("Create", func(b *testing.B) {
vmID := strings.ReplaceAll(b.Name(), "/", "")
opts := defaultLCOWOptions(b, vmID)
cache := layers.CacheFile(ctx, b, "")
vm := uvm.CreateAndStartLCOWFromOpts(ctx, b, opts)
vm := uvm.CreateAndStartLCOWFromOpts(ctx, b, defaultLCOWOptions(b))
uvm.SetSecurityPolicy(ctx, b, vm, "")
cache := layers.CacheFile(ctx, b, "")

b.StopTimer()
b.ResetTimer()
Expand Down Expand Up @@ -86,11 +82,9 @@ func BenchmarkLCOW_Container(b *testing.B) {
})

b.Run("Start", func(b *testing.B) {
vmID := strings.ReplaceAll(b.Name(), "/", "")
opts := defaultLCOWOptions(b, vmID)
cache := layers.CacheFile(ctx, b, "")
vm := uvm.CreateAndStartLCOWFromOpts(ctx, b, opts)
vm := uvm.CreateAndStartLCOWFromOpts(ctx, b, defaultLCOWOptions(b))
uvm.SetSecurityPolicy(ctx, b, vm, "")
cache := layers.CacheFile(ctx, b, "")

b.StopTimer()
b.ResetTimer()
Expand Down Expand Up @@ -121,11 +115,9 @@ func BenchmarkLCOW_Container(b *testing.B) {
})

b.Run("InitExec", func(b *testing.B) {
vmID := strings.ReplaceAll(b.Name(), "/", "")
opts := defaultLCOWOptions(b, vmID)
cache := layers.CacheFile(ctx, b, "")
vm := uvm.CreateAndStartLCOWFromOpts(ctx, b, opts)
vm := uvm.CreateAndStartLCOWFromOpts(ctx, b, defaultLCOWOptions(b))
uvm.SetSecurityPolicy(ctx, b, vm, "")
cache := layers.CacheFile(ctx, b, "")

b.StopTimer()
b.ResetTimer()
Expand Down Expand Up @@ -157,11 +149,9 @@ func BenchmarkLCOW_Container(b *testing.B) {
})

b.Run("InitExecKill", func(b *testing.B) {
vmID := strings.ReplaceAll(b.Name(), "/", "")
opts := defaultLCOWOptions(b, vmID)
cache := layers.CacheFile(ctx, b, "")
vm := uvm.CreateAndStartLCOWFromOpts(ctx, b, opts)
vm := uvm.CreateAndStartLCOWFromOpts(ctx, b, defaultLCOWOptions(b))
uvm.SetSecurityPolicy(ctx, b, vm, "")
cache := layers.CacheFile(ctx, b, "")

b.StopTimer()
b.ResetTimer()
Expand All @@ -188,11 +178,9 @@ func BenchmarkLCOW_Container(b *testing.B) {
})

b.Run("ContainerKill", func(b *testing.B) {
vmID := strings.ReplaceAll(b.Name(), "/", "")
opts := defaultLCOWOptions(b, vmID)
cache := layers.CacheFile(ctx, b, "")
vm := uvm.CreateAndStartLCOWFromOpts(ctx, b, opts)
vm := uvm.CreateAndStartLCOWFromOpts(ctx, b, defaultLCOWOptions(b))
uvm.SetSecurityPolicy(ctx, b, vm, "")
cache := layers.CacheFile(ctx, b, "")

b.StopTimer()
b.ResetTimer()
Expand Down
19 changes: 9 additions & 10 deletions test/functional/lcow_container_test.go
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/Microsoft/hcsshim/test/internal/cmd"
"github.com/Microsoft/hcsshim/test/internal/constants"
"github.com/Microsoft/hcsshim/test/internal/container"
"github.com/Microsoft/hcsshim/test/internal/containerd"
"github.com/Microsoft/hcsshim/test/internal/layers"
"github.com/Microsoft/hcsshim/test/internal/oci"
"github.com/Microsoft/hcsshim/test/internal/require"
Expand All @@ -27,10 +26,10 @@ func TestLCOW_ContainerLifecycle(t *testing.T) {
require.Build(t, osversion.RS5)

ctx, _, client := newContainerdClient(context.Background(), t)
chainID := containerd.PullImage(ctx, t, client, constants.ImageLinuxAlpineLatest, constants.PlatformLinux)
ls := layers.FromChainID(ctx, t, client, chainID, constants.SnapshotterLinux)
ls := layers.FromImage(ctx, t, client, constants.ImageLinuxAlpineLatest,
constants.PlatformLinux, constants.SnapshotterLinux)

opts := defaultLCOWOptions(t, t.Name())
opts := defaultLCOWOptions(t)
vm := uvm.CreateAndStartLCOWFromOpts(ctx, t, opts)
uvm.SetSecurityPolicy(ctx, t, vm, "")

Expand Down Expand Up @@ -84,10 +83,10 @@ func TestLCOW_ContainerIO(t *testing.T) {
require.Build(t, osversion.RS5)

ctx, _, client := newContainerdClient(context.Background(), t)
chainID := containerd.PullImage(ctx, t, client, constants.ImageLinuxAlpineLatest, constants.PlatformLinux)
ls := layers.FromChainID(ctx, t, client, chainID, constants.SnapshotterLinux)
ls := layers.FromImage(ctx, t, client, constants.ImageLinuxAlpineLatest,
constants.PlatformLinux, constants.SnapshotterLinux)

opts := defaultLCOWOptions(t, t.Name())
opts := defaultLCOWOptions(t)
cache := layers.CacheFile(ctx, t, "")
vm := uvm.CreateAndStartLCOWFromOpts(ctx, t, opts)
uvm.SetSecurityPolicy(ctx, t, vm, "")
Expand Down Expand Up @@ -129,10 +128,10 @@ func TestLCOW_ContainerExec(t *testing.T) {
require.Build(t, osversion.RS5)

ctx, _, client := newContainerdClient(context.Background(), t)
chainID := containerd.PullImage(ctx, t, client, constants.ImageLinuxAlpineLatest, constants.PlatformLinux)
ls := layers.FromChainID(ctx, t, client, chainID, constants.SnapshotterLinux)
ls := layers.FromImage(ctx, t, client, constants.ImageLinuxAlpineLatest,
constants.PlatformLinux, constants.SnapshotterLinux)

opts := defaultLCOWOptions(t, t.Name())
opts := defaultLCOWOptions(t)
vm := uvm.CreateAndStartLCOWFromOpts(ctx, t, opts)
uvm.SetSecurityPolicy(ctx, t, vm, "")

Expand Down
8 changes: 4 additions & 4 deletions test/functional/lcow_test.go
Expand Up @@ -39,7 +39,7 @@ func TestLCOW_UVMCreateWait(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
t.Cleanup(cancel)

vm := testuvm.CreateLCOW(ctx, t, defaultLCOWOptions(t, t.Name()))
vm := testuvm.CreateLCOW(ctx, t, defaultLCOWOptions(t))
testuvm.Close(ctx, t, vm)
}

Expand All @@ -48,7 +48,7 @@ func TestLCOW_UVMCreateWait(t *testing.T) {
func TestLCOW_UVMNoSCSINoVPMemInitrd(t *testing.T) {
requireFeatures(t, featureLCOW)

opts := defaultLCOWOptions(t, t.Name())
opts := defaultLCOWOptions(t)
opts.SCSIControllerCount = 0
opts.VPMemDeviceCount = 0
opts.PreferredRootFSType = uvm.PreferredRootFSTypeInitRd
Expand All @@ -63,7 +63,7 @@ func TestLCOW_UVMNoSCSINoVPMemInitrd(t *testing.T) {
func TestLCOW_UVMNoSCSISingleVPMemVHD(t *testing.T) {
requireFeatures(t, featureLCOW)

opts := defaultLCOWOptions(t, t.Name())
opts := defaultLCOWOptions(t)
opts.SCSIControllerCount = 0
opts.VPMemDeviceCount = 1
opts.PreferredRootFSType = uvm.PreferredRootFSTypeVHD
Expand Down Expand Up @@ -140,7 +140,7 @@ func testLCOWTimeUVMStart(t *testing.T, kernelDirect bool, rfsType uvm.Preferred
requireFeatures(t, featureLCOW)

for i := 0; i < 3; i++ {
opts := defaultLCOWOptions(t, t.Name())
opts := defaultLCOWOptions(t)
opts.KernelDirect = kernelDirect
opts.VPMemDeviceCount = 32
opts.PreferredRootFSType = rfsType
Expand Down
19 changes: 11 additions & 8 deletions test/functional/main_test.go
Expand Up @@ -13,6 +13,7 @@ import (
"log"
"os"
"os/exec"
"regexp"
"strconv"
"testing"
"time"
Expand Down Expand Up @@ -97,10 +98,6 @@ func init() {
pauseDurationOnCreateContainerFailure,
"The number of minutes to wait after a container creation failure to try again "+
"[%HCSSHIM_FUNCTIONAL_TESTS_PAUSE_ON_CREATECONTAINER_FAIL_IN_MINUTES%]")

// Try to stop any pre-existing compute processes
// cmd := exec.Command("powershell", `get-computeprocess | stop-computeprocess -force`)
// _ = cmd.Run()
}

func TestMain(m *testing.M) {
Expand Down Expand Up @@ -158,15 +155,21 @@ func newContainerdClient(ctx context.Context, t testing.TB) (context.Context, co
return getContainerdOptions().NewClient(ctx, t)
}

func defaultLCOWOptions(_ testing.TB, name string) *uvm.OptionsLCOW {
opts := uvm.NewDefaultOptionsLCOW(name, "")
func defaultLCOWOptions(t testing.TB) *uvm.OptionsLCOW {
opts := uvm.NewDefaultOptionsLCOW(cleanName(t.Name()), "")
opts.BootFilesPath = *flagLinuxBootFilesPath

return opts
}

func defaultWCOWOptions(_ testing.TB, name string) *uvm.OptionsWCOW {
opts := uvm.NewDefaultOptionsWCOW(name, "")
func defaultWCOWOptions(t testing.TB) *uvm.OptionsWCOW {
opts := uvm.NewDefaultOptionsWCOW(cleanName(t.Name()), "")

return opts
}

var _nameRegex = regexp.MustCompile(`[\\\/\s]`)

func cleanName(n string) string {
return _nameRegex.ReplaceAllString(n, "")
}
2 changes: 1 addition & 1 deletion test/functional/uvm_mem_backingtype_test.go
Expand Up @@ -49,7 +49,7 @@ func runMemTests(t *testing.T, os string) {
wopts.EnableDeferredCommit = bt.enableDeferredCommit
runMemStartWCOWTest(t, wopts)
} else {
lopts := defaultLCOWOptions(t, t.Name())
lopts := defaultLCOWOptions(t)
lopts.MemorySizeInMB = 512
lopts.AllowOvercommit = bt.allowOvercommit
lopts.EnableDeferredCommit = bt.enableDeferredCommit
Expand Down
2 changes: 1 addition & 1 deletion test/functional/uvm_memory_test.go
Expand Up @@ -25,7 +25,7 @@ func TestUVMMemoryUpdateLCOW(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 40*time.Second)
defer cancel()

opts := defaultLCOWOptions(t, t.Name())
opts := defaultLCOWOptions(t)
opts.MemorySizeInMB = 1024 * 2
u := tuvm.CreateAndStartLCOWFromOpts(ctx, t, opts)
defer u.Close()
Expand Down
4 changes: 2 additions & 2 deletions test/functional/uvm_plannine_test.go
Expand Up @@ -30,7 +30,7 @@ func TestPlan9(t *testing.T) {
requireFeatures(t, featureLCOW, featurePlan9)
ctx := context.Background()

vm := testuvm.CreateAndStartLCOWFromOpts(ctx, t, defaultLCOWOptions(t, t.Name()))
vm := testuvm.CreateAndStartLCOWFromOpts(ctx, t, defaultLCOWOptions(t))
defer vm.Close()
testuvm.SetSecurityPolicy(ctx, t, vm, "")

Expand Down Expand Up @@ -61,7 +61,7 @@ func TestPlan9_Writable(t *testing.T) {
requireFeatures(t, featureLCOW, featurePlan9)
ctx := context.Background()

opts := defaultLCOWOptions(t, t.Name())
opts := defaultLCOWOptions(t)
opts.NoWritableFileShares = true
vm := testuvm.CreateAndStartLCOWFromOpts(ctx, t, opts)
defer vm.Close()
Expand Down
2 changes: 1 addition & 1 deletion test/functional/uvm_properties_test.go
Expand Up @@ -20,7 +20,7 @@ func TestPropertiesGuestConnection_LCOW(t *testing.T) {
require.Build(t, osversion.RS5)
requireFeatures(t, featureLCOW)

uvm := tuvm.CreateAndStartLCOWFromOpts(context.Background(), t, defaultLCOWOptions(t, t.Name()))
uvm := tuvm.CreateAndStartLCOWFromOpts(context.Background(), t, defaultLCOWOptions(t))
defer uvm.Close()

p, gc := uvm.Capabilities()
Expand Down

0 comments on commit 3dc4f6a

Please sign in to comment.