nvidia_desktop_pre_installation_hook raises on package names with suffixes

Bug #2019016 reported by Fox Danger Piacenti
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
ubuntu-drivers-common (Ubuntu)
New
Undecided
Unassigned

Bug Description

The function nvidia_desktop_pre_installation_hook in /usr/lib/python3/dist-packages/UbuntuDrivers/detect.py on Ubuntu 22.04.2 LTS assumes that the driver package name ends with the driver version as the suffix.

However this does not account for the '-open' drivers. The following code from that function is at fault:

```
    # Enable KMS if nvidia >= 470
    for package_name in to_install:
        if package_name.startswith('nvidia-driver-'):
           try:
               version = int(package_name.split('-')[-1]) # <--- This here
               with_nvidia_kms = version >= 470
           except ValueError:
               pass
           finally:
               with_nvidia_kms = version >= 470 # <-- And this here, too, which will never succeed.

```

The line `version = int(package_name.split('-')[-1])` assumes a package name like `nvidia-driver-530` rather than `nvidia-driver-530-open`, however `nvidia-driver-530-open` is the autoselected package for my install.

This code could be fixed by switching to a regex, or else retrying with index -2 rather than index -1.

Also, the `finally` clause will always fail-- there should only ever be one matching `nvidia-driver-` prefixed package, and if that raises a ValueError, then `version` will not be set, raising an UnboundLocalError.

ProblemType: Bug
DistroRelease: Ubuntu 22.04
Package: ubuntu-drivers-common 1:0.9.6.1 [modified: usr/lib/python3/dist-packages/UbuntuDrivers/detect.py]
ProcVersionSignature: Ubuntu 5.19.0-41.42~22.04.1-generic 5.19.17
Uname: Linux 5.19.0-41-generic x86_64
ApportVersion: 2.20.11-0ubuntu82.4
Architecture: amd64
CasperMD5CheckResult: pass
CurrentDesktop: ubuntu:GNOME
Date: Tue May 9 10:47:07 2023
InstallationDate: Installed on 2022-08-20 (261 days ago)
InstallationMedia: Ubuntu 22.04.1 LTS "Jammy Jellyfish" - Release amd64 (20220809.1)
ProcEnviron:
 TERM=xterm-256color
 PATH=(custom, no user)
 XDG_RUNTIME_DIR=<set>
 LANG=en_US.UTF-8
 SHELL=/bin/zsh
SourcePackage: ubuntu-drivers-common
UpgradeStatus: No upgrade log present (probably fresh install)

Revision history for this message
Fox Danger Piacenti (foxyfoxie) wrote :
Revision history for this message
Alberto Milone (albertomilone) wrote :

Hi Fox, can you try ubuntu-drivers 1:0.9.6.2~0.22.04.3 from proposed, please?

The problem should be LP: #1993019

Revision history for this message
Fox Danger Piacenti (foxyfoxie) wrote :

Hi Alberto,

That seems to have worked for me. Thanks!

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.