@ -1,9 +1,12 @@
import sys
import sys
import os
import os
import time
import time
import datetime
from xmlrpc . client import DateTime
import docker
import docker
from colorama import Fore , Style
from colorama import Fore , Style
import subprocess
import subprocess
import calendar
# Declare variables for service name and sleep time
# Declare variables for service name and sleep time
test_name = sys . argv [ 1 ]
test_name = sys . argv [ 1 ]
@ -22,12 +25,7 @@ def stop(exit_code):
print ( subprocess . check_output ( " docker-compose -f " + compose_file + " down " , shell = True ) . decode ( ) )
print ( subprocess . check_output ( " docker-compose -f " + compose_file + " down " , shell = True ) . decode ( ) )
sys . exit ( exit_code )
sys . exit ( exit_code )
# Sleep for a defined amount of time
def health_checks ( deadline ) :
def sleep ( ) :
print ( Fore . LIGHTMAGENTA_EX + " Sleeping for " + str ( timeout ) + " m " + Style . RESET_ALL )
time . sleep ( timeout * 60 )
def health_checks ( ) :
exit_code = 0
exit_code = 0
#Iterating trough all containers dictionary
#Iterating trough all containers dictionary
for container in client . containers ( all = True ) :
for container in client . containers ( all = True ) :
@ -58,7 +56,9 @@ def health_checks():
#Adding the generated dictionary to a list
#Adding the generated dictionary to a list
containers . append ( containers_dict )
containers . append ( containers_dict )
if exit_code != 0 :
if exit_code == 0 :
return True
elif exit_code != 0 and deadline < datetime . datetime . now ( ) . timestamp ( ) :
stop ( exit_code )
stop ( exit_code )
def print_logs ( ) :
def print_logs ( ) :
@ -86,14 +86,20 @@ def hooks():
# Start up containers
# Start up containers
sys . stdout . flush ( )
sys . stdout . flush ( )
deadline = datetime . datetime . now ( ) + datetime . timedelta ( minutes = timeout )
deadline = calendar . timegm ( deadline . timetuple ( ) )
print ( subprocess . check_output ( " docker-compose -f " + compose_file + " up -d " , shell = True ) . decode ( ) )
print ( subprocess . check_output ( " docker-compose -f " + compose_file + " up -d " , shell = True ) . decode ( ) )
print ( )
print ( )
sleep ( )
print ( Fore . LIGHTMAGENTA_EX + " Sleeping for 10s " + Style . RESET_ALL )
time . sleep ( 10 )
print ( )
print ( )
sys . stdout . flush ( )
sys . stdout . flush ( )
print ( subprocess . check_output ( " docker ps -a " , shell = True ) . decode ( ) )
print ( subprocess . check_output ( " docker ps -a " , shell = True ) . decode ( ) )
print ( )
print ( )
health_checks ( )
while not health_checks ( deadline ) :
print ( Fore . LIGHTMAGENTA_EX + " Sleeping for 10s " + Style . RESET_ALL )
sys . stdout . flush ( )
time . sleep ( 10 )
print ( )
print ( )
hooks ( )
hooks ( )
print ( )
print ( )