in src/main/java/com/awslabs/aws/greengrass/provisioner/implementations/helpers/BasicGroupTestHelper.java [375:453]
private void handleLogMessage(String logMessage,
java.util.HashMap<String, Try> testStatus,
java.util.List<String> reportLocations) {
deviceTesterHelper.log(logMessage);
DeviceTesterLogMessageType logMessageType = deviceTesterHelper.getLogMessageType(logMessage);
// Failure to add a remote file resource can indicate that there was a failure to sudo inside of device tester
if (logMessageType.equals(DeviceTesterLogMessageType.FAIL_TO_ADD_REMOTE_FILE_RESOURCE)) {
log.warn("The user running Device Tester on the remote host may not have permissions to sudo without a password.");
log.warn("To use GGP with Device Tester the user will need to be able to perform a passwordless sudo.");
log.warn("To enable passwordless sudo see this article: https://serverfault.com/a/160587");
log.warn("");
log.warn("If Device Tester fails after this point please enable passwordless sudo for the user and try again.");
}
io.vavr.collection.Map<String, String> values = deviceTesterHelper.extractValuesFromLogMessage(logMessage);
Option<String> optionalTestCaseId = deviceTesterHelper.getOptionalTestCaseId(values);
if (logMessageType.equals(DeviceTesterLogMessageType.RUNNING)) {
// A test started
// Clear the test name
optionalCurrentRunningTest = Option.none();
}
if (optionalTestCaseId.isDefined()) {
// Use the test name from one of these specific message types since the test name is not always consistent across log messages
if (optionalCurrentRunningTest.isEmpty()) {
// If there's no existing name then use the current one
optionalCurrentRunningTest = optionalTestCaseId;
} else {
String currentRunningTest = optionalCurrentRunningTest.get();
String testCaseId = optionalTestCaseId.get();
if (testCaseId.length() > currentRunningTest.length()) {
// Use the longest (most precise) test name available
optionalCurrentRunningTest = optionalTestCaseId;
}
}
}
if (logMessageType.equals(DeviceTesterLogMessageType.ALL_TESTS_FINISHED)) {
String message = deviceTesterHelper.extractValuesFromLogMessage(logMessage).get(DeviceTesterHelper.MESSAGE_FIELD_NAME).get();
String aggregatedReportLocation = message.substring(DeviceTesterLogMessageType.Constants.ALL_TESTS_FINISHED_MESSAGE.length());
reportLocations.add(aggregatedReportLocation);
return;
}
if (logMessageType.equals(DeviceTesterLogMessageType.REPORT_GENERATED)) {
String message = deviceTesterHelper.extractValuesFromLogMessage(logMessage).get(DeviceTesterHelper.MESSAGE_FIELD_NAME).get();
String reportLocation = message.substring(DeviceTesterLogMessageType.Constants.REPORT_GENERATED_MESSAGE.length());
reportLocations.add(reportLocation);
return;
}
if (!logMessageType.equals(DeviceTesterLogMessageType.FAIL_WITH_DURATION) &&
!(logMessageType.equals(DeviceTesterLogMessageType.PASS))) {
// Not a pass/fail message
return;
}
String currentRunningTest = optionalCurrentRunningTest.get();
// A test passed or failed
// Store the related log lines in the test log index
/*
getTestLogs(currentRunningTest, logs, testLogIndex);
*/
// Store the pass/fail status
if (logMessageType.equals(DeviceTesterLogMessageType.FAIL_WITH_DURATION)) {
testStatus.put(currentRunningTest, Try.failure(new RuntimeException("Test failed")));
} else {
testStatus.put(currentRunningTest, Try.success(null));
}
}