YARN-10593. Fix incorrect string comparison in GpuDiscoverer. Contributed by Peter Bacsko

This commit is contained in:
Szilard Nemeth 2021-02-10 13:09:11 +01:00
parent 798df6d699
commit cacc870389
2 changed files with 31 additions and 5 deletions

View File

@ -284,11 +284,12 @@ public class GpuDiscoverer extends Configured {
binaryPath = configuredBinaryFile; binaryPath = configuredBinaryFile;
// If path exists but file name is incorrect don't execute the file // If path exists but file name is incorrect don't execute the file
String fileName = binaryPath.getName(); String fileName = binaryPath.getName();
if (DEFAULT_BINARY_NAME.equals(fileName)) { if (!DEFAULT_BINARY_NAME.equals(fileName)) {
String msg = String.format("Please check the configuration value of" String msg = String.format("Please check the configuration value of"
+" %s. It should point to an %s binary.", +" %s. It should point to an %s binary, which is now %s",
YarnConfiguration.NM_GPU_PATH_TO_EXEC, YarnConfiguration.NM_GPU_PATH_TO_EXEC,
DEFAULT_BINARY_NAME); DEFAULT_BINARY_NAME,
fileName);
throwIfNecessary(new YarnException(msg), config); throwIfNecessary(new YarnException(msg), config);
LOG.warn(msg); LOG.warn(msg);
} }

View File

@ -79,12 +79,23 @@ public class TestGpuDiscoverer {
} }
private File setupFakeBinary(Configuration conf) { private File setupFakeBinary(Configuration conf) {
return setupFakeBinary(conf,
GpuDiscoverer.DEFAULT_BINARY_NAME, false);
}
private File setupFakeBinary(Configuration conf, String filename,
boolean useFullPath) {
File fakeBinary; File fakeBinary;
try { try {
fakeBinary = new File(getTestParentFolder(), fakeBinary = new File(getTestParentFolder(),
GpuDiscoverer.DEFAULT_BINARY_NAME); filename);
touchFile(fakeBinary); touchFile(fakeBinary);
if (useFullPath) {
conf.set(YarnConfiguration.NM_GPU_PATH_TO_EXEC,
fakeBinary.getAbsolutePath());
} else {
conf.set(YarnConfiguration.NM_GPU_PATH_TO_EXEC, getTestParentFolder()); conf.set(YarnConfiguration.NM_GPU_PATH_TO_EXEC, getTestParentFolder());
}
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException("Failed to init fake binary", e); throw new RuntimeException("Failed to init fake binary", e);
} }
@ -513,4 +524,18 @@ public class TestGpuDiscoverer {
verify(gpuSpy, never()).getGpuDeviceInformation(); verify(gpuSpy, never()).getGpuDeviceInformation();
} }
@Test
public void testBinaryIsNotNvidiaSmi() throws YarnException {
exception.expect(YarnException.class);
exception.expectMessage(String.format(
"It should point to an %s binary, which is now %s",
"nvidia-smi", "badfile"));
Configuration conf = new Configuration(false);
setupFakeBinary(conf, "badfile", true);
GpuDiscoverer plugin = new GpuDiscoverer();
plugin.initialize(conf, binaryHelper);
}
} }