-
Notifications
You must be signed in to change notification settings - Fork 70
Add PyTest suite to mariadb-container #311
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
phracek
wants to merge
9
commits into
sclorg:master
Choose a base branch
from
phracek:container_pytests
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ec3c92e
Add PyTest suite to mariadb-container
phracek cce9f54
Fix tests caugh by real testing on Fedora Host and C9S host
phracek 57ab64b
Improvement of database testing.
phracek f990c37
Fix Fedora 11.8 test for replication
phracek f9be308
A huge refactoring. Let's use function once
phracek 8e7510d
Fix conftest.py so SSL_OPTION and PREVIOUS_VERSION
phracek b716efa
Fix calling get_cip_cid directly from 'container-ci-suite'.
phracek 158dc65
Use regexp and better naming for detection
phracek 2d65c49
Remove get_cip_cid function from all *.py files.
phracek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,60 @@ | ||
| import os | ||
| import sys | ||
|
|
||
| from pathlib import Path | ||
| from collections import namedtuple | ||
|
|
||
| from container_ci_suite.utils import check_variables | ||
|
|
||
| if not check_variables(): | ||
| sys.exit(1) | ||
|
|
||
| TAGS = { | ||
| "rhel8": "-el8", | ||
| "rhel9": "-el9", | ||
| "rhel10": "-el10", | ||
| } | ||
|
|
||
| MARIADB_PREVIOUS_VERSIONS = { | ||
| "10.3": "10.2", | ||
| "10.5": "10.3", | ||
| "10.11": "10.5", | ||
| "11.8": "10.11", | ||
| } | ||
| TEST_DIR = Path(__file__).parent.absolute() | ||
| Vars = namedtuple( | ||
| "Vars", | ||
| [ | ||
| "OS", | ||
| "VERSION", | ||
| "IMAGE_NAME", | ||
| "TEST_DIR", | ||
| "TAG", | ||
| "TEST_APP", | ||
| "VERY_LONG_DB_NAME", | ||
| "VERY_LONG_USER_NAME", | ||
| "SSL_OPTION", | ||
| "PREVIOUS_VERSION", | ||
| ], | ||
| ) | ||
| VERSION = os.getenv("VERSION") | ||
| OS = os.getenv("TARGET").lower() | ||
| TEST_APP = TEST_DIR / "test-app" | ||
| VERY_LONG_DB_NAME = "very_long_database_name_" + "x" * 40 | ||
| VERY_LONG_USER_NAME = "very_long_user_name_" + "x" * 40 | ||
| # MariaDB 11.3+ enforces stricter SSL/TLS verification (certificate & hostname checks), | ||
| # so tests may require this option for compatibility. | ||
| # https://mariadb.org/mission-impossible-zero-configuration-ssl/ | ||
| SSL_OPTION = "--disable-ssl-verify-server-cert" if VERSION == "11.8" else "" | ||
| VARS = Vars( | ||
| OS=OS, | ||
| VERSION=VERSION, | ||
| IMAGE_NAME=os.getenv("IMAGE_NAME"), | ||
| TEST_DIR=Path(__file__).parent.absolute(), | ||
| TAG=TAGS.get(OS), | ||
| TEST_APP=TEST_APP, | ||
| VERY_LONG_DB_NAME=VERY_LONG_DB_NAME, | ||
| VERY_LONG_USER_NAME=VERY_LONG_USER_NAME, | ||
| SSL_OPTION=SSL_OPTION, # used for tests that require SSL verification to be disabled | ||
| PREVIOUS_VERSION=MARIADB_PREVIOUS_VERSIONS.get(VERSION), | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| #!/bin/bash | ||
| # | ||
| # IMAGE_NAME specifies a name of the candidate image used for testing. | ||
| # The image has to be available before this script is executed. | ||
| # VERSION specifies the major version of the MariaDB in format of X.Y | ||
| # OS specifies RHEL version (e.g. OS=rhel10) | ||
| # | ||
|
|
||
| THISDIR=$(dirname ${BASH_SOURCE[0]}) | ||
|
|
||
| git show -s | ||
|
|
||
| PYTHON_VERSION="3.12" | ||
| if [[ ! -f "/usr/bin/python$PYTHON_VERSION" ]]; then | ||
| PYTHON_VERSION="3.13" | ||
| fi | ||
| cd "${THISDIR}" && "python${PYTHON_VERSION}" -m pytest -s -rA --showlocals -vv test_container_*.py |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| import shutil | ||
| import tempfile | ||
|
|
||
| from container_ci_suite.container_lib import ContainerTestLib | ||
| from container_ci_suite.container_lib import ContainerTestLibUtils | ||
| from container_ci_suite.engines.podman_wrapper import PodmanCLIWrapper | ||
| from pathlib import Path | ||
|
|
||
| from conftest import VARS | ||
|
|
||
|
|
||
| def build_s2i_app(app_path: Path) -> ContainerTestLib: | ||
| container_lib = ContainerTestLib(VARS.IMAGE_NAME) | ||
| app_name = app_path.name | ||
| s2i_app = container_lib.build_as_df( | ||
| app_path=app_path, | ||
| s2i_args="--pull-policy=never", | ||
| src_image=VARS.IMAGE_NAME, | ||
| dst_image=f"{VARS.IMAGE_NAME}-{app_name}", | ||
| ) | ||
| return s2i_app | ||
|
|
||
|
|
||
| class TestMariaDBBasicsContainer: | ||
| """ | ||
| Test MariaDB container configuration. | ||
| """ | ||
|
|
||
| def setup_method(self): | ||
| """ | ||
| Setup the test environment. | ||
| """ | ||
| self.app_image = build_s2i_app(app_path=VARS.TEST_DIR / "test-app") | ||
| self.app_image.set_new_db_type(db_type="mariadb") | ||
|
|
||
| def teardown_method(self): | ||
| """ | ||
| Teardown the test environment. | ||
| """ | ||
| self.app_image.cleanup() | ||
|
|
||
| def test_s2i_usage(self): | ||
| """ | ||
| Test if the MariaDB container works properly | ||
| Steps are: | ||
| 1. Test if the container creation fails with invalid combinations of arguments | ||
| 2. Test if the container creation succeeds with valid combinations of arguments | ||
| 3. Test if the database connection works | ||
| """ | ||
| cid_config_build = "s2i_usage_build" | ||
| self.app_image.assert_container_creation_fails( | ||
| cid_file_name=cid_config_build, | ||
| command="", | ||
| container_args=[ | ||
| "-e MYSQL_USER=root", | ||
| "-e MYSQL_PASSWORD=pass", | ||
| "-e MYSQL_DATABASE=db", | ||
| "-e MYSQL_ROOT_PASSWORD=pass", | ||
| ], | ||
| ) | ||
| assert self.app_image.create_container( | ||
| cid_file_name=cid_config_build, | ||
| container_args=[ | ||
| "-e MYSQL_USER=config_test_user", | ||
| "-e MYSQL_PASSWORD=config_test_user", | ||
| "-e MYSQL_DATABASE=db", | ||
| "-e MYSQL_OPERATIONS_USER=operations_user", | ||
| "-e MYSQL_OPERATIONS_PASSWORD=operations_user", | ||
| ], | ||
| ) | ||
| cip, cid = self.app_image.get_cip_cid(cid_file_name=cid_config_build) | ||
| assert cip, cid | ||
| assert self.app_image.test_db_connection( | ||
| container_ip=cip, username="operations_user", password="operations_user" | ||
| ) | ||
| PodmanCLIWrapper.call_podman_command(cmd=f"stop {cid}") | ||
|
|
||
| def test_s2i_usage_with_mount(self): | ||
| """ | ||
| Test if the MariaDB container works properly with mounted application directory. | ||
| Steps are: | ||
| 1. Copy the test-app directory to a temporary directory | ||
| 2. Create a container with the mounted application directory | ||
| 3. Test if the container creation succeeds with valid combinations of arguments | ||
| 4. Test if the database connection works with the operations user | ||
| 5. Stop the container | ||
| 6. Remove the temporary directory | ||
| """ | ||
| data_dir = tempfile.mkdtemp(prefix="/tmp/mariadb-test_data") | ||
| shutil.copytree(VARS.TEST_DIR / "test-app", f"{data_dir}/test-app") | ||
| assert ContainerTestLibUtils.commands_to_run( | ||
| commands_to_run=[ | ||
| f"chown -R 27:27 {data_dir}/test-app", | ||
| ] | ||
| ) | ||
| cid_s2i_test_mount = "s2i_test_mount" | ||
| assert self.app_image.create_container( | ||
| cid_file_name=cid_s2i_test_mount, | ||
| container_args=[ | ||
| "-e MYSQL_USER=config_test_user", | ||
| "-e MYSQL_PASSWORD=config_test_user", | ||
| "-e MYSQL_DATABASE=db", | ||
| "-e MYSQL_OPERATIONS_USER=operations_user", | ||
| "-e MYSQL_OPERATIONS_PASSWORD=operations_pass", | ||
| f"-v {data_dir}/test-app:/opt/app-root/src/:z", | ||
| ], | ||
| ) | ||
| cip, cid = self.app_image.get_cip_cid(cid_file_name=cid_s2i_test_mount) | ||
| assert cip, cid | ||
| assert self.app_image.test_db_connection( | ||
| container_ip=cip, | ||
| username="operations_user", | ||
| password="operations_pass", | ||
| max_attempts=10, | ||
| ) | ||
| PodmanCLIWrapper.call_podman_command(cmd=f"stop {cid}") | ||
| shutil.rmtree(data_dir) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.