Skip to content

Commit

Permalink
Changes for ARM Architecture
Browse files Browse the repository at this point in the history
  • Loading branch information
michalxo committed Apr 15, 2024
1 parent 4af81f9 commit 9b27073
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 1 deletion.
2 changes: 1 addition & 1 deletion common/src/main/java/io/brokerqe/claire/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public interface Constants {
String IMAGE_SYSTEMTEST_CLI_RHEA = "quay.io/messaging/cli-rhea:latest";
String IMAGE_MQTT_CLIENT = "quay.io/rhmessagingqe/hivemq-mqtt-cli";
// String IMAGE_OPENLDAP = "docker.io/bitnami/openldap:latest";
String IMAGE_OPENLDAP = "docker.io/bitnami/openldap:2.6.3";
String IMAGE_OPENLDAP = "docker.io/bitnami/openldap:2.6.7";
String IMAGE_POSTGRES = "docker.io/bitnami/postgresql:latest";
String IMAGE_MYSQL = "docker.io/bitnami/mysql:latest";
String IMAGE_MARIADB = "docker.io/bitnami/mariadb:latest";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* Copyright Broker QE authors.
* License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html).
*/
package io.brokerqe.claire;

public enum KubernetesArchitecture {
AMD64,
ARM64,
PPC64LE,
S390X // IBM Z
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* Copyright Broker QE authors.
* License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html).
*/
package io.brokerqe.claire.junit;

import io.brokerqe.claire.KubeClient;
import io.brokerqe.claire.KubernetesArchitecture;
import io.brokerqe.claire.ResourceManager;
import io.fabric8.kubernetes.api.model.Node;
import org.junit.jupiter.api.extension.ConditionEvaluationResult;
import org.junit.jupiter.api.extension.ExecutionCondition;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.platform.commons.PreconditionViolationException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.AnnotatedElement;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Locale;
import java.util.stream.Collectors;

import static org.junit.platform.commons.util.AnnotationUtils.findAnnotation;

/**
* This annotation disables execution of test/s for specified architecture.
* Supported values are "AMD64", "ARM64", "PPC64LE" and "S390X".
*/

@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@ExtendWith(DisabledTestArchitecture.SupportedPlatformTestCondition.class)
public @interface DisabledTestArchitecture {
KubernetesArchitecture[] archs();

class SupportedPlatformTestCondition implements ExecutionCondition {
private final static Logger LOGGER = LoggerFactory.getLogger(SupportedPlatformTestCondition.class);
private static final ConditionEvaluationResult ENABLED = ConditionEvaluationResult.enabled("@PlatformTest is not present");

@Override
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
AnnotatedElement element = context.getElement().orElse(null);
String testname = context.getRequiredTestClass().getName();
try {
testname += context.getRequiredTestMethod().getName();
} catch (PreconditionViolationException ignored) { }
String finalTestname = testname;
ConditionEvaluationResult result = findAnnotation(element, DisabledTestArchitecture.class).map(annotation -> toResult(element, annotation, finalTestname)).orElse(ENABLED);
return result;
}

private ConditionEvaluationResult toResult(AnnotatedElement element, DisabledTestArchitecture annotation, String testName) {
// convert Array of KubernetesArchitecture Enums to item.name() strings list
List<String> disabledArchNames = Arrays.stream(annotation.archs()).toList().stream().map(KubernetesArchitecture::name).collect(Collectors.toList());
Collection<KubeClient> kubeClients = ResourceManager.getEnvironment().getKubeClients().values();

for (KubeClient kubeClient : kubeClients) {
List<Node> nodes = kubeClient.getKubernetesClient().nodes().list().getItems();
for (Node node : nodes) {
String nodeArch = node.getMetadata().getLabels().get("kubernetes.io/arch");
if (disabledArchNames.contains(nodeArch.toUpperCase(Locale.ROOT))) {
LOGGER.trace("{} in {}", nodeArch, disabledArchNames);
LOGGER.info("[TEST][{}] Skipped: Test/class can't be executed on {} DisabledTestArchitecture criteria.", testName, nodeArch);
return ConditionEvaluationResult.disabled("[TEST] Skipped: Unsupported architecture for this test. " + nodeArch);
} else {
LOGGER.trace("{} not in {}", nodeArch, disabledArchNames);
return ConditionEvaluationResult.enabled("[TEST] Enabled on this architecture " + nodeArch);
}
}
}
return ConditionEvaluationResult.disabled("[TEST] No nodes info found. Disabling test.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.io.File;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;

public class Openldap {

Expand Down Expand Up @@ -95,6 +96,7 @@ public class Openldap {
.withRunAsNonRoot(true)
.withNewCapabilities()
.withDrop("ALL")
.withAdd("NET_BIND_SERVICE")
.endCapabilities()
.endSecurityContext()
.withPorts(new ContainerPortBuilder()
Expand Down Expand Up @@ -140,6 +142,7 @@ public void deployLdap() {
kubeClient.createSecretStringData(namespace, secretName, secretData, true);
openldapDeployment = kubeClient.getKubernetesClient().resource(openldapDeployment).inNamespace(namespace).createOrReplace();
service = kubeClient.getKubernetesClient().services().inNamespace(namespace).resource(service).createOrReplace();
kubeClient.getKubernetesClient().resource(openldapDeployment).waitUntilReady(2, TimeUnit.MINUTES);
}

public void undeployLdap() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
import io.brokerqe.claire.ArtemisConstants;
import io.brokerqe.claire.ArtemisVersion;
import io.brokerqe.claire.Constants;
import io.brokerqe.claire.KubernetesArchitecture;
import io.brokerqe.claire.ResourceManager;
import io.brokerqe.claire.junit.DisabledTestArchitecture;
import io.brokerqe.claire.junit.TestValidSince;
import io.brokerqe.claire.operator.ArtemisFileProvider;
import org.junit.jupiter.api.AfterAll;
Expand All @@ -22,6 +24,7 @@
import java.util.Map;

@TestValidSince(ArtemisVersion.VERSION_2_28)
@DisabledTestArchitecture(archs = KubernetesArchitecture.ARM64)
public class KeycloakLdapTests extends LdapTests {

private static final Logger LOGGER = LoggerFactory.getLogger(KeycloakLdapTests.class);
Expand Down

0 comments on commit 9b27073

Please sign in to comment.