Skip to content

[no-relnote] Update E2E test suite #1048

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,25 @@ jobs:

- name: Run e2e tests
env:
IMAGE_NAME: ghcr.io/nvidia/container-toolkit
VERSION: ${{ inputs.version }}
SSH_KEY: ${{ secrets.AWS_SSH_KEY }}
E2E_INSTALL_CTK: "true"
E2E_IMAGE_NAME: ghcr.io/nvidia/container-toolkit
E2E_IMAGE_TAG: ${{ inputs.version }}-ubuntu20.04
E2E_SSH_USER: ${{ secrets.E2E_SSH_USER }}
E2E_SSH_HOST: ${{ steps.holodeck_public_dns_name.outputs.result }}
E2E_INSTALL_CTK: "true"
run: |
e2e_ssh_key=$(mktemp)
echo "$SSH_KEY" > "$e2e_ssh_key"
echo "${{ secrets.AWS_SSH_KEY }}" > "$e2e_ssh_key"
chmod 600 "$e2e_ssh_key"
export E2E_SSH_KEY="$e2e_ssh_key"

make -f tests/e2e/Makefile test

- name: Archive Ginkgo logs
uses: actions/upload-artifact@v4
with:
name: ginkgo-logs
path: ginkgo.json
retention-days: 15
- name: Send Slack alert notification
if: ${{ failure() }}
uses: slackapi/[email protected]
Expand All @@ -94,5 +99,5 @@ jobs:
channel: ${{ secrets.SLACK_CHANNEL_ID }}
text: |
:x: On repository ${{ github.repository }}, the Workflow *${{ github.workflow }}* has failed.

Details: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@
/nvidia-ctk
/shared-*
/release-*
/bin
39 changes: 11 additions & 28 deletions tests/e2e/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved.
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -12,34 +13,16 @@
# See the License for the specific language governing permissions and
# limitations under the License.

GO_CMD ?= go
.PHONY: test $(GINKGO_BIN)

include $(CURDIR)/versions.mk
GINKGO_ARGS ?=
LOG_ARTIFACTS_DIR ?= $(CURDIR)/e2e_logs

E2E_RUNTIME ?= docker
GINKGO_BIN := $(CURDIR)/bin/ginkgo

E2E_INSTALL_CTK ?= false
test: $(GINKGO_BIN)
$(GINKGO_BIN) $(GINKGO_ARGS) -v --json-report ginkgo.json ./tests/e2e/...

ifeq ($($(DIST)),)
DIST ?= ubuntu20.04
endif
IMAGE_TAG ?= $(VERSION)-$(DIST)
IMAGE = $(IMAGE_NAME):$(IMAGE_TAG)

E2E_SSH_KEY ?=
E2E_SSH_USER ?=
E2E_SSH_HOST ?=
E2E_SSH_PORT ?= 22

.PHONY: test
test:
cd $(CURDIR)/tests/e2e && $(GO_CMD) test -v . -args \
-ginkgo.focus="$(E2E_RUNTIME)" \
-test.timeout=1h \
-ginkgo.v \
-install-ctk=$(E2E_INSTALL_CTK) \
-toolkit-image=$(IMAGE) \
-ssh-key=$(E2E_SSH_KEY) \
-ssh-user=$(E2E_SSH_USER) \
-remote-host=$(E2E_SSH_HOST) \
-remote-port=$(E2E_SSH_PORT)
$(GINKGO_BIN):
mkdir -p $(CURDIR)/bin
GOBIN=$(CURDIR)/bin go install github.com/onsi/ginkgo/v2/ginkgo@latest
120 changes: 88 additions & 32 deletions tests/e2e/e2e_test.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
/*
* Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
**/

package e2e

import (
"context"
"flag"
"errors"
"os"
"strconv"
"testing"

. "github.com/onsi/ginkgo/v2"
Expand All @@ -31,33 +34,86 @@ var (

installCTK bool

image string
imageName string
imageTag string

sshKey string
sshUser string
host string
sshHost string
sshPort string
)

func init() {
flag.BoolVar(&installCTK, "install-ctk", false, "Install the NVIDIA Container Toolkit")
flag.StringVar(&image, "toolkit-image", "", "Repository of the image to test")
flag.StringVar(&sshKey, "ssh-key", "", "SSH key to use for remote login")
flag.StringVar(&sshUser, "ssh-user", "", "SSH user to use for remote login")
flag.StringVar(&host, "remote-host", "", "Hostname of the remote machine")
flag.StringVar(&sshPort, "remote-port", "22", "SSH port to use for remote login")
}

func TestMain(t *testing.T) {
suiteName := "NVIDIA Container Toolkit E2E"
suiteName := "E2E NVIDIA Container Toolkit"

RegisterFailHandler(Fail)

ctx = context.Background()
getTestEnv()

RunSpecs(t,
suiteName,
)
}

// BeforeSuite runs before the test suite
var _ = BeforeSuite(func() {
ctx = context.Background()
})
// getTestEnv gets the test environment variables
func getTestEnv() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make sure that the envvars here match the ones in the README (or remove the readme section).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

defer GinkgoRecover()

installCTK = getEnvVarOrDefault("E2E_INSTALL_CTK", false)

if installCTK {
imageName = getRequiredEnvvar[string]("E2E_IMAGE_NAME")

imageTag = getRequiredEnvvar[string]("E2E_IMAGE_TAG")

}

sshKey = getRequiredEnvvar[string]("E2E_SSH_KEY")
sshUser = getRequiredEnvvar[string]("E2E_SSH_USER")
sshHost = getRequiredEnvvar[string]("E2E_SSH_HOST")

sshPort = getEnvVarOrDefault("E2E_SSH_PORT", "22")
}

// getRequiredEnvvar returns the specified envvar if set or raises an error.
func getRequiredEnvvar[T any](key string) T {
v, err := getEnvVarAs[T](key)
Expect(err).To(BeNil(), "required environement variable not set", key)
return v
}

func getEnvVarAs[T any](key string) (T, error) {
var zero T
value := os.Getenv(key)
if value == "" {
return zero, errors.New("env var not set")
}

switch any(zero).(type) {
case bool:
v, err := strconv.ParseBool(value)
if err != nil {
return zero, err
}
return any(v).(T), nil
case int:
v, err := strconv.Atoi(value)
if err != nil {
return zero, err
}
return any(v).(T), nil
case string:
return any(value).(T), nil
default:
return zero, errors.New("unsupported type")
}
}

func getEnvVarOrDefault[T any](key string, defaultValue T) T {
val, err := getEnvVarAs[T](key)
if err != nil {
return defaultValue
}
return val
}
Loading