-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.py
More file actions
121 lines (100 loc) · 3.4 KB
/
main.py
File metadata and controls
121 lines (100 loc) · 3.4 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import p2p
import common.test as t
import sys
# ParseCommand will try to parse arguments provided to an app
# if no arguments provided it will output help message and return non-zero status code
def ParseCommand(cmd, args):
if cmd == 'help':
ShowHelp()
return 1
if cmd == 'list':
List(args)
return 0
if cmd == 'run':
Run(args)
return 0
ShowHelp()
return 1
# ShowHelp prints help message to stdout
def ShowHelp():
print("Subutai Guardian\n")
print("Available commands:")
print("\thelp")
print("\t\tshow this help screen")
print("\tlist")
print("\t\tlist available components and tests if component name specified")
print("\trun")
print("\t\trun all tests. You can specify component name to run only specific component or component.test to run specific test")
return 0
# List is an entry point for `list` argument
def List(args):
if len(args) > 0:
ListComponentTests(args[0])
else:
ListComponents()
# ListComponents will print list of all components registered
def ListComponents():
components = []
print("Available components:")
for n, test in t.TestList.items():
exists = False
for c in components:
if c == test.GetComponent():
exists = True
break
if exists == False:
components.append(test.GetComponent())
print("\t" + test.GetComponent())
return 0
# LIstComponentTests will output list of tests within provided component to stdout
def ListComponentTests(component):
print("Available tests in " + component + ":")
for n, test in t.TestList.items():
if test.GetComponent() == component:
print("\t" + test.GetName())
return 0
# EchoTest will send an informing line to stdout without EOL
def EchoTest(name):
print("Running " + name + "\t", end="", flush=True)
# Run function will start test execution
# If no arguments provided all registered tests will be executed
# If a single word provided it's considered as a component name
# If argument provided in form of componentName.testName a specific test will be executed
def Run(args):
componentName = ''
testName = ''
# When argument provided we consider it to be component name (single word)
# or specific test name in a form of componaneName.testName
if len(args) > 0:
if args[0].find(".") > 0:
r = args[0].split(".")
if len(r) != 2:
print("Wrong format for run: " + args[0])
print("Specify component name or test name in a form componentName.testName")
return 4
componentName = r[0]
testName = r[1]
else:
componentName = args[0]
for name, test in t.TestList.items():
if componentName != "" and test.GetComponent() != componentName:
continue
if testName != "" and test.GetName() != testName:
continue
EchoTest(name)
test.Result(test.Start())
if test.GetStatus() == t.TestStatus.succeed:
print("[OK]")
elif test.GetStatus() == t.TestStatus.failed:
print("[Failed]")
else:
print("[Error]")
return 0
# Entry point
if len(sys.argv) > 1:
rc = ParseCommand(sys.argv[1], sys.argv[2:])
if rc != 0:
sys.exit(rc)
else:
ShowHelp()
sys.exit(1)