You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by "lordgamez (via GitHub)" <gi...@apache.org> on 2025/11/06 16:39:26 UTC
[PR] MINIFICPP-2666 Move Kafka tests to modular docker tests [nifi-minifi-cpp]
lordgamez opened a new pull request, #2059:
URL: https://github.com/apache/nifi-minifi-cpp/pull/2059
- Create SSL certificates for each MiNiFi container for SSL tests
Depends on https://github.com/apache/nifi-minifi-cpp/pull/2052
https://issues.apache.org/jira/browse/MINIFICPP-2666
----------------
Thank you for submitting a contribution to Apache NiFi - MiNiFi C++.
In order to streamline the review of the contribution we ask you
to ensure the following steps have been taken:
### For all changes:
- [ ] Is there a JIRA ticket associated with this PR? Is it referenced
in the commit message?
- [ ] Does your PR title start with MINIFICPP-XXXX where XXXX is the JIRA number you are trying to resolve? Pay particular attention to the hyphen "-" character.
- [ ] Has your PR been rebased against the latest commit within the target branch (typically main)?
- [ ] Is your initial contribution a single, squashed commit?
### For code changes:
- [ ] If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under [ASF 2.0](http://www.apache.org/legal/resolved.html#category-a)?
- [ ] If applicable, have you updated the LICENSE file?
- [ ] If applicable, have you updated the NOTICE file?
### For documentation related changes:
- [ ] Have you ensured that format looks appropriate for the output in which it is rendered?
### Note:
Please ensure that once the PR is submitted, you check GitHub Actions CI results for build issues and submit an update to your PR as soon as possible.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] MINIFICPP-2666 Move Kafka tests to modular docker tests [nifi-minifi-cpp]
Posted by "lordgamez (via GitHub)" <gi...@apache.org>.
lordgamez commented on code in PR #2059:
URL: https://github.com/apache/nifi-minifi-cpp/pull/2059#discussion_r2533897935
##########
behave_framework/src/minifi_test_framework/containers/container.py:
##########
@@ -204,6 +232,7 @@ def exited(self) -> bool:
def get_number_of_files(self, directory_path: str) -> int:
if not self.container or not self.not_empty_dir_exists(directory_path):
+ logging.warning(f"Container not running or directory does not exist: {directory_path}")
Review Comment:
Logging is imported on line 18.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] MINIFICPP-2666 Move Kafka tests to modular docker tests [nifi-minifi-cpp]
Posted by "szaszm (via GitHub)" <gi...@apache.org>.
szaszm commented on code in PR #2059:
URL: https://github.com/apache/nifi-minifi-cpp/pull/2059#discussion_r2661729999
##########
extensions/kafka/tests/features/steps/kafka_server_container.py:
##########
@@ -0,0 +1,126 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import logging
+import re
+import jks
+
+from OpenSSL import crypto
+from minifi_test_framework.core.helpers import wait_for_condition
+from minifi_test_framework.core.ssl_utils import make_server_cert
+from minifi_test_framework.containers.container import Container
+from minifi_test_framework.containers.file import File
+from minifi_test_framework.core.minifi_test_context import MinifiTestContext
+
+
+class KafkaServer(Container):
+ def __init__(self, test_context: MinifiTestContext):
+ super().__init__("apache/kafka:4.1.0", f"kafka-server-{test_context.scenario_id}", test_context.network)
+ self.environment.append("KAFKA_NODE_ID=1")
+ self.environment.append("KAFKA_PROCESS_ROLES=controller,broker")
+ self.environment.append("KAFKA_INTER_BROKER_LISTENER_NAME=PLAINTEXT")
+ self.environment.append("KAFKA_CONTROLLER_LISTENER_NAMES=CONTROLLER")
+ self.environment.append("KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR=1")
+ self.environment.append("KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR=1")
+ self.environment.append("KAFKA_TRANSACTION_STATE_LOG_MIN_ISR=1")
+ self.environment.append(f"KAFKA_CONTROLLER_QUORUM_VOTERS=1@kafka-server-{test_context.scenario_id}:9096")
+ self.environment.append(f"KAFKA_LISTENERS=PLAINTEXT://kafka-server-{test_context.scenario_id}:9092,SASL_PLAINTEXT://kafka-server-{test_context.scenario_id}:9094,SSL://kafka-server-{test_context.scenario_id}:9093,SASL_SSL://kafka-server-{test_context.scenario_id}:9095,CONTROLLER://kafka-server-{test_context.scenario_id}:9096")
+ self.environment.append(f"KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://kafka-server-{test_context.scenario_id}:9092,SASL_PLAINTEXT://kafka-server-{test_context.scenario_id}:9094,SSL://kafka-server-{test_context.scenario_id}:9093,SASL_SSL://kafka-server-{test_context.scenario_id}:9095,CONTROLLER://kafka-server-{test_context.scenario_id}:9096")
+ self.environment.append("KAFKA_LISTENER_SECURITY_PROTOCOL_MAP=PLAINTEXT:PLAINTEXT,SASL_PLAINTEXT:SASL_PLAINTEXT,SSL:SSL,SASL_SSL:SASL_SSL,CONTROLLER:PLAINTEXT")
+ self.environment.append("KAFKA_SASL_MECHANISM_INTER_BROKER_PROTOCOL=PLAIN")
+ self.environment.append("KAFKA_SASL_ENABLED_MECHANISMS=PLAIN")
+ self.environment.append("KAFKA_OPTS=-Djava.security.auth.login.config=/opt/kafka/config/kafka_jaas.conf -Dlog4j2.rootLogger.level=DEBUG -Dlog4j2.logger.org.apache.kafka.controller.level=DEBUG")
+ self.environment.append("KAFKA_SSL_PROTOCOL=TLS")
+ self.environment.append("KAFKA_SSL_ENABLED_PROTOCOLS=TLSv1.2")
+ self.environment.append("KAFKA_SSL_KEYSTORE_TYPE=JKS")
+ self.environment.append("KAFKA_SSL_KEYSTORE_FILENAME=kafka.keystore.jks")
+ self.environment.append("KAFKA_SSL_KEYSTORE_CREDENTIALS=credentials.conf")
+ self.environment.append("KAFKA_SSL_KEY_CREDENTIALS=credentials.conf")
+ self.environment.append("KAFKA_SSL_TRUSTSTORE_CREDENTIALS=credentials.conf")
+ self.environment.append("KAFKA_SSL_TRUSTSTORE_TYPE=JKS")
+ self.environment.append("KAFKA_SSL_TRUSTSTORE_FILENAME=kafka.truststore.jks")
+ self.environment.append("KAFKA_SSL_CLIENT_AUTH=none")
+
+ kafka_cert, kafka_key = make_server_cert(self.container_name, test_context.root_ca_cert, test_context.root_ca_key)
+
+ pke = jks.PrivateKeyEntry.new('kafka-broker-cert', [crypto.dump_certificate(crypto.FILETYPE_ASN1, kafka_cert)], crypto.dump_privatekey(crypto.FILETYPE_ASN1, kafka_key), 'rsa_raw')
+ server_keystore = jks.KeyStore.new('jks', [pke])
+ server_keystore_content = server_keystore.saves('abcdefgh')
+ self.files.append(File("/etc/kafka/secrets/kafka.keystore.jks", server_keystore_content, permissions=0o644))
+ self.files.append(File("/etc/kafka/secrets/credentials.conf", b'abcdefgh', permissions=0o644))
+
+ trusted_cert = jks.TrustedCertEntry.new(
+ 'root-ca', # Alias for the certificate
+ crypto.dump_certificate(crypto.FILETYPE_ASN1, test_context.root_ca_cert)
+ )
+
+ # Create a JKS keystore that will serve as a truststore with the trusted cert entry.
+ truststore = jks.KeyStore.new('jks', [trusted_cert])
+ truststore_content = truststore.saves('abcdefgh')
+ self.files.append(File("/etc/kafka/secrets/kafka.truststore.jks", truststore_content, permissions=0o644))
+
+ jaas_config_file_content = """
+KafkaServer {
+ org.apache.kafka.common.security.plain.PlainLoginModule required
+ username="admin"
+ password="admin-secret"
+ user_admin="admin-secret"
+ user_alice="alice-secret";
+};
+
+Client {
+ org.apache.kafka.common.security.plain.PlainLoginModule required
+ username="admin"
+ password="admin-secret";
+};
+"""
+ self.files.append(File("/opt/kafka/config/kafka_jaas.conf", jaas_config_file_content, permissions=0o644))
+
+ def deploy(self):
+ super().deploy()
+ finished_str = "Kafka Server started"
+ return wait_for_condition(
+ condition=lambda: finished_str in self.get_logs(),
+ timeout_seconds=60,
+ bail_condition=lambda: self.exited,
+ context=None)
+
+ def create_topic(self, topic_name: str):
+ (code, output) = self.exec_run(["/bin/sh", "-c", f"/opt/kafka/bin/kafka-topics.sh --create --topic '{topic_name}' --bootstrap-server '{self.container_name}':9092"])
+ logging.info(f"Create topic output: '{output}' with code {code}")
+ return code == 0
+
+ def produce_message(self, topic_name: str, message: str):
+ (code, output) = self.exec_run(["/bin/sh", "-c", f"echo '{message}' | /opt/kafka/bin/kafka-console-producer.sh --topic '{topic_name}' --bootstrap-server '{self.container_name}':9092"])
+ logging.info(f"Produce message output: '{output}' with code {code}")
+ return code == 0
+
+ def produce_message_with_key(self, topic_name: str, message: str, message_key: str):
+ (code, output) = self.exec_run(["/bin/sh", "-c", f" echo ''{message_key}:{message}'' | /opt/kafka/bin/kafka-console-producer.sh --property 'key.separator=:' --property 'parse.key=true' --topic '{topic_name}' --bootstrap-server '{self.container_name}':9092"])
Review Comment:
are the double single quotes intentional? I don't recognize it as a kind of escaping, but I don't know python syntax that well.
##########
behave_framework/src/minifi_test_framework/steps/checking_steps.py:
##########
@@ -152,3 +172,28 @@ def step_impl(context: MinifiTestContext, max_increase: str, duration: str):
time.sleep(time_in_seconds)
final_memory_usage = context.get_default_minifi_container().get_memory_usage()
assert final_memory_usage - initial_memory_usage <= max_increase_in_bytes
+
+
+@then('after a wait of {duration}, at least {lower_bound:d} and at most {upper_bound:d} flowfiles are produced and placed in the "{directory}" directory')
Review Comment:
On other steps, we changed them to talk about "files" placed instead of "flow files" placed, I'd change it here too
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] MINIFICPP-2666 Move Kafka tests to modular docker tests [nifi-minifi-cpp]
Posted by "lordgamez (via GitHub)" <gi...@apache.org>.
lordgamez commented on code in PR #2059:
URL: https://github.com/apache/nifi-minifi-cpp/pull/2059#discussion_r2661844266
##########
behave_framework/src/minifi_test_framework/steps/checking_steps.py:
##########
@@ -83,16 +84,34 @@ def step_impl(context: MinifiTestContext, message: str, duration: str):
context=context)
+@then("the Minifi logs match the following regex: \"{regex}\" in less than {duration}")
+def step_impl(context, regex, duration):
+ duration_seconds = humanfriendly.parse_timespan(duration)
+ assert wait_for_condition(condition=lambda: re.search(regex, context.get_default_minifi_container().get_logs()),
+ timeout_seconds=duration_seconds, bail_condition=lambda: context.get_default_minifi_container().exited,
+ context=context)
+
+
@step('no errors were generated on the http-proxy regarding "{url}"')
def step_impl(context: MinifiTestContext, url: str):
http_proxy_container = next(container for container in context.containers.values() if isinstance(container, HttpProxy))
assert http_proxy_container.check_http_proxy_access(url) or http_proxy_container.log_app_output()
+@then('no files are placed in the "{directory}" directory in {duration} of running time')
+def step_impl(context, directory, duration):
+ duration_seconds = humanfriendly.parse_timespan(duration)
+ assert check_condition_after_wait(condition=lambda: context.get_default_minifi_container().get_number_of_files(directory) < 1,
Review Comment:
Updated in https://github.com/apache/nifi-minifi-cpp/pull/2059/commits/ddab3ecd04476c801e3f6e2d3190e39bd7e0c25d as not creating an output directory should also return 0 (not created due to no output was generated).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] MINIFICPP-2666 Move Kafka tests to modular docker tests [nifi-minifi-cpp]
Posted by "lordgamez (via GitHub)" <gi...@apache.org>.
lordgamez commented on code in PR #2059:
URL: https://github.com/apache/nifi-minifi-cpp/pull/2059#discussion_r2533902912
##########
extensions/kafka/tests/features/steps/kafka_server_container.py:
##########
@@ -0,0 +1,126 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import logging
+import re
+import jks
+
+from OpenSSL import crypto
+from minifi_test_framework.core.helpers import wait_for_condition
+from minifi_test_framework.core.ssl_utils import make_server_cert
+from minifi_test_framework.containers.container import Container
+from minifi_test_framework.containers.file import File
+from minifi_test_framework.core.minifi_test_context import MinifiTestContext
+
+
+class KafkaServer(Container):
+ def __init__(self, test_context: MinifiTestContext):
+ super().__init__("apache/kafka:4.1.0", f"kafka-server-{test_context.scenario_id}", test_context.network)
+ self.environment.append("KAFKA_NODE_ID=1")
+ self.environment.append("KAFKA_PROCESS_ROLES=controller,broker")
+ self.environment.append("KAFKA_INTER_BROKER_LISTENER_NAME=PLAINTEXT")
+ self.environment.append("KAFKA_CONTROLLER_LISTENER_NAMES=CONTROLLER")
+ self.environment.append("KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR=1")
+ self.environment.append("KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR=1")
+ self.environment.append("KAFKA_TRANSACTION_STATE_LOG_MIN_ISR=1")
+ self.environment.append(f"KAFKA_CONTROLLER_QUORUM_VOTERS=1@kafka-server-{test_context.scenario_id}:9096")
+ self.environment.append(f"KAFKA_LISTENERS=PLAINTEXT://kafka-server-{test_context.scenario_id}:9092,SASL_PLAINTEXT://kafka-server-{test_context.scenario_id}:9094,SSL://kafka-server-{test_context.scenario_id}:9093,SASL_SSL://kafka-server-{test_context.scenario_id}:9095,CONTROLLER://kafka-server-{test_context.scenario_id}:9096")
+ self.environment.append(f"KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://kafka-server-{test_context.scenario_id}:9092,SASL_PLAINTEXT://kafka-server-{test_context.scenario_id}:9094,SSL://kafka-server-{test_context.scenario_id}:9093,SASL_SSL://kafka-server-{test_context.scenario_id}:9095,CONTROLLER://kafka-server-{test_context.scenario_id}:9096")
+ self.environment.append("KAFKA_LISTENER_SECURITY_PROTOCOL_MAP=PLAINTEXT:PLAINTEXT,SASL_PLAINTEXT:SASL_PLAINTEXT,SSL:SSL,SASL_SSL:SASL_SSL,CONTROLLER:PLAINTEXT")
+ self.environment.append("KAFKA_SASL_MECHANISM_INTER_BROKER_PROTOCOL=PLAIN")
+ self.environment.append("KAFKA_SASL_ENABLED_MECHANISMS=PLAIN")
+ self.environment.append("KAFKA_OPTS=-Djava.security.auth.login.config=/opt/kafka/config/kafka_jaas.conf -Dlog4j2.rootLogger.level=DEBUG -Dlog4j2.logger.org.apache.kafka.controller.level=DEBUG")
+ self.environment.append("KAFKA_SSL_PROTOCOL=TLS")
+ self.environment.append("KAFKA_SSL_ENABLED_PROTOCOLS=TLSv1.2")
+ self.environment.append("KAFKA_SSL_KEYSTORE_TYPE=JKS")
+ self.environment.append("KAFKA_SSL_KEYSTORE_FILENAME=kafka.keystore.jks")
+ self.environment.append("KAFKA_SSL_KEYSTORE_CREDENTIALS=credentials.conf")
+ self.environment.append("KAFKA_SSL_KEY_CREDENTIALS=credentials.conf")
+ self.environment.append("KAFKA_SSL_TRUSTSTORE_CREDENTIALS=credentials.conf")
+ self.environment.append("KAFKA_SSL_TRUSTSTORE_TYPE=JKS")
+ self.environment.append("KAFKA_SSL_TRUSTSTORE_FILENAME=kafka.truststore.jks")
+ self.environment.append("KAFKA_SSL_CLIENT_AUTH=none")
+
+ kafka_cert, kafka_key = make_server_cert(self.container_name, test_context.root_ca_cert, test_context.root_ca_key)
+
+ pke = jks.PrivateKeyEntry.new('kafka-broker-cert', [crypto.dump_certificate(crypto.FILETYPE_ASN1, kafka_cert)], crypto.dump_privatekey(crypto.FILETYPE_ASN1, kafka_key), 'rsa_raw')
+ server_keystore = jks.KeyStore.new('jks', [pke])
+ server_keystore_content = server_keystore.saves('abcdefgh')
+ self.files.append(File("/etc/kafka/secrets/kafka.keystore.jks", server_keystore_content, permissions=0o644))
+ self.files.append(File("/etc/kafka/secrets/credentials.conf", b'abcdefgh', permissions=0o644))
+
+ trusted_cert = jks.TrustedCertEntry.new(
+ 'root-ca', # Alias for the certificate
+ crypto.dump_certificate(crypto.FILETYPE_ASN1, test_context.root_ca_cert)
+ )
+
+ # Create a JKS keystore that will serve as a truststore with the trusted cert entry.
+ truststore = jks.KeyStore.new('jks', [trusted_cert])
+ truststore_content = truststore.saves('abcdefgh')
+ self.files.append(File("/etc/kafka/secrets/kafka.truststore.jks", truststore_content, permissions=0o644))
Review Comment:
We may consider this in the future, but will not address it in this PR.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] MINIFICPP-2666 Move Kafka tests to modular docker tests [nifi-minifi-cpp]
Posted by "lordgamez (via GitHub)" <gi...@apache.org>.
lordgamez commented on code in PR #2059:
URL: https://github.com/apache/nifi-minifi-cpp/pull/2059#discussion_r2660985459
##########
extensions/kafka/tests/features/consumekafka.feature:
##########
@@ -19,54 +19,55 @@ Feature: Receiving data from using Kafka streaming platform using ConsumeKafka
As a user of MiNiFi
I need to have ConsumeKafka processor
- Background:
- Given the content of "/tmp/output" is monitored
-
Scenario Outline: ConsumeKafka parses and uses kafka topics and topic name formats
- Given a ConsumeKafka processor set up in a "kafka-consumer-flow" flow
+ Given a Kafka server is set up
+ And ConsumeKafka processor is set up to communicate with that server
And the "Topic Names" property of the ConsumeKafka processor is set to "<topic names>"
And the "Topic Name Format" property of the ConsumeKafka processor is set to "<topic name format>"
And the "Offset Reset" property of the ConsumeKafka processor is set to "earliest"
- And a PutFile processor with the "Directory" property set to "/tmp/output" in the "kafka-consumer-flow" flow
+ And a PutFile processor with the "Directory" property set to "/tmp/output"
+ And PutFile is EVENT_DRIVEN
And the "success" relationship of the ConsumeKafka processor is connected to the PutFile
+ And PutFile's success relationship is auto-terminated
- And a kafka broker is set up in correspondence with the third-party kafka publisher
- And the kafka broker is started
+ And the Kafka server is started
And the topic "ConsumeKafkaTest" is initialized on the kafka broker
When a message with content "<message 1>" is published to the "ConsumeKafkaTest" topic
- And all other processes start up
+ And the MiNiFi instance starts up
And a message with content "<message 2>" is published to the "ConsumeKafkaTest" topic
- Then two flowfiles with the contents "<message 1>" and "<message 2>" are placed in the monitored directory in less than 90 seconds
+ Then the contents of "/tmp/output" in less than 30 seconds are: "<message 1>" and "<message 2>"
Examples: Topic names and formats to test
| message 1 | message 2 | topic names | topic name format |
- | Ulysses | James Joyce | ConsumeKafkaTest | (not set) |
| The Great Gatsby | F. Scott Fitzgerald | ConsumeKafkaTest | Names |
| War and Peace | Lev Tolstoy | a,b,c,ConsumeKafkaTest,d | Names |
| Nineteen Eighty Four | George Orwell | ConsumeKafkaTest | Patterns |
| Hamlet | William Shakespeare | Cons[emu]*KafkaTest | Patterns |
Scenario Outline: ConsumeKafka key attribute is encoded according to the "Key Attribute Encoding" property
- Given a ConsumeKafka processor set up in a "kafka-consumer-flow" flow
+ Given a Kafka server is set up
+ And ConsumeKafka processor is set up to communicate with that server
And the "Key Attribute Encoding" property of the ConsumeKafka processor is set to "<key attribute encoding>"
- And a RouteOnAttribute processor in the "kafka-consumer-flow" flow
- And a LogAttribute processor in the "kafka-consumer-flow" flow
- And a PutFile processor with the "Directory" property set to "/tmp/output" in the "kafka-consumer-flow" flow
+ And a RouteOnAttribute processor
+ And RouteOnAttribute is EVENT_DRIVEN
+ And a LogAttribute processor
+ And LogAttribute is EVENT_DRIVEN
+ And a PutFile processor with the "Directory" property set to "/tmp/output"
+ And PutFile is EVENT_DRIVEN
Review Comment:
Unfortunately with the new framework we do not know which is a source processor and which is not. Previously we had separate classes for each processor where these attributes could be specified, but now we only have their name to work with and only the flow configuration is generated without any processor objects. It's a bit of a hassle, but @martinzink's intention was to have this framework be more explicit in the test steps.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] MINIFICPP-2666 Move Kafka tests to modular docker tests [nifi-minifi-cpp]
Posted by "adamdebreceni (via GitHub)" <gi...@apache.org>.
adamdebreceni commented on code in PR #2059:
URL: https://github.com/apache/nifi-minifi-cpp/pull/2059#discussion_r2660998331
##########
behave_framework/src/minifi_test_framework/steps/checking_steps.py:
##########
@@ -83,16 +84,34 @@ def step_impl(context: MinifiTestContext, message: str, duration: str):
context=context)
+@then("the Minifi logs match the following regex: \"{regex}\" in less than {duration}")
+def step_impl(context, regex, duration):
+ duration_seconds = humanfriendly.parse_timespan(duration)
+ assert wait_for_condition(condition=lambda: re.search(regex, context.get_default_minifi_container().get_logs()),
+ timeout_seconds=duration_seconds, bail_condition=lambda: context.get_default_minifi_container().exited,
+ context=context)
+
+
@step('no errors were generated on the http-proxy regarding "{url}"')
def step_impl(context: MinifiTestContext, url: str):
http_proxy_container = next(container for container in context.containers.values() if isinstance(container, HttpProxy))
assert http_proxy_container.check_http_proxy_access(url) or http_proxy_container.log_app_output()
+@then('no files are placed in the "{directory}" directory in {duration} of running time')
+def step_impl(context, directory, duration):
+ duration_seconds = humanfriendly.parse_timespan(duration)
+ assert check_condition_after_wait(condition=lambda: context.get_default_minifi_container().get_number_of_files(directory) < 1,
Review Comment:
is the `< 1` intentional?
##########
behave_framework/src/minifi_test_framework/steps/checking_steps.py:
##########
@@ -152,3 +171,28 @@ def step_impl(context: MinifiTestContext, max_increase: str, duration: str):
time.sleep(time_in_seconds)
final_memory_usage = context.get_default_minifi_container().get_memory_usage()
assert final_memory_usage - initial_memory_usage <= max_increase_in_bytes
+
+
+@then('after a wait of {duration}, at least {lower_bound:d} and at most {upper_bound:d} flowfiles are produced and placed in the "{directory}" directory')
+def step_impl(context, lower_bound, upper_bound, duration, directory):
+ duration_seconds = humanfriendly.parse_timespan(duration)
+ assert check_condition_after_wait(condition=lambda: context.get_default_minifi_container().get_number_of_files(directory) >= lower_bound
+ and context.get_default_minifi_container().get_number_of_files(directory) <= upper_bound,
+ context=context, wait_time=duration_seconds)
+
+
+@then('exactly these files are in the "{directory}" directory in less than {duration}: "{contents}"')
+def step_impl(context, directory, duration, contents):
+ if not contents:
+ context.execute_steps(f'then no files are placed in the "{directory}" directory in {duration} of running time')
+ return
+ contents_arr = contents.split(",")
+ timeout_in_seconds = humanfriendly.parse_timespan(duration)
+ assert wait_for_condition(condition=lambda: context.get_default_minifi_container().verify_file_contents(directory, contents_arr),
+ timeout_seconds=timeout_in_seconds, bail_condition=lambda: False,
+ context=context)
+
+
+@then('exactly these files are in the "{directory}" directory in less than {duration}: ""')
Review Comment:
I feel like "exactly" and "in less than" conflict, shouldn't we wait for the exact amount of time with check_condition_after_wait
##########
behave_framework/src/minifi_test_framework/steps/flow_building_steps.py:
##########
@@ -220,3 +224,30 @@ def step_impl(context: MinifiTestContext, service_name: str, property_name: str,
controller_service = ControllerService(class_name=service_name, service_name=service_name)
controller_service.add_property(property_name, property_value)
context.get_or_create_default_minifi_container().flow_definition.controller_services.append(controller_service)
+
+
+@given("the \"{property_name}\" property of the {processor_name} processor is set to match the attribute \"{attribute_key}\" to \"{attribute_value}\"")
+def step_impl(context: MinifiTestContext, property_name: str, processor_name: str, attribute_key: str, attribute_value: str):
+ processor = context.get_or_create_default_minifi_container().flow_definition.get_processor(processor_name)
+ if attribute_value == "(not set)":
Review Comment:
I feel like matching an attribute to `(not set)` would mean there is no such attribute, but it seems we are ignoring the attribute, should we look for `(ignore)` here?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] MINIFICPP-2666 Move Kafka tests to modular docker tests [nifi-minifi-cpp]
Posted by "szaszm (via GitHub)" <gi...@apache.org>.
szaszm commented on code in PR #2059:
URL: https://github.com/apache/nifi-minifi-cpp/pull/2059#discussion_r2585016416
##########
extensions/kafka/tests/features/steps/kafka_server_container.py:
##########
@@ -0,0 +1,126 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import logging
+import re
+import jks
+
+from OpenSSL import crypto
+from minifi_test_framework.core.helpers import wait_for_condition
+from minifi_test_framework.core.ssl_utils import make_server_cert
+from minifi_test_framework.containers.container import Container
+from minifi_test_framework.containers.file import File
+from minifi_test_framework.core.minifi_test_context import MinifiTestContext
+
+
+class KafkaServer(Container):
+ def __init__(self, test_context: MinifiTestContext):
+ super().__init__("apache/kafka:4.1.0", f"kafka-server-{test_context.scenario_id}", test_context.network)
+ self.environment.append("KAFKA_NODE_ID=1")
+ self.environment.append("KAFKA_PROCESS_ROLES=controller,broker")
+ self.environment.append("KAFKA_INTER_BROKER_LISTENER_NAME=PLAINTEXT")
+ self.environment.append("KAFKA_CONTROLLER_LISTENER_NAMES=CONTROLLER")
+ self.environment.append("KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR=1")
+ self.environment.append("KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR=1")
+ self.environment.append("KAFKA_TRANSACTION_STATE_LOG_MIN_ISR=1")
+ self.environment.append(f"KAFKA_CONTROLLER_QUORUM_VOTERS=1@kafka-server-{test_context.scenario_id}:9096")
+ self.environment.append(f"KAFKA_LISTENERS=PLAINTEXT://kafka-server-{test_context.scenario_id}:9092,SASL_PLAINTEXT://kafka-server-{test_context.scenario_id}:9094,SSL://kafka-server-{test_context.scenario_id}:9093,SASL_SSL://kafka-server-{test_context.scenario_id}:9095,CONTROLLER://kafka-server-{test_context.scenario_id}:9096")
+ self.environment.append(f"KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://kafka-server-{test_context.scenario_id}:9092,SASL_PLAINTEXT://kafka-server-{test_context.scenario_id}:9094,SSL://kafka-server-{test_context.scenario_id}:9093,SASL_SSL://kafka-server-{test_context.scenario_id}:9095,CONTROLLER://kafka-server-{test_context.scenario_id}:9096")
+ self.environment.append("KAFKA_LISTENER_SECURITY_PROTOCOL_MAP=PLAINTEXT:PLAINTEXT,SASL_PLAINTEXT:SASL_PLAINTEXT,SSL:SSL,SASL_SSL:SASL_SSL,CONTROLLER:PLAINTEXT")
+ self.environment.append("KAFKA_SASL_MECHANISM_INTER_BROKER_PROTOCOL=PLAIN")
+ self.environment.append("KAFKA_SASL_ENABLED_MECHANISMS=PLAIN")
+ self.environment.append("KAFKA_OPTS=-Djava.security.auth.login.config=/opt/kafka/config/kafka_jaas.conf -Dlog4j2.rootLogger.level=DEBUG -Dlog4j2.logger.org.apache.kafka.controller.level=DEBUG")
+ self.environment.append("KAFKA_SSL_PROTOCOL=TLS")
+ self.environment.append("KAFKA_SSL_ENABLED_PROTOCOLS=TLSv1.2")
+ self.environment.append("KAFKA_SSL_KEYSTORE_TYPE=JKS")
+ self.environment.append("KAFKA_SSL_KEYSTORE_FILENAME=kafka.keystore.jks")
+ self.environment.append("KAFKA_SSL_KEYSTORE_CREDENTIALS=credentials.conf")
+ self.environment.append("KAFKA_SSL_KEY_CREDENTIALS=credentials.conf")
+ self.environment.append("KAFKA_SSL_TRUSTSTORE_CREDENTIALS=credentials.conf")
+ self.environment.append("KAFKA_SSL_TRUSTSTORE_TYPE=JKS")
+ self.environment.append("KAFKA_SSL_TRUSTSTORE_FILENAME=kafka.truststore.jks")
+ self.environment.append("KAFKA_SSL_CLIENT_AUTH=none")
+
+ kafka_cert, kafka_key = make_server_cert(self.container_name, test_context.root_ca_cert, test_context.root_ca_key)
+
+ pke = jks.PrivateKeyEntry.new('kafka-broker-cert', [crypto.dump_certificate(crypto.FILETYPE_ASN1, kafka_cert)], crypto.dump_privatekey(crypto.FILETYPE_ASN1, kafka_key), 'rsa_raw')
+ server_keystore = jks.KeyStore.new('jks', [pke])
+ server_keystore_content = server_keystore.saves('abcdefgh')
+ self.files.append(File("/etc/kafka/secrets/kafka.keystore.jks", server_keystore_content, permissions=0o644))
+ self.files.append(File("/etc/kafka/secrets/credentials.conf", b'abcdefgh', permissions=0o644))
+
+ trusted_cert = jks.TrustedCertEntry.new(
+ 'root-ca', # Alias for the certificate
+ crypto.dump_certificate(crypto.FILETYPE_ASN1, test_context.root_ca_cert)
+ )
+
+ # Create a JKS keystore that will serve as a truststore with the trusted cert entry.
+ truststore = jks.KeyStore.new('jks', [trusted_cert])
+ truststore_content = truststore.saves('abcdefgh')
+ self.files.append(File("/etc/kafka/secrets/kafka.truststore.jks", truststore_content, permissions=0o644))
+
+ jaas_config_file_content = """
+KafkaServer {
+ org.apache.kafka.common.security.plain.PlainLoginModule required
+ username="admin"
+ password="admin-secret"
+ user_admin="admin-secret"
+ user_alice="alice-secret";
+};
+
+Client {
+ org.apache.kafka.common.security.plain.PlainLoginModule required
+ username="admin"
+ password="admin-secret";
+};
+"""
+ self.files.append(File("/opt/kafka/config/kafka_jaas.conf", jaas_config_file_content, permissions=0o644))
+
+ def deploy(self):
+ super().deploy()
+ finished_str = "Kafka Server started"
+ return wait_for_condition(
+ condition=lambda: finished_str in self.get_logs(),
+ timeout_seconds=60,
+ bail_condition=lambda: self.exited,
+ context=None)
+
+ def create_topic(self, topic_name: str):
+ (code, output) = self.exec_run(["/bin/bash", "-c", f"/opt/kafka/bin/kafka-topics.sh --create --topic {topic_name} --bootstrap-server {self.container_name}:9092"])
Review Comment:
optional: sh + quotes to handle more special characters
```suggestion
(code, output) = self.exec_run(["/bin/sh", "-c", f"/opt/kafka/bin/kafka-topics.sh --create --topic '{topic_name}' --bootstrap-server '{self.container_name}':9092"])
```
##########
extensions/kafka/tests/features/consumekafka.feature:
##########
@@ -75,18 +76,19 @@ Feature: Receiving data from using Kafka streaming platform using ConsumeKafka
| Crime and Punishment | Фёдор Михайлович Достоевский | Hex |
Scenario Outline: ConsumeKafka transactional behaviour is supported
- Given a ConsumeKafka processor set up in a "kafka-consumer-flow" flow
+ Given a Kafka server is set up
+ And ConsumeKafka processor is set up to communicate with that server
And the "Topic Names" property of the ConsumeKafka processor is set to "ConsumeKafkaTest"
And the "Honor Transactions" property of the ConsumeKafka processor is set to "<honor transactions>"
- And a PutFile processor with the "Directory" property set to "/tmp/output" in the "kafka-consumer-flow" flow
+ And a PutFile processor with the "Directory" property set to "/tmp/output"
+ And PutFile is EVENT_DRIVEN
And the "success" relationship of the ConsumeKafka processor is connected to the PutFile
-
- And a kafka broker is set up in correspondence with the third-party kafka publisher
+ And PutFile's success relationship is auto-terminated
When all instances start up
And the publisher performs a <transaction type> transaction publishing to the "ConsumeKafkaTest" topic these messages: <messages sent>
- Then <number of flowfiles expected> flowfiles are placed in the monitored directory in less than 15 seconds
+ Then there are <number of flowfiles expected> files in the "/tmp/output" directory in less than 15 seconds
Review Comment:
@fgerlits comment applies to this too: it's clearer to expect an event than a state, so the old version was better.
##########
extensions/kafka/tests/features/consumekafka.feature:
##########
@@ -19,54 +19,55 @@ Feature: Receiving data from using Kafka streaming platform using ConsumeKafka
As a user of MiNiFi
I need to have ConsumeKafka processor
- Background:
- Given the content of "/tmp/output" is monitored
-
Scenario Outline: ConsumeKafka parses and uses kafka topics and topic name formats
- Given a ConsumeKafka processor set up in a "kafka-consumer-flow" flow
+ Given a Kafka server is set up
+ And ConsumeKafka processor is set up to communicate with that server
And the "Topic Names" property of the ConsumeKafka processor is set to "<topic names>"
And the "Topic Name Format" property of the ConsumeKafka processor is set to "<topic name format>"
And the "Offset Reset" property of the ConsumeKafka processor is set to "earliest"
- And a PutFile processor with the "Directory" property set to "/tmp/output" in the "kafka-consumer-flow" flow
+ And a PutFile processor with the "Directory" property set to "/tmp/output"
+ And PutFile is EVENT_DRIVEN
And the "success" relationship of the ConsumeKafka processor is connected to the PutFile
+ And PutFile's success relationship is auto-terminated
- And a kafka broker is set up in correspondence with the third-party kafka publisher
- And the kafka broker is started
+ And the Kafka server is started
And the topic "ConsumeKafkaTest" is initialized on the kafka broker
When a message with content "<message 1>" is published to the "ConsumeKafkaTest" topic
- And all other processes start up
+ And the MiNiFi instance starts up
And a message with content "<message 2>" is published to the "ConsumeKafkaTest" topic
- Then two flowfiles with the contents "<message 1>" and "<message 2>" are placed in the monitored directory in less than 90 seconds
+ Then the contents of "/tmp/output" in less than 30 seconds are: "<message 1>" and "<message 2>"
Examples: Topic names and formats to test
| message 1 | message 2 | topic names | topic name format |
- | Ulysses | James Joyce | ConsumeKafkaTest | (not set) |
| The Great Gatsby | F. Scott Fitzgerald | ConsumeKafkaTest | Names |
| War and Peace | Lev Tolstoy | a,b,c,ConsumeKafkaTest,d | Names |
| Nineteen Eighty Four | George Orwell | ConsumeKafkaTest | Patterns |
| Hamlet | William Shakespeare | Cons[emu]*KafkaTest | Patterns |
Scenario Outline: ConsumeKafka key attribute is encoded according to the "Key Attribute Encoding" property
- Given a ConsumeKafka processor set up in a "kafka-consumer-flow" flow
+ Given a Kafka server is set up
+ And ConsumeKafka processor is set up to communicate with that server
And the "Key Attribute Encoding" property of the ConsumeKafka processor is set to "<key attribute encoding>"
- And a RouteOnAttribute processor in the "kafka-consumer-flow" flow
- And a LogAttribute processor in the "kafka-consumer-flow" flow
- And a PutFile processor with the "Directory" property set to "/tmp/output" in the "kafka-consumer-flow" flow
+ And a RouteOnAttribute processor
+ And RouteOnAttribute is EVENT_DRIVEN
+ And a LogAttribute processor
+ And LogAttribute is EVENT_DRIVEN
+ And a PutFile processor with the "Directory" property set to "/tmp/output"
+ And PutFile is EVENT_DRIVEN
Review Comment:
Shouldn't it be default in the test framework to have non-source processors use event driven scheduling? to reduce boilerplate
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] MINIFICPP-2666 Move Kafka tests to modular docker tests [nifi-minifi-cpp]
Posted by "fgerlits (via GitHub)" <gi...@apache.org>.
fgerlits commented on code in PR #2059:
URL: https://github.com/apache/nifi-minifi-cpp/pull/2059#discussion_r2580675409
##########
behave_framework/src/minifi_test_framework/containers/container.py:
##########
@@ -254,6 +285,59 @@ def verify_file_contents(self, directory_path: str, expected_contents: list[str]
return sorted(actual_file_contents) == sorted(expected_contents)
+ def _verify_file_contents_in_stopped_container(self, directory_path: str, expected_contents: list[str]) -> bool:
+ if not self.container:
+ return False
+
+ with tempfile.TemporaryDirectory() as temp_dir:
+ extracted_dir = self._extract_directory_from_container(directory_path, temp_dir)
+ if not extracted_dir:
+ return False
+
+ actual_file_contents = self._read_files_from_directory(extracted_dir)
+ if actual_file_contents is None:
+ return False
+
+ return sorted(actual_file_contents) == sorted(expected_contents)
+
+ def _extract_directory_from_container(self, directory_path: str, temp_dir: str) -> str | None:
+ try:
+ bits, _ = self.container.get_archive(directory_path)
+ temp_tar_path = os.path.join(temp_dir, "archive.tar")
+
+ with open(temp_tar_path, 'wb') as f:
+ for chunk in bits:
+ f.write(chunk)
+
+ with tarfile.open(temp_tar_path) as tar:
+ tar.extractall(path=temp_dir)
+
+ return os.path.join(temp_dir, os.path.basename(directory_path.strip('/')))
+ except Exception as e:
+ logging.error(f"Error extracting files from container: {e}")
Review Comment:
Does `e` contain the container's name and `directory_path` here? If it doesn't, then I would add these two to the error message.
##########
extensions/kafka/tests/features/consumekafka.feature:
##########
@@ -19,54 +19,55 @@ Feature: Receiving data from using Kafka streaming platform using ConsumeKafka
As a user of MiNiFi
I need to have ConsumeKafka processor
- Background:
- Given the content of "/tmp/output" is monitored
-
Scenario Outline: ConsumeKafka parses and uses kafka topics and topic name formats
- Given a ConsumeKafka processor set up in a "kafka-consumer-flow" flow
+ Given a Kafka server is set up
+ And ConsumeKafka processor is set up to communicate with that server
And the "Topic Names" property of the ConsumeKafka processor is set to "<topic names>"
And the "Topic Name Format" property of the ConsumeKafka processor is set to "<topic name format>"
And the "Offset Reset" property of the ConsumeKafka processor is set to "earliest"
- And a PutFile processor with the "Directory" property set to "/tmp/output" in the "kafka-consumer-flow" flow
+ And a PutFile processor with the "Directory" property set to "/tmp/output"
+ And PutFile is EVENT_DRIVEN
And the "success" relationship of the ConsumeKafka processor is connected to the PutFile
+ And PutFile's success relationship is auto-terminated
- And a kafka broker is set up in correspondence with the third-party kafka publisher
- And the kafka broker is started
+ And the Kafka server is started
And the topic "ConsumeKafkaTest" is initialized on the kafka broker
When a message with content "<message 1>" is published to the "ConsumeKafkaTest" topic
- And all other processes start up
+ And the MiNiFi instance starts up
And a message with content "<message 2>" is published to the "ConsumeKafkaTest" topic
- Then two flowfiles with the contents "<message 1>" and "<message 2>" are placed in the monitored directory in less than 90 seconds
+ Then the contents of "/tmp/output" in less than 30 seconds are: "<message 1>" and "<message 2>"
Examples: Topic names and formats to test
| message 1 | message 2 | topic names | topic name format |
- | Ulysses | James Joyce | ConsumeKafkaTest | (not set) |
| The Great Gatsby | F. Scott Fitzgerald | ConsumeKafkaTest | Names |
| War and Peace | Lev Tolstoy | a,b,c,ConsumeKafkaTest,d | Names |
| Nineteen Eighty Four | George Orwell | ConsumeKafkaTest | Patterns |
| Hamlet | William Shakespeare | Cons[emu]*KafkaTest | Patterns |
Scenario Outline: ConsumeKafka key attribute is encoded according to the "Key Attribute Encoding" property
- Given a ConsumeKafka processor set up in a "kafka-consumer-flow" flow
+ Given a Kafka server is set up
+ And ConsumeKafka processor is set up to communicate with that server
And the "Key Attribute Encoding" property of the ConsumeKafka processor is set to "<key attribute encoding>"
- And a RouteOnAttribute processor in the "kafka-consumer-flow" flow
- And a LogAttribute processor in the "kafka-consumer-flow" flow
- And a PutFile processor with the "Directory" property set to "/tmp/output" in the "kafka-consumer-flow" flow
+ And a RouteOnAttribute processor
+ And RouteOnAttribute is EVENT_DRIVEN
+ And a LogAttribute processor
+ And LogAttribute is EVENT_DRIVEN
+ And a PutFile processor with the "Directory" property set to "/tmp/output"
+ And PutFile is EVENT_DRIVEN
And the "success" property of the RouteOnAttribute processor is set to match <key attribute encoding> encoded kafka message key "consume_kafka_test_key"
And the "success" relationship of the ConsumeKafka processor is connected to the LogAttribute
And the "success" relationship of the LogAttribute processor is connected to the RouteOnAttribute
And the "success" relationship of the RouteOnAttribute processor is connected to the PutFile
-
- And a kafka broker is set up in correspondence with the third-party kafka publisher
+ And PutFile's success relationship is auto-terminated
When all instances start up
And a message with content "<message 1>" is published to the "ConsumeKafkaTest" topic with key "consume_kafka_test_key"
And a message with content "<message 2>" is published to the "ConsumeKafkaTest" topic with key "consume_kafka_test_key"
- Then two flowfiles with the contents "<message 1>" and "<message 2>" are placed in the monitored directory in less than 45 seconds
+ Then the contents of "/tmp/output" in less than 30 seconds are: "<message 1>" and "<message 2>"
Review Comment:
The old phrasing sounds more natural and clearer to me: "happens in less than x seconds" requires an event ("flowfiles are placed"), not a state ("the contents are"). Can we change it back?
##########
extensions/kafka/tests/features/steps/kafka_server_container.py:
##########
@@ -0,0 +1,126 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import logging
+import re
+import jks
+
+from OpenSSL import crypto
+from minifi_test_framework.core.helpers import wait_for_condition
+from minifi_test_framework.core.ssl_utils import make_server_cert
+from minifi_test_framework.containers.container import Container
+from minifi_test_framework.containers.file import File
+from minifi_test_framework.core.minifi_test_context import MinifiTestContext
+
+
+class KafkaServer(Container):
+ def __init__(self, test_context: MinifiTestContext):
+ super().__init__("apache/kafka:4.1.0", f"kafka-server-{test_context.scenario_id}", test_context.network)
+ self.environment.append("KAFKA_NODE_ID=1")
+ self.environment.append("KAFKA_PROCESS_ROLES=controller,broker")
+ self.environment.append("KAFKA_INTER_BROKER_LISTENER_NAME=PLAINTEXT")
+ self.environment.append("KAFKA_CONTROLLER_LISTENER_NAMES=CONTROLLER")
+ self.environment.append("KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR=1")
+ self.environment.append("KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR=1")
+ self.environment.append("KAFKA_TRANSACTION_STATE_LOG_MIN_ISR=1")
+ self.environment.append(f"KAFKA_CONTROLLER_QUORUM_VOTERS=1@kafka-server-{test_context.scenario_id}:9096")
+ self.environment.append(f"KAFKA_LISTENERS=PLAINTEXT://kafka-server-{test_context.scenario_id}:9092,SASL_PLAINTEXT://kafka-server-{test_context.scenario_id}:9094,SSL://kafka-server-{test_context.scenario_id}:9093,SASL_SSL://kafka-server-{test_context.scenario_id}:9095,CONTROLLER://kafka-server-{test_context.scenario_id}:9096")
+ self.environment.append(f"KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://kafka-server-{test_context.scenario_id}:9092,SASL_PLAINTEXT://kafka-server-{test_context.scenario_id}:9094,SSL://kafka-server-{test_context.scenario_id}:9093,SASL_SSL://kafka-server-{test_context.scenario_id}:9095,CONTROLLER://kafka-server-{test_context.scenario_id}:9096")
+ self.environment.append("KAFKA_LISTENER_SECURITY_PROTOCOL_MAP=PLAINTEXT:PLAINTEXT,SASL_PLAINTEXT:SASL_PLAINTEXT,SSL:SSL,SASL_SSL:SASL_SSL,CONTROLLER:PLAINTEXT")
+ self.environment.append("KAFKA_SASL_MECHANISM_INTER_BROKER_PROTOCOL=PLAIN")
+ self.environment.append("KAFKA_SASL_ENABLED_MECHANISMS=PLAIN")
+ self.environment.append("KAFKA_OPTS=-Djava.security.auth.login.config=/opt/kafka/config/kafka_jaas.conf -Dlog4j2.rootLogger.level=DEBUG -Dlog4j2.logger.org.apache.kafka.controller.level=DEBUG")
+ self.environment.append("KAFKA_SSL_PROTOCOL=TLS")
+ self.environment.append("KAFKA_SSL_ENABLED_PROTOCOLS=TLSv1.2")
+ self.environment.append("KAFKA_SSL_KEYSTORE_TYPE=JKS")
+ self.environment.append("KAFKA_SSL_KEYSTORE_FILENAME=kafka.keystore.jks")
+ self.environment.append("KAFKA_SSL_KEYSTORE_CREDENTIALS=credentials.conf")
+ self.environment.append("KAFKA_SSL_KEY_CREDENTIALS=credentials.conf")
+ self.environment.append("KAFKA_SSL_TRUSTSTORE_CREDENTIALS=credentials.conf")
+ self.environment.append("KAFKA_SSL_TRUSTSTORE_TYPE=JKS")
+ self.environment.append("KAFKA_SSL_TRUSTSTORE_FILENAME=kafka.truststore.jks")
+ self.environment.append("KAFKA_SSL_CLIENT_AUTH=none")
+
+ kafka_cert, kafka_key = make_server_cert(self.container_name, test_context.root_ca_cert, test_context.root_ca_key)
+
+ pke = jks.PrivateKeyEntry.new('kafka-broker-cert', [crypto.dump_certificate(crypto.FILETYPE_ASN1, kafka_cert)], crypto.dump_privatekey(crypto.FILETYPE_ASN1, kafka_key), 'rsa_raw')
+ server_keystore = jks.KeyStore.new('jks', [pke])
+ server_keystore_content = server_keystore.saves('abcdefgh')
+ self.files.append(File("/etc/kafka/secrets/kafka.keystore.jks", server_keystore_content, permissions=0o644))
+ self.files.append(File("/etc/kafka/secrets/credentials.conf", b'abcdefgh', permissions=0o644))
+
+ trusted_cert = jks.TrustedCertEntry.new(
+ 'root-ca', # Alias for the certificate
+ crypto.dump_certificate(crypto.FILETYPE_ASN1, test_context.root_ca_cert)
+ )
+
+ # Create a JKS keystore that will serve as a truststore with the trusted cert entry.
+ truststore = jks.KeyStore.new('jks', [trusted_cert])
+ truststore_content = truststore.saves('abcdefgh')
+ self.files.append(File("/etc/kafka/secrets/kafka.truststore.jks", truststore_content, permissions=0o644))
+
+ jaas_config_file_content = """
+KafkaServer {
+ org.apache.kafka.common.security.plain.PlainLoginModule required
+ username="admin"
+ password="admin-secret"
+ user_admin="admin-secret"
+ user_alice="alice-secret";
+};
+
+Client {
+ org.apache.kafka.common.security.plain.PlainLoginModule required
+ username="admin"
+ password="admin-secret";
+};
+"""
+ self.files.append(File("/opt/kafka/config/kafka_jaas.conf", jaas_config_file_content, permissions=0o644))
+
+ def deploy(self):
+ super().deploy()
+ finished_str = "Kafka Server started"
+ return wait_for_condition(
+ condition=lambda: finished_str in self.get_logs(),
+ timeout_seconds=60,
+ bail_condition=lambda: self.exited,
+ context=None)
+
+ def create_topic(self, topic_name: str):
+ (code, output) = self.exec_run(["/bin/bash", "-c", f"/opt/kafka/bin/kafka-topics.sh --create --topic {topic_name} --bootstrap-server {self.container_name}:9092"])
+ logging.info("Create topic output: %s", output)
+ return code == 0
+
+ def produce_message(self, topic_name: str, message: str):
+ (code, output) = self.exec_run(["/bin/bash", "-c", f"/opt/kafka/bin/kafka-console-producer.sh --topic {topic_name} --bootstrap-server {self.container_name}:9092 <<< '{message}'"])
+ logging.info("Produce message output: %s", output)
+ return code == 0
+
+ def produce_message_with_key(self, topic_name: str, message: str, message_key: str):
+ (code, output) = self.exec_run(["/bin/bash", "-c", f"/opt/kafka/bin/kafka-console-producer.sh --property 'key.separator=:' --property 'parse.key=true' --topic {topic_name} --bootstrap-server {self.container_name}:9092 <<< '{message_key}:{message}'"])
+ logging.info("Produce message with key output: %s", output)
+ return code == 0
Review Comment:
Can we log `code`, as well, please?
##########
docker/test/integration/features/consumekafka.feature:
##########
@@ -19,54 +19,55 @@ Feature: Receiving data from using Kafka streaming platform using ConsumeKafka
As a user of MiNiFi
I need to have ConsumeKafka processor
- Background:
- Given the content of "/tmp/output" is monitored
-
Scenario Outline: ConsumeKafka parses and uses kafka topics and topic name formats
- Given a ConsumeKafka processor set up in a "kafka-consumer-flow" flow
+ Given a Kafka server is set up
+ And ConsumeKafka processor is set up to communicate with that server
And the "Topic Names" property of the ConsumeKafka processor is set to "<topic names>"
And the "Topic Name Format" property of the ConsumeKafka processor is set to "<topic name format>"
And the "Offset Reset" property of the ConsumeKafka processor is set to "earliest"
- And a PutFile processor with the "Directory" property set to "/tmp/output" in the "kafka-consumer-flow" flow
+ And a PutFile processor with the "Directory" property set to "/tmp/output"
+ And PutFile is EVENT_DRIVEN
And the "success" relationship of the ConsumeKafka processor is connected to the PutFile
+ And PutFile's success relationship is auto-terminated
- And a kafka broker is set up in correspondence with the third-party kafka publisher
- And the kafka broker is started
+ And the Kafka server is started
And the topic "ConsumeKafkaTest" is initialized on the kafka broker
When a message with content "<message 1>" is published to the "ConsumeKafkaTest" topic
- And all other processes start up
+ And the MiNiFi instance starts up
And a message with content "<message 2>" is published to the "ConsumeKafkaTest" topic
- Then two flowfiles with the contents "<message 1>" and "<message 2>" are placed in the monitored directory in less than 90 seconds
+ Then the contents of "/tmp/output" in less than 30 seconds are: "<message 1>" and "<message 2>"
Examples: Topic names and formats to test
| message 1 | message 2 | topic names | topic name format |
- | Ulysses | James Joyce | ConsumeKafkaTest | (not set) |
Review Comment:
why was this example removed?
##########
docker/test/integration/features/consumekafka.feature:
##########
@@ -19,54 +19,55 @@ Feature: Receiving data from using Kafka streaming platform using ConsumeKafka
As a user of MiNiFi
I need to have ConsumeKafka processor
- Background:
- Given the content of "/tmp/output" is monitored
-
Scenario Outline: ConsumeKafka parses and uses kafka topics and topic name formats
- Given a ConsumeKafka processor set up in a "kafka-consumer-flow" flow
+ Given a Kafka server is set up
+ And ConsumeKafka processor is set up to communicate with that server
And the "Topic Names" property of the ConsumeKafka processor is set to "<topic names>"
And the "Topic Name Format" property of the ConsumeKafka processor is set to "<topic name format>"
And the "Offset Reset" property of the ConsumeKafka processor is set to "earliest"
- And a PutFile processor with the "Directory" property set to "/tmp/output" in the "kafka-consumer-flow" flow
+ And a PutFile processor with the "Directory" property set to "/tmp/output"
+ And PutFile is EVENT_DRIVEN
And the "success" relationship of the ConsumeKafka processor is connected to the PutFile
+ And PutFile's success relationship is auto-terminated
- And a kafka broker is set up in correspondence with the third-party kafka publisher
- And the kafka broker is started
+ And the Kafka server is started
And the topic "ConsumeKafkaTest" is initialized on the kafka broker
When a message with content "<message 1>" is published to the "ConsumeKafkaTest" topic
- And all other processes start up
+ And the MiNiFi instance starts up
And a message with content "<message 2>" is published to the "ConsumeKafkaTest" topic
- Then two flowfiles with the contents "<message 1>" and "<message 2>" are placed in the monitored directory in less than 90 seconds
+ Then the contents of "/tmp/output" in less than 30 seconds are: "<message 1>" and "<message 2>"
Examples: Topic names and formats to test
| message 1 | message 2 | topic names | topic name format |
- | Ulysses | James Joyce | ConsumeKafkaTest | (not set) |
Review Comment:
why was this example removed?
##########
extensions/kafka/tests/features/consumekafka.feature:
##########
@@ -19,54 +19,55 @@ Feature: Receiving data from using Kafka streaming platform using ConsumeKafka
As a user of MiNiFi
I need to have ConsumeKafka processor
- Background:
- Given the content of "/tmp/output" is monitored
-
Scenario Outline: ConsumeKafka parses and uses kafka topics and topic name formats
- Given a ConsumeKafka processor set up in a "kafka-consumer-flow" flow
+ Given a Kafka server is set up
+ And ConsumeKafka processor is set up to communicate with that server
And the "Topic Names" property of the ConsumeKafka processor is set to "<topic names>"
And the "Topic Name Format" property of the ConsumeKafka processor is set to "<topic name format>"
And the "Offset Reset" property of the ConsumeKafka processor is set to "earliest"
- And a PutFile processor with the "Directory" property set to "/tmp/output" in the "kafka-consumer-flow" flow
+ And a PutFile processor with the "Directory" property set to "/tmp/output"
+ And PutFile is EVENT_DRIVEN
And the "success" relationship of the ConsumeKafka processor is connected to the PutFile
+ And PutFile's success relationship is auto-terminated
- And a kafka broker is set up in correspondence with the third-party kafka publisher
- And the kafka broker is started
+ And the Kafka server is started
And the topic "ConsumeKafkaTest" is initialized on the kafka broker
When a message with content "<message 1>" is published to the "ConsumeKafkaTest" topic
- And all other processes start up
+ And the MiNiFi instance starts up
And a message with content "<message 2>" is published to the "ConsumeKafkaTest" topic
- Then two flowfiles with the contents "<message 1>" and "<message 2>" are placed in the monitored directory in less than 90 seconds
+ Then the contents of "/tmp/output" in less than 30 seconds are: "<message 1>" and "<message 2>"
Examples: Topic names and formats to test
| message 1 | message 2 | topic names | topic name format |
- | Ulysses | James Joyce | ConsumeKafkaTest | (not set) |
| The Great Gatsby | F. Scott Fitzgerald | ConsumeKafkaTest | Names |
Review Comment:
why was the first example line removed?
##########
behave_framework/src/minifi_test_framework/containers/container.py:
##########
@@ -85,6 +97,22 @@ def deploy(self) -> bool:
raise
return True
+ def start(self):
+ if self.container:
+ self.container.start()
+
+ def stop(self):
+ if self.container:
+ self.container.stop()
+
+ def kill(self):
+ if self.container:
+ self.container.kill()
+
+ def restart(self):
+ if self.container:
+ self.container.restart()
Review Comment:
Could we log something if `self.container` does not exist? I assume that shouldn't happen normally, so a log would help with debugging if it does.
##########
docker/test/integration/features/consumekafka.feature:
##########
@@ -19,54 +19,55 @@ Feature: Receiving data from using Kafka streaming platform using ConsumeKafka
As a user of MiNiFi
I need to have ConsumeKafka processor
- Background:
- Given the content of "/tmp/output" is monitored
-
Scenario Outline: ConsumeKafka parses and uses kafka topics and topic name formats
- Given a ConsumeKafka processor set up in a "kafka-consumer-flow" flow
+ Given a Kafka server is set up
+ And ConsumeKafka processor is set up to communicate with that server
And the "Topic Names" property of the ConsumeKafka processor is set to "<topic names>"
And the "Topic Name Format" property of the ConsumeKafka processor is set to "<topic name format>"
And the "Offset Reset" property of the ConsumeKafka processor is set to "earliest"
- And a PutFile processor with the "Directory" property set to "/tmp/output" in the "kafka-consumer-flow" flow
+ And a PutFile processor with the "Directory" property set to "/tmp/output"
+ And PutFile is EVENT_DRIVEN
And the "success" relationship of the ConsumeKafka processor is connected to the PutFile
+ And PutFile's success relationship is auto-terminated
- And a kafka broker is set up in correspondence with the third-party kafka publisher
- And the kafka broker is started
+ And the Kafka server is started
And the topic "ConsumeKafkaTest" is initialized on the kafka broker
When a message with content "<message 1>" is published to the "ConsumeKafkaTest" topic
- And all other processes start up
+ And the MiNiFi instance starts up
And a message with content "<message 2>" is published to the "ConsumeKafkaTest" topic
- Then two flowfiles with the contents "<message 1>" and "<message 2>" are placed in the monitored directory in less than 90 seconds
+ Then the contents of "/tmp/output" in less than 30 seconds are: "<message 1>" and "<message 2>"
Examples: Topic names and formats to test
| message 1 | message 2 | topic names | topic name format |
- | Ulysses | James Joyce | ConsumeKafkaTest | (not set) |
Review Comment:
why was this example removed?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] MINIFICPP-2666 Move Kafka tests to modular docker tests [nifi-minifi-cpp]
Posted by "fgerlits (via GitHub)" <gi...@apache.org>.
fgerlits commented on code in PR #2059:
URL: https://github.com/apache/nifi-minifi-cpp/pull/2059#discussion_r2582337905
##########
docker/test/integration/features/consumekafka.feature:
##########
@@ -19,54 +19,55 @@ Feature: Receiving data from using Kafka streaming platform using ConsumeKafka
As a user of MiNiFi
I need to have ConsumeKafka processor
- Background:
- Given the content of "/tmp/output" is monitored
-
Scenario Outline: ConsumeKafka parses and uses kafka topics and topic name formats
- Given a ConsumeKafka processor set up in a "kafka-consumer-flow" flow
+ Given a Kafka server is set up
+ And ConsumeKafka processor is set up to communicate with that server
And the "Topic Names" property of the ConsumeKafka processor is set to "<topic names>"
And the "Topic Name Format" property of the ConsumeKafka processor is set to "<topic name format>"
And the "Offset Reset" property of the ConsumeKafka processor is set to "earliest"
- And a PutFile processor with the "Directory" property set to "/tmp/output" in the "kafka-consumer-flow" flow
+ And a PutFile processor with the "Directory" property set to "/tmp/output"
+ And PutFile is EVENT_DRIVEN
And the "success" relationship of the ConsumeKafka processor is connected to the PutFile
+ And PutFile's success relationship is auto-terminated
- And a kafka broker is set up in correspondence with the third-party kafka publisher
- And the kafka broker is started
+ And the Kafka server is started
And the topic "ConsumeKafkaTest" is initialized on the kafka broker
When a message with content "<message 1>" is published to the "ConsumeKafkaTest" topic
- And all other processes start up
+ And the MiNiFi instance starts up
And a message with content "<message 2>" is published to the "ConsumeKafkaTest" topic
- Then two flowfiles with the contents "<message 1>" and "<message 2>" are placed in the monitored directory in less than 90 seconds
+ Then the contents of "/tmp/output" in less than 30 seconds are: "<message 1>" and "<message 2>"
Examples: Topic names and formats to test
| message 1 | message 2 | topic names | topic name format |
- | Ulysses | James Joyce | ConsumeKafkaTest | (not set) |
Review Comment:
why was this example removed?
##########
docker/test/integration/features/consumekafka.feature:
##########
@@ -19,54 +19,55 @@ Feature: Receiving data from using Kafka streaming platform using ConsumeKafka
As a user of MiNiFi
I need to have ConsumeKafka processor
- Background:
- Given the content of "/tmp/output" is monitored
-
Scenario Outline: ConsumeKafka parses and uses kafka topics and topic name formats
- Given a ConsumeKafka processor set up in a "kafka-consumer-flow" flow
+ Given a Kafka server is set up
+ And ConsumeKafka processor is set up to communicate with that server
And the "Topic Names" property of the ConsumeKafka processor is set to "<topic names>"
And the "Topic Name Format" property of the ConsumeKafka processor is set to "<topic name format>"
And the "Offset Reset" property of the ConsumeKafka processor is set to "earliest"
- And a PutFile processor with the "Directory" property set to "/tmp/output" in the "kafka-consumer-flow" flow
+ And a PutFile processor with the "Directory" property set to "/tmp/output"
+ And PutFile is EVENT_DRIVEN
And the "success" relationship of the ConsumeKafka processor is connected to the PutFile
+ And PutFile's success relationship is auto-terminated
- And a kafka broker is set up in correspondence with the third-party kafka publisher
- And the kafka broker is started
+ And the Kafka server is started
And the topic "ConsumeKafkaTest" is initialized on the kafka broker
When a message with content "<message 1>" is published to the "ConsumeKafkaTest" topic
- And all other processes start up
+ And the MiNiFi instance starts up
And a message with content "<message 2>" is published to the "ConsumeKafkaTest" topic
- Then two flowfiles with the contents "<message 1>" and "<message 2>" are placed in the monitored directory in less than 90 seconds
+ Then the contents of "/tmp/output" in less than 30 seconds are: "<message 1>" and "<message 2>"
Examples: Topic names and formats to test
| message 1 | message 2 | topic names | topic name format |
- | Ulysses | James Joyce | ConsumeKafkaTest | (not set) |
Review Comment:
why was this example removed?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] MINIFICPP-2666 Move Kafka tests to modular docker tests [nifi-minifi-cpp]
Posted by "fgerlits (via GitHub)" <gi...@apache.org>.
fgerlits commented on code in PR #2059:
URL: https://github.com/apache/nifi-minifi-cpp/pull/2059#discussion_r2582336827
##########
docker/test/integration/features/consumekafka.feature:
##########
@@ -19,54 +19,55 @@ Feature: Receiving data from using Kafka streaming platform using ConsumeKafka
As a user of MiNiFi
I need to have ConsumeKafka processor
- Background:
- Given the content of "/tmp/output" is monitored
-
Scenario Outline: ConsumeKafka parses and uses kafka topics and topic name formats
- Given a ConsumeKafka processor set up in a "kafka-consumer-flow" flow
+ Given a Kafka server is set up
+ And ConsumeKafka processor is set up to communicate with that server
And the "Topic Names" property of the ConsumeKafka processor is set to "<topic names>"
And the "Topic Name Format" property of the ConsumeKafka processor is set to "<topic name format>"
And the "Offset Reset" property of the ConsumeKafka processor is set to "earliest"
- And a PutFile processor with the "Directory" property set to "/tmp/output" in the "kafka-consumer-flow" flow
+ And a PutFile processor with the "Directory" property set to "/tmp/output"
+ And PutFile is EVENT_DRIVEN
And the "success" relationship of the ConsumeKafka processor is connected to the PutFile
+ And PutFile's success relationship is auto-terminated
- And a kafka broker is set up in correspondence with the third-party kafka publisher
- And the kafka broker is started
+ And the Kafka server is started
And the topic "ConsumeKafkaTest" is initialized on the kafka broker
When a message with content "<message 1>" is published to the "ConsumeKafkaTest" topic
- And all other processes start up
+ And the MiNiFi instance starts up
And a message with content "<message 2>" is published to the "ConsumeKafkaTest" topic
- Then two flowfiles with the contents "<message 1>" and "<message 2>" are placed in the monitored directory in less than 90 seconds
+ Then the contents of "/tmp/output" in less than 30 seconds are: "<message 1>" and "<message 2>"
Examples: Topic names and formats to test
| message 1 | message 2 | topic names | topic name format |
- | Ulysses | James Joyce | ConsumeKafkaTest | (not set) |
Review Comment:
why was this example removed?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] MINIFICPP-2666 Move Kafka tests to modular docker tests [nifi-minifi-cpp]
Posted by "lordgamez (via GitHub)" <gi...@apache.org>.
lordgamez commented on code in PR #2059:
URL: https://github.com/apache/nifi-minifi-cpp/pull/2059#discussion_r2661840634
##########
extensions/kafka/tests/features/steps/kafka_server_container.py:
##########
@@ -0,0 +1,126 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import logging
+import re
+import jks
+
+from OpenSSL import crypto
+from minifi_test_framework.core.helpers import wait_for_condition
+from minifi_test_framework.core.ssl_utils import make_server_cert
+from minifi_test_framework.containers.container import Container
+from minifi_test_framework.containers.file import File
+from minifi_test_framework.core.minifi_test_context import MinifiTestContext
+
+
+class KafkaServer(Container):
+ def __init__(self, test_context: MinifiTestContext):
+ super().__init__("apache/kafka:4.1.0", f"kafka-server-{test_context.scenario_id}", test_context.network)
+ self.environment.append("KAFKA_NODE_ID=1")
+ self.environment.append("KAFKA_PROCESS_ROLES=controller,broker")
+ self.environment.append("KAFKA_INTER_BROKER_LISTENER_NAME=PLAINTEXT")
+ self.environment.append("KAFKA_CONTROLLER_LISTENER_NAMES=CONTROLLER")
+ self.environment.append("KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR=1")
+ self.environment.append("KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR=1")
+ self.environment.append("KAFKA_TRANSACTION_STATE_LOG_MIN_ISR=1")
+ self.environment.append(f"KAFKA_CONTROLLER_QUORUM_VOTERS=1@kafka-server-{test_context.scenario_id}:9096")
+ self.environment.append(f"KAFKA_LISTENERS=PLAINTEXT://kafka-server-{test_context.scenario_id}:9092,SASL_PLAINTEXT://kafka-server-{test_context.scenario_id}:9094,SSL://kafka-server-{test_context.scenario_id}:9093,SASL_SSL://kafka-server-{test_context.scenario_id}:9095,CONTROLLER://kafka-server-{test_context.scenario_id}:9096")
+ self.environment.append(f"KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://kafka-server-{test_context.scenario_id}:9092,SASL_PLAINTEXT://kafka-server-{test_context.scenario_id}:9094,SSL://kafka-server-{test_context.scenario_id}:9093,SASL_SSL://kafka-server-{test_context.scenario_id}:9095,CONTROLLER://kafka-server-{test_context.scenario_id}:9096")
+ self.environment.append("KAFKA_LISTENER_SECURITY_PROTOCOL_MAP=PLAINTEXT:PLAINTEXT,SASL_PLAINTEXT:SASL_PLAINTEXT,SSL:SSL,SASL_SSL:SASL_SSL,CONTROLLER:PLAINTEXT")
+ self.environment.append("KAFKA_SASL_MECHANISM_INTER_BROKER_PROTOCOL=PLAIN")
+ self.environment.append("KAFKA_SASL_ENABLED_MECHANISMS=PLAIN")
+ self.environment.append("KAFKA_OPTS=-Djava.security.auth.login.config=/opt/kafka/config/kafka_jaas.conf -Dlog4j2.rootLogger.level=DEBUG -Dlog4j2.logger.org.apache.kafka.controller.level=DEBUG")
+ self.environment.append("KAFKA_SSL_PROTOCOL=TLS")
+ self.environment.append("KAFKA_SSL_ENABLED_PROTOCOLS=TLSv1.2")
+ self.environment.append("KAFKA_SSL_KEYSTORE_TYPE=JKS")
+ self.environment.append("KAFKA_SSL_KEYSTORE_FILENAME=kafka.keystore.jks")
+ self.environment.append("KAFKA_SSL_KEYSTORE_CREDENTIALS=credentials.conf")
+ self.environment.append("KAFKA_SSL_KEY_CREDENTIALS=credentials.conf")
+ self.environment.append("KAFKA_SSL_TRUSTSTORE_CREDENTIALS=credentials.conf")
+ self.environment.append("KAFKA_SSL_TRUSTSTORE_TYPE=JKS")
+ self.environment.append("KAFKA_SSL_TRUSTSTORE_FILENAME=kafka.truststore.jks")
+ self.environment.append("KAFKA_SSL_CLIENT_AUTH=none")
+
+ kafka_cert, kafka_key = make_server_cert(self.container_name, test_context.root_ca_cert, test_context.root_ca_key)
+
+ pke = jks.PrivateKeyEntry.new('kafka-broker-cert', [crypto.dump_certificate(crypto.FILETYPE_ASN1, kafka_cert)], crypto.dump_privatekey(crypto.FILETYPE_ASN1, kafka_key), 'rsa_raw')
+ server_keystore = jks.KeyStore.new('jks', [pke])
+ server_keystore_content = server_keystore.saves('abcdefgh')
+ self.files.append(File("/etc/kafka/secrets/kafka.keystore.jks", server_keystore_content, permissions=0o644))
+ self.files.append(File("/etc/kafka/secrets/credentials.conf", b'abcdefgh', permissions=0o644))
+
+ trusted_cert = jks.TrustedCertEntry.new(
+ 'root-ca', # Alias for the certificate
+ crypto.dump_certificate(crypto.FILETYPE_ASN1, test_context.root_ca_cert)
+ )
+
+ # Create a JKS keystore that will serve as a truststore with the trusted cert entry.
+ truststore = jks.KeyStore.new('jks', [trusted_cert])
+ truststore_content = truststore.saves('abcdefgh')
+ self.files.append(File("/etc/kafka/secrets/kafka.truststore.jks", truststore_content, permissions=0o644))
+
+ jaas_config_file_content = """
+KafkaServer {
+ org.apache.kafka.common.security.plain.PlainLoginModule required
+ username="admin"
+ password="admin-secret"
+ user_admin="admin-secret"
+ user_alice="alice-secret";
+};
+
+Client {
+ org.apache.kafka.common.security.plain.PlainLoginModule required
+ username="admin"
+ password="admin-secret";
+};
+"""
+ self.files.append(File("/opt/kafka/config/kafka_jaas.conf", jaas_config_file_content, permissions=0o644))
+
+ def deploy(self):
+ super().deploy()
+ finished_str = "Kafka Server started"
+ return wait_for_condition(
+ condition=lambda: finished_str in self.get_logs(),
+ timeout_seconds=60,
+ bail_condition=lambda: self.exited,
+ context=None)
+
+ def create_topic(self, topic_name: str):
+ (code, output) = self.exec_run(["/bin/sh", "-c", f"/opt/kafka/bin/kafka-topics.sh --create --topic '{topic_name}' --bootstrap-server '{self.container_name}':9092"])
+ logging.info(f"Create topic output: '{output}' with code {code}")
+ return code == 0
+
+ def produce_message(self, topic_name: str, message: str):
+ (code, output) = self.exec_run(["/bin/sh", "-c", f"echo '{message}' | /opt/kafka/bin/kafka-console-producer.sh --topic '{topic_name}' --bootstrap-server '{self.container_name}':9092"])
+ logging.info(f"Produce message output: '{output}' with code {code}")
+ return code == 0
+
+ def produce_message_with_key(self, topic_name: str, message: str, message_key: str):
+ (code, output) = self.exec_run(["/bin/sh", "-c", f" echo ''{message_key}:{message}'' | /opt/kafka/bin/kafka-console-producer.sh --property 'key.separator=:' --property 'parse.key=true' --topic '{topic_name}' --bootstrap-server '{self.container_name}':9092"])
Review Comment:
Good catch, didn't notice since it was passing that way too, fixed in https://github.com/apache/nifi-minifi-cpp/pull/2059/commits/ddab3ecd04476c801e3f6e2d3190e39bd7e0c25d
##########
behave_framework/src/minifi_test_framework/steps/checking_steps.py:
##########
@@ -152,3 +172,28 @@ def step_impl(context: MinifiTestContext, max_increase: str, duration: str):
time.sleep(time_in_seconds)
final_memory_usage = context.get_default_minifi_container().get_memory_usage()
assert final_memory_usage - initial_memory_usage <= max_increase_in_bytes
+
+
+@then('after a wait of {duration}, at least {lower_bound:d} and at most {upper_bound:d} flowfiles are produced and placed in the "{directory}" directory')
Review Comment:
Updated in https://github.com/apache/nifi-minifi-cpp/pull/2059/commits/ddab3ecd04476c801e3f6e2d3190e39bd7e0c25d
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] MINIFICPP-2666 Move Kafka tests to modular docker tests [nifi-minifi-cpp]
Posted by "lordgamez (via GitHub)" <gi...@apache.org>.
lordgamez commented on code in PR #2059:
URL: https://github.com/apache/nifi-minifi-cpp/pull/2059#discussion_r2661354208
##########
behave_framework/src/minifi_test_framework/containers/container.py:
##########
@@ -254,6 +285,59 @@ def verify_file_contents(self, directory_path: str, expected_contents: list[str]
return sorted(actual_file_contents) == sorted(expected_contents)
+ def _verify_file_contents_in_stopped_container(self, directory_path: str, expected_contents: list[str]) -> bool:
+ if not self.container:
+ return False
+
+ with tempfile.TemporaryDirectory() as temp_dir:
+ extracted_dir = self._extract_directory_from_container(directory_path, temp_dir)
+ if not extracted_dir:
+ return False
+
+ actual_file_contents = self._read_files_from_directory(extracted_dir)
+ if actual_file_contents is None:
+ return False
+
+ return sorted(actual_file_contents) == sorted(expected_contents)
+
+ def _extract_directory_from_container(self, directory_path: str, temp_dir: str) -> str | None:
+ try:
+ bits, _ = self.container.get_archive(directory_path)
+ temp_tar_path = os.path.join(temp_dir, "archive.tar")
+
+ with open(temp_tar_path, 'wb') as f:
+ for chunk in bits:
+ f.write(chunk)
+
+ with tarfile.open(temp_tar_path) as tar:
+ tar.extractall(path=temp_dir)
+
+ return os.path.join(temp_dir, os.path.basename(directory_path.strip('/')))
+ except Exception as e:
+ logging.error(f"Error extracting files from container: {e}")
Review Comment:
Extended log message in https://github.com/apache/nifi-minifi-cpp/pull/2059/commits/595d85e0827fe540ca0011ef28dc9c5bb73e659e
##########
behave_framework/src/minifi_test_framework/containers/container.py:
##########
@@ -85,6 +97,22 @@ def deploy(self) -> bool:
raise
return True
+ def start(self):
+ if self.container:
+ self.container.start()
+
+ def stop(self):
+ if self.container:
+ self.container.stop()
+
+ def kill(self):
+ if self.container:
+ self.container.kill()
+
+ def restart(self):
+ if self.container:
+ self.container.restart()
Review Comment:
Added logs in https://github.com/apache/nifi-minifi-cpp/pull/2059/commits/595d85e0827fe540ca0011ef28dc9c5bb73e659e
##########
extensions/kafka/tests/features/steps/kafka_server_container.py:
##########
@@ -0,0 +1,126 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import logging
+import re
+import jks
+
+from OpenSSL import crypto
+from minifi_test_framework.core.helpers import wait_for_condition
+from minifi_test_framework.core.ssl_utils import make_server_cert
+from minifi_test_framework.containers.container import Container
+from minifi_test_framework.containers.file import File
+from minifi_test_framework.core.minifi_test_context import MinifiTestContext
+
+
+class KafkaServer(Container):
+ def __init__(self, test_context: MinifiTestContext):
+ super().__init__("apache/kafka:4.1.0", f"kafka-server-{test_context.scenario_id}", test_context.network)
+ self.environment.append("KAFKA_NODE_ID=1")
+ self.environment.append("KAFKA_PROCESS_ROLES=controller,broker")
+ self.environment.append("KAFKA_INTER_BROKER_LISTENER_NAME=PLAINTEXT")
+ self.environment.append("KAFKA_CONTROLLER_LISTENER_NAMES=CONTROLLER")
+ self.environment.append("KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR=1")
+ self.environment.append("KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR=1")
+ self.environment.append("KAFKA_TRANSACTION_STATE_LOG_MIN_ISR=1")
+ self.environment.append(f"KAFKA_CONTROLLER_QUORUM_VOTERS=1@kafka-server-{test_context.scenario_id}:9096")
+ self.environment.append(f"KAFKA_LISTENERS=PLAINTEXT://kafka-server-{test_context.scenario_id}:9092,SASL_PLAINTEXT://kafka-server-{test_context.scenario_id}:9094,SSL://kafka-server-{test_context.scenario_id}:9093,SASL_SSL://kafka-server-{test_context.scenario_id}:9095,CONTROLLER://kafka-server-{test_context.scenario_id}:9096")
+ self.environment.append(f"KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://kafka-server-{test_context.scenario_id}:9092,SASL_PLAINTEXT://kafka-server-{test_context.scenario_id}:9094,SSL://kafka-server-{test_context.scenario_id}:9093,SASL_SSL://kafka-server-{test_context.scenario_id}:9095,CONTROLLER://kafka-server-{test_context.scenario_id}:9096")
+ self.environment.append("KAFKA_LISTENER_SECURITY_PROTOCOL_MAP=PLAINTEXT:PLAINTEXT,SASL_PLAINTEXT:SASL_PLAINTEXT,SSL:SSL,SASL_SSL:SASL_SSL,CONTROLLER:PLAINTEXT")
+ self.environment.append("KAFKA_SASL_MECHANISM_INTER_BROKER_PROTOCOL=PLAIN")
+ self.environment.append("KAFKA_SASL_ENABLED_MECHANISMS=PLAIN")
+ self.environment.append("KAFKA_OPTS=-Djava.security.auth.login.config=/opt/kafka/config/kafka_jaas.conf -Dlog4j2.rootLogger.level=DEBUG -Dlog4j2.logger.org.apache.kafka.controller.level=DEBUG")
+ self.environment.append("KAFKA_SSL_PROTOCOL=TLS")
+ self.environment.append("KAFKA_SSL_ENABLED_PROTOCOLS=TLSv1.2")
+ self.environment.append("KAFKA_SSL_KEYSTORE_TYPE=JKS")
+ self.environment.append("KAFKA_SSL_KEYSTORE_FILENAME=kafka.keystore.jks")
+ self.environment.append("KAFKA_SSL_KEYSTORE_CREDENTIALS=credentials.conf")
+ self.environment.append("KAFKA_SSL_KEY_CREDENTIALS=credentials.conf")
+ self.environment.append("KAFKA_SSL_TRUSTSTORE_CREDENTIALS=credentials.conf")
+ self.environment.append("KAFKA_SSL_TRUSTSTORE_TYPE=JKS")
+ self.environment.append("KAFKA_SSL_TRUSTSTORE_FILENAME=kafka.truststore.jks")
+ self.environment.append("KAFKA_SSL_CLIENT_AUTH=none")
+
+ kafka_cert, kafka_key = make_server_cert(self.container_name, test_context.root_ca_cert, test_context.root_ca_key)
+
+ pke = jks.PrivateKeyEntry.new('kafka-broker-cert', [crypto.dump_certificate(crypto.FILETYPE_ASN1, kafka_cert)], crypto.dump_privatekey(crypto.FILETYPE_ASN1, kafka_key), 'rsa_raw')
+ server_keystore = jks.KeyStore.new('jks', [pke])
+ server_keystore_content = server_keystore.saves('abcdefgh')
+ self.files.append(File("/etc/kafka/secrets/kafka.keystore.jks", server_keystore_content, permissions=0o644))
+ self.files.append(File("/etc/kafka/secrets/credentials.conf", b'abcdefgh', permissions=0o644))
+
+ trusted_cert = jks.TrustedCertEntry.new(
+ 'root-ca', # Alias for the certificate
+ crypto.dump_certificate(crypto.FILETYPE_ASN1, test_context.root_ca_cert)
+ )
+
+ # Create a JKS keystore that will serve as a truststore with the trusted cert entry.
+ truststore = jks.KeyStore.new('jks', [trusted_cert])
+ truststore_content = truststore.saves('abcdefgh')
+ self.files.append(File("/etc/kafka/secrets/kafka.truststore.jks", truststore_content, permissions=0o644))
+
+ jaas_config_file_content = """
+KafkaServer {
+ org.apache.kafka.common.security.plain.PlainLoginModule required
+ username="admin"
+ password="admin-secret"
+ user_admin="admin-secret"
+ user_alice="alice-secret";
+};
+
+Client {
+ org.apache.kafka.common.security.plain.PlainLoginModule required
+ username="admin"
+ password="admin-secret";
+};
+"""
+ self.files.append(File("/opt/kafka/config/kafka_jaas.conf", jaas_config_file_content, permissions=0o644))
+
+ def deploy(self):
+ super().deploy()
+ finished_str = "Kafka Server started"
+ return wait_for_condition(
+ condition=lambda: finished_str in self.get_logs(),
+ timeout_seconds=60,
+ bail_condition=lambda: self.exited,
+ context=None)
+
+ def create_topic(self, topic_name: str):
+ (code, output) = self.exec_run(["/bin/bash", "-c", f"/opt/kafka/bin/kafka-topics.sh --create --topic {topic_name} --bootstrap-server {self.container_name}:9092"])
+ logging.info("Create topic output: %s", output)
+ return code == 0
+
+ def produce_message(self, topic_name: str, message: str):
+ (code, output) = self.exec_run(["/bin/bash", "-c", f"/opt/kafka/bin/kafka-console-producer.sh --topic {topic_name} --bootstrap-server {self.container_name}:9092 <<< '{message}'"])
+ logging.info("Produce message output: %s", output)
+ return code == 0
+
+ def produce_message_with_key(self, topic_name: str, message: str, message_key: str):
+ (code, output) = self.exec_run(["/bin/bash", "-c", f"/opt/kafka/bin/kafka-console-producer.sh --property 'key.separator=:' --property 'parse.key=true' --topic {topic_name} --bootstrap-server {self.container_name}:9092 <<< '{message_key}:{message}'"])
+ logging.info("Produce message with key output: %s", output)
+ return code == 0
Review Comment:
Added `code` to logs in https://github.com/apache/nifi-minifi-cpp/pull/2059/commits/595d85e0827fe540ca0011ef28dc9c5bb73e659e
##########
extensions/kafka/tests/features/consumekafka.feature:
##########
@@ -19,54 +19,55 @@ Feature: Receiving data from using Kafka streaming platform using ConsumeKafka
As a user of MiNiFi
I need to have ConsumeKafka processor
- Background:
- Given the content of "/tmp/output" is monitored
-
Scenario Outline: ConsumeKafka parses and uses kafka topics and topic name formats
- Given a ConsumeKafka processor set up in a "kafka-consumer-flow" flow
+ Given a Kafka server is set up
+ And ConsumeKafka processor is set up to communicate with that server
And the "Topic Names" property of the ConsumeKafka processor is set to "<topic names>"
And the "Topic Name Format" property of the ConsumeKafka processor is set to "<topic name format>"
And the "Offset Reset" property of the ConsumeKafka processor is set to "earliest"
- And a PutFile processor with the "Directory" property set to "/tmp/output" in the "kafka-consumer-flow" flow
+ And a PutFile processor with the "Directory" property set to "/tmp/output"
+ And PutFile is EVENT_DRIVEN
And the "success" relationship of the ConsumeKafka processor is connected to the PutFile
+ And PutFile's success relationship is auto-terminated
- And a kafka broker is set up in correspondence with the third-party kafka publisher
- And the kafka broker is started
+ And the Kafka server is started
And the topic "ConsumeKafkaTest" is initialized on the kafka broker
When a message with content "<message 1>" is published to the "ConsumeKafkaTest" topic
- And all other processes start up
+ And the MiNiFi instance starts up
And a message with content "<message 2>" is published to the "ConsumeKafkaTest" topic
- Then two flowfiles with the contents "<message 1>" and "<message 2>" are placed in the monitored directory in less than 90 seconds
+ Then the contents of "/tmp/output" in less than 30 seconds are: "<message 1>" and "<message 2>"
Examples: Topic names and formats to test
| message 1 | message 2 | topic names | topic name format |
- | Ulysses | James Joyce | ConsumeKafkaTest | (not set) |
| The Great Gatsby | F. Scott Fitzgerald | ConsumeKafkaTest | Names |
| War and Peace | Lev Tolstoy | a,b,c,ConsumeKafkaTest,d | Names |
| Nineteen Eighty Four | George Orwell | ConsumeKafkaTest | Patterns |
| Hamlet | William Shakespeare | Cons[emu]*KafkaTest | Patterns |
Scenario Outline: ConsumeKafka key attribute is encoded according to the "Key Attribute Encoding" property
- Given a ConsumeKafka processor set up in a "kafka-consumer-flow" flow
+ Given a Kafka server is set up
+ And ConsumeKafka processor is set up to communicate with that server
And the "Key Attribute Encoding" property of the ConsumeKafka processor is set to "<key attribute encoding>"
- And a RouteOnAttribute processor in the "kafka-consumer-flow" flow
- And a LogAttribute processor in the "kafka-consumer-flow" flow
- And a PutFile processor with the "Directory" property set to "/tmp/output" in the "kafka-consumer-flow" flow
+ And a RouteOnAttribute processor
+ And RouteOnAttribute is EVENT_DRIVEN
+ And a LogAttribute processor
+ And LogAttribute is EVENT_DRIVEN
+ And a PutFile processor with the "Directory" property set to "/tmp/output"
+ And PutFile is EVENT_DRIVEN
And the "success" property of the RouteOnAttribute processor is set to match <key attribute encoding> encoded kafka message key "consume_kafka_test_key"
And the "success" relationship of the ConsumeKafka processor is connected to the LogAttribute
And the "success" relationship of the LogAttribute processor is connected to the RouteOnAttribute
And the "success" relationship of the RouteOnAttribute processor is connected to the PutFile
-
- And a kafka broker is set up in correspondence with the third-party kafka publisher
+ And PutFile's success relationship is auto-terminated
When all instances start up
And a message with content "<message 1>" is published to the "ConsumeKafkaTest" topic with key "consume_kafka_test_key"
And a message with content "<message 2>" is published to the "ConsumeKafkaTest" topic with key "consume_kafka_test_key"
- Then two flowfiles with the contents "<message 1>" and "<message 2>" are placed in the monitored directory in less than 45 seconds
+ Then the contents of "/tmp/output" in less than 30 seconds are: "<message 1>" and "<message 2>"
Review Comment:
Updated in https://github.com/apache/nifi-minifi-cpp/pull/2059/commits/595d85e0827fe540ca0011ef28dc9c5bb73e659e
##########
extensions/kafka/tests/features/consumekafka.feature:
##########
@@ -19,54 +19,55 @@ Feature: Receiving data from using Kafka streaming platform using ConsumeKafka
As a user of MiNiFi
I need to have ConsumeKafka processor
- Background:
- Given the content of "/tmp/output" is monitored
-
Scenario Outline: ConsumeKafka parses and uses kafka topics and topic name formats
- Given a ConsumeKafka processor set up in a "kafka-consumer-flow" flow
+ Given a Kafka server is set up
+ And ConsumeKafka processor is set up to communicate with that server
And the "Topic Names" property of the ConsumeKafka processor is set to "<topic names>"
And the "Topic Name Format" property of the ConsumeKafka processor is set to "<topic name format>"
And the "Offset Reset" property of the ConsumeKafka processor is set to "earliest"
- And a PutFile processor with the "Directory" property set to "/tmp/output" in the "kafka-consumer-flow" flow
+ And a PutFile processor with the "Directory" property set to "/tmp/output"
+ And PutFile is EVENT_DRIVEN
And the "success" relationship of the ConsumeKafka processor is connected to the PutFile
+ And PutFile's success relationship is auto-terminated
- And a kafka broker is set up in correspondence with the third-party kafka publisher
- And the kafka broker is started
+ And the Kafka server is started
And the topic "ConsumeKafkaTest" is initialized on the kafka broker
When a message with content "<message 1>" is published to the "ConsumeKafkaTest" topic
- And all other processes start up
+ And the MiNiFi instance starts up
And a message with content "<message 2>" is published to the "ConsumeKafkaTest" topic
- Then two flowfiles with the contents "<message 1>" and "<message 2>" are placed in the monitored directory in less than 90 seconds
+ Then the contents of "/tmp/output" in less than 30 seconds are: "<message 1>" and "<message 2>"
Examples: Topic names and formats to test
| message 1 | message 2 | topic names | topic name format |
- | Ulysses | James Joyce | ConsumeKafkaTest | (not set) |
| The Great Gatsby | F. Scott Fitzgerald | ConsumeKafkaTest | Names |
Review Comment:
Good catch, it was a mistake, restored in https://github.com/apache/nifi-minifi-cpp/pull/2059/commits/595d85e0827fe540ca0011ef28dc9c5bb73e659e
##########
extensions/kafka/tests/features/steps/kafka_server_container.py:
##########
@@ -0,0 +1,126 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import logging
+import re
+import jks
+
+from OpenSSL import crypto
+from minifi_test_framework.core.helpers import wait_for_condition
+from minifi_test_framework.core.ssl_utils import make_server_cert
+from minifi_test_framework.containers.container import Container
+from minifi_test_framework.containers.file import File
+from minifi_test_framework.core.minifi_test_context import MinifiTestContext
+
+
+class KafkaServer(Container):
+ def __init__(self, test_context: MinifiTestContext):
+ super().__init__("apache/kafka:4.1.0", f"kafka-server-{test_context.scenario_id}", test_context.network)
+ self.environment.append("KAFKA_NODE_ID=1")
+ self.environment.append("KAFKA_PROCESS_ROLES=controller,broker")
+ self.environment.append("KAFKA_INTER_BROKER_LISTENER_NAME=PLAINTEXT")
+ self.environment.append("KAFKA_CONTROLLER_LISTENER_NAMES=CONTROLLER")
+ self.environment.append("KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR=1")
+ self.environment.append("KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR=1")
+ self.environment.append("KAFKA_TRANSACTION_STATE_LOG_MIN_ISR=1")
+ self.environment.append(f"KAFKA_CONTROLLER_QUORUM_VOTERS=1@kafka-server-{test_context.scenario_id}:9096")
+ self.environment.append(f"KAFKA_LISTENERS=PLAINTEXT://kafka-server-{test_context.scenario_id}:9092,SASL_PLAINTEXT://kafka-server-{test_context.scenario_id}:9094,SSL://kafka-server-{test_context.scenario_id}:9093,SASL_SSL://kafka-server-{test_context.scenario_id}:9095,CONTROLLER://kafka-server-{test_context.scenario_id}:9096")
+ self.environment.append(f"KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://kafka-server-{test_context.scenario_id}:9092,SASL_PLAINTEXT://kafka-server-{test_context.scenario_id}:9094,SSL://kafka-server-{test_context.scenario_id}:9093,SASL_SSL://kafka-server-{test_context.scenario_id}:9095,CONTROLLER://kafka-server-{test_context.scenario_id}:9096")
+ self.environment.append("KAFKA_LISTENER_SECURITY_PROTOCOL_MAP=PLAINTEXT:PLAINTEXT,SASL_PLAINTEXT:SASL_PLAINTEXT,SSL:SSL,SASL_SSL:SASL_SSL,CONTROLLER:PLAINTEXT")
+ self.environment.append("KAFKA_SASL_MECHANISM_INTER_BROKER_PROTOCOL=PLAIN")
+ self.environment.append("KAFKA_SASL_ENABLED_MECHANISMS=PLAIN")
+ self.environment.append("KAFKA_OPTS=-Djava.security.auth.login.config=/opt/kafka/config/kafka_jaas.conf -Dlog4j2.rootLogger.level=DEBUG -Dlog4j2.logger.org.apache.kafka.controller.level=DEBUG")
+ self.environment.append("KAFKA_SSL_PROTOCOL=TLS")
+ self.environment.append("KAFKA_SSL_ENABLED_PROTOCOLS=TLSv1.2")
+ self.environment.append("KAFKA_SSL_KEYSTORE_TYPE=JKS")
+ self.environment.append("KAFKA_SSL_KEYSTORE_FILENAME=kafka.keystore.jks")
+ self.environment.append("KAFKA_SSL_KEYSTORE_CREDENTIALS=credentials.conf")
+ self.environment.append("KAFKA_SSL_KEY_CREDENTIALS=credentials.conf")
+ self.environment.append("KAFKA_SSL_TRUSTSTORE_CREDENTIALS=credentials.conf")
+ self.environment.append("KAFKA_SSL_TRUSTSTORE_TYPE=JKS")
+ self.environment.append("KAFKA_SSL_TRUSTSTORE_FILENAME=kafka.truststore.jks")
+ self.environment.append("KAFKA_SSL_CLIENT_AUTH=none")
+
+ kafka_cert, kafka_key = make_server_cert(self.container_name, test_context.root_ca_cert, test_context.root_ca_key)
+
+ pke = jks.PrivateKeyEntry.new('kafka-broker-cert', [crypto.dump_certificate(crypto.FILETYPE_ASN1, kafka_cert)], crypto.dump_privatekey(crypto.FILETYPE_ASN1, kafka_key), 'rsa_raw')
+ server_keystore = jks.KeyStore.new('jks', [pke])
+ server_keystore_content = server_keystore.saves('abcdefgh')
+ self.files.append(File("/etc/kafka/secrets/kafka.keystore.jks", server_keystore_content, permissions=0o644))
+ self.files.append(File("/etc/kafka/secrets/credentials.conf", b'abcdefgh', permissions=0o644))
+
+ trusted_cert = jks.TrustedCertEntry.new(
+ 'root-ca', # Alias for the certificate
+ crypto.dump_certificate(crypto.FILETYPE_ASN1, test_context.root_ca_cert)
+ )
+
+ # Create a JKS keystore that will serve as a truststore with the trusted cert entry.
+ truststore = jks.KeyStore.new('jks', [trusted_cert])
+ truststore_content = truststore.saves('abcdefgh')
+ self.files.append(File("/etc/kafka/secrets/kafka.truststore.jks", truststore_content, permissions=0o644))
+
+ jaas_config_file_content = """
+KafkaServer {
+ org.apache.kafka.common.security.plain.PlainLoginModule required
+ username="admin"
+ password="admin-secret"
+ user_admin="admin-secret"
+ user_alice="alice-secret";
+};
+
+Client {
+ org.apache.kafka.common.security.plain.PlainLoginModule required
+ username="admin"
+ password="admin-secret";
+};
+"""
+ self.files.append(File("/opt/kafka/config/kafka_jaas.conf", jaas_config_file_content, permissions=0o644))
+
+ def deploy(self):
+ super().deploy()
+ finished_str = "Kafka Server started"
+ return wait_for_condition(
+ condition=lambda: finished_str in self.get_logs(),
+ timeout_seconds=60,
+ bail_condition=lambda: self.exited,
+ context=None)
+
+ def create_topic(self, topic_name: str):
+ (code, output) = self.exec_run(["/bin/bash", "-c", f"/opt/kafka/bin/kafka-topics.sh --create --topic {topic_name} --bootstrap-server {self.container_name}:9092"])
+ logging.info("Create topic output: %s", output)
+ return code == 0
+
+ def produce_message(self, topic_name: str, message: str):
+ (code, output) = self.exec_run(["/bin/bash", "-c", f"/opt/kafka/bin/kafka-console-producer.sh --topic {topic_name} --bootstrap-server {self.container_name}:9092 <<< '{message}'"])
Review Comment:
Updated in https://github.com/apache/nifi-minifi-cpp/pull/2059/commits/595d85e0827fe540ca0011ef28dc9c5bb73e659e
##########
extensions/kafka/tests/features/steps/kafka_server_container.py:
##########
@@ -0,0 +1,126 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import logging
+import re
+import jks
+
+from OpenSSL import crypto
+from minifi_test_framework.core.helpers import wait_for_condition
+from minifi_test_framework.core.ssl_utils import make_server_cert
+from minifi_test_framework.containers.container import Container
+from minifi_test_framework.containers.file import File
+from minifi_test_framework.core.minifi_test_context import MinifiTestContext
+
+
+class KafkaServer(Container):
+ def __init__(self, test_context: MinifiTestContext):
+ super().__init__("apache/kafka:4.1.0", f"kafka-server-{test_context.scenario_id}", test_context.network)
+ self.environment.append("KAFKA_NODE_ID=1")
+ self.environment.append("KAFKA_PROCESS_ROLES=controller,broker")
+ self.environment.append("KAFKA_INTER_BROKER_LISTENER_NAME=PLAINTEXT")
+ self.environment.append("KAFKA_CONTROLLER_LISTENER_NAMES=CONTROLLER")
+ self.environment.append("KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR=1")
+ self.environment.append("KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR=1")
+ self.environment.append("KAFKA_TRANSACTION_STATE_LOG_MIN_ISR=1")
+ self.environment.append(f"KAFKA_CONTROLLER_QUORUM_VOTERS=1@kafka-server-{test_context.scenario_id}:9096")
+ self.environment.append(f"KAFKA_LISTENERS=PLAINTEXT://kafka-server-{test_context.scenario_id}:9092,SASL_PLAINTEXT://kafka-server-{test_context.scenario_id}:9094,SSL://kafka-server-{test_context.scenario_id}:9093,SASL_SSL://kafka-server-{test_context.scenario_id}:9095,CONTROLLER://kafka-server-{test_context.scenario_id}:9096")
+ self.environment.append(f"KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://kafka-server-{test_context.scenario_id}:9092,SASL_PLAINTEXT://kafka-server-{test_context.scenario_id}:9094,SSL://kafka-server-{test_context.scenario_id}:9093,SASL_SSL://kafka-server-{test_context.scenario_id}:9095,CONTROLLER://kafka-server-{test_context.scenario_id}:9096")
+ self.environment.append("KAFKA_LISTENER_SECURITY_PROTOCOL_MAP=PLAINTEXT:PLAINTEXT,SASL_PLAINTEXT:SASL_PLAINTEXT,SSL:SSL,SASL_SSL:SASL_SSL,CONTROLLER:PLAINTEXT")
+ self.environment.append("KAFKA_SASL_MECHANISM_INTER_BROKER_PROTOCOL=PLAIN")
+ self.environment.append("KAFKA_SASL_ENABLED_MECHANISMS=PLAIN")
+ self.environment.append("KAFKA_OPTS=-Djava.security.auth.login.config=/opt/kafka/config/kafka_jaas.conf -Dlog4j2.rootLogger.level=DEBUG -Dlog4j2.logger.org.apache.kafka.controller.level=DEBUG")
+ self.environment.append("KAFKA_SSL_PROTOCOL=TLS")
+ self.environment.append("KAFKA_SSL_ENABLED_PROTOCOLS=TLSv1.2")
+ self.environment.append("KAFKA_SSL_KEYSTORE_TYPE=JKS")
+ self.environment.append("KAFKA_SSL_KEYSTORE_FILENAME=kafka.keystore.jks")
+ self.environment.append("KAFKA_SSL_KEYSTORE_CREDENTIALS=credentials.conf")
+ self.environment.append("KAFKA_SSL_KEY_CREDENTIALS=credentials.conf")
+ self.environment.append("KAFKA_SSL_TRUSTSTORE_CREDENTIALS=credentials.conf")
+ self.environment.append("KAFKA_SSL_TRUSTSTORE_TYPE=JKS")
+ self.environment.append("KAFKA_SSL_TRUSTSTORE_FILENAME=kafka.truststore.jks")
+ self.environment.append("KAFKA_SSL_CLIENT_AUTH=none")
+
+ kafka_cert, kafka_key = make_server_cert(self.container_name, test_context.root_ca_cert, test_context.root_ca_key)
+
+ pke = jks.PrivateKeyEntry.new('kafka-broker-cert', [crypto.dump_certificate(crypto.FILETYPE_ASN1, kafka_cert)], crypto.dump_privatekey(crypto.FILETYPE_ASN1, kafka_key), 'rsa_raw')
+ server_keystore = jks.KeyStore.new('jks', [pke])
+ server_keystore_content = server_keystore.saves('abcdefgh')
+ self.files.append(File("/etc/kafka/secrets/kafka.keystore.jks", server_keystore_content, permissions=0o644))
+ self.files.append(File("/etc/kafka/secrets/credentials.conf", b'abcdefgh', permissions=0o644))
+
+ trusted_cert = jks.TrustedCertEntry.new(
+ 'root-ca', # Alias for the certificate
+ crypto.dump_certificate(crypto.FILETYPE_ASN1, test_context.root_ca_cert)
+ )
+
+ # Create a JKS keystore that will serve as a truststore with the trusted cert entry.
+ truststore = jks.KeyStore.new('jks', [trusted_cert])
+ truststore_content = truststore.saves('abcdefgh')
+ self.files.append(File("/etc/kafka/secrets/kafka.truststore.jks", truststore_content, permissions=0o644))
+
+ jaas_config_file_content = """
+KafkaServer {
+ org.apache.kafka.common.security.plain.PlainLoginModule required
+ username="admin"
+ password="admin-secret"
+ user_admin="admin-secret"
+ user_alice="alice-secret";
+};
+
+Client {
+ org.apache.kafka.common.security.plain.PlainLoginModule required
+ username="admin"
+ password="admin-secret";
+};
+"""
+ self.files.append(File("/opt/kafka/config/kafka_jaas.conf", jaas_config_file_content, permissions=0o644))
+
+ def deploy(self):
+ super().deploy()
+ finished_str = "Kafka Server started"
+ return wait_for_condition(
+ condition=lambda: finished_str in self.get_logs(),
+ timeout_seconds=60,
+ bail_condition=lambda: self.exited,
+ context=None)
+
+ def create_topic(self, topic_name: str):
+ (code, output) = self.exec_run(["/bin/bash", "-c", f"/opt/kafka/bin/kafka-topics.sh --create --topic {topic_name} --bootstrap-server {self.container_name}:9092"])
+ logging.info("Create topic output: %s", output)
+ return code == 0
+
+ def produce_message(self, topic_name: str, message: str):
+ (code, output) = self.exec_run(["/bin/bash", "-c", f"/opt/kafka/bin/kafka-console-producer.sh --topic {topic_name} --bootstrap-server {self.container_name}:9092 <<< '{message}'"])
+ logging.info("Produce message output: %s", output)
+ return code == 0
+
+ def produce_message_with_key(self, topic_name: str, message: str, message_key: str):
+ (code, output) = self.exec_run(["/bin/bash", "-c", f"/opt/kafka/bin/kafka-console-producer.sh --property 'key.separator=:' --property 'parse.key=true' --topic {topic_name} --bootstrap-server {self.container_name}:9092 <<< '{message_key}:{message}'"])
Review Comment:
Updated in https://github.com/apache/nifi-minifi-cpp/pull/2059/commits/595d85e0827fe540ca0011ef28dc9c5bb73e659e
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] MINIFICPP-2666 Move Kafka tests to modular docker tests [nifi-minifi-cpp]
Posted by "lordgamez (via GitHub)" <gi...@apache.org>.
lordgamez commented on code in PR #2059:
URL: https://github.com/apache/nifi-minifi-cpp/pull/2059#discussion_r2661354750
##########
extensions/kafka/tests/features/steps/kafka_server_container.py:
##########
@@ -0,0 +1,126 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import logging
+import re
+import jks
+
+from OpenSSL import crypto
+from minifi_test_framework.core.helpers import wait_for_condition
+from minifi_test_framework.core.ssl_utils import make_server_cert
+from minifi_test_framework.containers.container import Container
+from minifi_test_framework.containers.file import File
+from minifi_test_framework.core.minifi_test_context import MinifiTestContext
+
+
+class KafkaServer(Container):
+ def __init__(self, test_context: MinifiTestContext):
+ super().__init__("apache/kafka:4.1.0", f"kafka-server-{test_context.scenario_id}", test_context.network)
+ self.environment.append("KAFKA_NODE_ID=1")
+ self.environment.append("KAFKA_PROCESS_ROLES=controller,broker")
+ self.environment.append("KAFKA_INTER_BROKER_LISTENER_NAME=PLAINTEXT")
+ self.environment.append("KAFKA_CONTROLLER_LISTENER_NAMES=CONTROLLER")
+ self.environment.append("KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR=1")
+ self.environment.append("KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR=1")
+ self.environment.append("KAFKA_TRANSACTION_STATE_LOG_MIN_ISR=1")
+ self.environment.append(f"KAFKA_CONTROLLER_QUORUM_VOTERS=1@kafka-server-{test_context.scenario_id}:9096")
+ self.environment.append(f"KAFKA_LISTENERS=PLAINTEXT://kafka-server-{test_context.scenario_id}:9092,SASL_PLAINTEXT://kafka-server-{test_context.scenario_id}:9094,SSL://kafka-server-{test_context.scenario_id}:9093,SASL_SSL://kafka-server-{test_context.scenario_id}:9095,CONTROLLER://kafka-server-{test_context.scenario_id}:9096")
+ self.environment.append(f"KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://kafka-server-{test_context.scenario_id}:9092,SASL_PLAINTEXT://kafka-server-{test_context.scenario_id}:9094,SSL://kafka-server-{test_context.scenario_id}:9093,SASL_SSL://kafka-server-{test_context.scenario_id}:9095,CONTROLLER://kafka-server-{test_context.scenario_id}:9096")
+ self.environment.append("KAFKA_LISTENER_SECURITY_PROTOCOL_MAP=PLAINTEXT:PLAINTEXT,SASL_PLAINTEXT:SASL_PLAINTEXT,SSL:SSL,SASL_SSL:SASL_SSL,CONTROLLER:PLAINTEXT")
+ self.environment.append("KAFKA_SASL_MECHANISM_INTER_BROKER_PROTOCOL=PLAIN")
+ self.environment.append("KAFKA_SASL_ENABLED_MECHANISMS=PLAIN")
+ self.environment.append("KAFKA_OPTS=-Djava.security.auth.login.config=/opt/kafka/config/kafka_jaas.conf -Dlog4j2.rootLogger.level=DEBUG -Dlog4j2.logger.org.apache.kafka.controller.level=DEBUG")
+ self.environment.append("KAFKA_SSL_PROTOCOL=TLS")
+ self.environment.append("KAFKA_SSL_ENABLED_PROTOCOLS=TLSv1.2")
+ self.environment.append("KAFKA_SSL_KEYSTORE_TYPE=JKS")
+ self.environment.append("KAFKA_SSL_KEYSTORE_FILENAME=kafka.keystore.jks")
+ self.environment.append("KAFKA_SSL_KEYSTORE_CREDENTIALS=credentials.conf")
+ self.environment.append("KAFKA_SSL_KEY_CREDENTIALS=credentials.conf")
+ self.environment.append("KAFKA_SSL_TRUSTSTORE_CREDENTIALS=credentials.conf")
+ self.environment.append("KAFKA_SSL_TRUSTSTORE_TYPE=JKS")
+ self.environment.append("KAFKA_SSL_TRUSTSTORE_FILENAME=kafka.truststore.jks")
+ self.environment.append("KAFKA_SSL_CLIENT_AUTH=none")
+
+ kafka_cert, kafka_key = make_server_cert(self.container_name, test_context.root_ca_cert, test_context.root_ca_key)
+
+ pke = jks.PrivateKeyEntry.new('kafka-broker-cert', [crypto.dump_certificate(crypto.FILETYPE_ASN1, kafka_cert)], crypto.dump_privatekey(crypto.FILETYPE_ASN1, kafka_key), 'rsa_raw')
+ server_keystore = jks.KeyStore.new('jks', [pke])
+ server_keystore_content = server_keystore.saves('abcdefgh')
+ self.files.append(File("/etc/kafka/secrets/kafka.keystore.jks", server_keystore_content, permissions=0o644))
+ self.files.append(File("/etc/kafka/secrets/credentials.conf", b'abcdefgh', permissions=0o644))
+
+ trusted_cert = jks.TrustedCertEntry.new(
+ 'root-ca', # Alias for the certificate
+ crypto.dump_certificate(crypto.FILETYPE_ASN1, test_context.root_ca_cert)
+ )
+
+ # Create a JKS keystore that will serve as a truststore with the trusted cert entry.
+ truststore = jks.KeyStore.new('jks', [trusted_cert])
+ truststore_content = truststore.saves('abcdefgh')
+ self.files.append(File("/etc/kafka/secrets/kafka.truststore.jks", truststore_content, permissions=0o644))
+
+ jaas_config_file_content = """
+KafkaServer {
+ org.apache.kafka.common.security.plain.PlainLoginModule required
+ username="admin"
+ password="admin-secret"
+ user_admin="admin-secret"
+ user_alice="alice-secret";
+};
+
+Client {
+ org.apache.kafka.common.security.plain.PlainLoginModule required
+ username="admin"
+ password="admin-secret";
+};
+"""
+ self.files.append(File("/opt/kafka/config/kafka_jaas.conf", jaas_config_file_content, permissions=0o644))
+
+ def deploy(self):
+ super().deploy()
+ finished_str = "Kafka Server started"
+ return wait_for_condition(
+ condition=lambda: finished_str in self.get_logs(),
+ timeout_seconds=60,
+ bail_condition=lambda: self.exited,
+ context=None)
+
+ def create_topic(self, topic_name: str):
+ (code, output) = self.exec_run(["/bin/bash", "-c", f"/opt/kafka/bin/kafka-topics.sh --create --topic {topic_name} --bootstrap-server {self.container_name}:9092"])
Review Comment:
Updated in https://github.com/apache/nifi-minifi-cpp/pull/2059/commits/595d85e0827fe540ca0011ef28dc9c5bb73e659e
##########
extensions/kafka/tests/features/consumekafka.feature:
##########
@@ -75,18 +76,19 @@ Feature: Receiving data from using Kafka streaming platform using ConsumeKafka
| Crime and Punishment | Фёдор Михайлович Достоевский | Hex |
Scenario Outline: ConsumeKafka transactional behaviour is supported
- Given a ConsumeKafka processor set up in a "kafka-consumer-flow" flow
+ Given a Kafka server is set up
+ And ConsumeKafka processor is set up to communicate with that server
And the "Topic Names" property of the ConsumeKafka processor is set to "ConsumeKafkaTest"
And the "Honor Transactions" property of the ConsumeKafka processor is set to "<honor transactions>"
- And a PutFile processor with the "Directory" property set to "/tmp/output" in the "kafka-consumer-flow" flow
+ And a PutFile processor with the "Directory" property set to "/tmp/output"
+ And PutFile is EVENT_DRIVEN
And the "success" relationship of the ConsumeKafka processor is connected to the PutFile
-
- And a kafka broker is set up in correspondence with the third-party kafka publisher
+ And PutFile's success relationship is auto-terminated
When all instances start up
And the publisher performs a <transaction type> transaction publishing to the "ConsumeKafkaTest" topic these messages: <messages sent>
- Then <number of flowfiles expected> flowfiles are placed in the monitored directory in less than 15 seconds
+ Then there are <number of flowfiles expected> files in the "/tmp/output" directory in less than 15 seconds
Review Comment:
Good point, updated the steps in https://github.com/apache/nifi-minifi-cpp/pull/2059/commits/595d85e0827fe540ca0011ef28dc9c5bb73e659e
##########
behave_framework/src/minifi_test_framework/steps/checking_steps.py:
##########
@@ -83,16 +84,34 @@ def step_impl(context: MinifiTestContext, message: str, duration: str):
context=context)
+@then("the Minifi logs match the following regex: \"{regex}\" in less than {duration}")
+def step_impl(context, regex, duration):
+ duration_seconds = humanfriendly.parse_timespan(duration)
+ assert wait_for_condition(condition=lambda: re.search(regex, context.get_default_minifi_container().get_logs()),
+ timeout_seconds=duration_seconds, bail_condition=lambda: context.get_default_minifi_container().exited,
+ context=context)
+
+
@step('no errors were generated on the http-proxy regarding "{url}"')
def step_impl(context: MinifiTestContext, url: str):
http_proxy_container = next(container for container in context.containers.values() if isinstance(container, HttpProxy))
assert http_proxy_container.check_http_proxy_access(url) or http_proxy_container.log_app_output()
+@then('no files are placed in the "{directory}" directory in {duration} of running time')
+def step_impl(context, directory, duration):
+ duration_seconds = humanfriendly.parse_timespan(duration)
+ assert check_condition_after_wait(condition=lambda: context.get_default_minifi_container().get_number_of_files(directory) < 1,
Review Comment:
Good catch, in case of a negative return value it should be an error, updated in https://github.com/apache/nifi-minifi-cpp/pull/2059/commits/595d85e0827fe540ca0011ef28dc9c5bb73e659e
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] MINIFICPP-2666 Move Kafka tests to modular docker tests [nifi-minifi-cpp]
Posted by "lordgamez (via GitHub)" <gi...@apache.org>.
lordgamez commented on code in PR #2059:
URL: https://github.com/apache/nifi-minifi-cpp/pull/2059#discussion_r2661341950
##########
behave_framework/src/minifi_test_framework/steps/checking_steps.py:
##########
@@ -152,3 +171,28 @@ def step_impl(context: MinifiTestContext, max_increase: str, duration: str):
time.sleep(time_in_seconds)
final_memory_usage = context.get_default_minifi_container().get_memory_usage()
assert final_memory_usage - initial_memory_usage <= max_increase_in_bytes
+
+
+@then('after a wait of {duration}, at least {lower_bound:d} and at most {upper_bound:d} flowfiles are produced and placed in the "{directory}" directory')
+def step_impl(context, lower_bound, upper_bound, duration, directory):
+ duration_seconds = humanfriendly.parse_timespan(duration)
+ assert check_condition_after_wait(condition=lambda: context.get_default_minifi_container().get_number_of_files(directory) >= lower_bound
+ and context.get_default_minifi_container().get_number_of_files(directory) <= upper_bound,
+ context=context, wait_time=duration_seconds)
+
+
+@then('exactly these files are in the "{directory}" directory in less than {duration}: "{contents}"')
+def step_impl(context, directory, duration, contents):
+ if not contents:
+ context.execute_steps(f'then no files are placed in the "{directory}" directory in {duration} of running time')
+ return
+ contents_arr = contents.split(",")
+ timeout_in_seconds = humanfriendly.parse_timespan(duration)
+ assert wait_for_condition(condition=lambda: context.get_default_minifi_container().verify_file_contents(directory, contents_arr),
+ timeout_seconds=timeout_in_seconds, bail_condition=lambda: False,
+ context=context)
+
+
+@then('exactly these files are in the "{directory}" directory in less than {duration}: ""')
Review Comment:
It is actually used that way in this specific scenario when no content is set. It calls "no files are placed" step which waits for the set amount of time. This step only uses this type of phrasing to be used in a single scenario outline together with other use case parameters.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] MINIFICPP-2666 Move Kafka tests to modular docker tests [nifi-minifi-cpp]
Posted by "lordgamez (via GitHub)" <gi...@apache.org>.
lordgamez commented on code in PR #2059:
URL: https://github.com/apache/nifi-minifi-cpp/pull/2059#discussion_r2533908747
##########
behave_framework/src/minifi_test_framework/containers/container.py:
##########
@@ -254,6 +285,59 @@ def verify_file_contents(self, directory_path: str, expected_contents: list[str]
return sorted(actual_file_contents) == sorted(expected_contents)
+ def _verify_file_contents_in_stopped_container(self, directory_path: str, expected_contents: list[str]) -> bool:
+ if not self.container:
+ return False
+
+ with tempfile.TemporaryDirectory() as temp_dir:
+ extracted_dir = self._extract_directory_from_container(directory_path, temp_dir)
+ if not extracted_dir:
+ return False
+
+ actual_file_contents = self._read_files_from_directory(extracted_dir)
+ if actual_file_contents is None:
+ return False
+
+ return sorted(actual_file_contents) == sorted(expected_contents)
+
+ def _extract_directory_from_container(self, directory_path: str, temp_dir: str) -> str | None:
+ try:
+ bits, _ = self.container.get_archive(directory_path)
+ temp_tar_path = os.path.join(temp_dir, "archive.tar")
+
+ with open(temp_tar_path, 'wb') as f:
+ for chunk in bits:
+ f.write(chunk)
+
+ with tarfile.open(temp_tar_path) as tar:
+ tar.extractall(path=temp_dir)
+
Review Comment:
We only use it for containers that are validated by us, so this should not be a problem, `tarfile.data_filter` will not work for use as we need to support the minimum python version 3.10.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] MINIFICPP-2666 Move Kafka tests to modular docker tests [nifi-minifi-cpp]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #2059:
URL: https://github.com/apache/nifi-minifi-cpp/pull/2059#discussion_r2533884357
##########
behave_framework/src/minifi_test_framework/containers/minifi_container.py:
##########
@@ -15,34 +15,44 @@
# limitations under the License.
#
-from docker.models.networks import Network
+import logging
+from OpenSSL import crypto
+from minifi_test_framework.core.minifi_test_context import MinifiTestContext
from minifi_test_framework.containers.file import File
from minifi_test_framework.minifi.flow_definition import FlowDefinition
+from minifi_test_framework.core.ssl_utils import make_cert_without_extended_usage
from .container import Container
class MinifiContainer(Container):
- def __init__(self, image_name: str, container_name: str, scenario_id: str, network: Network):
- super().__init__(image_name, f"{container_name}-{scenario_id}", network)
+ def __init__(self, container_name: str, test_context: MinifiTestContext):
+ super().__init__(test_context.minifi_container_image, f"{container_name}-{test_context.scenario_id}", test_context.network)
self.flow_config_str: str = ""
self.flow_definition = FlowDefinition()
self.properties: dict[str, str] = {}
self.log_properties: dict[str, str] = {}
- self.is_fhs = 'MINIFI_INSTALLATION_TYPE=FHS' in str(self.client.images.get(image_name).history())
+ minifi_client_cert, minifi_client_key = make_cert_without_extended_usage(common_name=self.container_name, ca_cert=test_context.root_ca_cert, ca_key=test_context.root_ca_key)
+ self.files.append(File("/tmp/resources/root_ca.crt", crypto.dump_certificate(type=crypto.FILETYPE_PEM, cert=test_context.root_ca_cert)))
+ self.files.append(File("/tmp/resources/minifi_client.crt", crypto.dump_certificate(type=crypto.FILETYPE_PEM, cert=minifi_client_cert)))
+ self.files.append(File("/tmp/resources/minifi_client.key", crypto.dump_privatekey(type=crypto.FILETYPE_PEM, pkey=minifi_client_key)))
Review Comment:
The `File` class is now initialized with `permissions` parameter but there's inconsistent usage. Some files use `permissions=0o644` while others don't specify permissions at all. For consistency and security, all files should explicitly specify appropriate permissions, especially for sensitive files like certificates and keys which should typically be `0o600` or `0o400` to prevent unauthorized access.
##########
behave_framework/src/minifi_test_framework/steps/flow_building_steps.py:
##########
@@ -77,7 +78,10 @@ def step_impl(context: MinifiTestContext, processor_type: str):
@step('the "{property_name}" property of the {processor_name} processor is set to "{property_value}"')
def step_impl(context: MinifiTestContext, property_name: str, processor_name: str, property_value: str):
processor = context.get_or_create_default_minifi_container().flow_definition.get_processor(processor_name)
- processor.add_property(property_name, property_value)
+ if property_value == "(not set)":
+ processor.remove_property(property_name)
+ else:
+ processor.add_property(property_name, property_value)
Review Comment:
[nitpick] The special handling for `"(not set)"` property values is added, but the logic may not be clear. When `property_value == "(not set)"`, the property is removed. However, this string literal comparison could be fragile. Consider documenting this behavior or using a more explicit constant (e.g., `PROPERTY_NOT_SET = "(not set)"`) to make the intent clearer and avoid accidental matches.
##########
extensions/kafka/tests/features/steps/kafka_server_container.py:
##########
@@ -0,0 +1,126 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import logging
+import re
+import jks
+
+from OpenSSL import crypto
+from minifi_test_framework.core.helpers import wait_for_condition
+from minifi_test_framework.core.ssl_utils import make_server_cert
+from minifi_test_framework.containers.container import Container
+from minifi_test_framework.containers.file import File
+from minifi_test_framework.core.minifi_test_context import MinifiTestContext
+
+
+class KafkaServer(Container):
+ def __init__(self, test_context: MinifiTestContext):
+ super().__init__("apache/kafka:4.1.0", f"kafka-server-{test_context.scenario_id}", test_context.network)
+ self.environment.append("KAFKA_NODE_ID=1")
+ self.environment.append("KAFKA_PROCESS_ROLES=controller,broker")
+ self.environment.append("KAFKA_INTER_BROKER_LISTENER_NAME=PLAINTEXT")
+ self.environment.append("KAFKA_CONTROLLER_LISTENER_NAMES=CONTROLLER")
+ self.environment.append("KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR=1")
+ self.environment.append("KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR=1")
+ self.environment.append("KAFKA_TRANSACTION_STATE_LOG_MIN_ISR=1")
+ self.environment.append(f"KAFKA_CONTROLLER_QUORUM_VOTERS=1@kafka-server-{test_context.scenario_id}:9096")
+ self.environment.append(f"KAFKA_LISTENERS=PLAINTEXT://kafka-server-{test_context.scenario_id}:9092,SASL_PLAINTEXT://kafka-server-{test_context.scenario_id}:9094,SSL://kafka-server-{test_context.scenario_id}:9093,SASL_SSL://kafka-server-{test_context.scenario_id}:9095,CONTROLLER://kafka-server-{test_context.scenario_id}:9096")
+ self.environment.append(f"KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://kafka-server-{test_context.scenario_id}:9092,SASL_PLAINTEXT://kafka-server-{test_context.scenario_id}:9094,SSL://kafka-server-{test_context.scenario_id}:9093,SASL_SSL://kafka-server-{test_context.scenario_id}:9095,CONTROLLER://kafka-server-{test_context.scenario_id}:9096")
+ self.environment.append("KAFKA_LISTENER_SECURITY_PROTOCOL_MAP=PLAINTEXT:PLAINTEXT,SASL_PLAINTEXT:SASL_PLAINTEXT,SSL:SSL,SASL_SSL:SASL_SSL,CONTROLLER:PLAINTEXT")
+ self.environment.append("KAFKA_SASL_MECHANISM_INTER_BROKER_PROTOCOL=PLAIN")
+ self.environment.append("KAFKA_SASL_ENABLED_MECHANISMS=PLAIN")
+ self.environment.append("KAFKA_OPTS=-Djava.security.auth.login.config=/opt/kafka/config/kafka_jaas.conf -Dlog4j2.rootLogger.level=DEBUG -Dlog4j2.logger.org.apache.kafka.controller.level=DEBUG")
+ self.environment.append("KAFKA_SSL_PROTOCOL=TLS")
+ self.environment.append("KAFKA_SSL_ENABLED_PROTOCOLS=TLSv1.2")
+ self.environment.append("KAFKA_SSL_KEYSTORE_TYPE=JKS")
+ self.environment.append("KAFKA_SSL_KEYSTORE_FILENAME=kafka.keystore.jks")
+ self.environment.append("KAFKA_SSL_KEYSTORE_CREDENTIALS=credentials.conf")
+ self.environment.append("KAFKA_SSL_KEY_CREDENTIALS=credentials.conf")
+ self.environment.append("KAFKA_SSL_TRUSTSTORE_CREDENTIALS=credentials.conf")
+ self.environment.append("KAFKA_SSL_TRUSTSTORE_TYPE=JKS")
+ self.environment.append("KAFKA_SSL_TRUSTSTORE_FILENAME=kafka.truststore.jks")
+ self.environment.append("KAFKA_SSL_CLIENT_AUTH=none")
+
+ kafka_cert, kafka_key = make_server_cert(self.container_name, test_context.root_ca_cert, test_context.root_ca_key)
+
+ pke = jks.PrivateKeyEntry.new('kafka-broker-cert', [crypto.dump_certificate(crypto.FILETYPE_ASN1, kafka_cert)], crypto.dump_privatekey(crypto.FILETYPE_ASN1, kafka_key), 'rsa_raw')
+ server_keystore = jks.KeyStore.new('jks', [pke])
+ server_keystore_content = server_keystore.saves('abcdefgh')
+ self.files.append(File("/etc/kafka/secrets/kafka.keystore.jks", server_keystore_content, permissions=0o644))
+ self.files.append(File("/etc/kafka/secrets/credentials.conf", b'abcdefgh', permissions=0o644))
+
+ trusted_cert = jks.TrustedCertEntry.new(
+ 'root-ca', # Alias for the certificate
+ crypto.dump_certificate(crypto.FILETYPE_ASN1, test_context.root_ca_cert)
+ )
+
+ # Create a JKS keystore that will serve as a truststore with the trusted cert entry.
+ truststore = jks.KeyStore.new('jks', [trusted_cert])
+ truststore_content = truststore.saves('abcdefgh')
+ self.files.append(File("/etc/kafka/secrets/kafka.truststore.jks", truststore_content, permissions=0o644))
Review Comment:
The hardcoded password 'abcdefgh' is used for keystores and truststores. This is a security concern even in test environments as it could be exploited if these containers are accidentally exposed. Consider using a randomly generated password or at least a more complex one, and potentially storing it in an environment variable.
##########
behave_framework/src/minifi_test_framework/containers/container.py:
##########
@@ -204,6 +232,7 @@ def exited(self) -> bool:
def get_number_of_files(self, directory_path: str) -> int:
if not self.container or not self.not_empty_dir_exists(directory_path):
+ logging.warning(f"Container not running or directory does not exist: {directory_path}")
Review Comment:
Missing import statement. The code uses `logging.warning()` on line 235, `logging.debug()` on line 247, and `logging.error()` on lines 250, 317, and 329, but `logging` is not imported at the top of this file. This will cause a `NameError` at runtime. Add `import logging` to the imports section.
##########
extensions/kafka/tests/features/steps/kafka_server_container.py:
##########
@@ -0,0 +1,126 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import logging
+import re
+import jks
+
+from OpenSSL import crypto
+from minifi_test_framework.core.helpers import wait_for_condition
+from minifi_test_framework.core.ssl_utils import make_server_cert
+from minifi_test_framework.containers.container import Container
+from minifi_test_framework.containers.file import File
+from minifi_test_framework.core.minifi_test_context import MinifiTestContext
+
+
+class KafkaServer(Container):
+ def __init__(self, test_context: MinifiTestContext):
+ super().__init__("apache/kafka:4.1.0", f"kafka-server-{test_context.scenario_id}", test_context.network)
+ self.environment.append("KAFKA_NODE_ID=1")
+ self.environment.append("KAFKA_PROCESS_ROLES=controller,broker")
+ self.environment.append("KAFKA_INTER_BROKER_LISTENER_NAME=PLAINTEXT")
+ self.environment.append("KAFKA_CONTROLLER_LISTENER_NAMES=CONTROLLER")
+ self.environment.append("KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR=1")
+ self.environment.append("KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR=1")
+ self.environment.append("KAFKA_TRANSACTION_STATE_LOG_MIN_ISR=1")
+ self.environment.append(f"KAFKA_CONTROLLER_QUORUM_VOTERS=1@kafka-server-{test_context.scenario_id}:9096")
+ self.environment.append(f"KAFKA_LISTENERS=PLAINTEXT://kafka-server-{test_context.scenario_id}:9092,SASL_PLAINTEXT://kafka-server-{test_context.scenario_id}:9094,SSL://kafka-server-{test_context.scenario_id}:9093,SASL_SSL://kafka-server-{test_context.scenario_id}:9095,CONTROLLER://kafka-server-{test_context.scenario_id}:9096")
+ self.environment.append(f"KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://kafka-server-{test_context.scenario_id}:9092,SASL_PLAINTEXT://kafka-server-{test_context.scenario_id}:9094,SSL://kafka-server-{test_context.scenario_id}:9093,SASL_SSL://kafka-server-{test_context.scenario_id}:9095,CONTROLLER://kafka-server-{test_context.scenario_id}:9096")
+ self.environment.append("KAFKA_LISTENER_SECURITY_PROTOCOL_MAP=PLAINTEXT:PLAINTEXT,SASL_PLAINTEXT:SASL_PLAINTEXT,SSL:SSL,SASL_SSL:SASL_SSL,CONTROLLER:PLAINTEXT")
+ self.environment.append("KAFKA_SASL_MECHANISM_INTER_BROKER_PROTOCOL=PLAIN")
+ self.environment.append("KAFKA_SASL_ENABLED_MECHANISMS=PLAIN")
+ self.environment.append("KAFKA_OPTS=-Djava.security.auth.login.config=/opt/kafka/config/kafka_jaas.conf -Dlog4j2.rootLogger.level=DEBUG -Dlog4j2.logger.org.apache.kafka.controller.level=DEBUG")
+ self.environment.append("KAFKA_SSL_PROTOCOL=TLS")
+ self.environment.append("KAFKA_SSL_ENABLED_PROTOCOLS=TLSv1.2")
+ self.environment.append("KAFKA_SSL_KEYSTORE_TYPE=JKS")
+ self.environment.append("KAFKA_SSL_KEYSTORE_FILENAME=kafka.keystore.jks")
+ self.environment.append("KAFKA_SSL_KEYSTORE_CREDENTIALS=credentials.conf")
+ self.environment.append("KAFKA_SSL_KEY_CREDENTIALS=credentials.conf")
+ self.environment.append("KAFKA_SSL_TRUSTSTORE_CREDENTIALS=credentials.conf")
+ self.environment.append("KAFKA_SSL_TRUSTSTORE_TYPE=JKS")
+ self.environment.append("KAFKA_SSL_TRUSTSTORE_FILENAME=kafka.truststore.jks")
+ self.environment.append("KAFKA_SSL_CLIENT_AUTH=none")
+
+ kafka_cert, kafka_key = make_server_cert(self.container_name, test_context.root_ca_cert, test_context.root_ca_key)
+
+ pke = jks.PrivateKeyEntry.new('kafka-broker-cert', [crypto.dump_certificate(crypto.FILETYPE_ASN1, kafka_cert)], crypto.dump_privatekey(crypto.FILETYPE_ASN1, kafka_key), 'rsa_raw')
+ server_keystore = jks.KeyStore.new('jks', [pke])
+ server_keystore_content = server_keystore.saves('abcdefgh')
+ self.files.append(File("/etc/kafka/secrets/kafka.keystore.jks", server_keystore_content, permissions=0o644))
+ self.files.append(File("/etc/kafka/secrets/credentials.conf", b'abcdefgh', permissions=0o644))
+
+ trusted_cert = jks.TrustedCertEntry.new(
+ 'root-ca', # Alias for the certificate
+ crypto.dump_certificate(crypto.FILETYPE_ASN1, test_context.root_ca_cert)
+ )
+
+ # Create a JKS keystore that will serve as a truststore with the trusted cert entry.
+ truststore = jks.KeyStore.new('jks', [trusted_cert])
+ truststore_content = truststore.saves('abcdefgh')
+ self.files.append(File("/etc/kafka/secrets/kafka.truststore.jks", truststore_content, permissions=0o644))
+
+ jaas_config_file_content = """
+KafkaServer {
+ org.apache.kafka.common.security.plain.PlainLoginModule required
+ username="admin"
+ password="admin-secret"
+ user_admin="admin-secret"
+ user_alice="alice-secret";
+};
+
+Client {
+ org.apache.kafka.common.security.plain.PlainLoginModule required
+ username="admin"
+ password="admin-secret";
+};
+"""
+ self.files.append(File("/opt/kafka/config/kafka_jaas.conf", jaas_config_file_content, permissions=0o644))
+
+ def deploy(self):
+ super().deploy()
+ finished_str = "Kafka Server started"
+ return wait_for_condition(
+ condition=lambda: finished_str in self.get_logs(),
+ timeout_seconds=15,
Review Comment:
[nitpick] The timeout for Kafka server startup is set to 15 seconds on line 96, which may be insufficient for slower test environments or CI/CD systems. Kafka can take longer to start, especially with SSL configuration. Consider increasing this timeout to at least 30-60 seconds to avoid flaky test failures.
```suggestion
timeout_seconds=60,
```
##########
behave_framework/src/minifi_test_framework/containers/container.py:
##########
@@ -254,6 +285,59 @@ def verify_file_contents(self, directory_path: str, expected_contents: list[str]
return sorted(actual_file_contents) == sorted(expected_contents)
+ def _verify_file_contents_in_stopped_container(self, directory_path: str, expected_contents: list[str]) -> bool:
+ if not self.container:
+ return False
+
+ with tempfile.TemporaryDirectory() as temp_dir:
+ extracted_dir = self._extract_directory_from_container(directory_path, temp_dir)
+ if not extracted_dir:
+ return False
+
+ actual_file_contents = self._read_files_from_directory(extracted_dir)
+ if actual_file_contents is None:
+ return False
+
+ return sorted(actual_file_contents) == sorted(expected_contents)
+
+ def _extract_directory_from_container(self, directory_path: str, temp_dir: str) -> str | None:
+ try:
+ bits, _ = self.container.get_archive(directory_path)
+ temp_tar_path = os.path.join(temp_dir, "archive.tar")
+
+ with open(temp_tar_path, 'wb') as f:
+ for chunk in bits:
+ f.write(chunk)
+
+ with tarfile.open(temp_tar_path) as tar:
+ tar.extractall(path=temp_dir)
+
Review Comment:
The method `_verify_file_contents_in_stopped_container` extracts files from a stopped container using tarfile. However, there's a potential security issue: the `tarfile.extractall()` call on line 313 is vulnerable to path traversal attacks if the tar archive contains malicious entries with absolute paths or `..` sequences. Consider using `tarfile.data_filter` (Python 3.12+) or manually validating paths before extraction.
```suggestion
def is_within_directory(directory, target):
abs_directory = os.path.abspath(directory)
abs_target = os.path.abspath(target)
return os.path.commonpath([abs_directory]) == os.path.commonpath([abs_directory, abs_target])
for member in tar.getmembers():
member_path = os.path.join(temp_dir, member.name)
if not is_within_directory(temp_dir, member_path):
logging.error(f"Attempted path traversal in tar file: {member.name}")
continue
tar.extract(member, path=temp_dir)
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] MINIFICPP-2666 Move Kafka tests to modular docker tests [nifi-minifi-cpp]
Posted by "fgerlits (via GitHub)" <gi...@apache.org>.
fgerlits commented on code in PR #2059:
URL: https://github.com/apache/nifi-minifi-cpp/pull/2059#discussion_r2580675409
##########
behave_framework/src/minifi_test_framework/containers/container.py:
##########
@@ -254,6 +285,59 @@ def verify_file_contents(self, directory_path: str, expected_contents: list[str]
return sorted(actual_file_contents) == sorted(expected_contents)
+ def _verify_file_contents_in_stopped_container(self, directory_path: str, expected_contents: list[str]) -> bool:
+ if not self.container:
+ return False
+
+ with tempfile.TemporaryDirectory() as temp_dir:
+ extracted_dir = self._extract_directory_from_container(directory_path, temp_dir)
+ if not extracted_dir:
+ return False
+
+ actual_file_contents = self._read_files_from_directory(extracted_dir)
+ if actual_file_contents is None:
+ return False
+
+ return sorted(actual_file_contents) == sorted(expected_contents)
+
+ def _extract_directory_from_container(self, directory_path: str, temp_dir: str) -> str | None:
+ try:
+ bits, _ = self.container.get_archive(directory_path)
+ temp_tar_path = os.path.join(temp_dir, "archive.tar")
+
+ with open(temp_tar_path, 'wb') as f:
+ for chunk in bits:
+ f.write(chunk)
+
+ with tarfile.open(temp_tar_path) as tar:
+ tar.extractall(path=temp_dir)
+
+ return os.path.join(temp_dir, os.path.basename(directory_path.strip('/')))
+ except Exception as e:
+ logging.error(f"Error extracting files from container: {e}")
Review Comment:
Does `e` contain the container's name and `directory_path`? If it doesn't, then I would add these two to the error message.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] MINIFICPP-2666 Move Kafka tests to modular docker tests [nifi-minifi-cpp]
Posted by "szaszm (via GitHub)" <gi...@apache.org>.
szaszm commented on code in PR #2059:
URL: https://github.com/apache/nifi-minifi-cpp/pull/2059#discussion_r2583043494
##########
behave_framework/src/minifi_test_framework/containers/container.py:
##########
@@ -254,6 +285,59 @@ def verify_file_contents(self, directory_path: str, expected_contents: list[str]
return sorted(actual_file_contents) == sorted(expected_contents)
+ def _verify_file_contents_in_stopped_container(self, directory_path: str, expected_contents: list[str]) -> bool:
+ if not self.container:
+ return False
+
+ with tempfile.TemporaryDirectory() as temp_dir:
+ extracted_dir = self._extract_directory_from_container(directory_path, temp_dir)
+ if not extracted_dir:
+ return False
+
+ actual_file_contents = self._read_files_from_directory(extracted_dir)
+ if actual_file_contents is None:
+ return False
+
+ return sorted(actual_file_contents) == sorted(expected_contents)
+
+ def _extract_directory_from_container(self, directory_path: str, temp_dir: str) -> str | None:
+ try:
+ bits, _ = self.container.get_archive(directory_path)
+ temp_tar_path = os.path.join(temp_dir, "archive.tar")
+
+ with open(temp_tar_path, 'wb') as f:
+ for chunk in bits:
+ f.write(chunk)
+
+ with tarfile.open(temp_tar_path) as tar:
+ tar.extractall(path=temp_dir)
+
+ return os.path.join(temp_dir, os.path.basename(directory_path.strip('/')))
+ except Exception as e:
+ logging.error(f"Error extracting files from container: {e}")
+ return None
+
+ def _read_files_from_directory(self, directory_path: str) -> list[str] | None:
+ try:
+ file_contents = []
+ for entry in os.scandir(directory_path):
+ if entry.is_file():
+ with open(entry.path, 'r') as f:
+ file_contents.append(f.read())
+ return file_contents
+ except Exception as e:
+ logging.error(f"Error reading extracted files: {e}")
+ return None
+
+ def verify_file_contents(self, directory_path: str, expected_contents: list[str]) -> bool:
+ if not self.container:
+ return False
+
+ if self.container.status == "running":
+ return self._verify_file_contents_in_running_container(directory_path, expected_contents)
+
+ return self._verify_file_contents_in_stopped_container(directory_path, expected_contents)
Review Comment:
what if the container stops after the check, before/during scanning the directory?
##########
extensions/kafka/tests/features/steps/kafka_server_container.py:
##########
@@ -0,0 +1,126 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import logging
+import re
+import jks
+
+from OpenSSL import crypto
+from minifi_test_framework.core.helpers import wait_for_condition
+from minifi_test_framework.core.ssl_utils import make_server_cert
+from minifi_test_framework.containers.container import Container
+from minifi_test_framework.containers.file import File
+from minifi_test_framework.core.minifi_test_context import MinifiTestContext
+
+
+class KafkaServer(Container):
+ def __init__(self, test_context: MinifiTestContext):
+ super().__init__("apache/kafka:4.1.0", f"kafka-server-{test_context.scenario_id}", test_context.network)
+ self.environment.append("KAFKA_NODE_ID=1")
+ self.environment.append("KAFKA_PROCESS_ROLES=controller,broker")
+ self.environment.append("KAFKA_INTER_BROKER_LISTENER_NAME=PLAINTEXT")
+ self.environment.append("KAFKA_CONTROLLER_LISTENER_NAMES=CONTROLLER")
+ self.environment.append("KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR=1")
+ self.environment.append("KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR=1")
+ self.environment.append("KAFKA_TRANSACTION_STATE_LOG_MIN_ISR=1")
+ self.environment.append(f"KAFKA_CONTROLLER_QUORUM_VOTERS=1@kafka-server-{test_context.scenario_id}:9096")
+ self.environment.append(f"KAFKA_LISTENERS=PLAINTEXT://kafka-server-{test_context.scenario_id}:9092,SASL_PLAINTEXT://kafka-server-{test_context.scenario_id}:9094,SSL://kafka-server-{test_context.scenario_id}:9093,SASL_SSL://kafka-server-{test_context.scenario_id}:9095,CONTROLLER://kafka-server-{test_context.scenario_id}:9096")
+ self.environment.append(f"KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://kafka-server-{test_context.scenario_id}:9092,SASL_PLAINTEXT://kafka-server-{test_context.scenario_id}:9094,SSL://kafka-server-{test_context.scenario_id}:9093,SASL_SSL://kafka-server-{test_context.scenario_id}:9095,CONTROLLER://kafka-server-{test_context.scenario_id}:9096")
+ self.environment.append("KAFKA_LISTENER_SECURITY_PROTOCOL_MAP=PLAINTEXT:PLAINTEXT,SASL_PLAINTEXT:SASL_PLAINTEXT,SSL:SSL,SASL_SSL:SASL_SSL,CONTROLLER:PLAINTEXT")
+ self.environment.append("KAFKA_SASL_MECHANISM_INTER_BROKER_PROTOCOL=PLAIN")
+ self.environment.append("KAFKA_SASL_ENABLED_MECHANISMS=PLAIN")
+ self.environment.append("KAFKA_OPTS=-Djava.security.auth.login.config=/opt/kafka/config/kafka_jaas.conf -Dlog4j2.rootLogger.level=DEBUG -Dlog4j2.logger.org.apache.kafka.controller.level=DEBUG")
+ self.environment.append("KAFKA_SSL_PROTOCOL=TLS")
+ self.environment.append("KAFKA_SSL_ENABLED_PROTOCOLS=TLSv1.2")
+ self.environment.append("KAFKA_SSL_KEYSTORE_TYPE=JKS")
+ self.environment.append("KAFKA_SSL_KEYSTORE_FILENAME=kafka.keystore.jks")
+ self.environment.append("KAFKA_SSL_KEYSTORE_CREDENTIALS=credentials.conf")
+ self.environment.append("KAFKA_SSL_KEY_CREDENTIALS=credentials.conf")
+ self.environment.append("KAFKA_SSL_TRUSTSTORE_CREDENTIALS=credentials.conf")
+ self.environment.append("KAFKA_SSL_TRUSTSTORE_TYPE=JKS")
+ self.environment.append("KAFKA_SSL_TRUSTSTORE_FILENAME=kafka.truststore.jks")
+ self.environment.append("KAFKA_SSL_CLIENT_AUTH=none")
+
+ kafka_cert, kafka_key = make_server_cert(self.container_name, test_context.root_ca_cert, test_context.root_ca_key)
+
+ pke = jks.PrivateKeyEntry.new('kafka-broker-cert', [crypto.dump_certificate(crypto.FILETYPE_ASN1, kafka_cert)], crypto.dump_privatekey(crypto.FILETYPE_ASN1, kafka_key), 'rsa_raw')
+ server_keystore = jks.KeyStore.new('jks', [pke])
+ server_keystore_content = server_keystore.saves('abcdefgh')
+ self.files.append(File("/etc/kafka/secrets/kafka.keystore.jks", server_keystore_content, permissions=0o644))
+ self.files.append(File("/etc/kafka/secrets/credentials.conf", b'abcdefgh', permissions=0o644))
+
+ trusted_cert = jks.TrustedCertEntry.new(
+ 'root-ca', # Alias for the certificate
+ crypto.dump_certificate(crypto.FILETYPE_ASN1, test_context.root_ca_cert)
+ )
+
+ # Create a JKS keystore that will serve as a truststore with the trusted cert entry.
+ truststore = jks.KeyStore.new('jks', [trusted_cert])
+ truststore_content = truststore.saves('abcdefgh')
+ self.files.append(File("/etc/kafka/secrets/kafka.truststore.jks", truststore_content, permissions=0o644))
+
+ jaas_config_file_content = """
+KafkaServer {
+ org.apache.kafka.common.security.plain.PlainLoginModule required
+ username="admin"
+ password="admin-secret"
+ user_admin="admin-secret"
+ user_alice="alice-secret";
+};
+
+Client {
+ org.apache.kafka.common.security.plain.PlainLoginModule required
+ username="admin"
+ password="admin-secret";
+};
+"""
+ self.files.append(File("/opt/kafka/config/kafka_jaas.conf", jaas_config_file_content, permissions=0o644))
+
+ def deploy(self):
+ super().deploy()
+ finished_str = "Kafka Server started"
+ return wait_for_condition(
+ condition=lambda: finished_str in self.get_logs(),
+ timeout_seconds=60,
+ bail_condition=lambda: self.exited,
+ context=None)
+
+ def create_topic(self, topic_name: str):
+ (code, output) = self.exec_run(["/bin/bash", "-c", f"/opt/kafka/bin/kafka-topics.sh --create --topic {topic_name} --bootstrap-server {self.container_name}:9092"])
+ logging.info("Create topic output: %s", output)
+ return code == 0
+
+ def produce_message(self, topic_name: str, message: str):
+ (code, output) = self.exec_run(["/bin/bash", "-c", f"/opt/kafka/bin/kafka-console-producer.sh --topic {topic_name} --bootstrap-server {self.container_name}:9092 <<< '{message}'"])
Review Comment:
optional: I'd avoid bashisms and use a standard pipe.
```suggestion
(code, output) = self.exec_run(["/bin/sh", "-c", f"echo '{message}' | /opt/kafka/bin/kafka-console-producer.sh --topic '{topic_name}' --bootstrap-server '{self.container_name}':9092"])
```
This will also likely fail on Windows, with @martinzink 's changes to run the tests on windows containers.
##########
extensions/kafka/tests/features/steps/kafka_server_container.py:
##########
@@ -0,0 +1,126 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import logging
+import re
+import jks
+
+from OpenSSL import crypto
+from minifi_test_framework.core.helpers import wait_for_condition
+from minifi_test_framework.core.ssl_utils import make_server_cert
+from minifi_test_framework.containers.container import Container
+from minifi_test_framework.containers.file import File
+from minifi_test_framework.core.minifi_test_context import MinifiTestContext
+
+
+class KafkaServer(Container):
+ def __init__(self, test_context: MinifiTestContext):
+ super().__init__("apache/kafka:4.1.0", f"kafka-server-{test_context.scenario_id}", test_context.network)
+ self.environment.append("KAFKA_NODE_ID=1")
+ self.environment.append("KAFKA_PROCESS_ROLES=controller,broker")
+ self.environment.append("KAFKA_INTER_BROKER_LISTENER_NAME=PLAINTEXT")
+ self.environment.append("KAFKA_CONTROLLER_LISTENER_NAMES=CONTROLLER")
+ self.environment.append("KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR=1")
+ self.environment.append("KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR=1")
+ self.environment.append("KAFKA_TRANSACTION_STATE_LOG_MIN_ISR=1")
+ self.environment.append(f"KAFKA_CONTROLLER_QUORUM_VOTERS=1@kafka-server-{test_context.scenario_id}:9096")
+ self.environment.append(f"KAFKA_LISTENERS=PLAINTEXT://kafka-server-{test_context.scenario_id}:9092,SASL_PLAINTEXT://kafka-server-{test_context.scenario_id}:9094,SSL://kafka-server-{test_context.scenario_id}:9093,SASL_SSL://kafka-server-{test_context.scenario_id}:9095,CONTROLLER://kafka-server-{test_context.scenario_id}:9096")
+ self.environment.append(f"KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://kafka-server-{test_context.scenario_id}:9092,SASL_PLAINTEXT://kafka-server-{test_context.scenario_id}:9094,SSL://kafka-server-{test_context.scenario_id}:9093,SASL_SSL://kafka-server-{test_context.scenario_id}:9095,CONTROLLER://kafka-server-{test_context.scenario_id}:9096")
+ self.environment.append("KAFKA_LISTENER_SECURITY_PROTOCOL_MAP=PLAINTEXT:PLAINTEXT,SASL_PLAINTEXT:SASL_PLAINTEXT,SSL:SSL,SASL_SSL:SASL_SSL,CONTROLLER:PLAINTEXT")
+ self.environment.append("KAFKA_SASL_MECHANISM_INTER_BROKER_PROTOCOL=PLAIN")
+ self.environment.append("KAFKA_SASL_ENABLED_MECHANISMS=PLAIN")
+ self.environment.append("KAFKA_OPTS=-Djava.security.auth.login.config=/opt/kafka/config/kafka_jaas.conf -Dlog4j2.rootLogger.level=DEBUG -Dlog4j2.logger.org.apache.kafka.controller.level=DEBUG")
+ self.environment.append("KAFKA_SSL_PROTOCOL=TLS")
+ self.environment.append("KAFKA_SSL_ENABLED_PROTOCOLS=TLSv1.2")
+ self.environment.append("KAFKA_SSL_KEYSTORE_TYPE=JKS")
+ self.environment.append("KAFKA_SSL_KEYSTORE_FILENAME=kafka.keystore.jks")
+ self.environment.append("KAFKA_SSL_KEYSTORE_CREDENTIALS=credentials.conf")
+ self.environment.append("KAFKA_SSL_KEY_CREDENTIALS=credentials.conf")
+ self.environment.append("KAFKA_SSL_TRUSTSTORE_CREDENTIALS=credentials.conf")
+ self.environment.append("KAFKA_SSL_TRUSTSTORE_TYPE=JKS")
+ self.environment.append("KAFKA_SSL_TRUSTSTORE_FILENAME=kafka.truststore.jks")
+ self.environment.append("KAFKA_SSL_CLIENT_AUTH=none")
+
+ kafka_cert, kafka_key = make_server_cert(self.container_name, test_context.root_ca_cert, test_context.root_ca_key)
+
+ pke = jks.PrivateKeyEntry.new('kafka-broker-cert', [crypto.dump_certificate(crypto.FILETYPE_ASN1, kafka_cert)], crypto.dump_privatekey(crypto.FILETYPE_ASN1, kafka_key), 'rsa_raw')
+ server_keystore = jks.KeyStore.new('jks', [pke])
+ server_keystore_content = server_keystore.saves('abcdefgh')
+ self.files.append(File("/etc/kafka/secrets/kafka.keystore.jks", server_keystore_content, permissions=0o644))
+ self.files.append(File("/etc/kafka/secrets/credentials.conf", b'abcdefgh', permissions=0o644))
+
+ trusted_cert = jks.TrustedCertEntry.new(
+ 'root-ca', # Alias for the certificate
+ crypto.dump_certificate(crypto.FILETYPE_ASN1, test_context.root_ca_cert)
+ )
+
+ # Create a JKS keystore that will serve as a truststore with the trusted cert entry.
+ truststore = jks.KeyStore.new('jks', [trusted_cert])
+ truststore_content = truststore.saves('abcdefgh')
+ self.files.append(File("/etc/kafka/secrets/kafka.truststore.jks", truststore_content, permissions=0o644))
+
+ jaas_config_file_content = """
+KafkaServer {
+ org.apache.kafka.common.security.plain.PlainLoginModule required
+ username="admin"
+ password="admin-secret"
+ user_admin="admin-secret"
+ user_alice="alice-secret";
+};
+
+Client {
+ org.apache.kafka.common.security.plain.PlainLoginModule required
+ username="admin"
+ password="admin-secret";
+};
+"""
+ self.files.append(File("/opt/kafka/config/kafka_jaas.conf", jaas_config_file_content, permissions=0o644))
+
+ def deploy(self):
+ super().deploy()
+ finished_str = "Kafka Server started"
+ return wait_for_condition(
+ condition=lambda: finished_str in self.get_logs(),
+ timeout_seconds=60,
+ bail_condition=lambda: self.exited,
+ context=None)
+
+ def create_topic(self, topic_name: str):
+ (code, output) = self.exec_run(["/bin/bash", "-c", f"/opt/kafka/bin/kafka-topics.sh --create --topic {topic_name} --bootstrap-server {self.container_name}:9092"])
+ logging.info("Create topic output: %s", output)
+ return code == 0
+
+ def produce_message(self, topic_name: str, message: str):
+ (code, output) = self.exec_run(["/bin/bash", "-c", f"/opt/kafka/bin/kafka-console-producer.sh --topic {topic_name} --bootstrap-server {self.container_name}:9092 <<< '{message}'"])
+ logging.info("Produce message output: %s", output)
+ return code == 0
+
+ def produce_message_with_key(self, topic_name: str, message: str, message_key: str):
+ (code, output) = self.exec_run(["/bin/bash", "-c", f"/opt/kafka/bin/kafka-console-producer.sh --property 'key.separator=:' --property 'parse.key=true' --topic {topic_name} --bootstrap-server {self.container_name}:9092 <<< '{message_key}:{message}'"])
Review Comment:
```suggestion
(code, output) = self.exec_run(["/bin/sh", "-c", f" echo ''{message_key}:{message}'' | /opt/kafka/bin/kafka-console-producer.sh --property 'key.separator=:' --property 'parse.key=true' --topic '{topic_name}' --bootstrap-server '{self.container_name}':9092"])
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] MINIFICPP-2666 Move Kafka tests to modular docker tests [nifi-minifi-cpp]
Posted by "lordgamez (via GitHub)" <gi...@apache.org>.
lordgamez commented on code in PR #2059:
URL: https://github.com/apache/nifi-minifi-cpp/pull/2059#discussion_r2660973972
##########
behave_framework/src/minifi_test_framework/containers/container.py:
##########
@@ -254,6 +285,59 @@ def verify_file_contents(self, directory_path: str, expected_contents: list[str]
return sorted(actual_file_contents) == sorted(expected_contents)
+ def _verify_file_contents_in_stopped_container(self, directory_path: str, expected_contents: list[str]) -> bool:
+ if not self.container:
+ return False
+
+ with tempfile.TemporaryDirectory() as temp_dir:
+ extracted_dir = self._extract_directory_from_container(directory_path, temp_dir)
+ if not extracted_dir:
+ return False
+
+ actual_file_contents = self._read_files_from_directory(extracted_dir)
+ if actual_file_contents is None:
+ return False
+
+ return sorted(actual_file_contents) == sorted(expected_contents)
+
+ def _extract_directory_from_container(self, directory_path: str, temp_dir: str) -> str | None:
+ try:
+ bits, _ = self.container.get_archive(directory_path)
+ temp_tar_path = os.path.join(temp_dir, "archive.tar")
+
+ with open(temp_tar_path, 'wb') as f:
+ for chunk in bits:
+ f.write(chunk)
+
+ with tarfile.open(temp_tar_path) as tar:
+ tar.extractall(path=temp_dir)
+
+ return os.path.join(temp_dir, os.path.basename(directory_path.strip('/')))
+ except Exception as e:
+ logging.error(f"Error extracting files from container: {e}")
+ return None
+
+ def _read_files_from_directory(self, directory_path: str) -> list[str] | None:
+ try:
+ file_contents = []
+ for entry in os.scandir(directory_path):
+ if entry.is_file():
+ with open(entry.path, 'r') as f:
+ file_contents.append(f.read())
+ return file_contents
+ except Exception as e:
+ logging.error(f"Error reading extracted files: {e}")
+ return None
+
+ def verify_file_contents(self, directory_path: str, expected_contents: list[str]) -> bool:
+ if not self.container:
+ return False
+
+ if self.container.status == "running":
+ return self._verify_file_contents_in_running_container(directory_path, expected_contents)
+
+ return self._verify_file_contents_in_stopped_container(directory_path, expected_contents)
Review Comment:
The directory scan will fail in that case as it cannot connect the non-running container. That should be okay, because we only expect the container to be stopped if we stopped it explicitly and that should had happened beforehand.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] MINIFICPP-2666 Move Kafka tests to modular docker tests [nifi-minifi-cpp]
Posted by "lordgamez (via GitHub)" <gi...@apache.org>.
lordgamez commented on code in PR #2059:
URL: https://github.com/apache/nifi-minifi-cpp/pull/2059#discussion_r2533891753
##########
behave_framework/src/minifi_test_framework/containers/minifi_container.py:
##########
@@ -15,34 +15,44 @@
# limitations under the License.
#
-from docker.models.networks import Network
+import logging
+from OpenSSL import crypto
+from minifi_test_framework.core.minifi_test_context import MinifiTestContext
from minifi_test_framework.containers.file import File
from minifi_test_framework.minifi.flow_definition import FlowDefinition
+from minifi_test_framework.core.ssl_utils import make_cert_without_extended_usage
from .container import Container
class MinifiContainer(Container):
- def __init__(self, image_name: str, container_name: str, scenario_id: str, network: Network):
- super().__init__(image_name, f"{container_name}-{scenario_id}", network)
+ def __init__(self, container_name: str, test_context: MinifiTestContext):
+ super().__init__(test_context.minifi_container_image, f"{container_name}-{test_context.scenario_id}", test_context.network)
self.flow_config_str: str = ""
self.flow_definition = FlowDefinition()
self.properties: dict[str, str] = {}
self.log_properties: dict[str, str] = {}
- self.is_fhs = 'MINIFI_INSTALLATION_TYPE=FHS' in str(self.client.images.get(image_name).history())
+ minifi_client_cert, minifi_client_key = make_cert_without_extended_usage(common_name=self.container_name, ca_cert=test_context.root_ca_cert, ca_key=test_context.root_ca_key)
+ self.files.append(File("/tmp/resources/root_ca.crt", crypto.dump_certificate(type=crypto.FILETYPE_PEM, cert=test_context.root_ca_cert)))
+ self.files.append(File("/tmp/resources/minifi_client.crt", crypto.dump_certificate(type=crypto.FILETYPE_PEM, cert=minifi_client_cert)))
+ self.files.append(File("/tmp/resources/minifi_client.key", crypto.dump_privatekey(type=crypto.FILETYPE_PEM, pkey=minifi_client_key)))
Review Comment:
We don't need to specify it at all times, we can have the default permissions if not specified.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] MINIFICPP-2666 Move Kafka tests to modular docker tests [nifi-minifi-cpp]
Posted by "lordgamez (via GitHub)" <gi...@apache.org>.
lordgamez commented on code in PR #2059:
URL: https://github.com/apache/nifi-minifi-cpp/pull/2059#discussion_r2533894007
##########
behave_framework/src/minifi_test_framework/steps/flow_building_steps.py:
##########
@@ -77,7 +78,10 @@ def step_impl(context: MinifiTestContext, processor_type: str):
@step('the "{property_name}" property of the {processor_name} processor is set to "{property_value}"')
def step_impl(context: MinifiTestContext, property_name: str, processor_name: str, property_value: str):
processor = context.get_or_create_default_minifi_container().flow_definition.get_processor(processor_name)
- processor.add_property(property_name, property_value)
+ if property_value == "(not set)":
+ processor.remove_property(property_name)
+ else:
+ processor.add_property(property_name, property_value)
Review Comment:
This is the legacy handling, we do not want to change this at this time.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] MINIFICPP-2666 Move Kafka tests to modular docker tests [nifi-minifi-cpp]
Posted by "szaszm (via GitHub)" <gi...@apache.org>.
szaszm commented on code in PR #2059:
URL: https://github.com/apache/nifi-minifi-cpp/pull/2059#discussion_r2661729999
##########
extensions/kafka/tests/features/steps/kafka_server_container.py:
##########
@@ -0,0 +1,126 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import logging
+import re
+import jks
+
+from OpenSSL import crypto
+from minifi_test_framework.core.helpers import wait_for_condition
+from minifi_test_framework.core.ssl_utils import make_server_cert
+from minifi_test_framework.containers.container import Container
+from minifi_test_framework.containers.file import File
+from minifi_test_framework.core.minifi_test_context import MinifiTestContext
+
+
+class KafkaServer(Container):
+ def __init__(self, test_context: MinifiTestContext):
+ super().__init__("apache/kafka:4.1.0", f"kafka-server-{test_context.scenario_id}", test_context.network)
+ self.environment.append("KAFKA_NODE_ID=1")
+ self.environment.append("KAFKA_PROCESS_ROLES=controller,broker")
+ self.environment.append("KAFKA_INTER_BROKER_LISTENER_NAME=PLAINTEXT")
+ self.environment.append("KAFKA_CONTROLLER_LISTENER_NAMES=CONTROLLER")
+ self.environment.append("KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR=1")
+ self.environment.append("KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR=1")
+ self.environment.append("KAFKA_TRANSACTION_STATE_LOG_MIN_ISR=1")
+ self.environment.append(f"KAFKA_CONTROLLER_QUORUM_VOTERS=1@kafka-server-{test_context.scenario_id}:9096")
+ self.environment.append(f"KAFKA_LISTENERS=PLAINTEXT://kafka-server-{test_context.scenario_id}:9092,SASL_PLAINTEXT://kafka-server-{test_context.scenario_id}:9094,SSL://kafka-server-{test_context.scenario_id}:9093,SASL_SSL://kafka-server-{test_context.scenario_id}:9095,CONTROLLER://kafka-server-{test_context.scenario_id}:9096")
+ self.environment.append(f"KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://kafka-server-{test_context.scenario_id}:9092,SASL_PLAINTEXT://kafka-server-{test_context.scenario_id}:9094,SSL://kafka-server-{test_context.scenario_id}:9093,SASL_SSL://kafka-server-{test_context.scenario_id}:9095,CONTROLLER://kafka-server-{test_context.scenario_id}:9096")
+ self.environment.append("KAFKA_LISTENER_SECURITY_PROTOCOL_MAP=PLAINTEXT:PLAINTEXT,SASL_PLAINTEXT:SASL_PLAINTEXT,SSL:SSL,SASL_SSL:SASL_SSL,CONTROLLER:PLAINTEXT")
+ self.environment.append("KAFKA_SASL_MECHANISM_INTER_BROKER_PROTOCOL=PLAIN")
+ self.environment.append("KAFKA_SASL_ENABLED_MECHANISMS=PLAIN")
+ self.environment.append("KAFKA_OPTS=-Djava.security.auth.login.config=/opt/kafka/config/kafka_jaas.conf -Dlog4j2.rootLogger.level=DEBUG -Dlog4j2.logger.org.apache.kafka.controller.level=DEBUG")
+ self.environment.append("KAFKA_SSL_PROTOCOL=TLS")
+ self.environment.append("KAFKA_SSL_ENABLED_PROTOCOLS=TLSv1.2")
+ self.environment.append("KAFKA_SSL_KEYSTORE_TYPE=JKS")
+ self.environment.append("KAFKA_SSL_KEYSTORE_FILENAME=kafka.keystore.jks")
+ self.environment.append("KAFKA_SSL_KEYSTORE_CREDENTIALS=credentials.conf")
+ self.environment.append("KAFKA_SSL_KEY_CREDENTIALS=credentials.conf")
+ self.environment.append("KAFKA_SSL_TRUSTSTORE_CREDENTIALS=credentials.conf")
+ self.environment.append("KAFKA_SSL_TRUSTSTORE_TYPE=JKS")
+ self.environment.append("KAFKA_SSL_TRUSTSTORE_FILENAME=kafka.truststore.jks")
+ self.environment.append("KAFKA_SSL_CLIENT_AUTH=none")
+
+ kafka_cert, kafka_key = make_server_cert(self.container_name, test_context.root_ca_cert, test_context.root_ca_key)
+
+ pke = jks.PrivateKeyEntry.new('kafka-broker-cert', [crypto.dump_certificate(crypto.FILETYPE_ASN1, kafka_cert)], crypto.dump_privatekey(crypto.FILETYPE_ASN1, kafka_key), 'rsa_raw')
+ server_keystore = jks.KeyStore.new('jks', [pke])
+ server_keystore_content = server_keystore.saves('abcdefgh')
+ self.files.append(File("/etc/kafka/secrets/kafka.keystore.jks", server_keystore_content, permissions=0o644))
+ self.files.append(File("/etc/kafka/secrets/credentials.conf", b'abcdefgh', permissions=0o644))
+
+ trusted_cert = jks.TrustedCertEntry.new(
+ 'root-ca', # Alias for the certificate
+ crypto.dump_certificate(crypto.FILETYPE_ASN1, test_context.root_ca_cert)
+ )
+
+ # Create a JKS keystore that will serve as a truststore with the trusted cert entry.
+ truststore = jks.KeyStore.new('jks', [trusted_cert])
+ truststore_content = truststore.saves('abcdefgh')
+ self.files.append(File("/etc/kafka/secrets/kafka.truststore.jks", truststore_content, permissions=0o644))
+
+ jaas_config_file_content = """
+KafkaServer {
+ org.apache.kafka.common.security.plain.PlainLoginModule required
+ username="admin"
+ password="admin-secret"
+ user_admin="admin-secret"
+ user_alice="alice-secret";
+};
+
+Client {
+ org.apache.kafka.common.security.plain.PlainLoginModule required
+ username="admin"
+ password="admin-secret";
+};
+"""
+ self.files.append(File("/opt/kafka/config/kafka_jaas.conf", jaas_config_file_content, permissions=0o644))
+
+ def deploy(self):
+ super().deploy()
+ finished_str = "Kafka Server started"
+ return wait_for_condition(
+ condition=lambda: finished_str in self.get_logs(),
+ timeout_seconds=60,
+ bail_condition=lambda: self.exited,
+ context=None)
+
+ def create_topic(self, topic_name: str):
+ (code, output) = self.exec_run(["/bin/sh", "-c", f"/opt/kafka/bin/kafka-topics.sh --create --topic '{topic_name}' --bootstrap-server '{self.container_name}':9092"])
+ logging.info(f"Create topic output: '{output}' with code {code}")
+ return code == 0
+
+ def produce_message(self, topic_name: str, message: str):
+ (code, output) = self.exec_run(["/bin/sh", "-c", f"echo '{message}' | /opt/kafka/bin/kafka-console-producer.sh --topic '{topic_name}' --bootstrap-server '{self.container_name}':9092"])
+ logging.info(f"Produce message output: '{output}' with code {code}")
+ return code == 0
+
+ def produce_message_with_key(self, topic_name: str, message: str, message_key: str):
+ (code, output) = self.exec_run(["/bin/sh", "-c", f" echo ''{message_key}:{message}'' | /opt/kafka/bin/kafka-console-producer.sh --property 'key.separator=:' --property 'parse.key=true' --topic '{topic_name}' --bootstrap-server '{self.container_name}':9092"])
Review Comment:
are the double single quotes intentional? I don't recognize it as a kind of escaping, but I don't know python syntax that well.
edit: it comes from my suggestion, my bad, I don't think it was intentional
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] MINIFICPP-2666 Move Kafka tests to modular docker tests [nifi-minifi-cpp]
Posted by "fgerlits (via GitHub)" <gi...@apache.org>.
fgerlits closed pull request #2059: MINIFICPP-2666 Move Kafka tests to modular docker tests
URL: https://github.com/apache/nifi-minifi-cpp/pull/2059
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] MINIFICPP-2666 Move Kafka tests to modular docker tests [nifi-minifi-cpp]
Posted by "lordgamez (via GitHub)" <gi...@apache.org>.
lordgamez commented on code in PR #2059:
URL: https://github.com/apache/nifi-minifi-cpp/pull/2059#discussion_r2661346735
##########
behave_framework/src/minifi_test_framework/steps/flow_building_steps.py:
##########
@@ -220,3 +224,30 @@ def step_impl(context: MinifiTestContext, service_name: str, property_name: str,
controller_service = ControllerService(class_name=service_name, service_name=service_name)
controller_service.add_property(property_name, property_value)
context.get_or_create_default_minifi_container().flow_definition.controller_services.append(controller_service)
+
+
+@given("the \"{property_name}\" property of the {processor_name} processor is set to match the attribute \"{attribute_key}\" to \"{attribute_value}\"")
+def step_impl(context: MinifiTestContext, property_name: str, processor_name: str, attribute_key: str, attribute_value: str):
+ processor = context.get_or_create_default_minifi_container().flow_definition.get_processor(processor_name)
+ if attribute_value == "(not set)":
Review Comment:
I think the `(not set)` parameter is more explicit when used in parameter tables. The rows in the table list the set parameters for each property, and `(not set)` specifies better that we do not want to set that specific parameter than writing `(ignore)` IMO.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org