Skip to content

Commit e1f2865

Browse files
authored
Merge pull request #5287 from claudiubelu/cri-integration-cleanup
Cri integration cleanup
2 parents c8c6eed + cabe677 commit e1f2865

17 files changed

Lines changed: 57 additions & 180 deletions

integration/addition_gids_test.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,8 @@ func TestAdditionalGids(t *testing.T) {
3636
defer os.RemoveAll(testPodLogDir)
3737

3838
t.Log("Create a sandbox with log directory")
39-
sbConfig := PodSandboxConfig("sandbox", "additional-gids",
39+
sb, sbConfig := PodSandboxConfigWithCleanup(t, "sandbox", "additional-gids",
4040
WithPodLogDirectory(testPodLogDir))
41-
sb, err := runtimeService.RunPodSandbox(sbConfig, *runtimeHandler)
42-
require.NoError(t, err)
43-
defer func() {
44-
assert.NoError(t, runtimeService.StopPodSandbox(sb))
45-
assert.NoError(t, runtimeService.RemovePodSandbox(sb))
46-
}()
4741

4842
var (
4943
testImage = GetImage(BusyBox)

integration/container_log_test.go

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,9 @@ func TestContainerLogWithoutTailingNewLine(t *testing.T) {
3636
defer os.RemoveAll(testPodLogDir)
3737

3838
t.Log("Create a sandbox with log directory")
39-
sbConfig := PodSandboxConfig("sandbox", "container-log-without-tailing-newline",
39+
sb, sbConfig := PodSandboxConfigWithCleanup(t, "sandbox", "container-log-without-tailing-newline",
4040
WithPodLogDirectory(testPodLogDir),
4141
)
42-
sb, err := runtimeService.RunPodSandbox(sbConfig, *runtimeHandler)
43-
require.NoError(t, err)
44-
defer func() {
45-
assert.NoError(t, runtimeService.StopPodSandbox(sb))
46-
assert.NoError(t, runtimeService.RemovePodSandbox(sb))
47-
}()
4842

4943
var (
5044
testImage = GetImage(BusyBox)
@@ -92,15 +86,9 @@ func TestLongContainerLog(t *testing.T) {
9286
defer os.RemoveAll(testPodLogDir)
9387

9488
t.Log("Create a sandbox with log directory")
95-
sbConfig := PodSandboxConfig("sandbox", "long-container-log",
89+
sb, sbConfig := PodSandboxConfigWithCleanup(t, "sandbox", "long-container-log",
9690
WithPodLogDirectory(testPodLogDir),
9791
)
98-
sb, err := runtimeService.RunPodSandbox(sbConfig, *runtimeHandler)
99-
require.NoError(t, err)
100-
defer func() {
101-
assert.NoError(t, runtimeService.StopPodSandbox(sb))
102-
assert.NoError(t, runtimeService.RemovePodSandbox(sb))
103-
}()
10492

10593
var (
10694
testImage = GetImage(BusyBox)

integration/container_restart_test.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,7 @@ import (
2626
// Test to verify container can be restarted
2727
func TestContainerRestart(t *testing.T) {
2828
t.Logf("Create a pod config and run sandbox container")
29-
sbConfig := PodSandboxConfig("sandbox1", "restart")
30-
sb, err := runtimeService.RunPodSandbox(sbConfig, *runtimeHandler)
31-
require.NoError(t, err)
32-
defer func() {
33-
assert.NoError(t, runtimeService.StopPodSandbox(sb))
34-
assert.NoError(t, runtimeService.RemovePodSandbox(sb))
35-
}()
29+
sb, sbConfig := PodSandboxConfigWithCleanup(t, "sandbox1", "restart")
3630

3731
EnsureImageExists(t, pauseImage)
3832

integration/container_stats_test.go

Lines changed: 23 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,7 @@ import (
3131
// Test to verify for a container ID
3232
func TestContainerStats(t *testing.T) {
3333
t.Logf("Create a pod config and run sandbox container")
34-
sbConfig := PodSandboxConfig("sandbox1", "stats")
35-
sb, err := runtimeService.RunPodSandbox(sbConfig, *runtimeHandler)
36-
require.NoError(t, err)
37-
defer func() {
38-
assert.NoError(t, runtimeService.StopPodSandbox(sb))
39-
assert.NoError(t, runtimeService.RemovePodSandbox(sb))
40-
}()
34+
sb, sbConfig := PodSandboxConfigWithCleanup(t, "sandbox1", "stats")
4135

4236
EnsureImageExists(t, pauseImage)
4337

@@ -78,20 +72,10 @@ func TestContainerStats(t *testing.T) {
7872
// Test to verify if the consumed stats are correct.
7973
func TestContainerConsumedStats(t *testing.T) {
8074
t.Logf("Create a pod config and run sandbox container")
81-
sbConfig := PodSandboxConfig("sandbox1", "stats")
82-
sb, err := runtimeService.RunPodSandbox(sbConfig, *runtimeHandler)
83-
require.NoError(t, err)
84-
defer func() {
85-
assert.NoError(t, runtimeService.StopPodSandbox(sb))
86-
assert.NoError(t, runtimeService.RemovePodSandbox(sb))
87-
}()
75+
sb, sbConfig := PodSandboxConfigWithCleanup(t, "sandbox1", "stats")
8876

8977
testImage := GetImage(ResourceConsumer)
90-
img, err := imageService.PullImage(&runtime.ImageSpec{Image: testImage}, nil, sbConfig)
91-
require.NoError(t, err)
92-
defer func() {
93-
assert.NoError(t, imageService.RemoveImage(&runtime.ImageSpec{Image: img}))
94-
}()
78+
EnsureImageExists(t, testImage)
9579

9680
t.Logf("Create a container config and run container in a pod")
9781
containerConfig := ContainerConfig(
@@ -154,14 +138,12 @@ func TestContainerConsumedStats(t *testing.T) {
154138

155139
// Test to verify filtering without any filter
156140
func TestContainerListStats(t *testing.T) {
141+
var (
142+
stats []*runtime.ContainerStats
143+
err error
144+
)
157145
t.Logf("Create a pod config and run sandbox container")
158-
sbConfig := PodSandboxConfig("running-pod", "statsls")
159-
sb, err := runtimeService.RunPodSandbox(sbConfig, *runtimeHandler)
160-
require.NoError(t, err)
161-
defer func() {
162-
assert.NoError(t, runtimeService.StopPodSandbox(sb))
163-
assert.NoError(t, runtimeService.RemovePodSandbox(sb))
164-
}()
146+
sb, sbConfig := PodSandboxConfigWithCleanup(t, "running-pod", "statsls")
165147

166148
EnsureImageExists(t, pauseImage)
167149

@@ -188,7 +170,6 @@ func TestContainerListStats(t *testing.T) {
188170
}
189171

190172
t.Logf("Fetch all container stats")
191-
var stats []*runtime.ContainerStats
192173
require.NoError(t, Eventually(func() (bool, error) {
193174
stats, err = runtimeService.ListContainerStats(&runtime.ContainerStatsFilter{})
194175
if err != nil {
@@ -211,14 +192,12 @@ func TestContainerListStats(t *testing.T) {
211192
// Test to verify filtering given a specific container ID
212193
// TODO Convert the filter tests into table driven tests and unit tests
213194
func TestContainerListStatsWithIdFilter(t *testing.T) {
195+
var (
196+
stats []*runtime.ContainerStats
197+
err error
198+
)
214199
t.Logf("Create a pod config and run sandbox container")
215-
sbConfig := PodSandboxConfig("running-pod", "statsls")
216-
sb, err := runtimeService.RunPodSandbox(sbConfig, *runtimeHandler)
217-
require.NoError(t, err)
218-
defer func() {
219-
assert.NoError(t, runtimeService.StopPodSandbox(sb))
220-
assert.NoError(t, runtimeService.RemovePodSandbox(sb))
221-
}()
200+
sb, sbConfig := PodSandboxConfigWithCleanup(t, "running-pod", "statsls")
222201

223202
EnsureImageExists(t, pauseImage)
224203

@@ -245,7 +224,6 @@ func TestContainerListStatsWithIdFilter(t *testing.T) {
245224
}
246225

247226
t.Logf("Fetch container stats for each container with Filter")
248-
var stats []*runtime.ContainerStats
249227
for id := range containerConfigMap {
250228
require.NoError(t, Eventually(func() (bool, error) {
251229
stats, err = runtimeService.ListContainerStats(
@@ -273,14 +251,12 @@ func TestContainerListStatsWithIdFilter(t *testing.T) {
273251
// Test to verify filtering given a specific Sandbox ID. Stats for
274252
// all the containers in a pod should be returned
275253
func TestContainerListStatsWithSandboxIdFilter(t *testing.T) {
254+
var (
255+
stats []*runtime.ContainerStats
256+
err error
257+
)
276258
t.Logf("Create a pod config and run sandbox container")
277-
sbConfig := PodSandboxConfig("running-pod", "statsls")
278-
sb, err := runtimeService.RunPodSandbox(sbConfig, *runtimeHandler)
279-
require.NoError(t, err)
280-
defer func() {
281-
assert.NoError(t, runtimeService.StopPodSandbox(sb))
282-
assert.NoError(t, runtimeService.RemovePodSandbox(sb))
283-
}()
259+
sb, sbConfig := PodSandboxConfigWithCleanup(t, "running-pod", "statsls")
284260

285261
EnsureImageExists(t, pauseImage)
286262

@@ -307,7 +283,6 @@ func TestContainerListStatsWithSandboxIdFilter(t *testing.T) {
307283
}
308284

309285
t.Logf("Fetch container stats for each container with Filter")
310-
var stats []*runtime.ContainerStats
311286
require.NoError(t, Eventually(func() (bool, error) {
312287
stats, err = runtimeService.ListContainerStats(
313288
&runtime.ContainerStatsFilter{PodSandboxId: sb})
@@ -332,14 +307,12 @@ func TestContainerListStatsWithSandboxIdFilter(t *testing.T) {
332307
// Test to verify filtering given a specific container ID and
333308
// sandbox ID
334309
func TestContainerListStatsWithIdSandboxIdFilter(t *testing.T) {
310+
var (
311+
stats []*runtime.ContainerStats
312+
err error
313+
)
335314
t.Logf("Create a pod config and run sandbox container")
336-
sbConfig := PodSandboxConfig("running-pod", "statsls")
337-
sb, err := runtimeService.RunPodSandbox(sbConfig, *runtimeHandler)
338-
require.NoError(t, err)
339-
defer func() {
340-
assert.NoError(t, runtimeService.StopPodSandbox(sb))
341-
assert.NoError(t, runtimeService.RemovePodSandbox(sb))
342-
}()
315+
sb, sbConfig := PodSandboxConfigWithCleanup(t, "running-pod", "statsls")
343316

344317
EnsureImageExists(t, pauseImage)
345318

@@ -365,7 +338,6 @@ func TestContainerListStatsWithIdSandboxIdFilter(t *testing.T) {
365338
}()
366339
}
367340
t.Logf("Fetch container stats for sandbox ID and container ID filter")
368-
var stats []*runtime.ContainerStats
369341
for id, config := range containerConfigMap {
370342
require.NoError(t, Eventually(func() (bool, error) {
371343
stats, err = runtimeService.ListContainerStats(

integration/container_stop_test.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,7 @@ func TestContainerStopCancellation(t *testing.T) {
7676
t.Skip("Skipped on Windows.")
7777
}
7878
t.Log("Create a pod sandbox")
79-
sbConfig := PodSandboxConfig("sandbox", "cancel-container-stop")
80-
sb, err := runtimeService.RunPodSandbox(sbConfig, *runtimeHandler)
81-
require.NoError(t, err)
82-
defer func() {
83-
assert.NoError(t, runtimeService.StopPodSandbox(sb))
84-
assert.NoError(t, runtimeService.RemovePodSandbox(sb))
85-
}()
79+
sb, sbConfig := PodSandboxConfigWithCleanup(t, "sandbox", "cancel-container-stop")
8680

8781
var (
8882
testImage = GetImage(BusyBox)

integration/container_update_resources_test.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,7 @@ func checkMemoryLimit(t *testing.T, spec *runtimespec.Spec, memLimit int64) {
4141
func TestUpdateContainerResources(t *testing.T) {
4242
// TODO(claudiub): Make this test work once https://github.com/microsoft/hcsshim/pull/931 merges.
4343
t.Log("Create a sandbox")
44-
sbConfig := PodSandboxConfig("sandbox", "update-container-resources")
45-
sb, err := runtimeService.RunPodSandbox(sbConfig, *runtimeHandler)
46-
require.NoError(t, err)
47-
defer func() {
48-
assert.NoError(t, runtimeService.StopPodSandbox(sb))
49-
assert.NoError(t, runtimeService.RemovePodSandbox(sb))
50-
}()
44+
sb, sbConfig := PodSandboxConfigWithCleanup(t, "sandbox", "update-container-resources")
5145

5246
EnsureImageExists(t, pauseImage)
5347

integration/container_volume_test.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,9 @@ func TestContainerSymlinkVolumes(t *testing.T) {
9999
require.NoError(t, err)
100100

101101
t.Log("Create test sandbox with log directory")
102-
sbConfig := PodSandboxConfig("sandbox", "test-symlink",
102+
sb, sbConfig := PodSandboxConfigWithCleanup(t, "sandbox", "test-symlink",
103103
WithPodLogDirectory(testPodLogDir),
104104
)
105-
sb, err := runtimeService.RunPodSandbox(sbConfig, *runtimeHandler)
106-
require.NoError(t, err)
107-
defer func() {
108-
assert.NoError(t, runtimeService.StopPodSandbox(sb))
109-
assert.NoError(t, runtimeService.RemovePodSandbox(sb))
110-
}()
111105

112106
var (
113107
testImage = GetImage(BusyBox)

integration/container_without_image_ref_test.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,7 @@ import (
2727
// Test container lifecycle can work without image references.
2828
func TestContainerLifecycleWithoutImageRef(t *testing.T) {
2929
t.Log("Create a sandbox")
30-
sbConfig := PodSandboxConfig("sandbox", "container-lifecycle-without-image-ref")
31-
sb, err := runtimeService.RunPodSandbox(sbConfig, *runtimeHandler)
32-
require.NoError(t, err)
33-
defer func() {
34-
assert.NoError(t, runtimeService.StopPodSandbox(sb))
35-
assert.NoError(t, runtimeService.RemovePodSandbox(sb))
36-
}()
30+
sb, sbConfig := PodSandboxConfigWithCleanup(t, "sandbox", "container-lifecycle-without-image-ref")
3731

3832
var (
3933
testImage = GetImage(BusyBox)

integration/containerd_image_test.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,7 @@ func TestContainerdImage(t *testing.T) {
122122
assert.Equal(t, imgByID.Labels()["io.cri-containerd.image"], "managed")
123123

124124
t.Logf("should be able to start container with the image")
125-
sbConfig := PodSandboxConfig("sandbox", "containerd-image")
126-
sb, err := runtimeService.RunPodSandbox(sbConfig, *runtimeHandler)
127-
require.NoError(t, err)
128-
defer func() {
129-
assert.NoError(t, runtimeService.StopPodSandbox(sb))
130-
assert.NoError(t, runtimeService.RemovePodSandbox(sb))
131-
}()
125+
sb, sbConfig := PodSandboxConfigWithCleanup(t, "sandbox", "containerd-image")
132126

133127
cnConfig := ContainerConfig(
134128
"test-container",
@@ -183,7 +177,7 @@ func TestContainerdImageInOtherNamespaces(t *testing.T) {
183177
}
184178
require.NoError(t, Consistently(checkImage, 100*time.Millisecond, time.Second))
185179

186-
PodSandboxConfig("sandbox", "test")
180+
PodSandboxConfigWithCleanup(t, "sandbox", "test")
187181
EnsureImageExists(t, testImage)
188182

189183
t.Logf("cri plugin should see the image now")

integration/duplicate_name_test.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,15 @@ package integration
1919
import (
2020
"testing"
2121

22-
"github.com/stretchr/testify/assert"
2322
"github.com/stretchr/testify/require"
2423
)
2524

2625
func TestDuplicateName(t *testing.T) {
2726
t.Logf("Create a sandbox")
28-
sbConfig := PodSandboxConfig("sandbox", "duplicate-name")
29-
sb, err := runtimeService.RunPodSandbox(sbConfig, *runtimeHandler)
30-
require.NoError(t, err)
31-
defer func() {
32-
assert.NoError(t, runtimeService.StopPodSandbox(sb))
33-
assert.NoError(t, runtimeService.RemovePodSandbox(sb))
34-
}()
27+
sb, sbConfig := PodSandboxConfigWithCleanup(t, "sandbox", "duplicate-name")
3528

3629
t.Logf("Create the sandbox again should fail")
37-
_, err = runtimeService.RunPodSandbox(sbConfig, *runtimeHandler)
30+
_, err := runtimeService.RunPodSandbox(sbConfig, *runtimeHandler)
3831
require.Error(t, err)
3932

4033
EnsureImageExists(t, pauseImage)

0 commit comments

Comments
 (0)