Skip to content

Commit 2861c87

Browse files
committed
Add common script to setup minikube for Playwright and system tests
Signed-off-by: Michael Edgar <medgar@redhat.com>
1 parent 25a5055 commit 2861c87

4 files changed

Lines changed: 177 additions & 61 deletions

File tree

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#!/usr/bin/env bash
2+
3+
set -euox pipefail
4+
5+
SOCAT_PID=""
6+
7+
function handle_error {
8+
echo "Error occurred at line $1"
9+
if [ -n "${SOCAT_PID}" ] ; then
10+
kill ${SOCAT_PID}
11+
fi
12+
kill 0 # kill the master shell and all subshells
13+
}
14+
15+
trap 'handle_error $LINENO' ERR
16+
17+
OLM_VERSION="v0.42.0"
18+
OLM_SCRIPT_SHA256="1e8065cb503d2ee94ce82dd2591618022852f53a43df908b9f8c7d314cff3532"
19+
20+
if [ -n "${MINIKUBE_PROFILE}" ] ; then
21+
MK_PROFILE_ARG="--profile=${MINIKUBE_PROFILE}"
22+
else
23+
MK_PROFILE_ARG=""
24+
fi
25+
26+
if ! minikube status ${MK_PROFILE_ARG} ; then
27+
minikube start ${MK_PROFILE_ARG} \
28+
--driver=${MINIKUBE_DRIVER:-kvm2} \
29+
--cpus=${MINIKUBE_CPU_COUNT:-6} \
30+
--memory=${MINIKUBE_MEMORY:-16384} \
31+
--container-runtime=${MINIKUBE_CONTAINER_RUNTIME:-docker} \
32+
--addons=registry,storage,ingress,ingress-dns,metrics-server \
33+
--insecure-registry="localhost:5000,10.0.0.0/24" \
34+
--extra-config=kubeadm.ignore-preflight-errors=SystemVerification \
35+
--extra-config=apiserver.authorization-mode=RBAC,Node
36+
fi
37+
38+
# Enable TLS/passthrough in Nginx -------------------------------
39+
if [ "$(kubectl get deployment -n ingress-nginx ingress-nginx-controller -ojson | \
40+
jq -r '.spec.template.spec.containers[0].args | index("--enable-ssl-passthrough")')" == "null" ] ; then
41+
kubectl patch deployment -n ingress-nginx ingress-nginx-controller \
42+
--type='json' \
43+
-p='[{"op": "add", "path": "/spec/template/spec/containers/0/args/-", "value":"--enable-ssl-passthrough"}]'
44+
fi
45+
46+
# Setup OLM -----------------------------------------------------
47+
OLM_INSTALL_SCRIPT=$(mktemp)
48+
49+
curl --proto "=https" --tlsv1.3 -o ${OLM_INSTALL_SCRIPT} -sL \
50+
https://github.com/operator-framework/operator-lifecycle-manager/releases/download/${OLM_VERSION}/install.sh
51+
52+
echo "${OLM_SCRIPT_SHA256} ${OLM_INSTALL_SCRIPT}" | sha256sum --check --status || { echo "Hash verification failed"; exit 1; }
53+
chmod +x ${OLM_INSTALL_SCRIPT}
54+
${OLM_INSTALL_SCRIPT} ${OLM_VERSION} || true
55+
rm -v ${OLM_INSTALL_SCRIPT}
56+
57+
# Build and push Console images ---------------------------------
58+
PROJECT_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout | tr '[:upper:]' '[:lower:]')
59+
CONTAINER_RUNTIME=$(which podman || which docker)
60+
SKOPEO_LOCAL=$(which podman >/dev/null && echo "containers-storage:" || echo "docker-daemon:")
61+
PLATFORMS=$(docker system info --format '{{.OSType}}/{{.Architecture}}' 2>/dev/null || podman info --format={{".Version.OsArch"}})
62+
63+
mvn clean package -Pcontainer-image -B --no-transfer-progress -DskipTests \
64+
-Dquarkus.kubernetes.namespace='$${NAMESPACE}' \
65+
-Dcontainer-image.tag=${PROJECT_VERSION} \
66+
-Dcontainer-image.registry='localhost:5000' \
67+
-Dcontainer-image.push=false
68+
69+
./operator/bin/modify-bundle-metadata.sh \
70+
"VERSION=${PROJECT_VERSION}" \
71+
"SKOPEO_TRANSPORT=${SKOPEO_LOCAL}" \
72+
"PLATFORMS=${PLATFORMS}"
73+
74+
${CONTAINER_RUNTIME} build \
75+
-t localhost:5000/streamshub/console-operator-bundle:${PROJECT_VERSION} \
76+
-f operator/target/bundle/streamshub-console-operator/bundle.Dockerfile
77+
78+
./operator/bin/generate-catalog.sh ./operator/target/bundle/streamshub-console-operator true
79+
80+
${CONTAINER_RUNTIME} build \
81+
-t localhost:5000/streamshub/console-operator-catalog:${PROJECT_VERSION} \
82+
-f operator/src/main/docker/catalog.Dockerfile \
83+
operator/
84+
85+
socat TCP-LISTEN:5000,reuseaddr,fork TCP:$(minikube ip ${MK_PROFILE_ARG}):5000 &
86+
SOCAT_PID=${!}
87+
# Wait for socat to warm up
88+
sleep 5
89+
90+
for img in console-api console-operator console-operator-bundle console-operator-catalog ; do
91+
skopeo copy --preserve-digests --dest-tls-verify=false \
92+
${SKOPEO_LOCAL}localhost:5000/streamshub/${img}:${PROJECT_VERSION} \
93+
docker://localhost:5000/streamshub/${img}:${PROJECT_VERSION}
94+
done
95+
96+
kill ${SOCAT_PID}
97+
SOCAT_PID=""

systemtests/src/main/java/com/github/streamshub/systemtests/setup/strimzi/KafkaSetup.java

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
package com.github.streamshub.systemtests.setup.strimzi;
22

3+
import java.io.File;
4+
import java.util.List;
5+
import java.util.Map;
6+
import java.util.stream.IntStream;
7+
8+
import org.apache.logging.log4j.Logger;
9+
310
import com.github.streamshub.systemtests.Environment;
411
import com.github.streamshub.systemtests.constants.Constants;
512
import com.github.streamshub.systemtests.logs.LogWrapper;
613
import com.github.streamshub.systemtests.utils.Utils;
714
import com.github.streamshub.systemtests.utils.WaitUtils;
815
import com.github.streamshub.systemtests.utils.resourceutils.ClusterUtils;
9-
import com.github.streamshub.systemtests.utils.resourceutils.ResourceUtils;
1016
import com.github.streamshub.systemtests.utils.resourceutils.kafka.KafkaNamingUtils;
17+
1118
import io.fabric8.kubernetes.api.model.ConfigMap;
1219
import io.fabric8.kubernetes.api.model.ConfigMapBuilder;
1320
import io.skodjob.kubetest4j.resources.KubeResourceManager;
@@ -28,12 +35,6 @@
2835
import io.strimzi.api.kafka.model.user.KafkaUserBuilder;
2936
import io.strimzi.api.kafka.model.user.acl.AclOperation;
3037
import io.strimzi.api.kafka.model.user.acl.AclResourcePatternType;
31-
import org.apache.logging.log4j.Logger;
32-
33-
import java.io.File;
34-
import java.util.List;
35-
import java.util.Map;
36-
import java.util.stream.IntStream;
3738

3839
import static io.skodjob.kubetest4j.KubeTestEnv.USER_PATH;
3940

@@ -83,16 +84,14 @@ public static void setupKafkaWithCcIfNeeded(String namespaceName, String cluster
8384
*/
8485
public static void setupKafkaIfNeeded(ConfigMap configMap, KafkaNodePool brokerNodePools, KafkaNodePool controllerNodePools, KafkaUser kafkaUser, Kafka kafka) {
8586
LOGGER.info("Setup test Kafka {}/{} and it's components", kafka.getMetadata().getNamespace(), kafka.getMetadata().getName());
86-
if (ResourceUtils.getKubeResource(Kafka.class, kafka.getMetadata().getNamespace(), kafka.getMetadata().getName()) == null) {
87-
KubeResourceManager.get().createResourceWithWait(configMap);
88-
KubeResourceManager.get().createResourceWithWait(brokerNodePools);
89-
KubeResourceManager.get().createResourceWithWait(controllerNodePools);
90-
KubeResourceManager.get().createResourceWithWait(kafka);
91-
KubeResourceManager.get().createResourceWithWait(kafkaUser);
92-
WaitUtils.waitForSecretReady(kafkaUser.getMetadata().getNamespace(), kafkaUser.getMetadata().getName());
93-
} else {
94-
LOGGER.warn("Skipping Kafka deployment, there already is a Kafka cluster");
95-
}
87+
KubeResourceManager.get().createOrUpdateResourceAsyncWait(
88+
configMap,
89+
brokerNodePools,
90+
controllerNodePools,
91+
kafka,
92+
kafkaUser
93+
);
94+
WaitUtils.waitForSecretReady(kafkaUser.getMetadata().getNamespace(), kafkaUser.getMetadata().getName());
9695
}
9796

9897
/**

systemtests/src/main/java/com/github/streamshub/systemtests/utils/playwright/PwUtils.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,11 @@ public static Browser createBrowser(Playwright playwright) {
7070
* @param tcc the test case configuration containing page and Kafka cluster information
7171
*/
7272
public static void login(TestCaseConfig tcc, String kafkaName) {
73-
final String loginUrl = PwPageUrls.getKafkaLoginPage(tcc, kafkaName);
74-
LOGGER.info("Logging in to the Console with URL: {}", loginUrl);
75-
waitForConsoleUiAnonymousLoginToBecomeReady(tcc);
73+
String overviewUrl = PwPageUrls.getOverviewPage(tcc, kafkaName);
74+
LOGGER.info("Logging in to the Console with URL: {}", overviewUrl);
7675
// Anonymous login
77-
navigate(tcc, loginUrl);
78-
waitForUrl(tcc, loginUrl, false);
79-
// Go to login
80-
waitForLocatorAndClick(tcc, CssSelectors.LOGIN_ANONYMOUSLY_BUTTON);
81-
waitForUrl(tcc, PwPageUrls.getOverviewPage(tcc, kafkaName), true);
76+
navigate(tcc, overviewUrl);
77+
waitForUrl(tcc, overviewUrl, true);
8278
LOGGER.info("Successfully logged into Console");
8379
}
8480

systemtests/src/test/java/com/github/streamshub/systemtests/messages/MessagesST.java

Lines changed: 60 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
package com.github.streamshub.systemtests.messages;
22

3+
import java.time.Instant;
4+
import java.time.OffsetDateTime;
5+
import java.time.ZoneId;
6+
import java.time.ZoneOffset;
7+
import java.time.format.DateTimeFormatter;
8+
import java.util.Map;
9+
import java.util.stream.Stream;
10+
11+
import org.apache.kafka.common.security.auth.SecurityProtocol;
12+
import org.apache.logging.log4j.Logger;
13+
import org.junit.jupiter.api.AfterAll;
14+
import org.junit.jupiter.api.BeforeAll;
15+
import org.junit.jupiter.api.Tag;
16+
import org.junit.jupiter.api.Test;
17+
import org.junit.jupiter.params.ParameterizedTest;
18+
import org.junit.jupiter.params.provider.Arguments;
19+
import org.junit.jupiter.params.provider.MethodSource;
20+
321
import com.github.streamshub.systemtests.AbstractST;
422
import com.github.streamshub.systemtests.MessageStore;
523
import com.github.streamshub.systemtests.TestCaseConfig;
@@ -24,24 +42,12 @@
2442
import com.github.streamshub.systemtests.utils.resourceutils.kafka.KafkaTopicUtils;
2543
import com.github.streamshub.systemtests.utils.resourceutils.kafka.KafkaUtils;
2644
import com.github.streamshub.systemtests.utils.testchecks.MessagesChecks;
27-
import io.skodjob.kubetest4j.resources.KubeResourceManager;
28-
import org.apache.kafka.common.security.auth.SecurityProtocol;
29-
import org.apache.logging.log4j.Logger;
30-
import org.junit.jupiter.api.AfterAll;
31-
import org.junit.jupiter.api.BeforeAll;
32-
import org.junit.jupiter.api.Tag;
33-
import org.junit.jupiter.api.Test;
34-
import org.junit.jupiter.params.ParameterizedTest;
35-
import org.junit.jupiter.params.provider.Arguments;
36-
import org.junit.jupiter.params.provider.MethodSource;
45+
import com.microsoft.playwright.Page.GetByRoleOptions;
46+
import com.microsoft.playwright.assertions.LocatorAssertions.ContainsTextOptions;
47+
import com.microsoft.playwright.assertions.PlaywrightAssertions;
48+
import com.microsoft.playwright.options.AriaRole;
3749

38-
import java.time.Instant;
39-
import java.time.OffsetDateTime;
40-
import java.time.ZoneId;
41-
import java.time.ZoneOffset;
42-
import java.time.format.DateTimeFormatter;
43-
import java.util.Map;
44-
import java.util.stream.Stream;
50+
import io.skodjob.kubetest4j.resources.KubeResourceManager;
4551

4652
import static com.github.streamshub.systemtests.utils.Utils.getTestCaseConfig;
4753
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -319,8 +325,12 @@ void testFilterMessagesUsingUIForm() {
319325
PwUtils.navigate(tcc, PwPageUrls.getMessagesPage(tcc, tcc.kafkaName(), topicId));
320326

321327
LOGGER.info("Wait for page toolbar to be fully loaded before filtering");
322-
PwUtils.waitForContainsText(tcc, CssSelectors.PAGES_CONTENT_HEADER_TITLE_CONTENT, kafkaTopicName, true);
323-
PwUtils.waitForLocatorVisible(tcc, MessagesPageSelectors.MPS_SEARCH_TOOLBAR_QUERY_INPUT);
328+
PlaywrightAssertions.assertThat(tcc.page().getByRole(AriaRole.HEADING, new GetByRoleOptions().setLevel(1)))
329+
.containsText(kafkaTopicName, new ContainsTextOptions().setTimeout(20000));
330+
PlaywrightAssertions.assertThat(tcc.page().getByPlaceholder("Search")).isVisible();
331+
332+
//PwUtils.waitForContainsText(tcc, CssSelectors.PAGES_CONTENT_HEADER_TITLE_CONTENT, kafkaTopicName, true);
333+
//PwUtils.waitForLocatorVisible(tcc, MessagesPageSelectors.MPS_SEARCH_TOOLBAR_QUERY_INPUT);
324334

325335
LOGGER.info("Verify default state of displayed messages");
326336
PwUtils.waitForLocatorCount(tcc, 50, MessagesPageSelectors.MPS_SEARCH_RESULTS_TABLE_ITEMS, true);
@@ -445,37 +455,51 @@ public void prepareVariousMessageTypes() {
445455

446456
// Setup UI form filtering
447457
// First set clients to send messages with KEY
448-
KafkaClients clients = new KafkaClientsBuilder()
458+
KafkaClients clients1 = new KafkaClientsBuilder()
449459
.withNamespaceName(tcc.namespace())
450460
.withTopicName(kafkaTopicName)
451461
.withMessageCount(MESSAGE_COUNT)
452462
.withDelayMs(0)
453-
.withProducerName(KafkaNamingUtils.producerName(kafkaTopicName))
454-
.withConsumerName(KafkaNamingUtils.consumerName(kafkaTopicName))
455-
.withConsumerGroup(KafkaNamingUtils.consumerGroupName(kafkaTopicName))
463+
.withProducerName(KafkaNamingUtils.producerName(kafkaTopicName) + "-1")
464+
.withConsumerName(KafkaNamingUtils.consumerName(kafkaTopicName) + "-1")
465+
.withConsumerGroup(KafkaNamingUtils.consumerGroupName(kafkaTopicName) + "-1")
456466
.withBootstrapAddress(KafkaUtils.getPlainScramShaBootstrapAddress(tcc.kafkaName()))
457467
.withUsername(tcc.kafkaUserName())
458468
.withMessage(KEY_FILTER_MESSAGE)
459469
.withMessageKey(KEY_FILTER)
460470
.withAdditionalConfig(KafkaClientsUtils.getScramShaConfig(tcc.namespace(), tcc.kafkaUserName(), SecurityProtocol.SASL_PLAINTEXT))
461471
.build();
462472

463-
KubeResourceManager.get().createResourceWithWait(clients.producer(), clients.consumer());
464-
WaitUtils.waitForClientsSuccess(clients);
465-
466473
// create second set of messages with different HEADER and MESSAGE
467-
clients.setMessageKey("NoDataInKey-True");
468-
clients.setHeaders(HEADER_FILTER);
469-
clients.setMessage(HEADER_FILTER_MESSAGE);
474+
KafkaClients clients2 = new KafkaClientsBuilder(clients1)
475+
.withProducerName(KafkaNamingUtils.producerName(kafkaTopicName) + "-2")
476+
.withConsumerName(KafkaNamingUtils.consumerName(kafkaTopicName) + "-2")
477+
.withConsumerGroup(KafkaNamingUtils.consumerGroupName(kafkaTopicName) + "-2")
478+
.withMessageKey("NoDataInKey-True")
479+
.withHeaders(HEADER_FILTER)
480+
.withMessage(HEADER_FILTER_MESSAGE)
481+
.build();
470482

471-
KubeResourceManager.get().createResourceWithWait(clients.producer(), clients.consumer());
472-
WaitUtils.waitForClientsSuccess(clients);
473483
// create third set of messages with different MESSAGE
474-
clients.setHeaders("NoDataInHeader=true");
475-
clients.setMessage(VALUE_FILTER);
476-
477-
KubeResourceManager.get().createResourceWithWait(clients.producer(), clients.consumer());
478-
WaitUtils.waitForClientsSuccess(clients);
484+
KafkaClients clients3 = new KafkaClientsBuilder(clients2)
485+
.withProducerName(KafkaNamingUtils.producerName(kafkaTopicName) + "-3")
486+
.withConsumerName(KafkaNamingUtils.consumerName(kafkaTopicName) + "-3")
487+
.withConsumerGroup(KafkaNamingUtils.consumerGroupName(kafkaTopicName) + "-3")
488+
.withHeaders("NoDataInHeader=true")
489+
.withMessage(VALUE_FILTER)
490+
.build();
491+
492+
KubeResourceManager.get().createOrUpdateResourceAsyncWait(
493+
clients1.producer(),
494+
clients1.consumer(),
495+
clients2.producer(),
496+
clients2.consumer(),
497+
clients3.producer(),
498+
clients3.consumer()
499+
);
500+
WaitUtils.waitForClientsSuccess(clients1);
501+
WaitUtils.waitForClientsSuccess(clients2);
502+
WaitUtils.waitForClientsSuccess(clients3);
479503
LOGGER.info("Filtering scenario prepared");
480504
}
481505

0 commit comments

Comments
 (0)