Skip to content

Commit

Permalink
OLM Version string smoke tests
Browse files Browse the repository at this point in the history
  • Loading branch information
michalxo committed Oct 6, 2023
1 parent ce4cf4c commit 3934109
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 7 deletions.
9 changes: 9 additions & 0 deletions common/src/main/java/io/brokerqe/claire/TestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import java.util.UUID;
import java.util.function.BooleanSupplier;
import java.util.stream.Stream;
import java.lang.Runtime.Version;

public final class TestUtils {

Expand Down Expand Up @@ -292,6 +293,14 @@ public static URLConnection makeHttpRequest(String uri, String method) {
}
}

// ========== String Operations ==========
public static String parseVersionMMM(String versionString) {
Version version = Version.parse(versionString);
String versionMMM = String.format("%d.%d.%d", version.feature(), version.interim(), version.update());
LOGGER.debug("Parsed version: {} from {}.", versionMMM, versionString);
return versionMMM;
}

// ========== File Operations ==========
public static void deleteFile(Path fileName) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,10 @@ protected void createTestPlan(TestPlan testPlan) {
});
String formattedTestPlan = String.join(",", testsList).replaceAll(",\\n,", "\n ").replaceFirst(",", " ");
totalTestCount = testsList.size();
LOGGER.warn("Initial test count={}", totalTestCount);
LOGGER.debug("Initial test count={}", totalTestCount);
totalTestCount = testsList.size() - Collections.frequency(testsList, "\n");
LOGGER.warn("Initial test count after removal of frequency={}", totalTestCount);
LOGGER.debug("Initial test count after removal of frequency={}", totalTestCount);
LOGGER.info("[TestPlan] Will execute following {} tests: {}", testsList.size() - Collections.frequency(testsList, "\n"), formattedTestPlan);

}

protected static void setupLoggingLevel() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ private void printAllUsedTestVariables() {
envVarsSB.append(Constants.EV_ARTEMIS_TEST_VERSION).append("=").append(artemisTestVersion).append(Constants.LINE_SEPARATOR);
}

envVarsSB.append("OLM").append("=").append(olmInstallation).append(Constants.LINE_SEPARATOR);
envVarsSB.append("OLM_INSTALLATION").append("=").append(olmInstallation).append(Constants.LINE_SEPARATOR);
if (olmInstallation) {
envVarsSB.append(Constants.EV_OLM_RELEASED).append("=").append(olmReleased).append(Constants.LINE_SEPARATOR);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
import io.brokerqe.claire.KubeClient;
import io.brokerqe.claire.ResourceManager;
import io.brokerqe.claire.TestUtils;
import io.brokerqe.claire.exception.ClaireRuntimeException;
import io.fabric8.kubernetes.api.model.apps.Deployment;
import io.fabric8.openshift.api.model.operatorhub.v1alpha1.ClusterServiceVersion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -27,6 +29,7 @@ public abstract class ArtemisCloudClusterOperator {
protected final List<String> watchedNamespaces;
protected final KubeClient kubeClient;
protected String operatorName;
public String amqBrokerOperatorName = "amq-broker-operator";
private final String operatorOldNameSuffix = "-operator";
private final String operatorNewNameSuffix = "-controller-manager";

Expand Down Expand Up @@ -97,4 +100,19 @@ public static String getOperatorControllerManagerName(Path yamlFile) {
Deployment operatorCODeployment = TestUtils.configFromYaml(yamlFile.toFile(), Deployment.class);
return operatorCODeployment.getMetadata().getName();
}

public String getOperatorOLMVersion(boolean returnMMM) {
if (environmentOperator.isOlmInstallation()) {
// String channel = ((ArtemisCloudClusterOperatorOlm) this).getOlmChannel();
ClusterServiceVersion csv = kubeClient.getClusterServiceVersion(deploymentNamespace, amqBrokerOperatorName);
String version = csv.getSpec().getVersion();
if (returnMMM) {
return TestUtils.parseVersionMMM(version);
} else {
return version;
}
} else {
throw new ClaireRuntimeException("Operator is not installed using OLM!");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public void deployOlmInstallation() {

try {
TestUtils.waitFor("broker-operator ClusterServiceVersion to be 'Succeeded'", Constants.DURATION_5_SECONDS, Constants.DURATION_2_MINUTES, () -> {
ClusterServiceVersion brokerCSV = kubeClient.getClusterServiceVersion(deploymentNamespace, "amq-broker-operator");
ClusterServiceVersion brokerCSV = kubeClient.getClusterServiceVersion(deploymentNamespace, amqBrokerOperatorName);
LOGGER.debug("[{}] Checking for status phase of {}", deploymentNamespace, brokerCSV.getMetadata().getName());
return brokerCSV.getStatus().getPhase().equals("Succeeded");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ public String getRandomName(String prefix, int randomLength) {
return prefix + "-" + TestUtils.getRandomString(randomLength);
}

public String getExpectedVersion() {
if (testEnvironmentOperator.isOlmInstallation()) {
return operator.getOperatorOLMVersion(true);
} else {
return testEnvironmentOperator.getArtemisVersion();
}
}

/******************************************************************************************************************
* Default setup and teardown methods
******************************************************************************************************************/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ void sendReceiveSystemTestsRheaClientMessageTest() {
@Test
@Tag(Constants.TAG_SMOKE)
void testDefaultBrokerVersion() {
String expectedVersion = testEnvironmentOperator.getArtemisVersion();
String expectedVersion = getExpectedVersion();
assumeFalse(expectedVersion.equals("main"), "version supplied is \"main\", skipping test.");

String expectedBrokerPattern = "Red Hat AMQ.*\\.GA";
Expand All @@ -328,7 +328,7 @@ void testDefaultBrokerVersion() {
@Test
@Tag(Constants.TAG_SMOKE)
void testDefaultOperatorVersion() {
String expectedVersion = testEnvironmentOperator.getArtemisVersion();
String expectedVersion = getExpectedVersion();
assumeFalse(expectedVersion.equals("main"), "version supplied is \"main\", skipping test.");
String expectedOperatorVersionPattern = "Version of the operator: .*\n";
Pod operatorPod = getClient().getFirstPodByPrefixName(testNamespace, operator.getOperatorName());
Expand Down

0 comments on commit 3934109

Please sign in to comment.