diff --git a/common/src/main/java/io/brokerqe/claire/Constants.java b/common/src/main/java/io/brokerqe/claire/Constants.java index 44984888..4c9f150c 100644 --- a/common/src/main/java/io/brokerqe/claire/Constants.java +++ b/common/src/main/java/io/brokerqe/claire/Constants.java @@ -10,7 +10,7 @@ public interface Constants { // Platform related strings String LINE_SEPARATOR = System.getProperty("line.separator"); String FILE_SEPARATOR = System.getProperty("file.separator"); - String DATE_FORMAT = "yyyy-MM-dd_HH:mm:ss"; + String DATE_FORMAT = "yyyy-MM-dd_HH-mm-ss"; // Test tags String TAG_JAAS = "jaas"; @@ -57,7 +57,7 @@ public interface Constants { // Test related strings String DEFAULT_KEYCLOAK_VERSION = "22.0.5"; - String DEFAULT_RHSSO_VERSION = "rhbk-operator.v22.0.6-opr.1"; + String DEFAULT_RHSSO_VERSION = "rhbk-operator.v22.0.7-opr.1"; // Networking String AMQP = "amqp"; @@ -79,6 +79,7 @@ public interface Constants { long DURATION_2_MINUTES = Duration.ofMinutes(2).toMillis(); long DURATION_3_MINUTES = Duration.ofMinutes(3).toMillis(); long DURATION_5_MINUTES = Duration.ofMinutes(5).toMillis(); + // Files String PROJECT_USER_DIR = System.getProperty("user.dir"); String PROJECT_TEST_DIR = PROJECT_USER_DIR + "/src/test"; @@ -86,7 +87,7 @@ public interface Constants { String TMP_DEFAULT_DIR = PROJECT_USER_DIR + "/test-tmp"; String DUMP_DEFAULT_DIR = PROJECT_USER_DIR + "/serialization-dump"; String DUMP_DEFAULT_TYPE = "yaml"; - String CERTS_GENERATION_DIR = PROJECT_USER_DIR + "/certificates/"; + String CERTS_GENERATION_DIR = "certificates"; String PROJECT_SETTINGS_PATH = PROJECT_USER_DIR + "/artemis/project-settings.properties"; String OPERATOR_CRDS_DIR_PATH = PROJECT_USER_DIR + "/artemis/crds/"; String OPERATOR_INSTALL_DIR_PATH = PROJECT_USER_DIR + "/artemis/install/"; @@ -135,7 +136,7 @@ public interface Constants { String PROP_YACFG_ARTEMIS_TEMPLATES_OVERRIDE_DIR = "yacfg.artemis.templates_override_dir"; String ARTEMIS_DEFAULT_CFG_DIR = "artemis/artemis_default_cfg"; - String ARTEMIS_TEST_CFG_DIR = "test_cfg"; + String ARTEMIS_TEST_CFG_DIR = "test-cfg"; String ARTEMIS_DEFAULT_CFG_BIN_DIR = ARTEMIS_DEFAULT_CFG_DIR + FILE_SEPARATOR + ArtemisConstants.BIN_DIR; String ARTEMIS_DEFAULT_CFG_LIB_DIR = ARTEMIS_DEFAULT_CFG_DIR + FILE_SEPARATOR + ArtemisConstants.LIB_DIR; diff --git a/common/src/main/java/io/brokerqe/claire/Environment.java b/common/src/main/java/io/brokerqe/claire/Environment.java index a16bf43f..71bfef68 100644 --- a/common/src/main/java/io/brokerqe/claire/Environment.java +++ b/common/src/main/java/io/brokerqe/claire/Environment.java @@ -26,6 +26,9 @@ public abstract class Environment { public abstract ArtemisVersion getArtemisTestVersion(); public abstract String getLogsDirLocation(); public abstract String getTmpDirLocation(); + public String getCertificatesLocation() { + return getTmpDirLocation() + Constants.FILE_SEPARATOR + Constants.CERTS_GENERATION_DIR; + } public abstract String getKeycloakVersion(); public abstract boolean isCollectTestData(); public abstract int getCustomExtraDelay(); diff --git a/common/src/main/java/io/brokerqe/claire/TestDataCollector.java b/common/src/main/java/io/brokerqe/claire/TestDataCollector.java index fed12225..aedfba38 100644 --- a/common/src/main/java/io/brokerqe/claire/TestDataCollector.java +++ b/common/src/main/java/io/brokerqe/claire/TestDataCollector.java @@ -34,15 +34,20 @@ public void handleTestExecutionException(ExtensionContext extensionContext, Thro throw throwable; } - archiveDir = environment.getLogsDirLocation() + Constants.FILE_SEPARATOR + testClass + "." + testMethod; + String classDir = TestUtils.getClassName(extensionContext); + String testDir = TestUtils.getTestName(extensionContext); + archiveDir = environment.getLogsDirLocation() + Constants.FILE_SEPARATOR + testDir; + String certificatesDir = Environment.get().getCertificatesLocation() + Constants.FILE_SEPARATOR + testDir; + String certificatesDirClass = Environment.get().getCertificatesLocation() + Constants.FILE_SEPARATOR + classDir; TestUtils.createDirectory(archiveDir); - String certificatesDirectory = archiveDir + Constants.FILE_SEPARATOR + "certificates"; - if (TestUtils.directoryExists(Constants.CERTS_GENERATION_DIR)) { - if (TestUtils.directoryExists(certificatesDirectory)) { - LOGGER.info("[TDC] Skipping duplicated copying of certificates into {}", certificatesDirectory); + String certificatesArchiveDirectory = archiveDir + Constants.FILE_SEPARATOR + "certificates"; + if (!TestUtils.isEmptyDirectory(certificatesDirClass) || !TestUtils.isEmptyDirectory(certificatesDir)) { + if (TestUtils.directoryExists(certificatesArchiveDirectory)) { + LOGGER.warn("[TDC] Skipping duplicated copying of certificates into {}", certificatesArchiveDirectory); } else { - TestUtils.copyDirectoryFlat(Constants.CERTS_GENERATION_DIR, certificatesDirectory); + TestUtils.copyDirectoryFlat(certificatesDir, certificatesArchiveDirectory); + TestUtils.copyDirectoryFlat(certificatesDirClass, certificatesArchiveDirectory); } } collectTestData(); diff --git a/common/src/main/java/io/brokerqe/claire/TestUtils.java b/common/src/main/java/io/brokerqe/claire/TestUtils.java index 4a021ddd..495dd802 100644 --- a/common/src/main/java/io/brokerqe/claire/TestUtils.java +++ b/common/src/main/java/io/brokerqe/claire/TestUtils.java @@ -19,6 +19,9 @@ import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; +import org.junit.jupiter.api.TestInfo; +import org.junit.jupiter.api.extension.ExtensionContext; +import org.junit.platform.commons.PreconditionViolationException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.w3c.dom.Document; @@ -61,11 +64,13 @@ import java.util.Base64; import java.util.Locale; import java.util.Map; +import java.util.NoSuchElementException; import java.util.UUID; import java.util.function.BooleanSupplier; import java.util.stream.Stream; import java.lang.Runtime.Version; +@SuppressWarnings({"checkstyle:ClassFanOutComplexity"}) public final class TestUtils { private static final Logger LOGGER = LoggerFactory.getLogger(TestUtils.class); @@ -78,6 +83,49 @@ public static Path getProjectRelativeFilePath(String projectRelativeFile) { return Paths.get(Constants.PROJECT_USER_DIR, projectRelativeFile).toAbsolutePath(); } + // ========== Junit Test Operations ========== + public static String getClassName(ExtensionContext extensionContext) { + return extensionContext.getRequiredTestClass().getName(); + } + public static String getClassName(TestInfo testInfo) { + return testInfo.getTestClass().orElseThrow().getName(); + } + + public static String getTestName(ExtensionContext extensionContext) { + String testClass = extensionContext.getRequiredTestClass().getName(); + String testMethod = null; + try { + testMethod = extensionContext.getRequiredTestMethod().getName(); + } catch (PreconditionViolationException e) { + LOGGER.trace("No testMethod in extensionContext, skipping methodName usage"); + } + return createTestName(extensionContext.getDisplayName(), testClass, testMethod); + } + + public static String getTestName(TestInfo testInfo) { + String testClass = testInfo.getTestClass().orElseThrow().getName(); + String testMethod = null; + try { + testMethod = testInfo.getTestMethod().orElseThrow().getName(); + } catch (NoSuchElementException e) { + LOGGER.trace("No testMethod in testInfo, skipping methodName usage"); + } + return createTestName(testInfo.getDisplayName(), testClass, testMethod); + } + + private static String createTestName(String displayName, String testClass, String testMethod) { + String sameTestCounter = ""; + String testFullName = testClass; + if (testMethod != null) { + testFullName += "." + testMethod; + } + if (displayName.startsWith("[")) { + sameTestCounter = displayName.substring(displayName.indexOf("[") + 1, displayName.indexOf("]")); + testFullName += "#" + sameTestCounter; + } + return testFullName; + } + // ========== Random Operations ========== public static String getRandomString(int length) { if (length > 96) { @@ -313,6 +361,7 @@ public static String parseVersionMMM(String versionString) { // ========== File Operations ========== public static void deleteFile(Path fileName) { try { + LOGGER.trace("Deleting {}", fileName); Files.delete(fileName); } catch (IOException e) { throw new RuntimeException(e); @@ -361,6 +410,24 @@ public static boolean directoryExists(String directoryName) { return Files.exists(path) && Files.isDirectory(path); } + public static boolean isEmptyDirectory(String directoryName) { + Path path = Paths.get(directoryName); + try { + return Files.exists(path) && Files.isDirectory(path) && Files.list(path).findAny().isEmpty(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + public static void deleteEmptyDirectories(String directoryName) { + for (String filename : new File(directoryName).list()) { + String fileToDelete = new File(Environment.get().getCertificatesLocation()).getAbsolutePath() + Constants.FILE_SEPARATOR + filename; + if (TestUtils.isEmptyDirectory(fileToDelete)) { + TestUtils.deleteFile(Path.of(fileToDelete)); + } + } + } + public static void createDirectory(String directoryName) { try { LOGGER.trace("Creating directory {}", directoryName); diff --git a/common/src/main/java/io/brokerqe/claire/junit/TestSeparator.java b/common/src/main/java/io/brokerqe/claire/junit/TestSeparator.java index 14a03af8..6ba3dfe9 100644 --- a/common/src/main/java/io/brokerqe/claire/junit/TestSeparator.java +++ b/common/src/main/java/io/brokerqe/claire/junit/TestSeparator.java @@ -4,6 +4,9 @@ */ package io.brokerqe.claire.junit; +import io.brokerqe.claire.Environment; +import io.brokerqe.claire.TestUtils; +import io.brokerqe.claire.security.CertificateManager; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeAll; @@ -24,6 +27,7 @@ public interface TestSeparator { static void beforeAllTests(ExtensionContext testContext) { LOGGER.info((char) 27 + "[34m" + String.join("", Collections.nCopies(76, SEPARATOR_CHAR)) + (char) 27 + "[0m"); LOGGER.info((char) 27 + "[33m" + String.format("Started Class: %s", testContext.getRequiredTestClass().getName()) + (char) 27 + "[0m"); + CertificateManager.setCertificateTestDirectory(TestUtils.getTestName(testContext)); } @BeforeEach default void beforeEachTest(ExtensionContext testContext) { @@ -31,6 +35,7 @@ default void beforeEachTest(ExtensionContext testContext) { LOGGER.info((char) 27 + "[33m" + String.format("[%s/%s] Started: %s.%s", ClaireExecutionListener.getCurrentTestCounter(), ClaireExecutionListener.getTotalTestCount(), testContext.getRequiredTestClass().getName(), testContext.getRequiredTestMethod().getName()) + (char) 27 + "[0m"); + CertificateManager.setCertificateTestDirectory(TestUtils.getTestName(testContext)); } @AfterEach @@ -44,5 +49,6 @@ default void afterEachTest(ExtensionContext testContext) { static void afterAllTests(ExtensionContext testContext) { LOGGER.info((char) 27 + "[33m" + String.format("Finished Class: %s", testContext.getRequiredTestClass().getName()) + (char) 27 + "[0m"); LOGGER.info((char) 27 + "[34m" + String.join("", Collections.nCopies(76, SEPARATOR_CHAR)) + (char) 27 + "[0m"); + TestUtils.deleteEmptyDirectories(Environment.get().getCertificatesLocation()); } } diff --git a/common/src/main/java/io/brokerqe/claire/security/CertificateData.java b/common/src/main/java/io/brokerqe/claire/security/CertificateData.java index 5db35ce2..2bcb2354 100644 --- a/common/src/main/java/io/brokerqe/claire/security/CertificateData.java +++ b/common/src/main/java/io/brokerqe/claire/security/CertificateData.java @@ -4,7 +4,6 @@ */ package io.brokerqe.claire.security; -import io.brokerqe.claire.Constants; import org.bouncycastle.asn1.x509.Extension; import javax.security.auth.x500.X500PrivateCredential; @@ -45,7 +44,7 @@ public CertificateData(String alias, String distinguishedName, List e this.distinguishedName = distinguishedName; this.certificate = CertificateManager.generate(keyPair, CertificateManager.SIGNATURE_ALGORITHM, distinguishedName, validNotBefore, validNotAfter, extensions, issuer); this.privateCredential = CertificateManager.createPrivateCredential(certificate, keyPair, alias); - this.fileName = Constants.CERTS_GENERATION_DIR + alias + ".crt"; + this.fileName = CertificateManager.getCurrentTestDirectory() + alias + ".crt"; CertificateManager.writeCertificateToFile(certificate, fileName); } @@ -61,7 +60,7 @@ public CertificateData(String alias, String distinguishedName, CertificateData i this.distinguishedName = distinguishedName; this.certificate = CertificateManager.generateCA(keyPair, CertificateManager.SIGNATURE_ALGORITHM, distinguishedName, validNotBefore, validNotAfter, issuer); this.privateCredential = CertificateManager.createPrivateCredential(certificate, keyPair, alias); - this.fileName = Constants.CERTS_GENERATION_DIR + alias + ".crt"; + this.fileName = CertificateManager.getCurrentTestDirectory() + alias + ".crt"; CertificateManager.writeCertificateToFile(certificate, fileName); } diff --git a/common/src/main/java/io/brokerqe/claire/security/CertificateManager.java b/common/src/main/java/io/brokerqe/claire/security/CertificateManager.java index 430e9c99..170d2ead 100644 --- a/common/src/main/java/io/brokerqe/claire/security/CertificateManager.java +++ b/common/src/main/java/io/brokerqe/claire/security/CertificateManager.java @@ -5,6 +5,7 @@ package io.brokerqe.claire.security; import io.brokerqe.claire.Constants; +import io.brokerqe.claire.Environment; import io.brokerqe.claire.TestUtils; import org.bouncycastle.asn1.DEROctetString; import org.bouncycastle.asn1.oiw.OIWObjectIdentifiers; @@ -74,8 +75,18 @@ public class CertificateManager { public static final String DEFAULT_CLIENT_ALIAS = "clientUser"; public static final String DEFAULT_CLIENT_PASSWORD = "clientPass"; + private static String currentTestDirectory = Environment.get().getCertificatesLocation() + Constants.FILE_SEPARATOR; static { - TestUtils.createDirectory(Constants.CERTS_GENERATION_DIR); + TestUtils.createDirectory(currentTestDirectory); + } + + public static void setCertificateTestDirectory(String testDirectory) { + currentTestDirectory = Environment.get().getCertificatesLocation() + Constants.FILE_SEPARATOR + testDirectory + Constants.FILE_SEPARATOR; + TestUtils.createDirectory(currentTestDirectory); + } + + public static String getCurrentTestDirectory() { + return currentTestDirectory; } public static TrustManager[] trustAllCertificates = new TrustManager[]{ @@ -261,8 +272,8 @@ public static X500PrivateCredential createPrivateCredential(X509Certificate cert */ public static Map createEntityKeystores(CertificateData certificateData, String keystorePassword) { Map keystores = new HashMap<>(); - String keyStoreFileName = Constants.CERTS_GENERATION_DIR + certificateData.getAlias() + "_keystore.jks"; - String trustStoreFileName = Constants.CERTS_GENERATION_DIR + certificateData.getAlias() + "_truststore.jks"; + String keyStoreFileName = currentTestDirectory + certificateData.getAlias() + "_keystore.jks"; + String trustStoreFileName = currentTestDirectory + certificateData.getAlias() + "_truststore.jks"; String keyStoreDataName = certificateData.getAlias() + ".ks"; String trustStoreDataName = certificateData.getAlias() + ".ts"; @@ -294,10 +305,10 @@ public static Map createEntityKeystores(CertificateData ce public static Map createKeystores(CertificateData brokerCertificateData, CertificateData clientCertificateData, String brokerAlias, String brokerPassword, String clientAlias, String clientPassword) { Map keystores = new HashMap<>(); - String brokerKeyStoreFileName = Constants.CERTS_GENERATION_DIR + brokerAlias + "_keystore.jks"; - String brokerTrustStoreFileName = Constants.CERTS_GENERATION_DIR + brokerAlias + "_truststore.jks"; - String clientKeyStoreFileName = Constants.CERTS_GENERATION_DIR + clientAlias + "_keystore.jks"; - String clientTrustStoreFileName = Constants.CERTS_GENERATION_DIR + clientAlias + "_truststore.jks"; + String brokerKeyStoreFileName = currentTestDirectory + brokerAlias + "_keystore.jks"; + String brokerTrustStoreFileName = currentTestDirectory + brokerAlias + "_truststore.jks"; + String clientKeyStoreFileName = currentTestDirectory + clientAlias + "_keystore.jks"; + String clientTrustStoreFileName = currentTestDirectory + clientAlias + "_truststore.jks"; try { LOGGER.info("[TLS] Creating Broker keystore"); @@ -376,12 +387,12 @@ public static void writeCertificateToFile(X509Certificate certificate, String fi public static Map generateDefaultCertificateKeystores(String brokerDN, String clientDN, List extensions, CertificateData issuer) { LOGGER.info("[TLS] Generating Broker KeyPair, Certificates"); CertificateData brokerCertData = new CertificateData(DEFAULT_BROKER_ALIAS, brokerDN, extensions, 30, issuer); - writeCertificateToFile(brokerCertData.getCertificate(), Constants.CERTS_GENERATION_DIR + DEFAULT_BROKER_ALIAS + ".crt"); + writeCertificateToFile(brokerCertData.getCertificate(), currentTestDirectory + DEFAULT_BROKER_ALIAS + ".crt"); // Client cert + keypair LOGGER.info("[TLS] Generating Client KeyPair, Certificates"); CertificateData clientCertData = new CertificateData(DEFAULT_CLIENT_ALIAS, clientDN); - writeCertificateToFile(clientCertData.getCertificate(), Constants.CERTS_GENERATION_DIR + DEFAULT_CLIENT_ALIAS + ".crt"); + writeCertificateToFile(clientCertData.getCertificate(), currentTestDirectory + DEFAULT_CLIENT_ALIAS + ".crt"); return CertificateManager.createKeystores(brokerCertData, clientCertData, DEFAULT_BROKER_ALIAS, DEFAULT_BROKER_PASSWORD, DEFAULT_CLIENT_ALIAS, DEFAULT_CLIENT_PASSWORD); @@ -474,11 +485,11 @@ public static void addToTruststore(KeyStoreData keyStoreData, String stringTlsCe */ public static Map reuseDefaultGeneratedKeystoresFromFiles() { Map keystores = new HashMap<>(); - if (TestUtils.directoryExists(Constants.CERTS_GENERATION_DIR)) { - String brokerKeyStoreFileName = Constants.CERTS_GENERATION_DIR + DEFAULT_BROKER_ALIAS + "_keystore.jks"; - String brokerTrustStoreFileName = Constants.CERTS_GENERATION_DIR + DEFAULT_BROKER_ALIAS + "_truststore.jks"; - String clientKeyStoreFileName = Constants.CERTS_GENERATION_DIR + DEFAULT_CLIENT_ALIAS + "_keystore.jks"; - String clientTrustStoreFileName = Constants.CERTS_GENERATION_DIR + DEFAULT_CLIENT_ALIAS + "_truststore.jks"; + if (TestUtils.directoryExists(currentTestDirectory)) { + String brokerKeyStoreFileName = currentTestDirectory + DEFAULT_BROKER_ALIAS + "_keystore.jks"; + String brokerTrustStoreFileName = currentTestDirectory + DEFAULT_BROKER_ALIAS + "_truststore.jks"; + String clientKeyStoreFileName = currentTestDirectory + DEFAULT_CLIENT_ALIAS + "_keystore.jks"; + String clientTrustStoreFileName = currentTestDirectory + DEFAULT_CLIENT_ALIAS + "_truststore.jks"; try { Security.addProvider(new BouncyCastleProvider()); @@ -503,7 +514,7 @@ public static Map reuseDefaultGeneratedKeystoresFromFiles( throw new RuntimeException(e); } } else { - LOGGER.error("[TLS] {} does not exist! Can not reuse it!", Constants.CERTS_GENERATION_DIR); + LOGGER.error("[TLS] {} does not exist! Can not reuse it!", currentTestDirectory); throw new RuntimeException("Can not find expected directory and load certificates!"); } } diff --git a/operator-suite/src/main/java/io/brokerqe/claire/EnvironmentOperator.java b/operator-suite/src/main/java/io/brokerqe/claire/EnvironmentOperator.java index 602c6b2d..ee8e84a5 100644 --- a/operator-suite/src/main/java/io/brokerqe/claire/EnvironmentOperator.java +++ b/operator-suite/src/main/java/io/brokerqe/claire/EnvironmentOperator.java @@ -50,13 +50,14 @@ public class EnvironmentOperator extends Environment { public EnvironmentOperator() { this.set(this); + String initialTimestamp = TestUtils.generateTimestamp(); artemisVersion = System.getenv(Constants.EV_ARTEMIS_VERSION); testLogLevel = System.getenv(Constants.EV_TEST_LOG_LEVEL); - logsDirLocation = System.getenv().getOrDefault(Constants.EV_LOGS_LOCATION, Constants.LOGS_DEFAULT_DIR) + Constants.FILE_SEPARATOR + TestUtils.generateTimestamp(); - tmpDirLocation = System.getenv().getOrDefault(Constants.EV_TMP_LOCATION, Constants.TMP_DEFAULT_DIR) + Constants.FILE_SEPARATOR + TestUtils.generateTimestamp(); + logsDirLocation = System.getenv().getOrDefault(Constants.EV_LOGS_LOCATION, Constants.LOGS_DEFAULT_DIR) + Constants.FILE_SEPARATOR + initialTimestamp; + tmpDirLocation = System.getenv().getOrDefault(Constants.EV_TMP_LOCATION, Constants.TMP_DEFAULT_DIR) + Constants.FILE_SEPARATOR + initialTimestamp; collectTestData = Boolean.parseBoolean(System.getenv().getOrDefault(Constants.EV_COLLECT_TEST_DATA, "true")); serializationEnabled = Boolean.parseBoolean(System.getenv().getOrDefault(Constants.EV_DUMP_ENABLED, "false")); - serializationDirectory = System.getenv().getOrDefault(Constants.EV_DUMP_LOCATION, Constants.DUMP_DEFAULT_DIR) + Constants.FILE_SEPARATOR + TestUtils.generateTimestamp(); + serializationDirectory = System.getenv().getOrDefault(Constants.EV_DUMP_LOCATION, Constants.DUMP_DEFAULT_DIR) + Constants.FILE_SEPARATOR + initialTimestamp; serializationFormat = System.getenv().getOrDefault(Constants.EV_DUMP_FORMAT, Constants.DUMP_DEFAULT_TYPE); kubeClient = new KubeClient("default"); diff --git a/operator-suite/src/main/java/io/brokerqe/claire/KubeClient.java b/operator-suite/src/main/java/io/brokerqe/claire/KubeClient.java index aca586c0..f7bb66c3 100644 --- a/operator-suite/src/main/java/io/brokerqe/claire/KubeClient.java +++ b/operator-suite/src/main/java/io/brokerqe/claire/KubeClient.java @@ -48,6 +48,7 @@ import java.security.cert.CertificateException; import java.security.cert.CertificateFactory; import java.security.cert.X509Certificate; +import java.time.Duration; import java.time.Instant; import java.time.ZoneOffset; import java.util.ArrayList; @@ -287,7 +288,7 @@ public Pod waitForPodReload(String namespace, Pod pod, String podName) { public Pod waitForPodReload(String namespace, Pod pod, String podName, long maxTimeout) { String originalUid = pod.getMetadata().getUid(); - LOGGER.info("[{}] Waiting for pod {} reload", namespace, podName); + LOGGER.info("[{}] Waiting {}s for pod {} reload", namespace, Duration.ofMillis(maxTimeout).toSeconds(), podName); TestUtils.waitFor("Pod to be reloaded and ready", Constants.DURATION_5_SECONDS, maxTimeout, () -> { Pod newPod = getFirstPodByPrefixName(namespace, podName); LOGGER.debug("[{}] OriginalPodUid {} vs currentPodUid {}", namespace, originalUid, newPod.getMetadata().getUid()); diff --git a/operator-suite/src/test/java/io/brokerqe/claire/AbstractSystemTests.java b/operator-suite/src/test/java/io/brokerqe/claire/AbstractSystemTests.java index 01c39227..f858303f 100644 --- a/operator-suite/src/test/java/io/brokerqe/claire/AbstractSystemTests.java +++ b/operator-suite/src/test/java/io/brokerqe/claire/AbstractSystemTests.java @@ -16,12 +16,13 @@ import io.brokerqe.claire.exception.ClaireRuntimeException; import io.brokerqe.claire.junit.TestSeparator; import io.brokerqe.claire.operator.ArtemisCloudClusterOperator; +import io.brokerqe.claire.security.CertificateManager; import io.fabric8.kubernetes.api.model.Pod; import io.fabric8.kubernetes.api.model.Service; import io.fabric8.kubernetes.api.model.ServicePort; import io.fabric8.kubernetes.api.model.apps.Deployment; import io.fabric8.kubernetes.client.KubernetesClient; -import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.TestInfo; import org.junit.jupiter.api.TestInstance; @@ -29,6 +30,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.nio.file.Path; import java.time.Duration; import java.time.Instant; import java.util.HashMap; @@ -55,11 +57,19 @@ public abstract class AbstractSystemTests implements TestSeparator { protected EnvironmentOperator testEnvironmentOperator; protected TestInfo testInfo; + @BeforeEach - @BeforeAll void init(TestInfo testInfo) { - ResourceManager.setTestInfo(testInfo); this.testInfo = testInfo; + ResourceManager.setTestInfo(testInfo); + CertificateManager.setCertificateTestDirectory(TestUtils.getTestName(testInfo)); + } + + @AfterEach + void cleanAfterTest() { + if (TestUtils.isEmptyDirectory(CertificateManager.getCurrentTestDirectory())) { + TestUtils.deleteFile(Path.of(CertificateManager.getCurrentTestDirectory())); + } } protected void cleanResourcesAfterTest(String namespace) { diff --git a/operator-suite/src/test/java/io/brokerqe/claire/security/KeycloakLdapTests.java b/operator-suite/src/test/java/io/brokerqe/claire/security/KeycloakLdapTests.java index 5d720d80..a1c9ec1f 100644 --- a/operator-suite/src/test/java/io/brokerqe/claire/security/KeycloakLdapTests.java +++ b/operator-suite/src/test/java/io/brokerqe/claire/security/KeycloakLdapTests.java @@ -34,7 +34,6 @@ public class KeycloakLdapTests extends LdapTests { String secretConfigName = "keycloak-jaas-config"; String consoleSecretName = brokerName + "-console-secret"; String brokerTruststoreSecretName = "broker-truststore"; - String brokerTruststoreFileName = Constants.CERTS_GENERATION_DIR + "brk_truststore.jks"; final boolean jwtTokenSupported = true; @BeforeAll @@ -129,6 +128,7 @@ public void createArtemisKeycloakSecurity() { } public void setupEnvironment() { + String brokerTruststoreFileName = CertificateManager.getCurrentTestDirectory() + "brk_truststore.jks"; getClient().createBrokerTruststoreSecretWithOpenshiftRouter(getClient(), testNamespace, brokerTruststoreSecretName, brokerTruststoreFileName); keycloak.importRealm(keycloakRealm, keycloak.realmArtemisLdap); keycloak.setupLdapModule(keycloakRealm); diff --git a/operator-suite/src/test/java/io/brokerqe/claire/security/TLSSecurityTests.java b/operator-suite/src/test/java/io/brokerqe/claire/security/TLSSecurityTests.java index 338d1d1f..8325fd38 100644 --- a/operator-suite/src/test/java/io/brokerqe/claire/security/TLSSecurityTests.java +++ b/operator-suite/src/test/java/io/brokerqe/claire/security/TLSSecurityTests.java @@ -11,9 +11,9 @@ import io.brokerqe.claire.ArtemisVersion; import io.brokerqe.claire.Constants; import io.brokerqe.claire.ResourceManager; -import io.brokerqe.claire.operator.ArtemisFileProvider; import io.brokerqe.claire.junit.TestValidSince; import io.brokerqe.claire.junit.TestValidUntil; +import io.brokerqe.claire.operator.ArtemisFileProvider; import io.fabric8.kubernetes.api.model.Pod; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; diff --git a/operator-suite/src/test/java/io/brokerqe/claire/smoke/SmokeTests.java b/operator-suite/src/test/java/io/brokerqe/claire/smoke/SmokeTests.java index abbe3cb2..12232109 100644 --- a/operator-suite/src/test/java/io/brokerqe/claire/smoke/SmokeTests.java +++ b/operator-suite/src/test/java/io/brokerqe/claire/smoke/SmokeTests.java @@ -58,7 +58,7 @@ void brokerErrorTest() { broker.getSpec().getDeploymentPlan().setSize(3); Pod brokerPod = getClient().getFirstPodByPrefixName(testNamespace, broker.getMetadata().getName()); broker = ResourceManager.getArtemisClient().inNamespace(testNamespace).resource(broker).createOrReplace(); - ResourceManager.waitForBrokerDeployment(testNamespace, broker, true, brokerPod); + ResourceManager.waitForBrokerDeployment(testNamespace, broker, false, brokerPod); throw new RuntimeException("Throwing random exception, to trigger TestDataCollection."); } diff --git a/standalone-suite/src/main/java/io/brokerqe/claire/EnvironmentStandalone.java b/standalone-suite/src/main/java/io/brokerqe/claire/EnvironmentStandalone.java index 8de7ace0..f5dc0a33 100644 --- a/standalone-suite/src/main/java/io/brokerqe/claire/EnvironmentStandalone.java +++ b/standalone-suite/src/main/java/io/brokerqe/claire/EnvironmentStandalone.java @@ -48,6 +48,7 @@ public class EnvironmentStandalone extends Environment { private final ArtemisVersion artemisVersion; private EnvironmentStandalone() { + String initialTimestamp = TestUtils.generateTimestamp(); loadProjectProperties(Constants.STANDALONE_MODULE_PROPERTIES_FILE); this.set(this); databaseFile = getConfigurationValue(Constants.EV_JDBC_DATA, Constants.PROP_JDBC_DATA, null); @@ -56,9 +57,9 @@ private EnvironmentStandalone() { logLevel = getConfigurationValue(Constants.EV_TEST_LOG_LEVEL, Constants.PROP_LOG_LEVEL, ArtemisConstants.DEFAULT_LOG_LEVEL); logsDirLocation = getConfigurationValue(Constants.EV_LOGS_LOCATION, Constants.PROP_LOG_DIR, Constants.LOGS_DEFAULT_DIR) - + Constants.FILE_SEPARATOR + TestUtils.generateTimestamp(); - tmpDirLocation = System.getProperty(Constants.EV_TMP_LOCATION, Constants.TMP_DEFAULT_DIR) - + Constants.FILE_SEPARATOR + TestUtils.generateTimestamp(); + + Constants.FILE_SEPARATOR + initialTimestamp; + tmpDirLocation = System.getenv().getOrDefault(Constants.EV_TMP_LOCATION, Constants.TMP_DEFAULT_DIR) + + Constants.FILE_SEPARATOR + initialTimestamp; logContainers = Boolean.parseBoolean(getConfigurationValue(Constants.EV_LOG_CONTAINERS, Constants.PROP_LOG_CONTAINERS, String.valueOf(Constants.DEFAULT_LOG_CONTAINERS))); collectTestData = Boolean.parseBoolean(System.getenv().getOrDefault(Constants.EV_COLLECT_TEST_DATA, "true")); diff --git a/standalone-suite/src/main/java/io/brokerqe/claire/container/YacfgArtemisContainer.java b/standalone-suite/src/main/java/io/brokerqe/claire/container/YacfgArtemisContainer.java index b05a3a80..46fe7c13 100644 --- a/standalone-suite/src/main/java/io/brokerqe/claire/container/YacfgArtemisContainer.java +++ b/standalone-suite/src/main/java/io/brokerqe/claire/container/YacfgArtemisContainer.java @@ -24,7 +24,7 @@ public class YacfgArtemisContainer extends AbstractGenericContainer { public static final String OPT_PARAM_KEY = "--opt"; public static final String TUNE_PARAM_KEY = "--tune"; - private static final String CLAIRE_STANDALONE_YACFG_PROFILES = "yacfg_profiles"; + private static final String CLAIRE_STANDALONE_YACFG_PROFILES = "yacfg-profiles"; private static final String YACFG_CONTAINER_DATA_DIR = "/data"; private static final String YACFG_CONTAINER_OUTPUT_DIR = YACFG_CONTAINER_DATA_DIR + "/output"; private static final String YACFG_CONTAINER_PROFILES_DIR = YACFG_CONTAINER_DATA_DIR + "/profiles"; diff --git a/standalone-suite/src/test/java/io/brokerqe/claire/AbstractSystemTests.java b/standalone-suite/src/test/java/io/brokerqe/claire/AbstractSystemTests.java index e32262f7..a3fd8893 100644 --- a/standalone-suite/src/test/java/io/brokerqe/claire/AbstractSystemTests.java +++ b/standalone-suite/src/test/java/io/brokerqe/claire/AbstractSystemTests.java @@ -7,15 +7,15 @@ import io.brokerqe.claire.clients.DeployableClient; import io.brokerqe.claire.clients.bundled.ArtemisCommand; import io.brokerqe.claire.clients.bundled.BundledArtemisClient; +import io.brokerqe.claire.container.ArtemisContainer; +import io.brokerqe.claire.container.NfsServerContainer; +import io.brokerqe.claire.container.YacfgArtemisContainer; +import io.brokerqe.claire.container.database.DatabaseContainer; import io.brokerqe.claire.database.Database; import io.brokerqe.claire.exception.ClaireRuntimeException; import io.brokerqe.claire.helper.ArtemisJmxHelper; import io.brokerqe.claire.helper.TimeHelper; import io.brokerqe.claire.junit.TestSeparator; -import io.brokerqe.claire.container.ArtemisContainer; -import io.brokerqe.claire.container.database.DatabaseContainer; -import io.brokerqe.claire.container.NfsServerContainer; -import io.brokerqe.claire.container.YacfgArtemisContainer; import org.apache.activemq.artemis.api.core.RoutingType; import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.StringUtils; diff --git a/standalone-suite/yacfg_profiles/claire-default-profile-2.21.0.yaml.jinja2 b/standalone-suite/yacfg-profiles/claire-default-profile-2.21.0.yaml.jinja2 similarity index 100% rename from standalone-suite/yacfg_profiles/claire-default-profile-2.21.0.yaml.jinja2 rename to standalone-suite/yacfg-profiles/claire-default-profile-2.21.0.yaml.jinja2 diff --git a/standalone-suite/yacfg_profiles/claire-default-profile-2.28.0.yaml.jinja2 b/standalone-suite/yacfg-profiles/claire-default-profile-2.28.0.yaml.jinja2 similarity index 100% rename from standalone-suite/yacfg_profiles/claire-default-profile-2.28.0.yaml.jinja2 rename to standalone-suite/yacfg-profiles/claire-default-profile-2.28.0.yaml.jinja2 diff --git a/standalone-suite/yacfg_profiles/claire-default-profile-2.29.0.yaml.jinja2 b/standalone-suite/yacfg-profiles/claire-default-profile-2.29.0.yaml.jinja2 similarity index 100% rename from standalone-suite/yacfg_profiles/claire-default-profile-2.29.0.yaml.jinja2 rename to standalone-suite/yacfg-profiles/claire-default-profile-2.29.0.yaml.jinja2 diff --git a/standalone-suite/yacfg_profiles/claire-default-profile-2.30.0.yaml.jinja2 b/standalone-suite/yacfg-profiles/claire-default-profile-2.30.0.yaml.jinja2 similarity index 100% rename from standalone-suite/yacfg_profiles/claire-default-profile-2.30.0.yaml.jinja2 rename to standalone-suite/yacfg-profiles/claire-default-profile-2.30.0.yaml.jinja2 diff --git a/standalone-suite/yacfg_profiles/claire-default-profile-2.31.0.yaml.jinja2 b/standalone-suite/yacfg-profiles/claire-default-profile-2.31.0.yaml.jinja2 similarity index 100% rename from standalone-suite/yacfg_profiles/claire-default-profile-2.31.0.yaml.jinja2 rename to standalone-suite/yacfg-profiles/claire-default-profile-2.31.0.yaml.jinja2 diff --git a/standalone-suite/yacfg_profiles/claire-default-profile-2.31.2.yaml.jinja2 b/standalone-suite/yacfg-profiles/claire-default-profile-2.31.2.yaml.jinja2 similarity index 100% rename from standalone-suite/yacfg_profiles/claire-default-profile-2.31.2.yaml.jinja2 rename to standalone-suite/yacfg-profiles/claire-default-profile-2.31.2.yaml.jinja2 diff --git a/standalone-suite/yacfg_profiles/tests/ha/replication/FailoverReplicationTests/backup-tune.yaml.jinja2 b/standalone-suite/yacfg-profiles/tests/ha/replication/FailoverReplicationTests/backup-tune.yaml.jinja2 similarity index 100% rename from standalone-suite/yacfg_profiles/tests/ha/replication/FailoverReplicationTests/backup-tune.yaml.jinja2 rename to standalone-suite/yacfg-profiles/tests/ha/replication/FailoverReplicationTests/backup-tune.yaml.jinja2 diff --git a/standalone-suite/yacfg_profiles/tests/ha/replication/FailoverReplicationTests/primary-tune.yaml.jinja2 b/standalone-suite/yacfg-profiles/tests/ha/replication/FailoverReplicationTests/primary-tune.yaml.jinja2 similarity index 100% rename from standalone-suite/yacfg_profiles/tests/ha/replication/FailoverReplicationTests/primary-tune.yaml.jinja2 rename to standalone-suite/yacfg-profiles/tests/ha/replication/FailoverReplicationTests/primary-tune.yaml.jinja2 diff --git a/standalone-suite/yacfg_profiles/tests/ha/sharedstore/FailoverSharedStoreTests/backup-tune.yaml.jinja2 b/standalone-suite/yacfg-profiles/tests/ha/sharedstore/FailoverSharedStoreTests/backup-tune.yaml.jinja2 similarity index 100% rename from standalone-suite/yacfg_profiles/tests/ha/sharedstore/FailoverSharedStoreTests/backup-tune.yaml.jinja2 rename to standalone-suite/yacfg-profiles/tests/ha/sharedstore/FailoverSharedStoreTests/backup-tune.yaml.jinja2 diff --git a/standalone-suite/yacfg_profiles/tests/ha/sharedstore/FailoverSharedStoreTests/primary-tune.yaml.jinja2 b/standalone-suite/yacfg-profiles/tests/ha/sharedstore/FailoverSharedStoreTests/primary-tune.yaml.jinja2 similarity index 100% rename from standalone-suite/yacfg_profiles/tests/ha/sharedstore/FailoverSharedStoreTests/primary-tune.yaml.jinja2 rename to standalone-suite/yacfg-profiles/tests/ha/sharedstore/FailoverSharedStoreTests/primary-tune.yaml.jinja2 diff --git a/standalone-suite/yacfg_profiles/tests/logging/audit/AuditCoreLogTests/tune-2.21.0.yaml.jinja2 b/standalone-suite/yacfg-profiles/tests/logging/audit/AuditCoreLogTests/tune-2.21.0.yaml.jinja2 similarity index 100% rename from standalone-suite/yacfg_profiles/tests/logging/audit/AuditCoreLogTests/tune-2.21.0.yaml.jinja2 rename to standalone-suite/yacfg-profiles/tests/logging/audit/AuditCoreLogTests/tune-2.21.0.yaml.jinja2 diff --git a/standalone-suite/yacfg_profiles/tests/logging/audit/AuditCoreLogTests/tune.yaml.jinja2 b/standalone-suite/yacfg-profiles/tests/logging/audit/AuditCoreLogTests/tune.yaml.jinja2 similarity index 100% rename from standalone-suite/yacfg_profiles/tests/logging/audit/AuditCoreLogTests/tune.yaml.jinja2 rename to standalone-suite/yacfg-profiles/tests/logging/audit/AuditCoreLogTests/tune.yaml.jinja2 diff --git a/standalone-suite/yacfg_profiles/tests/logging/audit/AuditLogTests/tune-2.21.0.yaml.jinja2 b/standalone-suite/yacfg-profiles/tests/logging/audit/AuditLogTests/tune-2.21.0.yaml.jinja2 similarity index 100% rename from standalone-suite/yacfg_profiles/tests/logging/audit/AuditLogTests/tune-2.21.0.yaml.jinja2 rename to standalone-suite/yacfg-profiles/tests/logging/audit/AuditLogTests/tune-2.21.0.yaml.jinja2 diff --git a/standalone-suite/yacfg_profiles/tests/logging/audit/AuditLogTests/tune.yaml.jinja2 b/standalone-suite/yacfg-profiles/tests/logging/audit/AuditLogTests/tune.yaml.jinja2 similarity index 100% rename from standalone-suite/yacfg_profiles/tests/logging/audit/AuditLogTests/tune.yaml.jinja2 rename to standalone-suite/yacfg-profiles/tests/logging/audit/AuditLogTests/tune.yaml.jinja2 diff --git a/standalone-suite/yacfg_profiles/tests/paging/MaxReadMessagesAndBytesTests/tune.yaml.jinja2 b/standalone-suite/yacfg-profiles/tests/paging/MaxReadMessagesAndBytesTests/tune.yaml.jinja2 similarity index 100% rename from standalone-suite/yacfg_profiles/tests/paging/MaxReadMessagesAndBytesTests/tune.yaml.jinja2 rename to standalone-suite/yacfg-profiles/tests/paging/MaxReadMessagesAndBytesTests/tune.yaml.jinja2