Search in sources :

Example 1 with K8sClient

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);
        }
    });
}
Also used : TestExecutor(io.pravega.test.system.framework.TestExecutor) RandomStringUtils.randomAlphanumeric(org.apache.commons.lang.RandomStringUtils.randomAlphanumeric) CompletableFuture(java.util.concurrent.CompletableFuture) TestFrameworkException(io.pravega.test.system.framework.TestFrameworkException) AtomicReference(java.util.concurrent.atomic.AtomicReference) V1VolumeMountBuilder(io.kubernetes.client.openapi.models.V1VolumeMountBuilder) V1VolumeBuilder(io.kubernetes.client.openapi.models.V1VolumeBuilder) Map(java.util.Map) NotImplementedException(org.apache.commons.lang.NotImplementedException) V1beta1ClusterRoleBinding(io.kubernetes.client.openapi.models.V1beta1ClusterRoleBinding) V1ServiceAccount(io.kubernetes.client.openapi.models.V1ServiceAccount) V1ContainerStatus(io.kubernetes.client.openapi.models.V1ContainerStatus) V1SecretVolumeSourceBuilder(io.kubernetes.client.openapi.models.V1SecretVolumeSourceBuilder) Utils(io.pravega.test.system.framework.Utils) V1beta1RoleRefBuilder(io.kubernetes.client.openapi.models.V1beta1RoleRefBuilder) Method(java.lang.reflect.Method) ImmutableMap(com.google.common.collect.ImmutableMap) K8sClient(io.pravega.test.system.framework.kubernetes.K8sClient) V1ServiceAccountBuilder(io.kubernetes.client.openapi.models.V1ServiceAccountBuilder) CompletionException(java.util.concurrent.CompletionException) Collectors(java.util.stream.Collectors) ClientFactory(io.pravega.test.system.framework.kubernetes.ClientFactory) V1beta1ClusterRoleBindingBuilder(io.kubernetes.client.openapi.models.V1beta1ClusterRoleBindingBuilder) Slf4j(lombok.extern.slf4j.Slf4j) V1PersistentVolumeClaimVolumeSourceBuilder(io.kubernetes.client.openapi.models.V1PersistentVolumeClaimVolumeSourceBuilder) V1PodBuilder(io.kubernetes.client.openapi.models.V1PodBuilder) V1beta1SubjectBuilder(io.kubernetes.client.openapi.models.V1beta1SubjectBuilder) V1ObjectMetaBuilder(io.kubernetes.client.openapi.models.V1ObjectMetaBuilder) Futures(io.pravega.common.concurrent.Futures) V1Pod(io.kubernetes.client.openapi.models.V1Pod) CompletableFuture(java.util.concurrent.CompletableFuture) K8sClient(io.pravega.test.system.framework.kubernetes.K8sClient) V1ContainerStatus(io.kubernetes.client.openapi.models.V1ContainerStatus) CompletionException(java.util.concurrent.CompletionException) V1Pod(io.kubernetes.client.openapi.models.V1Pod) AtomicReference(java.util.concurrent.atomic.AtomicReference)

Aggregations

ImmutableMap (com.google.common.collect.ImmutableMap)1 V1ContainerStatus (io.kubernetes.client.openapi.models.V1ContainerStatus)1 V1ObjectMetaBuilder (io.kubernetes.client.openapi.models.V1ObjectMetaBuilder)1 V1PersistentVolumeClaimVolumeSourceBuilder (io.kubernetes.client.openapi.models.V1PersistentVolumeClaimVolumeSourceBuilder)1 V1Pod (io.kubernetes.client.openapi.models.V1Pod)1 V1PodBuilder (io.kubernetes.client.openapi.models.V1PodBuilder)1 V1SecretVolumeSourceBuilder (io.kubernetes.client.openapi.models.V1SecretVolumeSourceBuilder)1 V1ServiceAccount (io.kubernetes.client.openapi.models.V1ServiceAccount)1 V1ServiceAccountBuilder (io.kubernetes.client.openapi.models.V1ServiceAccountBuilder)1 V1VolumeBuilder (io.kubernetes.client.openapi.models.V1VolumeBuilder)1 V1VolumeMountBuilder (io.kubernetes.client.openapi.models.V1VolumeMountBuilder)1 V1beta1ClusterRoleBinding (io.kubernetes.client.openapi.models.V1beta1ClusterRoleBinding)1 V1beta1ClusterRoleBindingBuilder (io.kubernetes.client.openapi.models.V1beta1ClusterRoleBindingBuilder)1 V1beta1RoleRefBuilder (io.kubernetes.client.openapi.models.V1beta1RoleRefBuilder)1 V1beta1SubjectBuilder (io.kubernetes.client.openapi.models.V1beta1SubjectBuilder)1 Futures (io.pravega.common.concurrent.Futures)1 TestExecutor (io.pravega.test.system.framework.TestExecutor)1 TestFrameworkException (io.pravega.test.system.framework.TestFrameworkException)1 Utils (io.pravega.test.system.framework.Utils)1 ClientFactory (io.pravega.test.system.framework.kubernetes.ClientFactory)1