33import pytest
44
55from container_ci_suite .container_lib import ContainerTestLib
6+ from container_ci_suite .engines .database import DatabaseWrapper
67from container_ci_suite .engines .podman_wrapper import PodmanCLIWrapper
78
89from conftest import VARS
@@ -14,9 +15,15 @@ class TestMySqlConfigurationContainer:
1415 """
1516
1617 def setup_method (self ):
18+ """
19+ Setup the test environment.
20+ """
1721 self .db = ContainerTestLib (image_name = VARS .IMAGE_NAME )
1822
1923 def teardown_method (self ):
24+ """
25+ Teardown the test environment.
26+ """
2027 self .db .cleanup ()
2128
2229 def test_container_creation_fails (self ):
@@ -108,78 +115,95 @@ class TestMySqlConfigurationTests:
108115 """
109116
110117 def setup_method (self ):
111- self .db = ContainerTestLib (image_name = VARS .IMAGE_NAME )
112- self .db .set_new_db_type (db_type = "mysql" )
118+ """
119+ Setup the test environment.
120+ """
121+ self .db_config = ContainerTestLib (image_name = VARS .IMAGE_NAME )
122+ self .db_config .set_new_db_type (db_type = "mysql" )
123+ self .db_api = DatabaseWrapper (image_name = VARS .IMAGE_NAME )
113124
114125 def teardown_method (self ):
115- self .db .cleanup ()
126+ """
127+ Teardown the test environment.
128+ """
129+ self .db_config .cleanup ()
116130
117131 def test_configuration_auto_calculated_settings (self ):
118132 """
119133 Test MySQL container configuration auto-calculated settings.
120134 """
121135 cid_config_test = "auto-config_test"
122- assert self .db .create_container (
136+ username = "config_test_user"
137+ password = "config_test"
138+ assert self .db_config .create_container (
123139 cid_file_name = cid_config_test ,
124140 container_args = [
125141 "--env MYSQL_COLLATION=latin2_czech_cs" ,
126142 "--env MYSQL_CHARSET=latin2" ,
127- "--env MYSQL_USER=config_test_user " ,
128- "--env MYSQL_PASSWORD=config_test " ,
143+ f "--env MYSQL_USER={ username } " ,
144+ f "--env MYSQL_PASSWORD={ password } " ,
129145 "--env MYSQL_DATABASE=db" ,
130146 ],
131147 docker_args = "--memory=512m" ,
132148 )
133- cip = self .db .get_cip (cid_file_name = cid_config_test )
149+ cip = self .db_config .get_cip (cid_file_name = cid_config_test )
134150 assert cip
135- return_value = self .db .test_db_connection (
151+ assert self .db_config .test_db_connection (
136152 container_ip = cip ,
137- username = "config_test_user" ,
138- password = "config_test" ,
153+ username = username ,
154+ password = password ,
139155 max_attempts = 10 ,
140156 )
141- assert return_value
142- cid = self .db .get_cid (cid_file_name = cid_config_test )
157+ cid = self .db_config .get_cid (cid_file_name = cid_config_test )
143158 db_configuration = PodmanCLIWrapper .podman_exec_shell_command (
144159 cid_file_name = cid ,
145160 cmd = "cat /etc/my.cnf /etc/my.cnf.d/*" ,
146161 )
147- assert db_configuration
148- assert re . search (
149- r"key_buffer_size\ s*=\s*51M " ,
150- db_configuration ,
151- )
152- assert re . search (
153- r"read_buffer_size\ s*=\s*25M " ,
154- db_configuration ,
155- )
156- assert re .search (
157- r"innodb_buffer_pool_size\s*=\s*256M" ,
158- db_configuration ,
159- )
160- assert re . search (
161- r"innodb_log_file_size\s*=\s*76M" ,
162- db_configuration ,
163- )
164- assert re . search (
165- r"innodb_log_buffer_size\s*=\s*76M " ,
166- db_configuration ,
162+ words = [
163+ "key_buffer_size \\ s*= \\ s*51M" ,
164+ "read_buffer_size \\ s*=\\ s*25M " ,
165+ "innodb_buffer_pool_size \\ s*= \\ s*256M" ,
166+ "innodb_log_file_size \\ s*= \\ s*76M" ,
167+ "innodb_log_buffer_size \\ s*= \\ s*76M" ,
168+ "authentication_policy \\ s*=\\ s*'caching_sha2_password,,' " ,
169+ ]
170+ for word in words :
171+ assert re .search ( word , db_configuration ), (
172+ f"Word { word } not found in { db_configuration } "
173+ )
174+ # do some real work to test replication in practice
175+ self . db_api . run_sql_command (
176+ container_ip = cip ,
177+ username = username ,
178+ password = password ,
179+ container_id = cid ,
180+ sql_cmd = "CREATE TABLE tbl (col VARCHAR(20)); " ,
181+ podman_run_command = "exec" ,
167182 )
168- assert re .search (
169- r"authentication_policy\s*=\s*'caching_sha2_password,,'" ,
170- db_configuration ,
183+ show_table_output = self .db_api .run_sql_command (
184+ container_ip = cip ,
185+ username = username ,
186+ password = password ,
187+ container_id = cid ,
188+ sql_cmd = "SHOW CREATE TABLE tbl;" ,
189+ podman_run_command = "exec" ,
171190 )
191+ assert "CHARSET=latin2" in show_table_output
192+ assert "COLLATE=latin2_czech_cs" in show_table_output
193+ PodmanCLIWrapper .call_podman_command (cmd = f"stop { cid } " )
172194
173195 def test_configuration_options_settings (self ):
174196 """
175197 Test MySQL container configuration options.
176198 """
177199 cid_config_test = "config_test"
178- assert self .db .create_container (
200+ username = "config_test_user"
201+ password = "config_test"
202+ assert self .db_config .create_container (
179203 cid_file_name = cid_config_test ,
180204 container_args = [
181- "--env MYSQL_USER=config_test_user " ,
182- "--env MYSQL_PASSWORD=config_test " ,
205+ f "--env MYSQL_USER={ username } " ,
206+ f "--env MYSQL_PASSWORD={ password } " ,
183207 "--env MYSQL_DATABASE=db" ,
184208 "--env MYSQL_LOWER_CASE_TABLE_NAMES=1" ,
185209 "--env MYSQL_LOG_QUERIES_ENABLED=1" ,
@@ -197,54 +221,41 @@ def test_configuration_options_settings(self):
197221 "--env MYSQL_AUTHENTICATION_POLICY=sha256_password" ,
198222 ],
199223 )
200- cip = self .db .get_cip (cid_file_name = cid_config_test )
224+ cip = self .db_config .get_cip (cid_file_name = cid_config_test )
201225 assert cip
202- assert self .db .test_db_connection (
203- container_ip = cip , username = "config_test_user" , password = "config_test"
226+ assert self .db_config .test_db_connection (
227+ container_ip = cip , username = username , password = password
204228 )
205- cip = self .db .get_cip (cid_file_name = cid_config_test )
229+ cip = self .db_config .get_cip (cid_file_name = cid_config_test )
206230 assert cip
207- return_value = self .db .test_db_connection (
231+ assert self .db_config .test_db_connection (
208232 container_ip = cip ,
209- username = "config_test_user" ,
210- password = "config_test" ,
233+ username = username ,
234+ password = password ,
211235 max_attempts = 10 ,
212236 )
213- assert return_value
214- cid = self .db .get_cid (cid_file_name = cid_config_test )
237+ cid = self .db_config .get_cid (cid_file_name = cid_config_test )
215238 db_configuration = PodmanCLIWrapper .podman_exec_shell_command (
216239 cid_file_name = cid ,
217240 cmd = "cat /etc/my.cnf /etc/my.cnf.d/*" ,
218241 )
219- assert db_configuration
220- assert re .search (
221- r"lower_case_table_names\s*=\s*1" ,
222- db_configuration ,
223- )
224- assert re .search (
225- r"general_log\s*=\s*1" ,
226- db_configuration ,
227- )
228- assert re .search (
229- r"max_connections\s*=\s*1337" ,
230- db_configuration ,
231- re .MULTILINE | re .IGNORECASE ,
232- )
233- assert re .search (r"ft_min_word_len\s*=\s*8" , db_configuration )
234- assert re .search (
235- r"ft_max_word_len\s*=\s*15" ,
236- db_configuration ,
237- )
238- assert re .search (r"max_allowed_packet\s*=\s*10M" , db_configuration )
239- assert re .search (r"table_open_cache\s*=\s*100" , db_configuration )
240- assert re .search (r"sort_buffer_size\s*=\s*256K" , db_configuration )
241- assert re .search (r"key_buffer_size\s*=\s*16M" , db_configuration )
242- assert re .search (r"read_buffer_size\s*=\s*16M" , db_configuration )
243- assert re .search (r"innodb_buffer_pool_size\s*=\s*16M" , db_configuration )
244- assert re .search (r"innodb_log_file_size\s*=\s*4M" , db_configuration )
245- assert re .search (r"innodb_log_buffer_size\s*=\s*4M" , db_configuration )
246- assert re .search (
247- r"authentication_policy\s*=\s*'sha256_password'" ,
248- db_configuration ,
249- re .MULTILINE ,
250- )
242+ words = [
243+ "lower_case_table_names\\ s*=\\ s*1" ,
244+ "general_log\\ s*=\\ s*1" ,
245+ "max_connections\\ s*=\\ s*1337" ,
246+ "ft_min_word_len\\ s*=\\ s*8" ,
247+ "ft_max_word_len\\ s*=\\ s*15" ,
248+ "max_allowed_packet\\ s*=\\ s*10M" ,
249+ "table_open_cache\\ s*=\\ s*100" ,
250+ "sort_buffer_size\\ s*=\\ s*256K" ,
251+ "key_buffer_size\\ s*=\\ s*16M" ,
252+ "read_buffer_size\\ s*=\\ s*16M" ,
253+ "innodb_log_file_size\\ s*=\\ s*4M" ,
254+ "innodb_log_buffer_size\\ s*=\\ s*4M" ,
255+ "authentication_policy\\ s*=\\ s*'sha256_password'" ,
256+ ]
257+ for word in words :
258+ assert re .search (word , db_configuration ), (
259+ f"Word { word } not found in { db_configuration } "
260+ )
261+ PodmanCLIWrapper .call_podman_command (cmd = f"stop { cid } " )
0 commit comments