提交 69cf2a28 编写于 作者: B Brian Johnson

Changed to only create one wallet manager per test run. GH #5674

上级 458e1946
......@@ -100,8 +100,8 @@ class Cluster(object):
# pylint: disable=too-many-return-statements
# pylint: disable=too-many-branches
# pylint: disable=too-many-statements
def launch(self, pnodes=1, totalNodes=1, prodCount=1, topo="mesh", p2pPlugin="net", delay=1, onlyBios=False, dontKill=False
, dontBootstrap=False, totalProducers=None, extraNodeosArgs=None, useBiosBootFile=True, specificExtraNodeosArgs=None):
def launch(self, pnodes=1, totalNodes=1, prodCount=1, topo="mesh", p2pPlugin="net", delay=1, onlyBios=False, dontBootstrap=False,
totalProducers=None, extraNodeosArgs=None, useBiosBootFile=True, specificExtraNodeosArgs=None):
"""Launch cluster.
pnodes: producer nodes count
totalNodes: producer + non-producer nodes count
......@@ -348,14 +348,16 @@ class Cluster(object):
return True
Utils.Print("Bootstrap cluster.")
if self.walletMgr is None:
self.walletMgr=WalletMgr(True)
if onlyBios or not useBiosBootFile:
self.biosNode=Cluster.bootstrap(totalNodes, prodCount, totalProducers, Cluster.__BiosHost, Cluster.__BiosPort, dontKill, onlyBios)
self.biosNode=Cluster.bootstrap(totalNodes, prodCount, totalProducers, Cluster.__BiosHost, Cluster.__BiosPort, self.walletMgr, onlyBios)
if self.biosNode is None:
Utils.Print("ERROR: Bootstrap failed.")
return False
else:
self.useBiosBootFile=True
self.biosNode=Cluster.bios_bootstrap(totalNodes, Cluster.__BiosHost, Cluster.__BiosPort, dontKill)
self.biosNode=Cluster.bios_bootstrap(totalNodes, Cluster.__BiosHost, Cluster.__BiosPort, self.walletMgr)
if self.biosNode is None:
Utils.Print("ERROR: Bootstrap failed.")
return False
......@@ -839,7 +841,7 @@ class Cluster(object):
return producerKeys
@staticmethod
def bios_bootstrap(totalNodes, biosHost, biosPort, dontKill=False):
def bios_bootstrap(totalNodes, biosHost, biosPort, walletMgr):
"""Bootstrap cluster using the bios_boot.sh script generated by eosio-launcher."""
Utils.Print("Starting cluster bootstrap.")
......@@ -868,16 +870,14 @@ class Cluster(object):
Utils.Print("ERROR: Failed to parse private keys from cluster config files.")
return None
walletMgr=WalletMgr(True)
walletMgr.killall()
walletMgr.cleanup()
if not walletMgr.launch():
Utils.Print("ERROR: Failed to launch bootstrap wallet.")
return None
biosNode.setWalletEndpointArgs(walletMgr.walletEndpointArgs)
biosNode.setWalletEndpointArgs(walletMgr.getWalletEndpointArgs())
try:
ignWallet=walletMgr.create("ignition")
if ignWallet is None:
Utils.Print("ERROR: Failed to create ignition wallet.")
......@@ -919,15 +919,11 @@ class Cluster(object):
return None
Utils.Print("Cluster bootstrap done.")
finally:
if not dontKill:
walletMgr.killall()
walletMgr.cleanup()
return biosNode
@staticmethod
def bootstrap(totalNodes, prodCount, totalProducers, biosHost, biosPort, dontKill=False, onlyBios=False):
def bootstrap(totalNodes, prodCount, totalProducers, biosHost, biosPort, walletMgr, onlyBios=False):
"""Create 'prodCount' init accounts and deposits 10000000000 SYS in each. If prodCount is -1 will initialize all possible producers.
Ensure nodes are inter-connected prior to this call. One way to validate this will be to check if every node has block 1."""
......@@ -949,16 +945,14 @@ class Cluster(object):
Utils.Print("ERROR: Failed to parse %d producer keys from cluster config files, only found %d." % (totalProducers+1,len(producerKeys)))
return None
walletMgr=WalletMgr(True)
walletMgr.killall()
walletMgr.cleanup()
if not walletMgr.launch():
Utils.Print("ERROR: Failed to launch bootstrap wallet.")
return None
biosNode.setWalletEndpointArgs(walletMgr.walletEndpointArgs)
biosNode.setWalletEndpointArgs(walletMgr.getWalletEndpointArgs())
try:
ignWallet=walletMgr.create("ignition")
eosioName="eosio"
......@@ -1186,10 +1180,6 @@ class Cluster(object):
return None
Utils.Print("Cluster bootstrap done.")
finally:
if not dontKill:
walletMgr.killall()
walletMgr.cleanup()
return biosNode
......
......@@ -50,11 +50,12 @@ class Node(object):
self.lastRetrievedHeadBlockNum=None
self.lastRetrievedLIB=None
self.transCache={}
self.walletEndpointArgs=""
if self.enableMongo:
self.mongoEndpointArgs += "--host %s --port %d %s" % (mongoHost, mongoPort, mongoDb)
def eosClientArgs(self):
return self.endpointArgs + " " + self.miscEosClientArgs
return self.endpointArgs + self.walletEndpointArgs + " " + self.miscEosClientArgs
def __str__(self):
#return "Host: %s, Port:%d, Pid:%s, Cmd:\"%s\"" % (self.host, self.port, self.pid, self.cmd)
......@@ -227,7 +228,7 @@ class Node(object):
return arr.decode("utf-8")
def setWalletEndpointArgs(self, args):
self.endpointArgs="--url http://%s:%d %s" % (self.host, self.port, args)
self.walletEndpointArgs=args
def validateAccounts(self, accounts):
assert(accounts)
......
......@@ -25,17 +25,27 @@ class WalletMgr(object):
self.host=host
self.wallets={}
self.__walletPid=None
self.endpointArgs="--url http://%s:%d" % (self.nodeosHost, self.nodeosPort)
self.walletEndpointArgs=""
if self.walletd:
self.walletEndpointArgs += " --wallet-url http://%s:%d" % (self.host, self.port)
self.endpointArgs += self.walletEndpointArgs
def getWalletEndpointArgs(self):
if not self.walletd:
return ""
return " --wallet-url http://%s:%d" % (self.host, self.port)
def getEndpointArgs(self):
return " --url http://%s:%d%s" % (self.nodeosHost, self.nodeosPort, self.getWalletEndpointArgs())
def isLaunched(self):
return self.__walletPid is not None
def launch(self):
if not self.walletd:
Utils.Print("ERROR: Wallet Manager wasn't configured to launch keosd")
return False
if self.isLaunched():
return True
if Utils.Debug:
portStatus="N/A"
portTaken=False
......@@ -80,7 +90,7 @@ class WalletMgr(object):
return wallet
p = re.compile(r'\n\"(\w+)\"\n', re.MULTILINE)
cmdDesc="wallet create"
cmd="%s %s %s --name %s --to-console" % (Utils.EosClientPath, self.endpointArgs, cmdDesc, name)
cmd="%s %s %s --name %s --to-console" % (Utils.EosClientPath, self.getEndpointArgs(), cmdDesc, name)
if Utils.Debug: Utils.Print("cmd: %s" % (cmd))
retStr=None
maxRetryCount=4
......@@ -139,7 +149,7 @@ class WalletMgr(object):
def importKey(self, account, wallet, ignoreDupKeyWarning=False):
warningMsg="Key already in wallet"
cmd="%s %s wallet import --name %s --private-key %s" % (
Utils.EosClientPath, self.endpointArgs, wallet.name, account.ownerPrivateKey)
Utils.EosClientPath, self.getEndpointArgs(), wallet.name, account.ownerPrivateKey)
if Utils.Debug: Utils.Print("cmd: %s" % (cmd))
try:
Utils.checkOutput(cmd.split())
......@@ -156,7 +166,7 @@ class WalletMgr(object):
Utils.Print("WARNING: Active private key is not defined for account \"%s\"" % (account.name))
else:
cmd="%s %s wallet import --name %s --private-key %s" % (
Utils.EosClientPath, self.endpointArgs, wallet.name, account.activePrivateKey)
Utils.EosClientPath, self.getEndpointArgs(), wallet.name, account.activePrivateKey)
if Utils.Debug: Utils.Print("cmd: %s" % (cmd))
try:
Utils.checkOutput(cmd.split())
......@@ -173,7 +183,7 @@ class WalletMgr(object):
return True
def lockWallet(self, wallet):
cmd="%s %s wallet lock --name %s" % (Utils.EosClientPath, self.endpointArgs, wallet.name)
cmd="%s %s wallet lock --name %s" % (Utils.EosClientPath, self.getEndpointArgs(), wallet.name)
if Utils.Debug: Utils.Print("cmd: %s" % (cmd))
if 0 != subprocess.call(cmd.split(), stdout=Utils.FNull):
Utils.Print("ERROR: Failed to lock wallet %s." % (wallet.name))
......@@ -182,7 +192,7 @@ class WalletMgr(object):
return True
def unlockWallet(self, wallet):
cmd="%s %s wallet unlock --name %s" % (Utils.EosClientPath, self.endpointArgs, wallet.name)
cmd="%s %s wallet unlock --name %s" % (Utils.EosClientPath, self.getEndpointArgs(), wallet.name)
if Utils.Debug: Utils.Print("cmd: %s" % (cmd))
popen=subprocess.Popen(cmd.split(), stdout=Utils.FNull, stdin=subprocess.PIPE)
_, errs = popen.communicate(input=wallet.password.encode("utf-8"))
......@@ -193,7 +203,7 @@ class WalletMgr(object):
return True
def lockAllWallets(self):
cmd="%s %s wallet lock_all" % (Utils.EosClientPath, self.endpointArgs)
cmd="%s %s wallet lock_all" % (Utils.EosClientPath, self.getEndpointArgs())
if Utils.Debug: Utils.Print("cmd: %s" % (cmd))
if 0 != subprocess.call(cmd.split(), stdout=Utils.FNull):
Utils.Print("ERROR: Failed to lock all wallets.")
......@@ -205,7 +215,7 @@ class WalletMgr(object):
wallets=[]
p = re.compile(r'\s+\"(\w+)\s\*\",?\n', re.MULTILINE)
cmd="%s %s wallet list" % (Utils.EosClientPath, self.endpointArgs)
cmd="%s %s wallet list" % (Utils.EosClientPath, self.getEndpointArgs())
if Utils.Debug: Utils.Print("cmd: %s" % (cmd))
retStr=None
try:
......@@ -227,7 +237,7 @@ class WalletMgr(object):
keys=[]
p = re.compile(r'\n\s+\"(\w+)\"\n', re.MULTILINE)
cmd="%s %s wallet private_keys --name %s --password %s " % (Utils.EosClientPath, self.endpointArgs, wallet.name, wallet.password)
cmd="%s %s wallet private_keys --name %s --password %s " % (Utils.EosClientPath, self.getEndpointArgs(), wallet.name, wallet.password)
if Utils.Debug: Utils.Print("cmd: %s" % (cmd))
retStr=None
try:
......
......@@ -257,11 +257,6 @@ def myTest(transWillEnterBlock):
currencyAccount=accounts[0]
currencyAccount.name="currency0000"
Print("Stand up walletd")
if walletMgr.launch() is False:
error("Failed to stand up eos walletd.")
return False
testWalletName="test"
Print("Creating wallet \"%s\"." % (testWalletName))
testWallet=walletMgr.create(testWalletName)
......
......@@ -47,11 +47,15 @@ try:
if not cluster.initializeNodesFromJson(jsonStr):
errorExit("Failed to initilize nodes from Json string.")
total_nodes=len(cluster.getNodes())
walletMgr.killall(allInstances=killAll)
walletMgr.cleanup()
print("Stand up walletd")
if walletMgr.launch() is False:
errorExit("Failed to stand up keosd.")
else:
cluster.killall(allInstances=killAll)
cluster.cleanup()
walletMgr.killall(allInstances=killAll)
walletMgr.cleanup()
Print ("producing nodes: %s, non-producing nodes: %d, topology: %s, delay between nodes launch(seconds): %d" %
(pnodes, total_nodes-pnodes, topo, delay))
......@@ -65,12 +69,6 @@ try:
if not cluster.waitOnClusterBlockNumSync(3):
errorExit("Cluster never stabilized")
Print("Stand up EOS wallet keosd")
walletMgr.killall(allInstances=killAll)
walletMgr.cleanup()
if walletMgr.launch() is False:
errorExit("Failed to stand up keosd.")
accountsCount=total_nodes
walletName="MyWallet-%d" % (random.randrange(10000))
Print("Creating wallet %s if one doesn't already exist." % walletName)
......
......@@ -46,20 +46,26 @@ Utils.setIrreversibleTimeout(timeout)
try:
TestHelper.printSystemInfo("BEGIN")
walletMgr.killall(allInstances=killAll)
walletMgr.cleanup()
cluster.setWalletMgr(walletMgr)
if not dontLaunch:
cluster.killall(allInstances=killAll)
cluster.cleanup()
Print("Stand up cluster")
if cluster.launch(pnodes=4, dontKill=dontKill, p2pPlugin=p2pPlugin) is False:
if cluster.launch(pnodes=4, p2pPlugin=p2pPlugin) is False:
cmdError("launcher")
errorExit("Failed to stand up eos cluster.")
else:
walletMgr.killall(allInstances=killAll)
walletMgr.cleanup()
cluster.initializeNodes(defproduceraPrvtKey=defproduceraPrvtKey)
killEosInstances=False
print("Stand up walletd")
if walletMgr.launch() is False:
cmdError("%s" % (WalletdName))
errorExit("Failed to stand up eos walletd.")
Print("Validating system accounts after bootstrap")
cluster.validateAccounts(None)
......@@ -86,13 +92,6 @@ try:
exchangeAccount.ownerPrivateKey=PRV_KEY2
exchangeAccount.ownerPublicKey=PUB_KEY2
Print("Stand up %s" % (WalletdName))
walletMgr.killall(allInstances=killAll)
walletMgr.cleanup()
if walletMgr.launch() is False:
cmdError("%s" % (WalletdName))
errorExit("Failed to stand up eos walletd.")
testWalletName="test"
Print("Creating wallet \"%s\"." % (testWalletName))
testWallet=walletMgr.create(testWalletName, [cluster.eosioAccount,cluster.defproduceraAccount])
......
......@@ -128,6 +128,7 @@ ClientName="cleos"
try:
TestHelper.printSystemInfo("BEGIN")
cluster.setWalletMgr(walletMgr)
cluster.killall(allInstances=killAll)
cluster.cleanup()
Print("Stand up cluster")
......@@ -141,7 +142,7 @@ try:
# "bridge" shape connects defprocera through defproducerk (in node0) to each other and defproducerl through defproduceru (in node01)
# and the only connection between those 2 groups is through the bridge node
if cluster.launch(prodCount=prodCount, onlyBios=False, dontKill=dontKill, topo="bridge", pnodes=totalProducerNodes,
if cluster.launch(prodCount=prodCount, onlyBios=False, topo="bridge", pnodes=totalProducerNodes,
totalNodes=totalNodes, totalProducers=totalProducers, p2pPlugin=p2pPlugin,
useBiosBootFile=False, specificExtraNodeosArgs=specificExtraNodeosArgs) is False:
Utils.cmdError("launcher")
......@@ -164,12 +165,6 @@ try:
testWalletName="test"
Print("Creating wallet \"%s\"." % (testWalletName))
walletMgr.killall(allInstances=killAll)
walletMgr.cleanup()
if walletMgr.launch() is False:
Utils.cmdError("%s" % (WalletdName))
Utils.errorExit("Failed to stand up eos walletd.")
testWallet=walletMgr.create(testWalletName, [cluster.eosioAccount,accounts[0],accounts[1],accounts[2],accounts[3],accounts[4]])
for _, account in cluster.defProducerAccounts.items():
......
......@@ -42,7 +42,7 @@ try:
Print ("producing nodes: %s, non-producing nodes: %d, topology: %s, delay between nodes launch(seconds): %d" %
(pnodes, total_nodes-pnodes, topo, delay))
Print("Stand up cluster")
if cluster.launch(pnodes, total_nodes, prodCount, topo, delay, onlyBios=onlyBios, dontKill=dontKill) is False:
if cluster.launch(pnodes, total_nodes, prodCount, topo, delay, onlyBios=onlyBios) is False:
errorExit("Failed to stand up eos cluster.")
Print ("Wait for Cluster stabilization")
......
......@@ -55,25 +55,30 @@ Utils.setIrreversibleTimeout(timeout)
try:
TestHelper.printSystemInfo("BEGIN")
cluster.setWalletMgr(walletMgr)
Print("SERVER: %s" % (server))
Print("PORT: %d" % (port))
if enableMongo and not cluster.isMongodDbRunning():
errorExit("MongoDb doesn't seem to be running.")
walletMgr.killall(allInstances=killAll)
walletMgr.cleanup()
if localTest and not dontLaunch:
cluster.killall(allInstances=killAll)
cluster.cleanup()
Print("Stand up cluster")
if cluster.launch(prodCount=prodCount, onlyBios=onlyBios, dontKill=dontKill, dontBootstrap=dontBootstrap, p2pPlugin=p2pPlugin) is False:
if cluster.launch(prodCount=prodCount, onlyBios=onlyBios, dontBootstrap=dontBootstrap, p2pPlugin=p2pPlugin) is False:
cmdError("launcher")
errorExit("Failed to stand up eos cluster.")
else:
cluster.initializeNodes(defproduceraPrvtKey=defproduceraPrvtKey, defproducerbPrvtKey=defproducerbPrvtKey)
killEosInstances=False
Print("Stand up %s" % (WalletdName))
walletMgr.killall(allInstances=killAll)
walletMgr.cleanup()
print("Stand up walletd")
if walletMgr.launch() is False:
cmdError("%s" % (WalletdName))
errorExit("Failed to stand up eos walletd.")
if sanityTest:
testSuccessful=True
......@@ -105,13 +110,6 @@ try:
exchangeAccount.ownerPrivateKey=PRV_KEY2
exchangeAccount.ownerPublicKey=PUB_KEY2
Print("Stand up %s" % (WalletdName))
walletMgr.killall(allInstances=killAll)
walletMgr.cleanup()
if walletMgr.launch() is False:
cmdError("%s" % (WalletdName))
errorExit("Failed to stand up eos walletd.")
testWalletName="test"
Print("Creating wallet \"%s\"." % (testWalletName))
testWallet=walletMgr.create(testWalletName, [cluster.eosioAccount,cluster.defproduceraAccount,cluster.defproducerbAccount])
......
......@@ -73,6 +73,7 @@ ClientName="cleos"
try:
TestHelper.printSystemInfo("BEGIN")
cluster.setWalletMgr(walletMgr)
cluster.killall(allInstances=killAll)
cluster.cleanup()
......@@ -82,7 +83,7 @@ try:
maxRAMFlag="--chain-state-db-size-mb"
maxRAMValue=1010
extraNodeosArgs=" %s %d %s %d " % (minRAMFlag, minRAMValue, maxRAMFlag, maxRAMValue)
if cluster.launch(onlyBios=False, dontKill=dontKill, pnodes=totalNodes, totalNodes=totalNodes, totalProducers=totalNodes, extraNodeosArgs=extraNodeosArgs, useBiosBootFile=False) is False:
if cluster.launch(onlyBios=False, pnodes=totalNodes, totalNodes=totalNodes, totalProducers=totalNodes, extraNodeosArgs=extraNodeosArgs, useBiosBootFile=False) is False:
Utils.cmdError("launcher")
errorExit("Failed to stand up eos cluster.")
......@@ -96,12 +97,6 @@ try:
testWalletName="test"
Print("Creating wallet \"%s\"." % (testWalletName))
walletMgr.killall(allInstances=killAll)
walletMgr.cleanup()
if walletMgr.launch() is False:
Utils.cmdError("%s" % (WalletdName))
errorExit("Failed to stand up eos walletd.")
testWallet=walletMgr.create(testWalletName, [cluster.eosioAccount])
for _, account in cluster.defProducerAccounts.items():
......
......@@ -161,11 +161,12 @@ ClientName="cleos"
try:
TestHelper.printSystemInfo("BEGIN")
cluster.setWalletMgr(walletMgr)
cluster.killall(allInstances=killAll)
cluster.cleanup()
Print("Stand up cluster")
if cluster.launch(prodCount=prodCount, onlyBios=False, dontKill=dontKill, pnodes=totalNodes, totalNodes=totalNodes, totalProducers=totalNodes*21, p2pPlugin=p2pPlugin, useBiosBootFile=False) is False:
if cluster.launch(prodCount=prodCount, onlyBios=False, pnodes=totalNodes, totalNodes=totalNodes, totalProducers=totalNodes*21, p2pPlugin=p2pPlugin, useBiosBootFile=False) is False:
Utils.cmdError("launcher")
Utils.errorExit("Failed to stand up eos cluster.")
......@@ -184,12 +185,6 @@ try:
testWalletName="test"
Print("Creating wallet \"%s\"." % (testWalletName))
walletMgr.killall(allInstances=killAll)
walletMgr.cleanup()
if walletMgr.launch() is False:
Utils.cmdError("%s" % (WalletdName))
Utils.errorExit("Failed to stand up eos walletd.")
testWallet=walletMgr.create(testWalletName, [cluster.eosioAccount,accounts[0],accounts[1],accounts[2],accounts[3],accounts[4]])
for _, account in cluster.defProducerAccounts.items():
......
......@@ -52,6 +52,7 @@ walletMgr=WalletMgr(True)
try:
TestHelper.printSystemInfo("BEGIN")
cluster.setWalletMgr(walletMgr)
cluster.setChainStrategy(chainSyncStrategyStr)
cluster.setWalletMgr(walletMgr)
......@@ -74,11 +75,6 @@ try:
errorExit("Cluster never stabilized")
Print("Stand up EOS wallet keosd")
walletMgr.killall(allInstances=killAll)
walletMgr.cleanup()
if walletMgr.launch() is False:
errorExit("Failed to stand up keosd.")
accountsCount=total_nodes
walletName="MyWallet"
Print("Creating wallet %s if one doesn't already exist." % walletName)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册