Skip to content

Commit 566a34d

Browse files
authored
[func.test]update lcow layer processing (microsoft#1795)
Signed-off-by: Hamza El-Saawy <[email protected]>
1 parent 9fd0e72 commit 566a34d

2 files changed

Lines changed: 46 additions & 11 deletions

File tree

test/functional/lcow_container_bench_test.go

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,20 @@
44
package functional
55

66
import (
7+
"path/filepath"
78
"testing"
89

910
ctrdoci "github.com/containerd/containerd/oci"
1011
cri_util "github.com/containerd/containerd/pkg/cri/util"
1112

1213
"github.com/Microsoft/hcsshim/internal/hcsoci"
14+
"github.com/Microsoft/hcsshim/internal/layers"
1315
"github.com/Microsoft/hcsshim/internal/resources"
1416
"github.com/Microsoft/hcsshim/osversion"
1517

1618
"github.com/Microsoft/hcsshim/test/internal/cmd"
1719
"github.com/Microsoft/hcsshim/test/internal/container"
18-
"github.com/Microsoft/hcsshim/test/internal/layers"
20+
testlayers "github.com/Microsoft/hcsshim/test/internal/layers"
1921
"github.com/Microsoft/hcsshim/test/internal/oci"
2022
"github.com/Microsoft/hcsshim/test/pkg/require"
2123
"github.com/Microsoft/hcsshim/test/pkg/uvm"
@@ -32,13 +34,13 @@ func BenchmarkLCOW_Container(b *testing.B) {
3234

3335
b.Run("Create", func(b *testing.B) {
3436
vm := uvm.CreateAndStartLCOWFromOpts(ctx, b, defaultLCOWOptions(b))
35-
cache := layers.CacheFile(ctx, b, "")
37+
cache := testlayers.CacheFile(ctx, b, "")
3638

3739
b.StopTimer()
3840
b.ResetTimer()
3941
for i := 0; i < b.N; i++ {
4042
id := cri_util.GenerateID()
41-
scratch, _ := layers.ScratchSpace(ctx, b, vm, "", "", cache)
43+
scratch, _ := testlayers.ScratchSpace(ctx, b, vm, "", "", cache)
4244
spec := oci.CreateLinuxSpec(ctx, b, id,
4345
oci.DefaultLinuxSpecOpts(id,
4446
ctrdoci.WithProcessArgs("/bin/sh", "-c", "true"),
@@ -53,6 +55,15 @@ func BenchmarkLCOW_Container(b *testing.B) {
5355
NetworkNamespace: "",
5456
}
5557

58+
co.LCOWLayers = &layers.LCOWLayers{
59+
Layers: make([]*layers.LCOWLayer, 0, len(ls)),
60+
ScratchVHDPath: filepath.Join(scratch, "sandbox.vhdx"),
61+
}
62+
63+
for _, p := range ls {
64+
co.LCOWLayers.Layers = append(co.LCOWLayers.Layers, &layers.LCOWLayer{VHDPath: filepath.Join(p, "layer.vhd")})
65+
}
66+
5667
b.StartTimer()
5768
c, r, err := hcsoci.CreateContainer(ctx, co)
5869
if err != nil {
@@ -79,13 +90,13 @@ func BenchmarkLCOW_Container(b *testing.B) {
7990

8091
b.Run("Start", func(b *testing.B) {
8192
vm := uvm.CreateAndStartLCOWFromOpts(ctx, b, defaultLCOWOptions(b))
82-
cache := layers.CacheFile(ctx, b, "")
93+
cache := testlayers.CacheFile(ctx, b, "")
8394

8495
b.StopTimer()
8596
b.ResetTimer()
8697
for i := 0; i < b.N; i++ {
8798
id := cri_util.GenerateID()
88-
scratch, _ := layers.ScratchSpace(ctx, b, vm, "", "", cache)
99+
scratch, _ := testlayers.ScratchSpace(ctx, b, vm, "", "", cache)
89100
spec := oci.CreateLinuxSpec(ctx, b, id,
90101
oci.DefaultLinuxSpecOpts(id,
91102
ctrdoci.WithProcessArgs("/bin/sh", "-c", "true"),
@@ -111,13 +122,13 @@ func BenchmarkLCOW_Container(b *testing.B) {
111122

112123
b.Run("InitExec", func(b *testing.B) {
113124
vm := uvm.CreateAndStartLCOWFromOpts(ctx, b, defaultLCOWOptions(b))
114-
cache := layers.CacheFile(ctx, b, "")
125+
cache := testlayers.CacheFile(ctx, b, "")
115126

116127
b.StopTimer()
117128
b.ResetTimer()
118129
for i := 0; i < b.N; i++ {
119130
id := cri_util.GenerateID()
120-
scratch, _ := layers.ScratchSpace(ctx, b, vm, "", "", cache)
131+
scratch, _ := testlayers.ScratchSpace(ctx, b, vm, "", "", cache)
121132
spec := oci.CreateLinuxSpec(ctx, b, id,
122133
oci.DefaultLinuxSpecOpts(id,
123134
ctrdoci.WithProcessArgs("/bin/sh", "-c", oci.TailNullArgs),
@@ -144,13 +155,13 @@ func BenchmarkLCOW_Container(b *testing.B) {
144155

145156
b.Run("InitExecKill", func(b *testing.B) {
146157
vm := uvm.CreateAndStartLCOWFromOpts(ctx, b, defaultLCOWOptions(b))
147-
cache := layers.CacheFile(ctx, b, "")
158+
cache := testlayers.CacheFile(ctx, b, "")
148159

149160
b.StopTimer()
150161
b.ResetTimer()
151162
for i := 0; i < b.N; i++ {
152163
id := cri_util.GenerateID()
153-
scratch, _ := layers.ScratchSpace(ctx, b, vm, "", "", cache)
164+
scratch, _ := testlayers.ScratchSpace(ctx, b, vm, "", "", cache)
154165
spec := oci.CreateLinuxSpec(ctx, b, id,
155166
oci.DefaultLinuxSpecOpts(id,
156167
ctrdoci.WithProcessArgs("/bin/sh", "-c", oci.TailNullArgs),
@@ -172,13 +183,13 @@ func BenchmarkLCOW_Container(b *testing.B) {
172183

173184
b.Run("ContainerKill", func(b *testing.B) {
174185
vm := uvm.CreateAndStartLCOWFromOpts(ctx, b, defaultLCOWOptions(b))
175-
cache := layers.CacheFile(ctx, b, "")
186+
cache := testlayers.CacheFile(ctx, b, "")
176187

177188
b.StopTimer()
178189
b.ResetTimer()
179190
for i := 0; i < b.N; i++ {
180191
id := cri_util.GenerateID()
181-
scratch, _ := layers.ScratchSpace(ctx, b, vm, "", "", cache)
192+
scratch, _ := testlayers.ScratchSpace(ctx, b, vm, "", "", cache)
182193
spec := oci.CreateLinuxSpec(ctx, b, id,
183194
oci.DefaultLinuxSpecOpts(id,
184195
ctrdoci.WithProcessArgs("/bin/sh", "-c", "true"),

test/internal/container/container.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ package container
44

55
import (
66
"context"
7+
"path/filepath"
78
"testing"
89

910
"github.com/opencontainers/runtime-spec/specs-go"
1011

1112
"github.com/Microsoft/hcsshim/internal/cmd"
1213
"github.com/Microsoft/hcsshim/internal/cow"
1314
"github.com/Microsoft/hcsshim/internal/hcsoci"
15+
"github.com/Microsoft/hcsshim/internal/layers"
1416
"github.com/Microsoft/hcsshim/internal/resources"
1517
"github.com/Microsoft/hcsshim/internal/uvm"
1618

@@ -39,6 +41,28 @@ func Create(
3941
NetworkNamespace: "", //spec.Windows.Network.NetworkNamespace,
4042
}
4143

44+
if co.Spec.Linux != nil {
45+
var layerFolders []string
46+
if co.Spec.Windows != nil {
47+
layerFolders = co.Spec.Windows.LayerFolders
48+
}
49+
if len(layerFolders) <= 1 {
50+
tb.Fatalf("LCOW requires at least 2 layers (including scratch): %v", layerFolders)
51+
}
52+
scratch := layerFolders[len(layerFolders)-1]
53+
parents := layerFolders[:len(layerFolders)-1]
54+
55+
// todo: support partitioned layers
56+
co.LCOWLayers = &layers.LCOWLayers{
57+
Layers: make([]*layers.LCOWLayer, 0, len(parents)),
58+
ScratchVHDPath: filepath.Join(scratch, "sandbox.vhdx"),
59+
}
60+
61+
for _, p := range parents {
62+
co.LCOWLayers.Layers = append(co.LCOWLayers.Layers, &layers.LCOWLayer{VHDPath: filepath.Join(p, "layer.vhd")})
63+
}
64+
}
65+
4266
c, r, err := hcsoci.CreateContainer(ctx, co)
4367
if err != nil {
4468
tb.Fatalf("could not create container %q: %v", co.ID, err)

0 commit comments

Comments
 (0)