Skip to content

Commit

Permalink
test/e2e: Refactor VerifyImagePullTimer
Browse files Browse the repository at this point in the history
Refactor out the logic that checks if the image pull timing,
to make the assessment_runner flow cleaner.

Signed-off-by: stevenhorsman <steven@uk.ibm.com>
  • Loading branch information
stevenhorsman committed Oct 25, 2024
1 parent d98b67f commit 99071df
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
14 changes: 14 additions & 0 deletions src/cloud-api-adaptor/test/e2e/assessment_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,20 @@ func VerifyNydusSnapshotter(ctx context.Context, t *testing.T, client klient.Cli
return nil
}

func VerifyImagePullTimer(ctx context.Context, t *testing.T, client klient.Client, pod *v1.Pod) error {
caaPod, err := getCaaPod(ctx, client, t)
if err != nil {
return fmt.Errorf("VerifyImagePullTimer: failed to getCaaPod: %v", err)
}

imagePullTime, err := WatchImagePullTime(ctx, client, caaPod, pod)
if err != nil {
return fmt.Errorf("VerifyImagePullTimer: WatchImagePullTime failed with %v", err)
}
t.Logf("Time Taken to pull 4GB Image: %s", imagePullTime)
return nil
}

func GetNodeNameFromPod(ctx context.Context, client klient.Client, customPod *v1.Pod) (string, error) {
var getNodeName = func(ctx context.Context, client klient.Client, pod *v1.Pod) (string, error) {
return pod.Spec.NodeName, nil
Expand Down
15 changes: 3 additions & 12 deletions src/cloud-api-adaptor/test/e2e/assessment_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,18 +334,9 @@ func (tc *TestCase) Run() {

if tc.pod != nil {
if tc.imagePullTimer {
if err := client.Resources("confidential-containers-system").List(ctx, &podlist); err != nil {
t.Fatal(err)
}
for _, caaPod := range podlist.Items {
if caaPod.Labels["app"] == "cloud-api-adaptor" {
imagePullTime, err := WatchImagePullTime(ctx, client, &caaPod, tc.pod)
if err != nil {
t.Fatal(err)
}
t.Logf("Time Taken to pull 4GB Image: %s", imagePullTime)
break
}
err := VerifyImagePullTimer(ctx, t, client, tc.pod)
if err != nil {
t.Error(err)
}
}

Expand Down

0 comments on commit 99071df

Please sign in to comment.