Skip to content

fix: set -e bypasses vgpu-util match error handler - #955

Open
andrewwhitecdw wants to merge 1 commit into
NVIDIA:mainfrom
andrewwhitecdw:bugfix/nvidia-driver-set-e-bypasses-vgpu-util-match-error
Open

fix: set -e bypasses vgpu-util match error handler#955
andrewwhitecdw wants to merge 1 commit into
NVIDIA:mainfrom
andrewwhitecdw:bugfix/nvidia-driver-set-e-bypasses-vgpu-util-match-error

Conversation

@andrewwhitecdw

Copy link
Copy Markdown

This PR addresses the following issue in ubuntu22.04/nvidia-driver: set -e bypasses vgpu-util match error handler.

Changes

  • ubuntu22.04/nvidia-driver: set -e bypasses vgpu-util match error handler.

Details

--- a/ubuntu22.04/nvidia-driver
+++ b/ubuntu22.04/nvidia-driver
@@ -1,2 +1,1 @@
-    version=$(vgpu-util match -i /drivers -c /drivers/vgpuDriverCatalog.yaml)
-    if [ $? -ne 0 ]; then
+    if ! version=$(vgpu-util match -i /drivers -c /drivers/vgpuDriverCatalog.yaml); then

Tests

  • tests/test_vgpu_match.sh
--- /dev/null
+++ b/tests/test_vgpu_match.sh
@@ -0,0 +1,52 @@
+#!/bin/bash
+# Regression test: _find_vgpu_driver_version must return 1 on a failing
+# `vgpu-util match` and print an error message, even with set -e active.
+
+set -u
+
+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+DRIVER_SCRIPT="${SCRIPT_DIR}/../ubuntu22.04/nvidia-driver"
+
+if [ ! -f "$DRIVER_SCRIPT" ]; then
+    echo "ERROR: $DRIVER_SCRIPT not found"
+    exit 1
+fi
+
+func_body=$(sed -n '/^_find_vgpu_driver_version() {/,/^}/p' "$DRIVER_SCRIPT")
+if [ -z "$func_body" ]; then
+    echo "ERROR: could not extract _find_vgpu_driver_version from $DRIVER_SCRIPT"
+    exit 1
+fi
+
+output=$( (
+    set -e
+    eval "$func_body"
+
+    vgpu-util() {
+        if [ "$1" = "count" ]; then
+            echo "count=1"
+            return 0
+        fi
+        return 1
+    }
+
+    DISABLE_VGPU_VERSION_CHECK=false
+
+    # Function should return 1 when match fails.
+    if _find_vgpu_driver_version; then
+        echo "FAIL: expected _find_vgpu_driver_version to return non-zero"
+        exit 1
+    fi
+
+    echo "PASS"
+) 2>&1 )
+status=$?
+
+if [ "$status" -ne 0 ] || [[ "$output" != *"PASS"* ]]; then
+    echo "FAIL: _find_vgpu_driver_version did not handle vgpu-util match failure"
+    echo "$output"
+    exit 1
+fi
+
+echo "PASS"

Contributor guidelines

Per this repo's CONTRIBUTING.md:

  • All commits are signed off (Signed-off-by trailer, DCO).

@copy-pr-bot

copy-pr-bot Bot commented Aug 13, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant