use of org.opensearch.node.NodeValidationException in project OpenSearch by opensearch-project.
the class BootstrapChecksTests method runMightForkTest.
private void runMightForkTest(final BootstrapChecks.MightForkCheck check, final AtomicBoolean isSystemCallFilterInstalled, final Runnable disableMightFork, final Runnable enableMightFork, final Consumer<NodeValidationException> consumer) throws NodeValidationException {
// if system call filter is disabled, nothing should happen
isSystemCallFilterInstalled.set(false);
if (randomBoolean()) {
disableMightFork.run();
} else {
enableMightFork.run();
}
BootstrapChecks.check(emptyContext, true, Collections.singletonList(check));
// if system call filter is enabled, but we will not fork, nothing should
// happen
isSystemCallFilterInstalled.set(true);
disableMightFork.run();
BootstrapChecks.check(emptyContext, true, Collections.singletonList(check));
// if system call filter is enabled, and we might fork, the check should be enforced, regardless of bootstrap checks being enabled
// or not
isSystemCallFilterInstalled.set(true);
enableMightFork.run();
final NodeValidationException e = expectThrows(NodeValidationException.class, () -> BootstrapChecks.check(emptyContext, randomBoolean(), Collections.singletonList(check)));
consumer.accept(e);
}
use of org.opensearch.node.NodeValidationException in project OpenSearch by opensearch-project.
the class BootstrapChecksTests method testUseSerialGCCheck.
public void testUseSerialGCCheck() throws NodeValidationException {
final AtomicReference<String> useSerialGC = new AtomicReference<>("true");
final BootstrapCheck check = new BootstrapChecks.UseSerialGCCheck() {
@Override
String getUseSerialGC() {
return useSerialGC.get();
}
};
final NodeValidationException e = expectThrows(NodeValidationException.class, () -> BootstrapChecks.check(emptyContext, true, Collections.singletonList(check)));
assertThat(e.getMessage(), containsString("JVM is using the serial collector but should not be for the best performance; " + "" + "either it's the default for the VM [" + JvmInfo.jvmInfo().getVmName() + "] or -XX:+UseSerialGC was explicitly specified"));
useSerialGC.set("false");
BootstrapChecks.check(emptyContext, true, Collections.singletonList(check));
}
use of org.opensearch.node.NodeValidationException in project OpenSearch by opensearch-project.
the class BootstrapChecksTests method testMaxFileSizeCheck.
public void testMaxFileSizeCheck() throws NodeValidationException {
final long rlimInfinity = Constants.MAC_OS_X ? 9223372036854775807L : -1L;
final AtomicLong maxFileSize = new AtomicLong(randomIntBetween(0, Integer.MAX_VALUE));
final BootstrapChecks.MaxFileSizeCheck check = new BootstrapChecks.MaxFileSizeCheck() {
@Override
long getMaxFileSize() {
return maxFileSize.get();
}
@Override
long getRlimInfinity() {
return rlimInfinity;
}
};
final NodeValidationException e = expectThrows(NodeValidationException.class, () -> BootstrapChecks.check(emptyContext, true, Collections.singletonList(check)));
assertThat(e.getMessage(), containsString("max file size"));
maxFileSize.set(rlimInfinity);
BootstrapChecks.check(emptyContext, true, Collections.singletonList(check));
// nothing should happen if max file size is not available
maxFileSize.set(Long.MIN_VALUE);
BootstrapChecks.check(emptyContext, true, Collections.singletonList(check));
}
use of org.opensearch.node.NodeValidationException in project OpenSearch by opensearch-project.
the class BootstrapChecksTests method testMlockallCheck.
public void testMlockallCheck() throws NodeValidationException {
class MlockallCheckTestCase {
private final boolean mlockallSet;
private final boolean isMemoryLocked;
private final boolean shouldFail;
MlockallCheckTestCase(final boolean mlockallSet, final boolean isMemoryLocked, final boolean shouldFail) {
this.mlockallSet = mlockallSet;
this.isMemoryLocked = isMemoryLocked;
this.shouldFail = shouldFail;
}
}
final List<MlockallCheckTestCase> testCases = new ArrayList<>();
testCases.add(new MlockallCheckTestCase(true, true, false));
testCases.add(new MlockallCheckTestCase(true, false, true));
testCases.add(new MlockallCheckTestCase(false, true, false));
testCases.add(new MlockallCheckTestCase(false, false, false));
for (final MlockallCheckTestCase testCase : testCases) {
final BootstrapChecks.MlockallCheck check = new BootstrapChecks.MlockallCheck() {
@Override
boolean isMemoryLocked() {
return testCase.isMemoryLocked;
}
};
BootstrapContext bootstrapContext = createTestContext(Settings.builder().put("bootstrap.memory_lock", testCase.mlockallSet).build(), null);
if (testCase.shouldFail) {
final NodeValidationException e = expectThrows(NodeValidationException.class, () -> BootstrapChecks.check(bootstrapContext, true, Collections.singletonList(check)));
assertThat(e.getMessage(), containsString("memory locking requested for opensearch process but memory is not locked"));
} else {
// nothing should happen
BootstrapChecks.check(bootstrapContext, true, Collections.singletonList(check));
}
}
}
use of org.opensearch.node.NodeValidationException in project OpenSearch by opensearch-project.
the class BootstrapChecksTests method testAllPermissionCheck.
public void testAllPermissionCheck() throws NodeValidationException {
final AtomicBoolean isAllPermissionGranted = new AtomicBoolean(true);
final BootstrapChecks.AllPermissionCheck allPermissionCheck = new BootstrapChecks.AllPermissionCheck() {
@Override
boolean isAllPermissionGranted() {
return isAllPermissionGranted.get();
}
};
final List<BootstrapCheck> checks = Collections.singletonList(allPermissionCheck);
final NodeValidationException e = expectThrows(NodeValidationException.class, () -> BootstrapChecks.check(emptyContext, true, checks));
assertThat(e, hasToString(containsString("granting the all permission effectively disables security")));
// if all permissions are not granted, nothing should happen
isAllPermissionGranted.set(false);
BootstrapChecks.check(emptyContext, true, checks);
}
Aggregations