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 from pprint import pprint
import LANforge.LFUtils import LANforge.LFUtils
from LANforge.LFUtils import * from LANforge.LFUtils import *
import traceback
from traceback import extract_stack
class LFCliBase: class LFCliBase:
# do not use `super(LFCLiBase,self).__init__(self, host, port, _debugOn) # do not use `super(LFCLiBase,self).__init__(self, host, port, _debugOn)
@@ -17,13 +18,22 @@ class LFCliBase:
self.mgr_url = "http://%s:%s/" % (self.lfjson_host, self.lfjson_port) self.mgr_url = "http://%s:%s/" % (self.lfjson_host, self.lfjson_port)
def jsonPost(self, _req_url, _data): def jsonPost(self, _req_url, _data):
lf_r = LFRequest.LFRequest(self.mgr_url + _req_url) json_response = None
_data['suppress_preexec_cli'] = True if self.mgr_url.endswith('/') and _req_url.startswith('/'):
_data['suppress_preexec_method'] = True _req_url = _req_url[1:]
lf_r.addPostData(_data) try:
if (self.debugOn): lf_r = LFRequest.LFRequest(self.mgr_url + _req_url)
LANforge.LFUtils.debug_printer.pprint(_data) _data['suppress_preexec_cli'] = True
json_response = lf_r.jsonPost(self.debugOn) _data['suppress_preexec_method'] = True
lf_r.addPostData(_data)
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 # Debugging
# if (json_response != None): # if (json_response != None):
# print("jsonReq: response: ") # print("jsonReq: response: ")
@@ -31,8 +41,18 @@ class LFCliBase:
return json_response return json_response
def jsonGet(self, _req_url): def jsonGet(self, _req_url):
lf_r = LFRequest.LFRequest(self.mgr_url + _req_url) json_response = None
json_response = lf_r.getAsJson(self.debugOn) 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 return json_response
def checkConnect(self): def checkConnect(self):