Skip to content

fix: vgpu-util failures abort under set -e before $? check - #947

Open
andrewwhitecdw wants to merge 1 commit into
NVIDIA:mainfrom
andrewwhitecdw:codequality/nvidia-driver-vgpu-util-failures-abort-under-set-e
Open

fix: vgpu-util failures abort under set -e before $? check#947
andrewwhitecdw wants to merge 1 commit into
NVIDIA:mainfrom
andrewwhitecdw:codequality/nvidia-driver-vgpu-util-failures-abort-under-set-e

Conversation

@andrewwhitecdw

Copy link
Copy Markdown

This PR addresses the following issue in ubuntu24.04/nvidia-driver: vgpu-util failures abort under set -e before $? check.

Changes

  • ubuntu24.04/nvidia-driver: vgpu-util failures abort under set -e before $? check.

Details

--- a/ubuntu24.04/nvidia-driver
+++ b/ubuntu24.04/nvidia-driver
@@ -1,18 +1,16 @@
-    count=$(vgpu-util count)
-    if [ $? -ne 0 ]; then
-         echo "cannot find vgpu devices on host, pleae check /var/log/vgpu-util.log for more details..."
-         return 0
-    fi
-    NUM_VGPU_DEVICES=$(echo "$count" | awk -F= '{print $2}')
-    if [ $NUM_VGPU_DEVICES -eq 0 ]; then
-        # no vgpu devices found, treat as passthrough
-        return 0
-    fi
-    echo "found $NUM_VGPU_DEVICES vgpu devices on host"
-
-    # find compatible guest driver using drive catalog
-    version=$(vgpu-util match -i /drivers -c /drivers/vgpuDriverCatalog.yaml)
-    if [ $? -ne 0 ]; then
-        echo "cannot find match for compatible vgpu driver from available list, please check /var/log/vgpu-util.log for more details..."
-        return 1
-    fi
+    if ! count=$(vgpu-util count); then
+         echo "cannot find vgpu devices on host, pleae check /var/log/vgpu-util.log for more details..."
+         return 0
+    fi
+    NUM_VGPU_DEVICES=$(echo "$count" | awk -F= '{print $2}')
+    if [ $NUM_VGPU_DEVICES -eq 0 ]; then
+        # no vgpu devices found, treat as passthrough
+        return 0
+    fi
+    echo "found $NUM_VGPU_DEVICES vgpu devices on host"
+
+    # find compatible guest driver using drive catalog
+    if ! version=$(vgpu-util match -i /drivers -c /drivers/vgpuDriverCatalog.yaml); then
+        echo "cannot find match for compatible vgpu driver from available list, please check /var/log/vgpu-util.log for more details..."
+        return 1
+    fi

Tests

  • tests/test_vgpu_error_handling.sh
--- /dev/null
+++ tests/test_vgpu_error_handling.sh
@@ -0,0 +1,18 @@
+#!/bin/bash
+set -eu
+
+DRIVER_FILE="ubuntu24.04/nvidia-driver"
+
+if grep -F '    count=$(vgpu-util count)' "$DRIVER_FILE"; then
+    echo "FAIL: vgpu-util count uses unchecked command substitution" >&2
+    exit 1
+fi
+
+if grep -F '    version=$(vgpu-util match -i /drivers -c /drivers/vgpuDriverCatalog.yaml)' "$DRIVER_FILE"; then
+    echo "FAIL: vgpu-util match uses unchecked command substitution" >&2
+    exit 1
+fi
+
+echo "PASS: vgpu-util errors are caught with conditional command substitution"

Contributor guidelines

Per this repo's CONTRIBUTING.md:

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

Signed-off-by: andrewwhitecdw <andrewwhitecdw@users.noreply.github.com>
@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