@@ -348,12 +348,20 @@ def check_envs_set(
348348 return True
349349
350350 def get_cid (self , cid_file_name : str ) -> str :
351+ """Get container ID from cid_file."""
351352 logging .debug (f"Get content of CID_NAME: { cid_file_name } " )
352353 return self .lib .get_cid (cid_file_name = cid_file_name )
353354
354355 def get_cip (self , cid_file_name : str = "app_dockerfile" ) -> str :
356+ """Get container IP address from cid_file."""
355357 return self .lib .get_cip (cid_file_name = cid_file_name )
356358
359+ def get_cip_cid (self , cid_file_name : str = "app_dockerfile" ) -> tuple [str , str ]:
360+ """Get container ID and IP address from cid_file."""
361+ cip = self .lib .get_cip (cid_file_name = cid_file_name )
362+ cid = self .lib .get_cid (cid_file_name = cid_file_name )
363+ return cip , cid
364+
357365 def test_db_connection (
358366 self ,
359367 container_ip : str = "" ,
@@ -364,6 +372,20 @@ def test_db_connection(
364372 sleep_time : int = 3 ,
365373 sql_cmd : Optional [str ] = None ,
366374 ) -> bool :
375+ """
376+ Test database connection.
377+
378+ Args:
379+ container_ip: Container IP address
380+ username: Database username
381+ password: Database password
382+ database: Database name
383+ max_attempts: Maximum number of attempts
384+ sleep_time: Time to sleep between attempts
385+ sql_cmd: SQL command to execute
386+ Returns:
387+ True if database connection test succeeded, False otherwise
388+ """
367389 return self .db_lib .test_connection (
368390 container_ip = container_ip ,
369391 username = username ,
@@ -400,7 +422,9 @@ def assert_container_creation_fails(
400422 while attempt <= max_attempts :
401423 if not ContainerImage .is_container_running (container_id ):
402424 logging .info (
403- f"Container { container_id } is not running after { attempt } attempts."
425+ "Container %s is not running after %s attempts." ,
426+ container_id ,
427+ attempt ,
404428 )
405429 break
406430 time .sleep (2 )
@@ -409,7 +433,13 @@ def assert_container_creation_fails(
409433 PodmanCLIWrapper .call_podman_command (
410434 cmd = f"stop { container_id } " , ignore_error = True
411435 )
412- return False
436+ logger .debug (
437+ "Container %s is not running after %s attempts. \
438+ It is expected to fail." ,
439+ container_id ,
440+ attempt ,
441+ )
442+ return True
413443 # Check exit status
414444 try :
415445 exit_status = PodmanCLIWrapper .call_podman_command (
@@ -517,7 +547,9 @@ def assert_container_creation_succeeds(
517547 ... )
518548 """
519549 # Generate unique container name
520- cid_file = f"success-{ self .random_string (length = 10 )} "
550+ self .success_cid_file = (
551+ f"{ self .cid_file_dir } /success-{ self .random_string (length = 10 )} "
552+ )
521553
522554 # Convert list to string if needed
523555 if isinstance (container_args , list ):
@@ -531,13 +563,15 @@ def assert_container_creation_succeeds(
531563 # Create the container
532564 logging .info (f"Creating container with args: { container_args } " )
533565 if not self .create_container (
534- cid_file_name = cid_file , container_args = container_args , command = command
566+ cid_file_name = self .success_cid_file ,
567+ container_args = container_args ,
568+ command = command ,
535569 ):
536570 logging .error ("Failed to create container" )
537571 return False
538572
539573 # Get container ID
540- container_id = self .get_cid (cid_file )
574+ container_id = self .get_cid (self . success_cid_file )
541575 logging .info (f"Container created successfully: { container_id } " )
542576
543577 # Wait a bit for container to start
@@ -568,7 +602,9 @@ def assert_container_creation_succeeds(
568602 if test_connection_func and connection_params :
569603 logging .info ("Testing connection..." )
570604 try :
571- if not test_connection_func (cid_file , connection_params ):
605+ if not test_connection_func (
606+ self .success_cid_file , connection_params
607+ ):
572608 logging .error ("Connection test failed" )
573609 return False
574610 logging .info ("Connection test passed" )
0 commit comments