lfcli_base.py: attempt to improve error capture and reporting

This commit is contained in:
Jed Reynolds
2020-06-03 15:31:14 -07:00
parent fac2d4b2c1
commit f2c1e71281

View File

@@ -4,7 +4,8 @@
from pprint import pprint
import LANforge.LFUtils
from LANforge.LFUtils import *
import traceback
from traceback import extract_stack
class LFCliBase:
# do not use `super(LFCLiBase,self).__init__(self, host, port, _debugOn)
@@ -17,6 +18,10 @@ class LFCliBase:
self.mgr_url = "http://%s:%s/" % (self.lfjson_host, self.lfjson_port)
def jsonPost(self, _req_url, _data):
json_response = None
if self.mgr_url.endswith('/') and _req_url.startswith('/'):
_req_url = _req_url[1:]
try:
lf_r = LFRequest.LFRequest(self.mgr_url + _req_url)
_data['suppress_preexec_cli'] = True
_data['suppress_preexec_method'] = True
@@ -24,6 +29,11 @@ class LFCliBase:
if (self.debugOn):
LANforge.LFUtils.debug_printer.pprint(_data)
json_response = lf_r.jsonPost(self.debugOn)
except Exception as x:
print(f"jsonPost posted to {_req_url}")
pprint(_data)
print(x.__traceback__)
# Debugging
# if (json_response != None):
# print("jsonReq: response: ")
@@ -31,8 +41,18 @@ class LFCliBase:
return json_response
def jsonGet(self, _req_url):
json_response = None
if self.mgr_url.endswith('/') and _req_url.startswith('/'):
_req_url = _req_url[1:]
try:
lf_r = LFRequest.LFRequest(self.mgr_url + _req_url)
json_response = lf_r.getAsJson(self.debugOn)
if (json_response is None) and self.debugOn:
raise ValueError(json_response)
except ValueError as ve:
print("jsonGet asked for "+_req_url)
print(ve.__traceback__)
return json_response
def checkConnect(self):