From 4032e7128d2093cf12a0557cca25503ed1b19d9b Mon Sep 17 00:00:00 2001 From: Ionut Filip Date: Mon, 5 Nov 2018 12:34:52 +0200 Subject: [PATCH] Calling email test as hook with msg as arg --- tests/compose/core/01_email_test.sh | 1 + tests/compose/filters/01_email_test.sh | 1 + tests/compose/test.py | 29 +++++++++++++------------- tests/email_test.py | 18 ++++------------ 4 files changed, 21 insertions(+), 28 deletions(-) create mode 100755 tests/compose/core/01_email_test.sh create mode 100755 tests/compose/filters/01_email_test.sh diff --git a/tests/compose/core/01_email_test.sh b/tests/compose/core/01_email_test.sh new file mode 100755 index 00000000..97dd6e4b --- /dev/null +++ b/tests/compose/core/01_email_test.sh @@ -0,0 +1 @@ +python3 tests/email_test.py message-core \ No newline at end of file diff --git a/tests/compose/filters/01_email_test.sh b/tests/compose/filters/01_email_test.sh new file mode 100755 index 00000000..64fa3fba --- /dev/null +++ b/tests/compose/filters/01_email_test.sh @@ -0,0 +1 @@ +python3 tests/email_test.py message-filters \ No newline at end of file diff --git a/tests/compose/test.py b/tests/compose/test.py index 576e128d..690855d4 100755 --- a/tests/compose/test.py +++ b/tests/compose/test.py @@ -19,7 +19,7 @@ containers = [] def stop(exit_code): print_logs() sys.stdout.flush() - print(subprocess.check_output("docker-compose -f " + compose_file + " down", shell=True)) + print(subprocess.check_output("docker-compose -f " + compose_file + " down", shell=True).decode()) sys.exit(exit_code) # Sleep for a defined amount of time @@ -67,30 +67,31 @@ def print_logs(): for container in containers: print(Fore.LIGHTMAGENTA_EX + "Printing logs for: " + Fore.GREEN + container['Name'] + Style.RESET_ALL) sys.stdout.flush() - print(subprocess.check_output('docker container logs ' + container['Name'], shell=True)) + print(subprocess.check_output('docker container logs ' + container['Name'], shell=True).decode()) #Iterating over hooks in test folder and running them def hooks(): - print("Running hooks") + print(Fore.LIGHTMAGENTA_EX + "Running hooks" + Style.RESET_ALL) for test_file in sorted(os.listdir(test_path)): - if test_file.endswith(".py"): - sys.stdout.flush() - print(subprocess.check_output("python3 " + test_path + test_file, shell=True)) - elif test_file.endswith(".sh"): - sys.stdout.flush() - print(subprocess.check_output("./" + test_path + test_file, shell=True)) - - sys.stdout.flush() - print(subprocess.check_output("python3 tests/email_test.py", shell=True)) + try: + if test_file.endswith(".py"): + sys.stdout.flush() + print(subprocess.check_output("python3 " + test_path + test_file, shell=True).decode()) + elif test_file.endswith(".sh"): + sys.stdout.flush() + print(subprocess.check_output("./" + test_path + test_file, shell=True).decode()) + except subprocess.CalledProcessError as e: + sys.stderr.write("[ERROR]: output = %s, error code = %s\n" % (e.output.decode(), e.returncode)) + stop(1) # Start up containers sys.stdout.flush() -print(subprocess.check_output("docker-compose -f " + compose_file + " up -d", shell=True)) +print(subprocess.check_output("docker-compose -f " + compose_file + " up -d", shell=True).decode()) print() sleep() print() sys.stdout.flush() -print(subprocess.check_output("docker ps -a", shell=True)) +print(subprocess.check_output("docker ps -a", shell=True).decode()) print() health_checks() print() diff --git a/tests/email_test.py b/tests/email_test.py index c56c1f57..7148365e 100755 --- a/tests/email_test.py +++ b/tests/email_test.py @@ -1,19 +1,9 @@ -import string -import random import smtplib import imaplib import time import sys -def secret(length=16): - charset = string.ascii_uppercase + string.digits - return ''.join( - random.SystemRandom().choice(charset) - for _ in range(length) - ) - -#Generating secret message -secret_message = secret(16) +email_msg = sys.argv[1] #Login to smt server and sending email with secret message def send_email(msg): @@ -42,16 +32,16 @@ def read_email(): print("email received with message " + str(data[0][1])) - if secret_message in str(data[0][1]): + if email_msg in str(data[0][1]): print("Success!") else: - print("Failed! Something went wrong") + print("Failed receiving email with message %s" % email_msg) sys.exit(1) server.close() server.logout() -send_email(secret_message) +send_email(email_msg) print("Sleeping for 1m") time.sleep(60) read_email()