Skip to content

Commit ca4fa86

Browse files
lordgamezfgerlits
authored andcommitted
MINIFICPP-2674 Move Couchbase tests to modular docker tests
Closes #2066 Signed-off-by: Ferenc Gerlits <[email protected]>
1 parent 9b84de3 commit ca4fa86

File tree

17 files changed

+363
-368
lines changed

17 files changed

+363
-368
lines changed

behave_framework/src/minifi_test_framework/containers/minifi_container.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from minifi_test_framework.core.minifi_test_context import MinifiTestContext
2222
from minifi_test_framework.containers.file import File
2323
from minifi_test_framework.minifi.flow_definition import FlowDefinition
24-
from minifi_test_framework.core.ssl_utils import make_cert_without_extended_usage
24+
from minifi_test_framework.core.ssl_utils import make_cert_without_extended_usage, make_client_cert
2525
from .container import Container
2626

2727

@@ -38,6 +38,10 @@ def __init__(self, container_name: str, test_context: MinifiTestContext):
3838
self.files.append(File("/tmp/resources/minifi_client.crt", crypto.dump_certificate(type=crypto.FILETYPE_PEM, cert=minifi_client_cert)))
3939
self.files.append(File("/tmp/resources/minifi_client.key", crypto.dump_privatekey(type=crypto.FILETYPE_PEM, pkey=minifi_client_key)))
4040

41+
clientuser_cert, clientuser_key = make_client_cert("clientuser", ca_cert=test_context.root_ca_cert, ca_key=test_context.root_ca_key)
42+
self.files.append(File("/tmp/resources/clientuser.crt", crypto.dump_certificate(type=crypto.FILETYPE_PEM, cert=clientuser_cert)))
43+
self.files.append(File("/tmp/resources/clientuser.key", crypto.dump_privatekey(type=crypto.FILETYPE_PEM, pkey=clientuser_key)))
44+
4145
self.is_fhs = 'MINIFI_INSTALLATION_TYPE=FHS' in str(self.client.images.get(test_context.minifi_container_image).history())
4246

4347
self._fill_default_properties()

behave_framework/src/minifi_test_framework/core/helpers.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import logging
2121
import time
22+
import functools
2223
from collections.abc import Callable
2324

2425
import docker
@@ -82,3 +83,21 @@ def run_cmd_in_docker_image(image_name: str, cmd: str | list, network: str) -> s
8283

8384
def run_shell_cmd_in_docker_image(image_name: str, cmd: str, network: str) -> str:
8485
return run_cmd_in_docker_image(image_name, ["/bin/sh", "-c", cmd], network)
86+
87+
88+
def retry_check(max_tries: int = 5, retry_interval_seconds: int = 1):
89+
"""
90+
Decorator for retrying a checker function that returns a boolean. The decorated function is called repeatedly until it returns True
91+
or the maximum number of attempts is reached. The maximum number of attempts and the interval between attempts in seconds can be configured.
92+
"""
93+
def retry_check_func(func):
94+
@functools.wraps(func)
95+
def retry_wrapper(*args, **kwargs):
96+
for i in range(max_tries):
97+
if func(*args, **kwargs):
98+
return True
99+
if i < max_tries - 1:
100+
time.sleep(retry_interval_seconds)
101+
return False
102+
return retry_wrapper
103+
return retry_check_func

behave_framework/src/minifi_test_framework/steps/flow_building_steps.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@
2929
from minifi_test_framework.minifi.processor import Processor
3030

3131

32+
@given("a MiNiFi CPP server with yaml config")
33+
def step_impl(context: MinifiTestContext):
34+
pass # TODO(lordgamez): Needs to be implemented after JSON config is set to be default
35+
36+
3237
@given("a transient MiNiFi flow with a LogOnDestructionProcessor processor")
3338
def step_impl(context: MinifiTestContext):
3439
context.get_or_create_default_minifi_container().command = ["/bin/sh", "-c", "timeout 10s ./bin/minifi.sh run && sleep 100"]
@@ -140,6 +145,7 @@ def step_impl(context: MinifiTestContext, parameter_name: str, parameter_value:
140145

141146

142147
@step('a directory at "{directory}" has a file with the content "{content}" in the "{flow_name}" flow')
148+
@step("a directory at '{directory}' has a file with the content '{content}' in the '{flow_name}' flow")
143149
def step_impl(context: MinifiTestContext, directory: str, content: str, flow_name: str):
144150
new_content = content.replace("\\n", "\n")
145151
new_dir = Directory(directory)
@@ -148,6 +154,7 @@ def step_impl(context: MinifiTestContext, directory: str, content: str, flow_nam
148154

149155

150156
@step('a directory at "{directory}" has a file with the content "{content}"')
157+
@step("a directory at '{directory}' has a file with the content '{content}'")
151158
def step_impl(context: MinifiTestContext, directory: str, content: str):
152159
context.execute_steps(f'given a directory at "{directory}" has a file with the content "{content}" in the "{DEFAULT_MINIFI_CONTAINER_NAME}" flow')
153160

@@ -240,14 +247,22 @@ def step_impl(context: MinifiTestContext, property_name: str, processor_name: st
240247

241248

242249
# TLS
243-
@given("an ssl context service is set up for {processor_name}")
244-
@given("an ssl context service with a manual CA cert file is set up for {processor_name}")
245-
def step_impl(context, processor_name):
250+
def add_ssl_context_service_for_minifi(context: MinifiTestContext, cert_name: str):
246251
controller_service = ControllerService(class_name="SSLContextService", service_name="SSLContextService")
247-
controller_service.add_property("Client Certificate", "/tmp/resources/minifi_client.crt")
248-
controller_service.add_property("Private Key", "/tmp/resources/minifi_client.key")
252+
controller_service.add_property("Client Certificate", f"/tmp/resources/{cert_name}.crt")
253+
controller_service.add_property("Private Key", f"/tmp/resources/{cert_name}.key")
249254
controller_service.add_property("CA Certificate", "/tmp/resources/root_ca.crt")
250255
context.get_or_create_default_minifi_container().flow_definition.controller_services.append(controller_service)
251256

257+
258+
@given("an ssl context service is set up")
259+
def step_impl(context: MinifiTestContext):
260+
add_ssl_context_service_for_minifi(context, "minifi_client")
261+
262+
263+
@given("an ssl context service is set up for {processor_name}")
264+
@given("an ssl context service with a manual CA cert file is set up for {processor_name}")
265+
def step_impl(context, processor_name):
266+
add_ssl_context_service_for_minifi(context, "minifi_client")
252267
processor = context.get_or_create_default_minifi_container().flow_definition.get_processor(processor_name)
253268
processor.add_property('SSL Context Service', 'SSLContextService')

docker/RunBehaveTests.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,4 +200,5 @@ exec \
200200
"${docker_dir}/../extensions/sql/tests/features" \
201201
"${docker_dir}/../extensions/llamacpp/tests/features" \
202202
"${docker_dir}/../extensions/opc/tests/features" \
203-
"${docker_dir}/../extensions/kafka/tests/features"
203+
"${docker_dir}/../extensions/kafka/tests/features" \
204+
"${docker_dir}/../extensions/couchbase/tests/features"

docker/requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,4 @@ azure-storage-blob==12.24.1
1010
prometheus-api-client==0.5.5
1111
humanfriendly==10.0
1212
requests<2.29 # https://github.com/docker/docker-py/issues/3113
13-
couchbase==4.3.5
1413
paho-mqtt==2.1.0

docker/test/integration/cluster/ContainerStore.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
from .containers.GrafanaLokiContainer import GrafanaLokiContainer
3737
from .containers.GrafanaLokiContainer import GrafanaLokiOptions
3838
from .containers.ReverseProxyContainer import ReverseProxyContainer
39-
from .containers.CouchbaseServerContainer import CouchbaseServerContainer
4039
from .FeatureContext import FeatureContext
4140

4241

@@ -266,14 +265,6 @@ def acquire_container(self, context, container_name: str, engine='minifi-cpp', c
266265
network=self.network,
267266
image_store=self.image_store,
268267
command=command))
269-
elif engine == "couchbase-server":
270-
return self.containers.setdefault(container_name,
271-
CouchbaseServerContainer(feature_context=feature_context,
272-
name=container_name,
273-
vols=self.vols,
274-
network=self.network,
275-
image_store=self.image_store,
276-
command=command))
277268
else:
278269
raise Exception('invalid flow engine: \'%s\'' % engine)
279270

docker/test/integration/cluster/DockerTestCluster.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
from .checkers.SplunkChecker import SplunkChecker
3636
from .checkers.GrafanaLokiChecker import GrafanaLokiChecker
3737
from .checkers.ModbusChecker import ModbusChecker
38-
from .checkers.CouchbaseChecker import CouchbaseChecker
3938
from .checkers.MqttHelper import MqttHelper
4039
from utils import get_peak_memory_usage, get_minifi_pid, get_memory_usage, retry_check
4140

@@ -56,7 +55,6 @@ def __init__(self, context, feature_id):
5655
self.grafana_loki_checker = GrafanaLokiChecker()
5756
self.minifi_controller_executor = MinifiControllerExecutor(self.container_communicator)
5857
self.modbus_checker = ModbusChecker(self.container_communicator)
59-
self.couchbase_checker = CouchbaseChecker()
6058
self.mqtt_helper = MqttHelper()
6159

6260
def cleanup(self):
@@ -447,8 +445,5 @@ def set_value_on_plc_with_modbus(self, container_name, modbus_cmd):
447445
def enable_ssl_in_nifi(self):
448446
self.container_store.enable_ssl_in_nifi()
449447

450-
def is_data_present_in_couchbase(self, doc_id: str, bucket_name: str, expected_data: str, expected_data_type: str):
451-
return self.couchbase_checker.is_data_present_in_couchbase(doc_id, bucket_name, expected_data, expected_data_type)
452-
453448
def publish_test_mqtt_message(self, topic: str, message: str):
454449
self.mqtt_helper.publish_test_mqtt_message(topic, message)

docker/test/integration/cluster/checkers/CouchbaseChecker.py

Lines changed: 0 additions & 69 deletions
This file was deleted.

docker/test/integration/cluster/containers/CouchbaseServerContainer.py

Lines changed: 0 additions & 125 deletions
This file was deleted.

docker/test/integration/features/MiNiFi_integration_test_driver.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,6 @@ def start_minifi_c2_server(self, context):
8585
self.cluster.deploy_container('minifi-c2-server')
8686
assert self.cluster.wait_for_container_startup_to_finish('minifi-c2-server') or self.cluster.log_app_output()
8787

88-
def start_couchbase_server(self, context):
89-
self.cluster.acquire_container(context=context, name='couchbase-server', engine='couchbase-server')
90-
self.cluster.deploy_container('couchbase-server')
91-
assert self.cluster.wait_for_container_startup_to_finish('couchbase-server') or self.cluster.log_app_output()
92-
9388
def start_nifi(self, context):
9489
self.cluster.acquire_container(context=context, name='nifi', engine='nifi')
9590
self.cluster.deploy_container('nifi')
@@ -507,8 +502,5 @@ def set_value_on_plc_with_modbus(self, container_name, modbus_cmd):
507502
def enable_ssl_in_nifi(self):
508503
self.cluster.enable_ssl_in_nifi()
509504

510-
def check_is_data_present_on_couchbase(self, doc_id: str, bucket_name: str, expected_data: str, expected_data_type: str):
511-
assert self.cluster.is_data_present_in_couchbase(doc_id, bucket_name, expected_data, expected_data_type)
512-
513505
def publish_test_mqtt_message(self, topic, message):
514506
self.cluster.publish_test_mqtt_message(topic, message)

0 commit comments

Comments
 (0)