Disable nouveau driver

Change-Id: I7f4ba2ba173d40baa9ba140007e7c4bb8055f000
This commit is contained in:
Aurelien Lourot 2022-03-01 16:43:13 +01:00
parent 46eb5aedd6
commit ffef5fe4bc
4 changed files with 28 additions and 2 deletions

View File

@ -95,6 +95,11 @@ def install_nvidia_software_if_needed(stored, config, resources):
apt_install([nvidia_software_path], fatal=True)
stored.last_installed_resource_hash = nvidia_software_hash
# The nouveau driver prevents the nvidia-vgpu-mgr service from
# starting, thus it needs to be disabled. Unfortunately this requires
# a reboot. The operator will be notified via a blocked unit status.
nvidia_utils.disable_nouveau_driver()
def check_status(config, services):
"""Determine the unit status to be set.

View File

@ -16,8 +16,11 @@
import logging
import os
from charmhelpers.core.hookenv import cached
from charmhelpers.core.kernel import update_initramfs
from charmhelpers.core.templating import render
from charmhelpers.fetch import (
apt_cache,
)
@ -45,6 +48,17 @@ def installed_nvidia_software_package_names():
_installed_nvidia_software_packages()]
def disable_nouveau_driver():
"""Disable the nouveau driver.
This driver prevents the nvidia-vgpu-mgr service from starting. A reboot is
required.
"""
config_file = '/etc/modprobe.d/disable-nouveau.conf'
render(os.path.basename(config_file), config_file, {})
update_initramfs()
@cached
def has_nvidia_gpu_hardware():
"""Search for NVIDIA GPU hardware.

View File

@ -0,0 +1,2 @@
blacklist nouveau
options nouveau modeset=0

View File

@ -15,7 +15,7 @@
import sys
import unittest
from mock import MagicMock, patch
from mock import ANY, MagicMock, patch
sys.path.append('src') # noqa
@ -45,12 +45,14 @@ class TestCharmUtils(unittest.TestCase):
charm_utils.is_nvidia_software_to_be_installed_notcached({
'force-install-nvidia-vgpu': False}))
@patch('nvidia_utils.update_initramfs')
@patch('nvidia_utils.render')
@patch('charm_utils.apt_install')
@patch('charm_utils._path_and_hash_nvidia_resource')
@patch('charm_utils.is_nvidia_software_to_be_installed')
def test_install_nvidia_software_if_needed(
self, is_software_to_be_installed_mock, path_and_hash_mock,
apt_install_mock):
apt_install_mock, render_template_mock, update_initramfs_mock):
is_software_to_be_installed_mock.return_value = True
unit_stored_state = MagicMock()
unit_stored_state.last_installed_resource_hash = 'hash-1'
@ -75,6 +77,9 @@ class TestCharmUtils(unittest.TestCase):
None)
apt_install_mock.assert_called_once_with(['path-to-software'],
fatal=True)
render_template_mock.assert_called_once_with(
'disable-nouveau.conf', ANY, ANY)
update_initramfs_mock.assert_called_once_with()
@patch('charm_utils.ows_check_services_running')
@patch('charm_utils.is_nvidia_software_to_be_installed')