Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.2] Cleanup regression python test handling of CalledProcessError #214

Merged
merged 2 commits into from
Sep 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions tests/TestHarness/Cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ def getClientVersion(fullVersion=False):
verStr=m.group(1)
return verStr
except subprocess.CalledProcessError as ex:
msg=ex.output.decode("utf-8")
msg=ex.stderr.decode("utf-8")
Utils.Print("ERROR: Exception during client version query. %s" % (msg))
raise

Expand Down Expand Up @@ -666,7 +666,7 @@ def createAccountKeys(count):
if Utils.Debug: Utils.Print("name: %s, key(owner): ['%s', '%s], key(active): ['%s', '%s']" % (name, ownerPublic, ownerPrivate, activePublic, activePrivate))

except subprocess.CalledProcessError as ex:
msg=ex.output.decode("utf-8")
msg=ex.stderr.decode("utf-8")
Utils.Print("ERROR: Exception during key creation. %s" % (msg))
break

Expand Down Expand Up @@ -1353,7 +1353,7 @@ def myFunc():
psOut=Utils.checkOutput(cmd.split())
return psOut
except subprocess.CalledProcessError as ex:
msg=ex.output.decode("utf-8")
msg=ex.stderr.decode("utf-8")
Utils.Print("ERROR: call of \"%s\" failed. %s" % (cmd, msg))
return None
return None
Expand Down
22 changes: 10 additions & 12 deletions tests/TestHarness/Node.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def stdinAndCheckOutput(cmd, subcommand):
outs,errs=popen.communicate(input=subcommand.encode("utf-8"))
ret=popen.wait()
except subprocess.CalledProcessError as ex:
msg=ex.output
msg=ex.stderr
return (ex.returncode, msg, None)

return (ret, outs, errs)
Expand Down Expand Up @@ -580,7 +580,7 @@ def transferFunds(self, source, destination, amountStr, memo="memo", force=False
self.trackCmdTransaction(trans, reportStatus=reportStatus)
except subprocess.CalledProcessError as ex:
end=time.perf_counter()
msg=ex.output.decode("utf-8")
msg=ex.stderr.decode("utf-8")
Utils.Print("ERROR: Exception during funds transfer. cmd Duration: %.3f sec. %s" % (end-start, msg))
if exitOnError:
Utils.cmdError("could not transfer \"%s\" from %s to %s" % (amountStr, source, destination))
Expand All @@ -604,7 +604,7 @@ def transferFundsAsync(self, source, destination, amountStr, memo="memo", force=
Utils.Print("cmd Duration: %.3f sec" % (end-start))
except subprocess.CalledProcessError as ex:
end=time.perf_counter()
msg=ex.output.decode("utf-8")
msg=ex.stderr.decode("utf-8")
Utils.Print("ERROR: Exception during spawn of funds transfer. cmd Duration: %.3f sec. %s" % (end-start, msg))
if exitOnError:
Utils.cmdError("could not transfer \"%s\" from %s to %s" % (amountStr, source, destination))
Expand Down Expand Up @@ -764,7 +764,7 @@ def getAccountCodeHash(self, account):
return m.group(1)
except subprocess.CalledProcessError as ex:
end=time.perf_counter()
msg=ex.output.decode("utf-8")
msg=ex.stderr.decode("utf-8")
Utils.Print("ERROR: Exception during code hash retrieval. cmd Duration: %.3f sec. %s" % (end-start, msg))
return None

Expand All @@ -786,17 +786,15 @@ def publishContract(self, account, contractDir, wasmFile, abiFile, waitForTransB
except subprocess.CalledProcessError as ex:
if not shouldFail:
end=time.perf_counter()
msg=ex.output.decode("utf-8")
msg=ex.stderr.decode("utf-8")
Utils.Print("ERROR: Exception during set contract. cmd Duration: %.3f sec. %s" % (end-start, msg))
return None
else:
retMap={}
retMap["returncode"]=ex.returncode
retMap["cmd"]=ex.cmd
retMap["output"]=ex.output
# commented below as they are available only in Python3.5 and above
# retMap["stdout"]=ex.stdout
# retMap["stderr"]=ex.stderr
retMap["stderr"]=ex.stderr
return retMap

if shouldFail:
Expand Down Expand Up @@ -865,7 +863,7 @@ def pushTransaction(self, trans, opts="", silentErrors=False, permissions=None):
Utils.Print("cmd Duration: %.3f sec" % (end-start))
return (Node.getTransStatus(retTrans) == 'executed', retTrans)
except subprocess.CalledProcessError as ex:
msg=ex.output.decode("utf-8")
msg=ex.stderr.decode("utf-8")
if not silentErrors:
end=time.perf_counter()
Utils.Print("ERROR: Exception during push transaction. cmd Duration=%.3f sec. %s" % (end - start, msg))
Expand Down Expand Up @@ -893,7 +891,7 @@ def pushMessage(self, account, action, data, opts, silentErrors=False, signature
Utils.Print("cmd Duration: %.3f sec" % (end-start))
return (Node.getTransStatus(trans) == 'executed' if expectTrxTrace else True, trans)
except subprocess.CalledProcessError as ex:
msg=ex.output.decode("utf-8")
msg=ex.stderr.decode("utf-8")
if not silentErrors:
end=time.perf_counter()
Utils.Print("ERROR: Exception during push message. cmd Duration=%.3f sec. %s" % (end - start, msg))
Expand Down Expand Up @@ -994,7 +992,7 @@ def processCleosCmd(self, cmd, cmdDesc, silentErrors=True, exitOnError=False, ex
except subprocess.CalledProcessError as ex:
if not silentErrors:
end=time.perf_counter()
msg=ex.output.decode("utf-8")
msg=ex.stderr.decode("utf-8")
errorMsg="Exception during \"%s\". Exception message: %s. cmd Duration=%.3f sec. %s" % (cmdDesc, msg, end-start, exitMsg)
if exitOnError:
Utils.cmdError(errorMsg)
Expand Down Expand Up @@ -1040,7 +1038,7 @@ def processCurlCmd(self, resource, command, payload, silentErrors=True, exitOnEr
except subprocess.CalledProcessError as ex:
if not silentErrors:
end=time.perf_counter()
msg=ex.output.decode("utf-8")
msg=ex.stderr.decode("utf-8")
errorMsg="Exception during \"%s\". %s. cmd Duration=%.3f sec." % (cmd, msg, end-start)
if exitOnError:
Utils.cmdError(errorMsg)
Expand Down
12 changes: 7 additions & 5 deletions tests/TestHarness/WalletMgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ def launch(self):
psOut=Utils.checkOutput(pgrepCmd.split())
if Utils.Debug: Utils.Print("Launched %s. {%s}" % (Utils.EosWalletName, psOut))
except subprocess.CalledProcessError as ex:
Utils.Print(f"STDOUT: {ex.output}")
Utils.Print(f"STDERR: {ex.stderr}")
Utils.errorExit("Failed to launch the wallet manager")

return True
Expand Down Expand Up @@ -131,7 +133,7 @@ def create(self, name, accounts=None, exitOnError=True):
time.sleep(delay)
continue

msg=ex.output.decode("utf-8")
msg=ex.stderr.decode("utf-8")
errorMsg="ERROR: Failed to create wallet - %s. %s" % (name, msg)
if exitOnError:
Utils.errorExit("%s" % (errorMsg))
Expand Down Expand Up @@ -170,7 +172,7 @@ def importKey(self, account, wallet, ignoreDupKeyWarning=False):
try:
Utils.checkOutput(cmd.split())
except subprocess.CalledProcessError as ex:
msg=ex.output.decode("utf-8")
msg=ex.stderr.decode("utf-8")
if warningMsg in msg:
if not ignoreDupKeyWarning:
Utils.Print("WARNING: This key is already imported into the wallet.")
Expand All @@ -187,7 +189,7 @@ def importKey(self, account, wallet, ignoreDupKeyWarning=False):
try:
Utils.checkOutput(cmd.split())
except subprocess.CalledProcessError as ex:
msg=ex.output.decode("utf-8")
msg=ex.stderr.decode("utf-8")
if warningMsg in msg:
if not ignoreDupKeyWarning:
Utils.Print("WARNING: This key is already imported into the wallet.")
Expand Down Expand Up @@ -237,7 +239,7 @@ def getOpenWallets(self):
try:
retStr=Utils.checkOutput(cmd.split())
except subprocess.CalledProcessError as ex:
msg=ex.output.decode("utf-8")
msg=ex.stderr.decode("utf-8")
Utils.Print("ERROR: Failed to open wallets. %s" % (msg))
return False

Expand All @@ -259,7 +261,7 @@ def getKeys(self, wallet):
try:
retStr=Utils.checkOutput(cmd.split())
except subprocess.CalledProcessError as ex:
msg=ex.output.decode("utf-8")
msg=ex.stderr.decode("utf-8")
Utils.Print("ERROR: Failed to get keys. %s" % (msg))
return False
m=p.findall(retStr)
Expand Down
6 changes: 2 additions & 4 deletions tests/TestHarness/testUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,7 @@ def checkDelayedOutput(popen, cmd, ignoreError=False):
(output,error)=popen.communicate()
Utils.checkOutputFileWrite(start, cmd, output, error)
if popen.returncode != 0 and not ignoreError:
Utils.Print("ERROR: %s" % error)
# for now just include both stderr and stdout in output, python 3.5+ supports both a stdout and stderr attributes
raise subprocess.CalledProcessError(returncode=popen.returncode, cmd=cmd, output=error+bytes(" ", 'utf-8')+output)
raise subprocess.CalledProcessError(returncode=popen.returncode, cmd=cmd, output=output, stderr=error)
return output.decode("utf-8")

@staticmethod
Expand Down Expand Up @@ -397,7 +395,7 @@ def getBlockLog(blockLogLocation, blockLogAction=BlockLogAction.return_blocks, o
if throwException:
raise
if not silentErrors:
msg=ex.output.decode("utf-8")
msg=ex.stderr.decode("utf-8")
errorMsg="Exception during \"%s\". %s" % (cmd, msg)
if exitOnError:
Utils.cmdError(errorMsg)
Expand Down
6 changes: 4 additions & 2 deletions tests/cli_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ def cleos_sign_test():
outs,errs=popen.communicate()
popen.wait()
except subprocess.CalledProcessError as ex:
print(ex.output)
print(f"STDOUT: {ex.output}")
print(f"STDERR: {ex.stderr}")
# make sure fields are unpacked
assert(b'"expiration": "2019-08-01T07:15:49"' in errs)
assert(b'"ref_block_num": 34881' in errs)
Expand All @@ -145,7 +146,8 @@ def processCleosCommand(cmd):
outs, errs = popen.communicate()
popen.wait()
except subprocess.CalledProcessError as ex:
print(ex.output)
print(f"STDOUT: {ex.output}")
print(f"STDERR: {ex.stderr}")
return outs, errs

def cleos_abi_file_test():
Expand Down