@@ -28,8 +28,11 @@ import (
28
28
"testing"
29
29
30
30
"github.com/containerd/containerd/oci"
31
- "github.com/containerd/containerd/runtime/linux/runctypes"
32
- "github.com/containerd/containerd/runtime/v2/runc/options"
31
+ )
32
+
33
+ const (
34
+ v1runtime = "io.containerd.runtime.v1.linux"
35
+ testCheckpointName = "checkpoint-test:latest"
33
36
)
34
37
35
38
func TestCheckpointRestorePTY (t * testing.T ) {
@@ -41,6 +44,9 @@ func TestCheckpointRestorePTY(t *testing.T) {
41
44
t .Fatal (err )
42
45
}
43
46
defer client .Close ()
47
+ if client .runtime == v1runtime {
48
+ t .Skip ()
49
+ }
44
50
45
51
var (
46
52
ctx , cancel = testContext ()
@@ -56,7 +62,8 @@ func TestCheckpointRestorePTY(t *testing.T) {
56
62
WithNewSnapshot (id , image ),
57
63
WithNewSpec (oci .WithImageConfig (image ),
58
64
oci .WithProcessArgs ("sh" , "-c" , "read A; echo z${A}z" ),
59
- oci .WithTTY ))
65
+ oci .WithTTY ),
66
+ )
60
67
if err != nil {
61
68
t .Fatal (err )
62
69
}
@@ -83,7 +90,12 @@ func TestCheckpointRestorePTY(t *testing.T) {
83
90
t .Fatal (err )
84
91
}
85
92
86
- checkpoint , err := task .Checkpoint (ctx , withExit (client ))
93
+ checkpoint , err := container .Checkpoint (ctx , testCheckpointName + "withpty" , []CheckpointOpts {
94
+ WithCheckpointRuntime ,
95
+ WithCheckpointRW ,
96
+ WithCheckpointTaskExit ,
97
+ WithCheckpointTask ,
98
+ }... )
87
99
if err != nil {
88
100
t .Fatal (err )
89
101
}
@@ -94,6 +106,10 @@ func TestCheckpointRestorePTY(t *testing.T) {
94
106
t .Fatal (err )
95
107
}
96
108
direct .Delete ()
109
+ if err := container .Delete (ctx , WithSnapshotCleanup ); err != nil {
110
+ t .Fatal (err )
111
+ }
112
+
97
113
direct , err = newDirectIO (ctx , true )
98
114
if err != nil {
99
115
t .Fatal (err )
@@ -109,6 +125,15 @@ func TestCheckpointRestorePTY(t *testing.T) {
109
125
io .Copy (buf , direct .Stdout )
110
126
}()
111
127
128
+ if container , err = client .Restore (ctx , id , checkpoint , []RestoreOpts {
129
+ WithRestoreImage ,
130
+ WithRestoreSpec ,
131
+ WithRestoreSnapshot ,
132
+ WithRestoreRuntime ,
133
+ WithRestoreRW ,
134
+ }... ); err != nil {
135
+ t .Fatal (err )
136
+ }
112
137
if task , err = container .NewTask (ctx , direct .IOCreate ,
113
138
WithTaskCheckpoint (checkpoint )); err != nil {
114
139
t .Fatal (err )
@@ -146,6 +171,9 @@ func TestCheckpointRestore(t *testing.T) {
146
171
t .Fatal (err )
147
172
}
148
173
defer client .Close ()
174
+ if client .runtime == v1runtime {
175
+ t .Skip ()
176
+ }
149
177
150
178
var (
151
179
ctx , cancel = testContext ()
@@ -157,7 +185,7 @@ func TestCheckpointRestore(t *testing.T) {
157
185
if err != nil {
158
186
t .Fatal (err )
159
187
}
160
- container , err := client .NewContainer (ctx , id , WithNewSnapshot (id , image ), WithNewSpec (oci .WithImageConfig (image ), oci .WithProcessArgs ("sleep" , "100 " )))
188
+ container , err := client .NewContainer (ctx , id , WithNewSnapshot (id , image ), WithNewSpec (oci .WithImageConfig (image ), oci .WithProcessArgs ("sleep" , "10 " )))
161
189
if err != nil {
162
190
t .Fatal (err )
163
191
}
@@ -178,7 +206,11 @@ func TestCheckpointRestore(t *testing.T) {
178
206
t .Fatal (err )
179
207
}
180
208
181
- checkpoint , err := task .Checkpoint (ctx , withExit (client ))
209
+ checkpoint , err := container .Checkpoint (ctx , testCheckpointName + "restore" , []CheckpointOpts {
210
+ WithCheckpointRuntime ,
211
+ WithCheckpointRW ,
212
+ WithCheckpointTask ,
213
+ }... )
182
214
if err != nil {
183
215
t .Fatal (err )
184
216
}
@@ -188,6 +220,19 @@ func TestCheckpointRestore(t *testing.T) {
188
220
if _ , err := task .Delete (ctx ); err != nil {
189
221
t .Fatal (err )
190
222
}
223
+ if err := container .Delete (ctx , WithSnapshotCleanup ); err != nil {
224
+ t .Fatal (err )
225
+ }
226
+
227
+ if container , err = client .Restore (ctx , id , checkpoint , []RestoreOpts {
228
+ WithRestoreImage ,
229
+ WithRestoreSpec ,
230
+ WithRestoreSnapshot ,
231
+ WithRestoreRuntime ,
232
+ WithRestoreRW ,
233
+ }... ); err != nil {
234
+ t .Fatal (err )
235
+ }
191
236
if task , err = container .NewTask (ctx , empty (), WithTaskCheckpoint (checkpoint )); err != nil {
192
237
t .Fatal (err )
193
238
}
@@ -217,6 +262,9 @@ func TestCheckpointRestoreNewContainer(t *testing.T) {
217
262
t .Fatal (err )
218
263
}
219
264
defer client .Close ()
265
+ if client .runtime == v1runtime {
266
+ t .Skip ()
267
+ }
220
268
221
269
id := t .Name ()
222
270
ctx , cancel := testContext ()
@@ -226,7 +274,7 @@ func TestCheckpointRestoreNewContainer(t *testing.T) {
226
274
if err != nil {
227
275
t .Fatal (err )
228
276
}
229
- container , err := client .NewContainer (ctx , id , WithNewSnapshot (id , image ), WithNewSpec (oci .WithImageConfig (image ), oci .WithProcessArgs ("sleep" , "100 " )))
277
+ container , err := client .NewContainer (ctx , id , WithNewSnapshot (id , image ), WithNewSpec (oci .WithImageConfig (image ), oci .WithProcessArgs ("sleep" , "5 " )))
230
278
if err != nil {
231
279
t .Fatal (err )
232
280
}
@@ -247,7 +295,11 @@ func TestCheckpointRestoreNewContainer(t *testing.T) {
247
295
t .Fatal (err )
248
296
}
249
297
250
- checkpoint , err := task .Checkpoint (ctx , withExit (client ))
298
+ checkpoint , err := container .Checkpoint (ctx , testCheckpointName + "newcontainer" , []CheckpointOpts {
299
+ WithCheckpointRuntime ,
300
+ WithCheckpointRW ,
301
+ WithCheckpointTask ,
302
+ }... )
251
303
if err != nil {
252
304
t .Fatal (err )
253
305
}
@@ -260,7 +312,13 @@ func TestCheckpointRestoreNewContainer(t *testing.T) {
260
312
if err := container .Delete (ctx , WithSnapshotCleanup ); err != nil {
261
313
t .Fatal (err )
262
314
}
263
- if container , err = client .NewContainer (ctx , id , WithCheckpoint (checkpoint , id )); err != nil {
315
+ if container , err = client .Restore (ctx , id , checkpoint , []RestoreOpts {
316
+ WithRestoreImage ,
317
+ WithRestoreSpec ,
318
+ WithRestoreSnapshot ,
319
+ WithRestoreRuntime ,
320
+ WithRestoreRW ,
321
+ }... ); err != nil {
264
322
t .Fatal (err )
265
323
}
266
324
if task , err = container .NewTask (ctx , empty (), WithTaskCheckpoint (checkpoint )); err != nil {
@@ -290,11 +348,14 @@ func TestCheckpointLeaveRunning(t *testing.T) {
290
348
if ! supportsCriu {
291
349
t .Skip ("system does not have criu installed" )
292
350
}
293
- client , err := New ( address )
351
+ client , err := newClient ( t , address )
294
352
if err != nil {
295
353
t .Fatal (err )
296
354
}
297
355
defer client .Close ()
356
+ if client .runtime == v1runtime {
357
+ t .Skip ()
358
+ }
298
359
299
360
var (
300
361
ctx , cancel = testContext ()
@@ -327,7 +388,12 @@ func TestCheckpointLeaveRunning(t *testing.T) {
327
388
t .Fatal (err )
328
389
}
329
390
330
- if _ , err := task .Checkpoint (ctx ); err != nil {
391
+ // checkpoint
392
+ if _ , err := container .Checkpoint (ctx , testCheckpointName + "leaverunning" , []CheckpointOpts {
393
+ WithCheckpointRuntime ,
394
+ WithCheckpointRW ,
395
+ WithCheckpointTask ,
396
+ }... ); err != nil {
331
397
t .Fatal (err )
332
398
}
333
399
@@ -345,19 +411,3 @@ func TestCheckpointLeaveRunning(t *testing.T) {
345
411
346
412
<- statusC
347
413
}
348
-
349
- func withExit (client * Client ) CheckpointTaskOpts {
350
- return func (r * CheckpointTaskInfo ) error {
351
- switch client .runtime {
352
- case "io.containerd.runc.v1" :
353
- r .Options = & options.CheckpointOptions {
354
- Exit : true ,
355
- }
356
- default :
357
- r .Options = & runctypes.CheckpointOptions {
358
- Exit : true ,
359
- }
360
- }
361
- return nil
362
- }
363
- }
0 commit comments