Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions behave_framework/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
[project]
name = "minifi-test-framework"
version = "0.1.0"
version = "0.2.0"
requires-python = ">= 3.10"
description = "A testing framework for MiNiFi extensions."
dependencies = [
"behavex==4.6.0",
"docker==7.1.0",
"PyYAML==6.0.3",
"humanfriendly==10.0",
"m2crypto==0.46.2",
"pyopenssl==25.0.0",
"cryptography==46.0.5",
"pyjks==20.0.0"
]

[tool.setuptools]
package-dir = {"" = "src"}
packages = ["minifi_test_framework"]

[tool.setuptools.packages.find]
where = ["src"]
include = ["minifi_test_framework*"]

Comment on lines 15 to +21
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is required for wheel building

Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,31 @@
# limitations under the License.
#
from __future__ import annotations
from typing import TYPE_CHECKING

import json
import logging
import os
import shlex
import tempfile
import tarfile
import tempfile
import uuid

import docker
from docker.models.networks import Network

from minifi_test_framework.containers.container_protocol import ContainerProtocol
from minifi_test_framework.containers.directory import Directory
from minifi_test_framework.containers.file import File
from minifi_test_framework.containers.host_file import HostFile
from typing import TYPE_CHECKING

import docker

if TYPE_CHECKING:
from minifi_test_framework.core.minifi_test_context import MinifiTestContext


class Container:
def __init__(self, image_name: str, container_name: str, network: Network, command: str | None = None, entrypoint: str | None = None):
class LinuxContainer(ContainerProtocol):
def __init__(self, image_name: str, container_name: str, network: Network, command: str | None = None,
entrypoint: str | None = None):
super().__init__()
self.image_name: str = image_name
self.container_name: str = container_name
self.network: Network = network
Expand Down Expand Up @@ -120,10 +122,11 @@ def deploy(self, context: MinifiTestContext | None) -> bool:
pass
try:
logging.info(f"Creating and starting container '{self.container_name}'...")
self.container = self.client.containers.run(
image=self.image_name, name=self.container_name, ports=self.ports,
environment=self.environment, volumes=self.volumes, network=self.network.name,
command=self.command, entrypoint=self.entrypoint, user=self.user, detach=True)
self.container = self.client.containers.run(image=self.image_name, name=self.container_name,
ports=self.ports, environment=self.environment,
volumes=self.volumes, network=self.network.name,
command=self.command, entrypoint=self.entrypoint,
user=self.user, detach=True)
except Exception as e:
logging.error(f"Error starting container: {e}")
raise
Expand Down Expand Up @@ -211,7 +214,8 @@ def directory_contains_file_with_regex(self, directory_path: str, regex_str: str
exit_code, output = self.exec_run("sh -c {}".format(shlex.quote(command)))

if exit_code != 0:
logging.debug("While looking for regex %s in directory %s, grep returned exit code %d, output: %s", regex_str, directory_path, exit_code, output)
logging.debug("While looking for regex %s in directory %s, grep returned exit code %d, output: %s",
regex_str, directory_path, exit_code, output)
return exit_code == 0

def path_with_content_exists(self, path: str, content: str) -> bool:
Expand Down Expand Up @@ -375,7 +379,8 @@ def _extract_directory_from_container(self, directory_path: str, temp_dir: str)

return os.path.join(temp_dir, os.path.basename(directory_path.strip('/')))
except Exception as e:
logging.error(f"Error extracting files from directory path '{directory_path}' from container '{self.container_name}': {e}")
logging.error(
f"Error extracting files from directory path '{directory_path}' from container '{self.container_name}': {e}")
return None

def _read_files_from_directory(self, directory_path: str) -> list[str] | None:
Expand Down Expand Up @@ -478,3 +483,11 @@ def directory_contains_file_with_minimum_size(self, directory_path: str, expecte
return True

return False

def get_memory_usage(self) -> int | None:
exit_code, output = self.exec_run(["awk", "/VmRSS/ { printf \"%d\\n\", $2 }", "/proc/1/status"])
if exit_code != 0:
return None
memory_usage_in_bytes = int(output.strip()) * 1024
logging.info(f"{self.container_name} memory usage: {memory_usage_in_bytes} bytes")
return memory_usage_in_bytes
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from typing import Protocol, List

from minifi_test_framework.containers.directory import Directory
from minifi_test_framework.containers.file import File
from minifi_test_framework.containers.host_file import HostFile


class ContainerProtocol(Protocol):
image_name: str
container_name: str
dirs: List[Directory]
files: List[File]
host_files: List[HostFile]

def deploy(self, context) -> bool:
...

def clean_up(self):
...

def exec_run(self, command):
...

def directory_contains_file_with_content(self, directory_path: str, expected_content: str) -> bool:
...

def directory_contains_file_with_regex(self, directory_path: str, regex_str: str) -> bool:
...

def path_with_content_exists(self, path: str, content: str) -> bool:
...

def get_logs(self) -> str:
...

@property
def exited(self) -> bool:
...

def get_number_of_files(self, directory_path: str) -> int:
...

def verify_file_contents(self, directory_path: str, expected_contents: list[str]) -> bool:
...

def log_app_output(self) -> bool:
...
Loading
Loading