@@ -40,7 +40,7 @@ import (
40
40
)
41
41
42
42
// upgradeVerifyCaseFunc is used to verify the behavior after upgrade.
43
- type upgradeVerifyCaseFunc func (t * testing.T , criRuntimeService cri.RuntimeService )
43
+ type upgradeVerifyCaseFunc func (t * testing.T , criRuntimeService cri.RuntimeService , criImageService cri. ImageManagerService )
44
44
45
45
// TODO: Support Windows
46
46
func TestUpgrade (t * testing.T ) {
@@ -50,6 +50,7 @@ func TestUpgrade(t *testing.T) {
50
50
t .Run ("recover" , runUpgradeTestCase (previousReleaseBinDir , shouldRecoverAllThePodsAfterUpgrade ))
51
51
t .Run ("exec" , runUpgradeTestCase (previousReleaseBinDir , execToExistingContainer ))
52
52
t .Run ("manipulate" , runUpgradeTestCase (previousReleaseBinDir , shouldManipulateContainersInPodAfterUpgrade ))
53
+ t .Run ("recover-images" , runUpgradeTestCase (previousReleaseBinDir , shouldRecoverExistingImages ))
53
54
// TODO:
54
55
// Add stats/stop-existing-running-pods/...
55
56
}
@@ -107,7 +108,7 @@ func runUpgradeTestCase(
107
108
})
108
109
109
110
t .Log ("Verifing" )
110
- upgradeCaseFunc (t , currentProc .criRuntimeService (t ))
111
+ upgradeCaseFunc (t , currentProc .criRuntimeService (t ), currentProc . criImageService ( t ) )
111
112
}
112
113
}
113
114
@@ -148,7 +149,7 @@ func shouldRecoverAllThePodsAfterUpgrade(t *testing.T, criRuntimeService cri.Run
148
149
t .Log ("Stop second sandbox" )
149
150
require .NoError (t , criRuntimeService .StopPodSandbox (secondSB ))
150
151
151
- return func (t * testing.T , criRuntimeService cri.RuntimeService ) {
152
+ return func (t * testing.T , criRuntimeService cri.RuntimeService , _ cri. ImageManagerService ) {
152
153
t .Log ("List Pods" )
153
154
154
155
pods , err := criRuntimeService .ListPodSandbox (nil )
@@ -212,7 +213,7 @@ func execToExistingContainer(t *testing.T, criRuntimeService cri.RuntimeService,
212
213
// NOTE: Wait for containerd to flush data into log
213
214
time .Sleep (2 * time .Second )
214
215
215
- return func (t * testing.T , criRuntimeService cri.RuntimeService ) {
216
+ return func (t * testing.T , criRuntimeService cri.RuntimeService , _ cri. ImageManagerService ) {
216
217
pods , err := criRuntimeService .ListPodSandbox (nil )
217
218
require .NoError (t , err )
218
219
require .Len (t , pods , 1 )
@@ -288,7 +289,7 @@ func shouldManipulateContainersInPodAfterUpgrade(t *testing.T, criRuntimeService
288
289
require .NoError (t , criRuntimeService .StartContainer (cn3 ))
289
290
require .NoError (t , criRuntimeService .StopContainer (cn3 , 0 ))
290
291
291
- return func (t * testing.T , criRuntimeService cri.RuntimeService ) {
292
+ return func (t * testing.T , criRuntimeService cri.RuntimeService , _ cri. ImageManagerService ) {
292
293
t .Log ("Manipulating containers in the previous pod" )
293
294
// For the running container, we get status and stats of it,
294
295
// exec and execsync in it, stop and remove it
@@ -346,6 +347,32 @@ func shouldManipulateContainersInPodAfterUpgrade(t *testing.T, criRuntimeService
346
347
}
347
348
}
348
349
350
+ func shouldRecoverExistingImages (t * testing.T , criRuntimeService cri.RuntimeService , criImageService cri.ImageManagerService ) upgradeVerifyCaseFunc {
351
+ images := []string {images .Get (images .BusyBox ), images .Get (images .Alpine )}
352
+
353
+ expectedRefs := []string {}
354
+ for _ , img := range images {
355
+ t .Logf ("Pulling image %q" , img )
356
+ imgRef , err := criImageService .PullImage (& criruntime.ImageSpec {Image : img }, nil , nil )
357
+ require .NoError (t , err )
358
+ expectedRefs = append (expectedRefs , imgRef )
359
+ }
360
+
361
+ return func (t * testing.T , _ cri.RuntimeService , criImageService cri.ImageManagerService ) {
362
+ t .Log ("List all images" )
363
+ res , err := criImageService .ListImages (nil )
364
+ require .NoError (t , err )
365
+ require .Len (t , res , 2 )
366
+
367
+ for idx , img := range images {
368
+ t .Logf ("Check image %s status" , img )
369
+ gotImg , err := criImageService .ImageStatus (& criruntime.ImageSpec {Image : img })
370
+ require .NoError (t , err )
371
+ require .Equal (t , expectedRefs [idx ], gotImg .Id )
372
+ }
373
+ }
374
+ }
375
+
349
376
// cleanupPods deletes all the pods based on the cri.RuntimeService connection.
350
377
func cleanupPods (t * testing.T , criRuntimeService cri.RuntimeService ) {
351
378
pods , err := criRuntimeService .ListPodSandbox (nil )
0 commit comments