use of io.pravega.test.system.framework.kubernetes.K8sClient in project pravega by pravega.
the class K8SequentialExecutor method startTestExecution.
@Override
public CompletableFuture<Void> startTestExecution(Method testMethod) {
final String className = testMethod.getDeclaringClass().getName();
final String methodName = testMethod.getName();
// pod name is the combination of a test method name and random Alphanumeric. It cannot be more than 63 characters.
final String podName = (methodName + "-" + randomAlphanumeric(5)).toLowerCase();
log.info("Start execution of test {}#{} on the KUBERNETES Cluster", className, methodName);
final K8sClient client = ClientFactory.INSTANCE.getK8sClient();
Map<String, V1ContainerStatus> podStatusBeforeTest = getPravegaPodStatus(client);
final V1Pod pod = getTestPod(className, methodName, podName.toLowerCase());
final AtomicReference<CompletableFuture<Void>> logDownload = new AtomicReference<>(CompletableFuture.completedFuture(null));
return // create service Account, ignore if already present.
client.createServiceAccount(NAMESPACE, getServiceAccount()).thenCompose(// ensure test pod has cluster admin rights.
v -> client.createClusterRoleBinding(getClusterRoleBinding())).thenCompose(// deploy test pod.
v -> client.deployPod(NAMESPACE, pod)).thenCompose(v -> {
// start download of logs.
if (!Utils.isSkipLogDownloadEnabled()) {
logDownload.set(client.downloadLogs(pod, "./build/test-results/" + podName));
}
return client.waitUntilPodCompletes(NAMESPACE, podName);
}).handle((s, t) -> {
Futures.getAndHandleExceptions(logDownload.get(), t1 -> {
log.error("Failed to download logs for {}#{}", className, methodName, t1);
return null;
});
if (t == null) {
log.info("Test {}#{} execution completed with status {}", className, methodName, s);
verifyPravegaPodRestart(podStatusBeforeTest, getPravegaPodStatus(client));
if (s.getExitCode() != 0) {
log.error("Test {}#{} failed. Details: {}", className, methodName, s);
throw new AssertionError(methodName + " test failed due to " + s.getReason() + " with message " + s.getMessage());
} else {
return null;
}
} else {
throw new CompletionException("Error while invoking the test " + podName, t);
}
});
}
Aggregations