Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ST] Change the way how we assert values in logs from Pods #11187

Merged
merged 1 commit into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import io.strimzi.systemtest.utils.kubeUtils.controllers.JobUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.hamcrest.CoreMatchers;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
Expand All @@ -39,6 +38,7 @@

import static io.strimzi.systemtest.TestTags.REGRESSION;
import static io.strimzi.test.k8s.KubeClusterResource.kubeClient;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assumptions.assumeFalse;

Expand Down Expand Up @@ -133,7 +133,7 @@ void testKafkaQuotasPluginIntegration() {

String belowLimitLog = String.format("below the limit of %s", minAvailableBytes);

assertThat("Kafka log doesn't contain '" + belowLimitLog + "' log", kafkaLog, CoreMatchers.containsString(belowLimitLog));
assertThat("Kafka log doesn't contain '" + belowLimitLog + "' log", kafkaLog.contains(belowLimitLog), is(true));

LOGGER.info("Sending messages with user that is specified in list of excluded principals, we should be able to send the messages without problem");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ void testSimpleDynamicConfiguration() {

for (String cmName : StUtils.getKafkaConfigurationConfigMaps(Environment.TEST_SUITE_NAMESPACE, testStorage.getClusterName())) {
String kafkaConfiguration = kubeClient().getConfigMap(Environment.TEST_SUITE_NAMESPACE, cmName).getData().get("server.config");
assertThat(kafkaConfiguration, containsString("offsets.topic.replication.factor=1"));
assertThat(kafkaConfiguration, containsString("transaction.state.log.replication.factor=1"));
assertThat("Kafka configuration CM doesn't contain 'offsets.topic.replication.factor=1'", kafkaConfiguration.contains("offsets.topic.replication.factor=1"), is(true));
assertThat("Kafka configuration CM doesn't contain 'transaction.state.log.replication.factor=1'", kafkaConfiguration.contains("transaction.state.log.replication.factor=1"), is(true));
}

String kafkaConfigurationFromPod = KafkaCmdClient.describeKafkaBrokerUsingPodCli(Environment.TEST_SUITE_NAMESPACE, scraperPodName, KafkaResources.plainBootstrapAddress(testStorage.getClusterName()), podNum);
Expand All @@ -135,9 +135,9 @@ void testSimpleDynamicConfiguration() {

for (String cmName : StUtils.getKafkaConfigurationConfigMaps(Environment.TEST_SUITE_NAMESPACE, testStorage.getClusterName())) {
String kafkaConfiguration = kubeClient().getConfigMap(Environment.TEST_SUITE_NAMESPACE, cmName).getData().get("server.config");
assertThat(kafkaConfiguration, containsString("offsets.topic.replication.factor=1"));
assertThat(kafkaConfiguration, containsString("transaction.state.log.replication.factor=1"));
assertThat(kafkaConfiguration, containsString("unclean.leader.election.enable=true"));
assertThat("Kafka configuration CM doesn't contain 'offsets.topic.replication.factor=1'", kafkaConfiguration.contains("offsets.topic.replication.factor=1"), is(true));
assertThat("Kafka configuration CM doesn't contain 'transaction.state.log.replication.factor=1'", kafkaConfiguration.contains("transaction.state.log.replication.factor=1"), is(true));
assertThat("Kafka configuration CM doesn't contain 'unclean.leader.election.enable=true'", kafkaConfiguration.contains("unclean.leader.election.enable=true"), is(true));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@
import static io.strimzi.systemtest.TestTags.REGRESSION;
import static io.strimzi.test.k8s.KubeClusterResource.cmdKubeClient;
import static io.strimzi.test.k8s.KubeClusterResource.kubeClient;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.notNullValue;
Expand Down Expand Up @@ -445,7 +444,7 @@ void testCruiseControlLogChange() {

LOGGER.info("Checking logs in CruiseControl - make sure no DEBUG is found there");
String logOut = StUtils.getLogFromPodByTime(Environment.TEST_SUITE_NAMESPACE, cruiseControlPodName, TestConstants.CRUISE_CONTROL_CONTAINER_NAME, "20s");
assertThat(logOut.toUpperCase(Locale.ENGLISH), not(containsString(debugText)));
assertThat(String.format("CC log contains '%s' and it shouldn't", debugText), logOut.toUpperCase(Locale.ENGLISH).contains(debugText), is(false));

InlineLogging logging = new InlineLogging();
logging.setLoggers(Collections.singletonMap("rootLogger.level", debugText.strip()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@
import static io.strimzi.test.k8s.KubeClusterResource.kubeClient;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertFalse;
Expand Down Expand Up @@ -563,8 +562,8 @@ void testMirrorMaker2CorrectlyMirrorsHeaders() {
String header1 = "key: header_key_one, value: header_value_one";
String header2 = "key: header_key_two, value: header_value_two";
String log = StUtils.getLogFromPodByTime(testStorage.getNamespaceName(), kubeClient(testStorage.getNamespaceName()).listPodsByPrefixInName(testStorage.getConsumerName()).get(0).getMetadata().getName(), "", testStorage.getMessageCount() + "s");
assertThat(log, containsString(header1));
assertThat(log, containsString(header2));
assertThat(String.format("Consumer's log doesn't contain header: %s", header1), log.contains(header1), is(true));
assertThat(String.format("Consumer's log doesn't contain header: %s", header2), log.contains(header2), is(true));
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import static io.strimzi.systemtest.TestTags.REGRESSION;
import static io.strimzi.systemtest.resources.ResourceManager.kubeClient;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
Expand Down Expand Up @@ -89,7 +88,7 @@ void testLeaderElection() {
String logFromNewLeader = StUtils.getLogFromPodByTime(clusterOperator.getDeploymentNamespace(), currentLeaderPodName, clusterOperator.getClusterOperatorName(), "300s");

LOGGER.info("Checking if the new leader is elected");
assertThat("Log doesn't contains mention about election of the new leader", logFromNewLeader, containsString(LEADER_MESSAGE));
assertThat("Log doesn't contains mention about election of the new leader", logFromNewLeader.contains(LEADER_MESSAGE), is(true));
assertThat("Old and current leaders are same", oldLeaderPodName, not(equalTo(currentLeaderPodName)));
}

Expand All @@ -111,8 +110,7 @@ void testLeaderElectionDisabled() {

// Assert that the Lease does not exist
assertThat("Lease for CO exists", notExistingLease, is(nullValue()));

assertThat("Log contains message about leader election", logFromCoPod, not(containsString(LEADER_MESSAGE)));
assertThat("Log contains message about leader election", logFromCoPod.contains(LEADER_MESSAGE), is(false));
}

void checkDeploymentFiles() throws Exception {
Expand All @@ -126,10 +124,10 @@ void checkDeploymentFiles() throws Exception {

String clusterOperatorDep = Files.readString(Paths.get(pathToDepFile));

assertThat(clusterOperatorDep, containsString("STRIMZI_LEADER_ELECTION_ENABLED"));
assertThat(clusterOperatorDep, containsString("STRIMZI_LEADER_ELECTION_LEASE_NAME"));
assertThat(clusterOperatorDep, containsString("STRIMZI_LEADER_ELECTION_LEASE_NAMESPACE"));
assertThat(clusterOperatorDep, containsString("STRIMZI_LEADER_ELECTION_IDENTITY"));
assertThat("Cluster Operator's Deployment doesn't contain 'STRIMZI_LEADER_ELECTION_ENABLED' env variable", clusterOperatorDep.contains("STRIMZI_LEADER_ELECTION_ENABLED"), is(true));
assertThat("Cluster Operator's Deployment doesn't contain 'STRIMZI_LEADER_ELECTION_LEASE_NAME' env variable", clusterOperatorDep.contains("STRIMZI_LEADER_ELECTION_LEASE_NAME"), is(true));
assertThat("Cluster Operator's Deployment doesn't contain 'STRIMZI_LEADER_ELECTION_LEASE_NAMESPACE' env variable", clusterOperatorDep.contains("STRIMZI_LEADER_ELECTION_LEASE_NAMESPACE"), is(true));
assertThat("Cluster Operator's Deployment doesn't contain 'STRIMZI_LEADER_ELECTION_IDENTITY' env variable", clusterOperatorDep.contains("STRIMZI_LEADER_ELECTION_IDENTITY"), is(true));
}

@BeforeAll
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ void testTopicWithoutLabels() {
// Checking TO logs
String tOPodName = cmdKubeClient(testStorage.getNamespaceName()).listResourcesByLabel("pod", Labels.STRIMZI_NAME_LABEL + "=" + testStorage.getClusterName() + "-entity-operator").get(0);
String tOlogs = kubeClient(testStorage.getNamespaceName()).logsInSpecificNamespace(testStorage.getNamespaceName(), tOPodName, "topic-operator");
assertThat(tOlogs, not(containsString(String.format("Created topic '%s'", testStorage.getTargetTopicName()))));
assertThat("TO's log contains information about created topic", tOlogs.contains(String.format("Created topic '%s'", testStorage.getTargetTopicName())), is(false));

//Deleting topic
cmdKubeClient(testStorage.getNamespaceName()).deleteByName("kafkatopic", testStorage.getTargetTopicName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,10 @@ private void createSecretsForDeployments(final String namespace) {
*/
protected final void verifyOauthConfiguration(final String componentLogs) {
for (Map.Entry<String, Object> configField : COMPONENT_FIELDS_TO_VERIFY.entrySet()) {
assertThat(componentLogs, CoreMatchers.containsString(configField.getKey() + ": " + configField.getValue()));
String expectedKeyValue = configField.getKey() + ": " + configField.getValue();
assertThat(String.format("Component's log doesn't contain expected key/value: %s", expectedKeyValue), componentLogs.contains(expectedKeyValue), CoreMatchers.is(true));
}
assertThat(componentLogs, CoreMatchers.containsString("Successfully logged in"));
assertThat("Component's log doesn't contain 'Successfully logged in' sentence", componentLogs.contains("Successfully logged in"), CoreMatchers.is(true));
}

/**
Expand All @@ -172,9 +173,10 @@ protected final void verifyOauthConfiguration(final String componentLogs) {
*/
protected final void verifyOauthListenerConfiguration(final String kafkaLogs) {
for (Map.Entry<String, Object> configField : LISTENER_FIELDS_TO_VERIFY.entrySet()) {
assertThat(kafkaLogs, CoreMatchers.containsString(configField.getKey() + ": " + configField.getValue()));
String expectedKeyValue = configField.getKey() + ": " + configField.getValue();
assertThat(String.format("Kafka's log doesn't contain expected key/value: %s", expectedKeyValue), kafkaLogs.contains(expectedKeyValue), CoreMatchers.is(true));
}
assertThat(kafkaLogs, CoreMatchers.containsString("Successfully logged in"));
assertThat("Kafka's log doesn't contain 'Successfully logged in' sentence", kafkaLogs.contains("Successfully logged in"), CoreMatchers.is(true));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import io.strimzi.systemtest.utils.StUtils;
import io.strimzi.systemtest.utils.kubeUtils.controllers.JobUtils;
import io.strimzi.systemtest.utils.kubeUtils.objects.PodUtils;
import org.hamcrest.CoreMatchers;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Tag;

Expand All @@ -42,6 +41,7 @@
import static io.strimzi.systemtest.TestTags.OAUTH;
import static io.strimzi.systemtest.TestTags.REGRESSION;
import static io.strimzi.systemtest.resources.ResourceManager.kubeClient;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;

@Tag(OAUTH)
Expand Down Expand Up @@ -126,11 +126,16 @@ void testScopeKafkaConnectSetCorrectly() {
String kafkaConnectPodName = kubeClient().listPodsByPrefixInName(Environment.TEST_SUITE_NAMESPACE, StrimziPodSetResource.getBrokerComponentName(oauthClusterName)).get(0).getMetadata().getName();

String kafkaLog = kubeClient().logsInSpecificNamespace(Environment.TEST_SUITE_NAMESPACE, kafkaConnectPodName);
assertThat(kafkaLog, CoreMatchers.containsString("Access token expires at"));
assertThat(kafkaLog, CoreMatchers.containsString("Evaluating path: $[*][?]"));
assertThat(kafkaLog, CoreMatchers.containsString("Evaluating path: @['scope']"));
assertThat(kafkaLog, CoreMatchers.containsString("User validated"));
assertThat(kafkaLog, CoreMatchers.containsString("Set validated token on callback"));
assertThat("Kafka's log doesn't contain information about expiration of the access token",
kafkaLog.contains("Access token expires at"), is(true));
assertThat("Kafka's log doesn't contain information about evaluating path",
kafkaLog.contains("Evaluating path: $[*][?]"), is(true));
assertThat("Kafka's log doesn't contain information about evaluating path for scope",
kafkaLog.contains("Evaluating path: @['scope']"), is(true));
assertThat("Kafka's log doesn't contain information about user validation",
kafkaLog.contains("User validated"), is(true));
assertThat("Kafka's log doesn't contain information about setting validated token on callback",
kafkaLog.contains("Set validated token on callback"), is(true));
}

@ParallelTest
Expand Down