Repository navigation
Expand file tree
/
Copy pathTestHelper.py
More file actions
195 lines (174 loc) · 9.66 KB
/
Copy pathTestHelper.py
File metadata and controls
195 lines (174 loc) · 9.66 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
from testUtils import Utils
from Cluster import Cluster
from WalletMgr import WalletMgr
from datetime import datetime
import platform
import argparse
class AppArgs:
def __init__(self):
self.args=[]
class AppArg:
def __init__(self, flag, help, type=None, default=None, choices=None, action=None):
self.flag=flag
self.type=type
self.help=help
self.default=default
self.choices=choices
self.action=action
def add(self, flag, type, help, default, choices=None):
arg=self.AppArg(flag, help, type=type, default=default, choices=choices)
self.args.append(arg)
def add_bool(self, flag, help, action='store_true'):
arg=self.AppArg(flag, help, action=action)
self.args.append(arg)
# pylint: disable=too-many-instance-attributes
class TestHelper(object):
LOCAL_HOST="localhost"
DEFAULT_PORT=8888
DEFAULT_WALLET_PORT=9899
@staticmethod
# pylint: disable=too-many-branches
# pylint: disable=too-many-statements
def parse_args(includeArgs, applicationSpecificArgs=AppArgs()):
"""Accepts set of arguments, builds argument parser and returns parse_args() output."""
assert(includeArgs)
assert(isinstance(includeArgs, set))
assert(isinstance(applicationSpecificArgs, AppArgs))
parser = argparse.ArgumentParser(add_help=False)
parser.add_argument('-?', action='help', default=argparse.SUPPRESS,
help=argparse._('show this help message and exit'))
if "-p" in includeArgs:
parser.add_argument("-p", type=int, help="producing nodes count", default=1)
if "-n" in includeArgs:
parser.add_argument("-n", type=int, help="total nodes", default=0)
if "-d" in includeArgs:
parser.add_argument("-d", type=int, help="delay between nodes startup", default=1)
if "--nodes-file" in includeArgs:
parser.add_argument("--nodes-file", type=str, help="File containing nodes info in JSON format.")
if "-s" in includeArgs:
parser.add_argument("-s", type=str, help="topology", choices=["mesh"], default="mesh")
if "-c" in includeArgs:
parser.add_argument("-c", type=str, help="chain strategy",
choices=[Utils.SyncResyncTag, Utils.SyncReplayTag, Utils.SyncNoneTag, Utils.SyncHardReplayTag],
default=Utils.SyncResyncTag)
if "--kill-sig" in includeArgs:
parser.add_argument("--kill-sig", type=str, choices=[Utils.SigKillTag, Utils.SigTermTag], help="kill signal.",
default=Utils.SigKillTag)
if "--kill-count" in includeArgs:
parser.add_argument("--kill-count", type=int, help="nodeos instances to kill", default=-1)
if "--terminate-at-block" in includeArgs:
parser.add_argument("--terminate-at-block", type=int, help="block to terminate on when replaying", default=0)
if "--seed" in includeArgs:
parser.add_argument("--seed", type=int, help="random seed", default=1)
if "--host" in includeArgs:
parser.add_argument("-h", "--host", type=str, help="%s host name" % (Utils.EosServerName),
default=TestHelper.LOCAL_HOST)
if "--port" in includeArgs:
parser.add_argument("--port", type=int, help="%s host port" % Utils.EosServerName,
default=TestHelper.DEFAULT_PORT)
if "--wallet-host" in includeArgs:
parser.add_argument("--wallet-host", type=str, help="%s host" % Utils.EosWalletName,
default=TestHelper.LOCAL_HOST)
if "--wallet-port" in includeArgs:
parser.add_argument("--wallet-port", type=int, help="%s port" % Utils.EosWalletName,
default=TestHelper.DEFAULT_WALLET_PORT)
if "--amqp-address" in includeArgs:
parser.add_argument("--amqp-address", type=str, help="AMQP address.")
if "--prod-count" in includeArgs:
parser.add_argument("-c", "--prod-count", type=int, help="Per node producer count", default=1)
if "--defproducera_prvt_key" in includeArgs:
parser.add_argument("--defproducera_prvt_key", type=str, help="defproducera private key.")
if "--defproducerb_prvt_key" in includeArgs:
parser.add_argument("--defproducerb_prvt_key", type=str, help="defproducerb private key.")
if "--dump-error-details" in includeArgs:
parser.add_argument("--dump-error-details",
help="Upon error print etc/eosio/node_*/config.ini and var/lib/node_*/stderr.log to stdout",
action='store_true')
if "--dont-launch" in includeArgs:
parser.add_argument("--dont-launch", help="Don't launch own node. Assume node is already running.",
action='store_true')
if "--keep-logs" in includeArgs:
parser.add_argument("--keep-logs", help="Don't delete var/lib/node_* folders upon test completion",
action='store_true')
if "-v" in includeArgs:
parser.add_argument("-v", help="verbose logging", action='store_true')
if "--leave-running" in includeArgs:
parser.add_argument("--leave-running", help="Leave cluster running after test finishes", action='store_true')
if "--only-bios" in includeArgs:
parser.add_argument("--only-bios", help="Limit testing to bios node.", action='store_true')
if "--clean-run" in includeArgs:
parser.add_argument("--clean-run", help="Kill all nodeos and kleos instances", action='store_true')
if "--sanity-test" in includeArgs:
parser.add_argument("--sanity-test", help="Validates nodeos and kleos are in path and can be started up.", action='store_true')
if "--alternate-version-labels-file" in includeArgs:
parser.add_argument("--alternate-version-labels-file", type=str, help="Provide a file to define the labels that can be used in the test and the path to the version installation associated with that.")
if "--signing-delay" in includeArgs:
parser.add_argument("--signing-delay", type=int, help="signing delay in milliseconds", default=0)
if "--disconnect-leader" in includeArgs:
parser.add_argument("--disconnect-leader", help="disconnect/kill leader in producerpha cluster", action='store_true')
for arg in applicationSpecificArgs.args:
if arg.type is not None:
parser.add_argument(arg.flag, type=arg.type, help=arg.help, choices=arg.choices, default=arg.default)
else:
parser.add_argument(arg.flag, help=arg.help, action=arg.action)
args = parser.parse_args()
return args
@staticmethod
def printSystemInfo(prefix):
"""Print system information to stdout. Print prefix first."""
if prefix:
Utils.Print(str(prefix))
clientVersion=Cluster.getClientVersion()
Utils.Print("UTC time: %s" % str(datetime.utcnow()))
Utils.Print("EOS Client version: %s" % (clientVersion))
Utils.Print("Processor: %s" % (platform.processor()))
Utils.Print("OS name: %s" % (platform.platform()))
@staticmethod
# pylint: disable=too-many-arguments
def shutdown(cluster, walletMgr, testSuccessful=True, killEosInstances=True, killWallet=True, keepLogs=False, cleanRun=True, dumpErrorDetails=False):
"""Cluster and WalletMgr shutdown and cleanup."""
assert(cluster)
assert(isinstance(cluster, Cluster))
if walletMgr:
assert(isinstance(walletMgr, WalletMgr))
assert(isinstance(testSuccessful, bool))
assert(isinstance(killEosInstances, bool))
assert(isinstance(killWallet, bool))
assert(isinstance(cleanRun, bool))
assert(isinstance(dumpErrorDetails, bool))
Utils.ShuttingDown=True
if testSuccessful:
Utils.Print("Test succeeded.")
else:
Utils.Print("Test failed.")
def reportProductionAnalysis(thresholdMs):
Utils.Print(Utils.FileDivider)
for node in cluster.getAllNodes():
missedBlocks=node.analyzeProduction(thresholdMs=thresholdMs)
if len(missedBlocks) > 0:
Utils.Print("NodeId: %s produced the following blocks late: %s" % (node.nodeId, missedBlocks))
if not testSuccessful and dumpErrorDetails:
cluster.reportStatus()
Utils.Print(Utils.FileDivider)
psOut = Cluster.pgrepEosServers(timeout=60)
Utils.Print("pgrep output:\n%s" % (psOut))
reportProductionAnalysis(thresholdMs=0)
Utils.Print("== Errors see above ==")
elif dumpErrorDetails:
# for now report these to know how many blocks we are missing production windows for
reportProductionAnalysis(thresholdMs=200)
if killEosInstances:
Utils.Print("Shut down the cluster.")
cluster.killall(allInstances=cleanRun, kill=testSuccessful)
if testSuccessful and not keepLogs:
Utils.Print("Cleanup cluster data.")
cluster.cleanup()
if walletMgr and killWallet:
Utils.Print("Shut down the wallet.")
walletMgr.killall(allInstances=cleanRun)
if testSuccessful and not keepLogs:
Utils.Print("Cleanup wallet data.")
walletMgr.cleanup()
if Utils.checkOutputFile is not None:
Utils.checkOutputFile.close()
Utils.checkOutputFile = None