@@ -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 } " )
0 commit comments