Skip to content

Commit 51689b6

Browse files
committed
integration: introduce hook for upgrade test suite
We can inject failpoint in beforeUpgradeHookFunc. Signed-off-by: Wei Fu <[email protected]>
1 parent a95c8ed commit 51689b6

File tree

1 file changed

+27
-11
lines changed

1 file changed

+27
-11
lines changed

integration/release_upgrade_linux_test.go

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ import (
4141
)
4242

4343
// upgradeVerifyCaseFunc is used to verify the behavior after upgrade.
44-
type upgradeVerifyCaseFunc func(t *testing.T, criRuntimeService cri.RuntimeService, criImageService cri.ImageManagerService)
44+
type upgradeVerifyCaseFunc func(*testing.T, cri.RuntimeService, cri.ImageManagerService)
45+
46+
// beforeUpgradeHookFunc is a hook before upgrade.
47+
type beforeUpgradeHookFunc func(*testing.T)
4548

4649
// TODO: Support Windows
4750
func TestUpgrade(t *testing.T) {
@@ -58,7 +61,7 @@ func TestUpgrade(t *testing.T) {
5861

5962
func runUpgradeTestCase(
6063
previousReleaseBinDir string,
61-
setupUpgradeVerifyCase func(t *testing.T, criRuntimeService cri.RuntimeService, criImageService cri.ImageManagerService) upgradeVerifyCaseFunc,
64+
setupUpgradeVerifyCase func(*testing.T, cri.RuntimeService, cri.ImageManagerService) (upgradeVerifyCaseFunc, beforeUpgradeHookFunc),
6265
) func(t *testing.T) {
6366
return func(t *testing.T) {
6467
// NOTE: Using t.TempDir() here is to ensure there are no leaky
@@ -88,13 +91,18 @@ func runUpgradeTestCase(
8891
})
8992

9093
t.Log("Prepare pods for current release")
91-
upgradeCaseFunc := setupUpgradeVerifyCase(t, previousProc.criRuntimeService(t), previousProc.criImageService(t))
94+
upgradeCaseFunc, hookFunc := setupUpgradeVerifyCase(t, previousProc.criRuntimeService(t), previousProc.criImageService(t))
9295
needToCleanup = false
9396

9497
t.Log("Gracefully stop previous release's containerd process")
9598
require.NoError(t, previousProc.kill(syscall.SIGTERM))
9699
require.NoError(t, previousProc.wait(5*time.Minute))
97100

101+
if hookFunc != nil {
102+
t.Log("Run hook before upgrade")
103+
hookFunc(t)
104+
}
105+
98106
t.Log("Install default config for current release")
99107
currentReleaseCtrdDefaultConfig(t, workDir)
100108

@@ -115,7 +123,9 @@ func runUpgradeTestCase(
115123
}
116124
}
117125

118-
func shouldRecoverAllThePodsAfterUpgrade(t *testing.T, rSvc cri.RuntimeService, iSvc cri.ImageManagerService) upgradeVerifyCaseFunc {
126+
func shouldRecoverAllThePodsAfterUpgrade(t *testing.T,
127+
rSvc cri.RuntimeService, iSvc cri.ImageManagerService) (upgradeVerifyCaseFunc, beforeUpgradeHookFunc) {
128+
119129
var busyboxImage = images.Get(images.BusyBox)
120130

121131
pullImagesByCRI(t, iSvc, busyboxImage)
@@ -175,10 +185,12 @@ func shouldRecoverAllThePodsAfterUpgrade(t *testing.T, rSvc cri.RuntimeService,
175185
t.Errorf("unexpected pod %s", pod.Id)
176186
}
177187
}
178-
}
188+
}, nil
179189
}
180190

181-
func execToExistingContainer(t *testing.T, rSvc cri.RuntimeService, iSvc cri.ImageManagerService) upgradeVerifyCaseFunc {
191+
func execToExistingContainer(t *testing.T,
192+
rSvc cri.RuntimeService, iSvc cri.ImageManagerService) (upgradeVerifyCaseFunc, beforeUpgradeHookFunc) {
193+
182194
var busyboxImage = images.Get(images.BusyBox)
183195

184196
pullImagesByCRI(t, iSvc, busyboxImage)
@@ -231,7 +243,7 @@ func execToExistingContainer(t *testing.T, rSvc cri.RuntimeService, iSvc cri.Ima
231243
require.NoError(t, err)
232244
require.Len(t, stderr, 0)
233245
require.Equal(t, "true", string(stdout))
234-
}
246+
}, nil
235247
}
236248

237249
// getFileSize returns file's size.
@@ -241,7 +253,9 @@ func getFileSize(t *testing.T, filePath string) int64 {
241253
return st.Size()
242254
}
243255

244-
func shouldManipulateContainersInPodAfterUpgrade(t *testing.T, rSvc cri.RuntimeService, iSvc cri.ImageManagerService) upgradeVerifyCaseFunc {
256+
func shouldManipulateContainersInPodAfterUpgrade(t *testing.T,
257+
rSvc cri.RuntimeService, iSvc cri.ImageManagerService) (upgradeVerifyCaseFunc, beforeUpgradeHookFunc) {
258+
245259
var busyboxImage = images.Get(images.BusyBox)
246260

247261
pullImagesByCRI(t, iSvc, busyboxImage)
@@ -335,10 +349,12 @@ func shouldManipulateContainersInPodAfterUpgrade(t *testing.T, rSvc cri.RuntimeS
335349
ents, err := os.ReadDir(cntrDataDir)
336350
require.NoError(t, err)
337351
require.Len(t, ents, 0, cntrDataDir)
338-
}
352+
}, nil
339353
}
340354

341-
func shouldRecoverExistingImages(t *testing.T, _ cri.RuntimeService, iSvc cri.ImageManagerService) upgradeVerifyCaseFunc {
355+
func shouldRecoverExistingImages(t *testing.T,
356+
_ cri.RuntimeService, iSvc cri.ImageManagerService) (upgradeVerifyCaseFunc, beforeUpgradeHookFunc) {
357+
342358
images := []string{images.Get(images.BusyBox), images.Get(images.Alpine)}
343359
expectedRefs := pullImagesByCRI(t, iSvc, images...)
344360

@@ -354,7 +370,7 @@ func shouldRecoverExistingImages(t *testing.T, _ cri.RuntimeService, iSvc cri.Im
354370
require.NoError(t, err)
355371
require.Equal(t, expectedRefs[idx], gotImg.Id)
356372
}
357-
}
373+
}, nil
358374
}
359375

360376
func newPodTCtx(t *testing.T, rSvc cri.RuntimeService,

0 commit comments

Comments
 (0)