-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
92 lines (74 loc) · 3.17 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import os
import time
import shutil
from utils import *
from fogArmX import store_app
MAIN_FOLDER = "."
BASE_FOLDER = MAIN_FOLDER+"/test"
TOT = 0
PASSED = 0
FAILED = []
def mkdir(path):
if not os.path.exists(path):
os.makedirs(path)
def mkfile(path, content):
with open(path, "w+") as f:
f.write(content)
def test_scenario(scenario):
global TOT
global PASSED
TOT += 1
shutil.copyfile(BASE_FOLDER+f"/scenarios/{scenario}/docker-compose.yml", BASE_FOLDER+"/docker-compose.yml")
shutil.copyfile(BASE_FOLDER+f"/scenarios/{scenario}/requirements.yml", BASE_FOLDER+"/requirements.yml")
shutil.copyfile(BASE_FOLDER+f"/scenarios/{scenario}/infra.pl", MAIN_FOLDER+"/infrastructure/infra.pl")
if execute_cmd("fogarmx add "+BASE_FOLDER):
if verify_placement("test"):
print("-------------------------------------------------------------")
print(f"*** Scenario '{scenario}': PASSED ***")
print("-------------------------------------------------------------")
PASSED += 1
return True
else:
print("-------------------------------------------------------------")
print(f"*** Scenario '{scenario}': FAILED ***")
FAILED.append(scenario)
print("-------------------------------------------------------------")
else:
print("-------------------------------------------------------------")
print(f"* Scenario '{scenario}': AN ERROR OCCURED")
FAILED.append(scenario)
print("-------------------------------------------------------------")
return False
if __name__ == "__main__":
mkdir(MAIN_FOLDER+"/infrastructure")
mkfile(MAIN_FOLDER+"/infrastructure/infra.pl", "")
print("Building applications...")
execute_cmd("docker-compose build", cwd=BASE_FOLDER)
print("Pushing application...")
execute_cmd("docker-compose push", cwd=BASE_FOLDER)
print("Application ready")
print("-------------------------------------------------------------")
print("*** TESTING SCENARIOS ***")
print("\nPlease, be sure that a registry is running and\nthe test service is pushed to it")
print("-------------------------------------------------------------")
execute_cmd("fogarmx watcher stop")
execute_cmd("fogarmx rm test")
time.sleep(10)
store_app(BASE_FOLDER)
scenarios = sorted(os.listdir(BASE_FOLDER+"/scenarios"))
for scenario in scenarios:
print("-------------------------------------------------------------")
print(f"*** Starting Scenario '{scenario}' ***")
print("-------------------------------------------------------------")
test_scenario(scenario)
execute_cmd("fogarmx rm test")
print("-------------------------------------------------------------")
if TOT != 0:
if PASSED == TOT:
print(f"RESULTS: {(PASSED/TOT)*100}% ({PASSED}/{TOT}) SUCCESS!")
else:
print(f"RESULTS: {(PASSED/TOT)*100}% ({PASSED}/{TOT}) SUCCESS")
print(f"FAILED SCENARIOS: {FAILED}")
else:
print("0 SCENARIOS TESTED")
print("-------------------------------------------------------------")