Skip to content
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

Feature to Install NVIDIA GPU Drivers and CUDA Toolkit in Windows #87

Merged
merged 13 commits into from
May 16, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace VirtualClient.Dependencies
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -43,6 +44,7 @@ public class CUDAAndNvidiaGPUDriverInstallationTests
private TestComponent component;
private Mock<ProcessManager> mockProcessManager;
private State mockState;
private DependencyPath mockPackage;

[SetUp]
public void SetupTests()
Expand All @@ -56,15 +58,6 @@ public void TearDown()
this.component.Dispose();
}

[Test]
public void CUDAAndNvidiaGPUDriverInstallationDependencyThrowsForPlatformsOtherThanUnix()
{
this.SetupDefaultMockBehavior(PlatformID.Win32NT, "11.6");

WorkloadException exc = Assert.ThrowsAsync<WorkloadException>(() => this.component.ExecuteAsync(CancellationToken.None));
Assert.AreEqual(ErrorReason.PlatformNotSupported, exc.Reason);
}

[Test]
public void CUDAAndNvidiaGPUDriverInstallationDependencyThrowsForUnsupportedDistros()
{
Expand All @@ -82,10 +75,9 @@ public void CUDAAndNvidiaGPUDriverInstallationDependencyThrowsForUnsupportedDist
}

[Test]
[TestCase("11.6")]
public async Task CUDAAndNvidiaGPUDriverInstallationDependencyStartsCorrectProcessesOnExecute(string version)
public async Task CUDAAndNvidiaGPUDriverInstallationDependencyStartsCorrectProcessesOnExecute()
{
this.SetupDefaultMockBehavior(PlatformID.Unix, version);
this.SetupDefaultMockBehavior(PlatformID.Unix);

this.SetupProcessManager("sudo", UpdateCommand, Environment.CurrentDirectory);
this.SetupProcessManager("sudo", BuildEssentialInstallationCommand, Environment.CurrentDirectory);
Expand All @@ -103,10 +95,9 @@ public async Task CUDAAndNvidiaGPUDriverInstallationDependencyStartsCorrectProce
}

[Test]
[TestCase("11.6")]
public async Task CUDAAndNvidiaGPUDriverInstallationDependencyDoesNotInstallCUDAAndNvidiaGPUDriverIfAlreadyInstalled(string version)
public async Task CUDAAndNvidiaGPUDriverInstallationDependencyDoesNotInstallCUDAAndNvidiaGPUDriverIfAlreadyInstalled()
{
this.SetupDefaultMockBehavior(PlatformID.Unix, version);
this.SetupDefaultMockBehavior(PlatformID.Unix);

this.fixture.StateManager.OnGetState(nameof(CudaAndNvidiaGPUDriverInstallation)).ReturnsAsync(JObject.FromObject(this.mockState));

Expand All @@ -117,10 +108,9 @@ public async Task CUDAAndNvidiaGPUDriverInstallationDependencyDoesNotInstallCUDA
}

[Test]
[TestCase("11.6")]
public void CUDAAndNvidiaGPUDriverInstallationDependencySurfacesExceptionWhenProcessDoesNotExitSuccessfullyOnExecute(string version)
public void CUDAAndNvidiaGPUDriverInstallationDependencySurfacesExceptionWhenProcessDoesNotExitSuccessfullyOnExecute()
{
this.SetupDefaultMockBehavior(PlatformID.Unix, version);
this.SetupDefaultMockBehavior(PlatformID.Unix);

this.SetupProcessManager("sudo", UpdateCommand, Environment.CurrentDirectory);
this.SetupProcessManager("sudo", BuildEssentialInstallationCommand, Environment.CurrentDirectory);
Expand All @@ -138,17 +128,45 @@ public void CUDAAndNvidiaGPUDriverInstallationDependencySurfacesExceptionWhenPro
Assert.AreEqual(ErrorReason.DependencyInstallationFailed, exc.Reason);
}

private void SetupDefaultMockBehavior(PlatformID platformID, string version = "")
[Test]
public async Task CUDAAndNvidiaGPUDriverInstallationDependencyExecutesCorrectInsatllerCommandOnWindows()
{
this.fixture.Setup(platformID);
this.SetupDefaultMockBehavior(PlatformID.Win32NT);
this.fixture.Parameters["packageName"] = "NvidiaDrivers";
this.fixture.Directory.Setup(di => di.Exists(It.IsAny<string>()))
.Returns(true);

this.fixture.FileSystem.Setup(fe => fe.FileStream.Create(It.IsAny<string>(), FileMode.Create, FileAccess.Write, FileShare.None))
.Returns(Stream.Null);

this.fixture.FileSystem.Setup(fe => fe.Directory.GetFiles(It.IsAny<string>(), It.IsAny<string>(), SearchOption.AllDirectories))
.Returns(new string[] { this.fixture.Combine(this.mockPackage.Path, "nvidiaDriversInstaller.exe") });

this.fixture.FileSystem.Setup(fe => fe.Directory.GetCurrentDirectory())
.Returns(this.mockPackage.Path);

this.SetupProcessManager(this.fixture.Combine(this.mockPackage.Path, "nvidiaDriversInstaller.exe"), "-y -s", Environment.CurrentDirectory);

this.component = new TestComponent(this.fixture.Dependencies, this.fixture.Parameters);

await this.component.ExecuteAsync(CancellationToken.None);
this.mockProcessManager.Verify();
}

private void SetupDefaultMockBehavior(PlatformID platformID)
{
this.fixture.Setup(platformID);
this.mockPackage = new DependencyPath("NvidiaDrivers", this.fixture.GetPackagePath("NvidiaDrivers"));
this.fixture.PackageManager.OnGetPackage("NvidiaDrivers").ReturnsAsync(this.mockPackage);
this.mockProcessManager = new Mock<ProcessManager>();

this.fixture.Parameters = new Dictionary<string, IConvertible>()
{
{ "CudaVersion", "11.6" },
{ "DriverVersion", "510" },
{ "LinuxCudaVersion", "11.6" },
{ "LinuxDriverVersion", "510" },
{ "Username", "anyuser" },
{ "LocalRunFile", "https://developer.download.nvidia.com/compute/cuda/11.6.0/local_installers/cuda_11.6.0_510.39.01_linux.run" }
{ "LinuxLocalRunFile", "https://developer.download.nvidia.com/compute/cuda/11.6.0/local_installers/cuda_11.6.0_510.39.01_linux.run" },
{ "RebootRequired", false }
};

this.component = new TestComponent(this.fixture.Dependencies, this.fixture.Parameters);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace VirtualClient.Dependencies.Packaging
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -158,6 +159,59 @@ public async Task WgetPackageInstallationExecutesTheExpectedOperationsOnWindowsS
}
}

[Test]
[TestCase(PlatformID.Unix, Architecture.X64, "wget")]
[TestCase(PlatformID.Unix, Architecture.Arm64, "wget")]
[TestCase(PlatformID.Win32NT, Architecture.X64, "wget.exe")]
[TestCase(PlatformID.Win32NT, Architecture.Arm64, "wget.exe")]
public async Task WgetPackageInstallationExecutesTheExpectedOperationsForNonArchiveFileType(PlatformID platform, Architecture architecture, string wgetBinary)
{
this.SetupDefaults(platform, architecture);

this.mockFixture.Parameters = new Dictionary<string, IConvertible>
{
{ nameof(WgetPackageInstallation.PackageName), "any-package" },
{ nameof(WgetPackageInstallation.PackageUri), "https://any.company.com/files/any-file.1.0.0.exe" }
};

using (WgetPackageInstallation installation = new WgetPackageInstallation(this.mockFixture.Dependencies, this.mockFixture.Parameters))
{
installation.RetryPolicy = Policy.NoOpAsync();

string expectedDownloadPath = this.mockFixture.GetPackagePath("any-file.1.0.0.exe");
string expectedPackageRegistrationPath = this.mockFixture.GetPackagePath("any-package");
string expectedDownloadedFileCopyPath = this.mockFixture.GetPackagePath("any-package", "any-file.1.0.0.exe");

bool downloadPathConfirmed = false;
bool installationPathConfirmed = false;
bool packageRegistrationConfirmed = false;

// The package will be copied to expectedDownloadedFileCopyPath on the system once it is downloaded.
// e.g.
// /packages/any-file.1.0.0.exe -> /packages/any-package/any-file.1.0.0.exe
this.mockFixture.FileSystem.Setup(fe => fe.File.Copy(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>()))
.Callback<string, string, bool>((downloadFilePath, destinationPath, overWrite) =>
{
downloadPathConfirmed = downloadFilePath.Equals(expectedDownloadPath);
installationPathConfirmed = destinationPath.Equals(expectedDownloadedFileCopyPath);
});

// Once the package is downloaded and copied, it is registered on the system with Virtual Client.
this.mockFixture.PackageManager.Setup(mgr => mgr.RegisterPackageAsync(It.IsAny<DependencyPath>(), It.IsAny<CancellationToken>()))
.Callback<DependencyPath, CancellationToken>((package, token) =>
{
packageRegistrationConfirmed = package.Name == installation.PackageName && package.Path == expectedPackageRegistrationPath;
});

await installation.ExecuteAsync(CancellationToken.None);

Assert.IsTrue(this.mockFixture.ProcessManager.CommandsExecuted($"{wgetBinary} {installation.PackageUri}"), "Wget download command incorrect.");
Assert.IsTrue(downloadPathConfirmed, "Archive file path incorrect.");
Assert.IsTrue(installationPathConfirmed, "Package installation path incorrect.");
Assert.IsTrue(packageRegistrationConfirmed, "Package registration incorrect.");
}
}

[Test]
[TestCase(PlatformID.Unix, Architecture.X64)]
[TestCase(PlatformID.Unix, Architecture.Arm64)]
Expand Down
Loading