Skip to content

Commit d9532f0

Browse files
committed
Update tests suite based on the review
done by @frenzymadness Signed-off-by: Petr "Stone" Hracek <phracek@redhat.com>
1 parent 477cbdc commit d9532f0

File tree

6 files changed

+51
-65
lines changed

6 files changed

+51
-65
lines changed

test/test_container_basics.py

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -85,35 +85,34 @@ def test_connection_with_mount(self):
8585
2. Create a container with the mounted directory
8686
3. Test if the database connection works with the operations user
8787
"""
88-
data_dir = tempfile.mkdtemp(prefix="/tmp/mysql-test_data")
89-
shutil.copytree(VARS.TEST_APP, f"{data_dir}/test-app")
90-
assert ContainerTestLibUtils.commands_to_run(
91-
commands_to_run=[
92-
f"chown -R 27:27 {data_dir}/test-app",
93-
]
94-
)
95-
cid_with_mount = "connection_with_mount"
96-
operation_user = "operations_user"
97-
operation_pass = "operations_pass"
88+
with tempfile.TemporaryDirectory(prefix="/tmp/mysql-test_data") as data_dir:
89+
shutil.copytree(VARS.TEST_APP, f"{data_dir}/test-app")
90+
assert ContainerTestLibUtils.commands_to_run(
91+
commands_to_run=[
92+
f"chown -R 27:27 {data_dir}/test-app",
93+
]
94+
)
95+
cid_with_mount = "connection_with_mount"
96+
operation_user = "operations_user"
97+
operation_pass = "operations_pass"
9898

99-
self.app_image.create_container(
100-
cid_file_name=cid_with_mount,
101-
container_args=[
102-
"-e MYSQL_USER=config_test_user",
103-
"-e MYSQL_PASSWORD=config_test_user",
104-
"-e MYSQL_DATABASE=db",
105-
f"-e MYSQL_OPERATIONS_USER={operation_user}",
106-
f"-e MYSQL_OPERATIONS_PASSWORD={operation_pass}",
107-
f"-v {data_dir}/test-app:/opt/app-root/src/:z",
108-
],
109-
)
110-
cip, cid = self.app_image.get_cip_cid(cid_file_name=cid_with_mount)
111-
assert cip and cid
112-
assert self.app_image.test_db_connection(
113-
container_ip=cip,
114-
username=operation_user,
115-
password=operation_pass,
116-
max_attempts=10,
117-
)
118-
PodmanCLIWrapper.call_podman_command(cmd=f"stop {cid}")
119-
shutil.rmtree(data_dir)
99+
self.app_image.create_container(
100+
cid_file_name=cid_with_mount,
101+
container_args=[
102+
"-e MYSQL_USER=config_test_user",
103+
"-e MYSQL_PASSWORD=config_test_user",
104+
"-e MYSQL_DATABASE=db",
105+
f"-e MYSQL_OPERATIONS_USER={operation_user}",
106+
f"-e MYSQL_OPERATIONS_PASSWORD={operation_pass}",
107+
f"-v {data_dir}/test-app:/opt/app-root/src/:z",
108+
],
109+
)
110+
cip, cid = self.app_image.get_cip_cid(cid_file_name=cid_with_mount)
111+
assert cip and cid
112+
assert self.app_image.test_db_connection(
113+
container_ip=cip,
114+
username=operation_user,
115+
password=operation_pass,
116+
max_attempts=10,
117+
)
118+
PodmanCLIWrapper.call_podman_command(cmd=f"stop {cid}")

test/test_container_configuration.py

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,25 +35,11 @@ def test_container_creation_fails(self):
3535
cid_file_name=cid_config_test, container_args=[], command=""
3636
)
3737

38-
@pytest.mark.parametrize(
39-
"container_args",
40-
[
41-
["-e MYSQL_USER=user", "-e MYSQL_DATABASE=db"],
42-
["-e MYSQL_PASSWORD=pass", "-e MYSQL_DATABASE=db"],
43-
],
44-
)
45-
def test_try_image_invalid_combinations(self, container_args):
46-
"""
47-
Test container creation fails with invalid combinations of arguments.
48-
"""
49-
cid_file_name = "try_image_invalid_combinations"
50-
assert self.db.assert_container_creation_fails(
51-
cid_file_name=cid_file_name, container_args=container_args, command=""
52-
)
53-
5438
@pytest.mark.parametrize(
5539
"mysql_user, mysql_password, mysql_database, mysql_root_password",
5640
[
41+
["user", "", "db", ""],
42+
["", "pass", "db", ""],
5743
["user", "pass", "", ""],
5844
[
5945
"$invalid",
@@ -196,7 +182,8 @@ def test_configuration_auto_calculated_settings(self):
196182
assert re.search(value, db_configuration), (
197183
f"Expected value {value} not found in {db_configuration}"
198184
)
199-
# do some real work to test replication in practice
185+
# Create table and show its configuration to verify
186+
# charset and collation settings
200187
self.db_api.run_sql_command(
201188
container_ip=cip,
202189
username=username,

test/test_container_general.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def test_run(self, docker_args, username, password, root_password):
6767
command="run-mysqld --innodb_buffer_pool_size=5242880",
6868
)
6969
cip, cid = self.db_image.get_cip_cid(cid_file_name=cid_file_name)
70-
assert cip, cid
70+
assert cip and cid
7171
assert self.db_image.test_db_connection(
7272
container_ip=cip, username=username, password=password
7373
)
@@ -112,7 +112,6 @@ def test_run(self, docker_args, username, password, root_password):
112112
f"Root login access failed for {user}:{pwd} with expected success {ret_value}"
113113
)
114114
root_login_access = False
115-
continue
116115
assert root_login_access
117116
assert self.db_image.db_lib.assert_local_access(container_id=cid)
118117
self.database_test(cip, username, password)
@@ -165,7 +164,13 @@ def database_test(self, cip, username, password):
165164

166165
def test_datadir_actions(self):
167166
"""
168-
Test container creation fails with invalid combinations of arguments.
167+
Test container with specific data directory actions.
168+
Steps are:
169+
1. Create a container with a mounted data directory and check the connection.
170+
2. Create a container with MYSQL_DATADIR_ACTION=analyze and
171+
check the logs for the analyze command.
172+
3. Create a container with MYSQL_DATADIR_ACTION=optimize and
173+
check the logs for the optimize command.
169174
"""
170175
cid_testupg1 = "testupg1"
171176
datadir = tempfile.mkdtemp(prefix="/tmp/mysql-datadir-actions")
@@ -206,7 +211,7 @@ def test_datadir_actions(self):
206211
],
207212
)
208213
cip, cid = self.db_image.get_cip_cid(cid_file_name=cid_testupg5)
209-
assert cip, cid
214+
assert cip and cid
210215
assert self.db_image.test_db_connection(
211216
container_ip=cip, username=mysql_user, password=mysql_password
212217
)
@@ -228,7 +233,7 @@ def test_datadir_actions(self):
228233
],
229234
)
230235
cip, cid = self.db_image.get_cip_cid(cid_file_name=cid_testupg6)
231-
assert cip, cid
236+
assert cip and cid
232237
assert self.db_image.test_db_connection(
233238
container_ip=cip, username=mysql_user, password=mysql_password
234239
)

test/test_container_password.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def password_change_test(
9393
container_args=container_args,
9494
)
9595
cip, cid = self.pwd_change.get_cip_cid(cid_file_name=cid_file_name)
96-
assert cip, cid
96+
assert cip and cid
9797
if user_change:
9898
username = "user"
9999
password = "foo"

test/test_container_replication.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,8 @@ def test_replication(self):
4747
docker_args=cluster_args,
4848
command="run-mysqld-source",
4949
)
50-
source_cip = self.replication_db.get_cip(cid_file_name=source_cid)
51-
source_cid = self.replication_db.get_cid(cid_file_name=source_cid)
52-
assert source_cid
50+
source_cip, source_cid = self.replication_db.get_cip_cid(cid_file_name=source_cid)
51+
assert source_cip and source_cid
5352
# Run the MySQL replica
5453
replica_cid = "replica.cid"
5554
assert self.replication_db.create_container(
@@ -61,10 +60,8 @@ def test_replication(self):
6160
docker_args=cluster_args,
6261
command="run-mysqld-replica",
6362
)
64-
replica_cip = self.replication_db.get_cip(cid_file_name=replica_cid)
65-
assert replica_cip
66-
replica_cid = self.replication_db.get_cid(cid_file_name=replica_cid)
67-
assert replica_cid
63+
replica_cip, replica_cid = self.replication_db.get_cip_cid(cid_file_name=replica_cid)
64+
assert replica_cip and replica_cid
6865
# Now wait till the SOURCE will see the REPLICA
6966
result = self.replication_db.test_db_connection(
7067
container_ip=replica_cip,

test/test_container_ssl.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,11 @@ def test_ssl(self):
7575
f"-v {ssl_dir}:/opt/app-root/src/:z",
7676
],
7777
)
78-
cip = self.ssl_db.get_cip(cid_file_name=cid_file_name)
79-
assert cip
78+
cip, cid = self.ssl_db.get_cip_cid(cid_file_name=cid_file_name)
79+
assert cip and cid
8080
assert self.ssl_db.test_db_connection(
8181
container_ip=cip, username=username, password=password
8282
)
83-
cid = self.ssl_db.get_cid(cid_file_name=cid_file_name)
84-
assert cid
8583

8684
mysql_cmd = (
8785
f"mysql --host {cip} -u{username} -p{password} --ssl-ca={ca_cert_path}"

0 commit comments

Comments
 (0)