From: tierno Date: Mon, 15 Jan 2018 13:01:30 +0000 (+0100) Subject: Fix database insertion error field oversize X-Git-Tag: v3.1.0~2 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=refs%2Fchanges%2F15%2F5815%2F1;p=osm%2Fopenvim.git Fix database insertion error field oversize Change-Id: Ifcf5a6a2323bb92e0397ebfb199700fbddac040f Signed-off-by: tierno --- diff --git a/osm_openvim/openflow_thread.py b/osm_openvim/openflow_thread.py index 24fc77f..e41fb6b 100644 --- a/osm_openvim/openflow_thread.py +++ b/osm_openvim/openflow_thread.py @@ -111,7 +111,13 @@ class openflow_thread(threading.Thread): self.logger.setLevel(getattr(logging, debug)) self.queueLock = threading.Lock() self.taskQueue = Queue.Queue(2000) - + + @staticmethod + def _format_error_msg(error_text, max_length=1024): + if error_text and len(error_text) >= max_length: + return error_text[:max_length//2-3] + " ... " + error_text[-max_length//2+3:] + return error_text + def insert_task(self, task, *aditional): try: self.queueLock.acquire() @@ -139,10 +145,10 @@ class openflow_thread(threading.Thread): continue if task[0] == 'update-net': - r,c = self.update_of_flows(task[1]) + r, c = self.update_of_flows(task[1]) # update database status if r<0: - UPDATE={'status':'ERROR', 'last_error': str(c)} + UPDATE={'status':'ERROR', 'last_error': self._format_error_msg(str(c), 255)} self.logger.error("processing task 'update-net' %s: %s", str(task[1]), c) self.set_openflow_controller_status(OFC_STATUS_ERROR, "Error updating net {}".format(task[1])) else: @@ -588,7 +594,7 @@ class openflow_thread(threading.Thread): ofc = {} ofc['status'] = status - ofc['last_error'] = error_text + ofc['last_error'] = self._format_error_msg(error_text, 255) self.db_lock.acquire() result, content = self.db.update_rows('ofcs', ofc, WHERE={'uuid': self.of_uuid}, log=False) self.db_lock.release() diff --git a/osm_openvim/ovim.py b/osm_openvim/ovim.py index 1177d42..942855c 100755 --- a/osm_openvim/ovim.py +++ b/osm_openvim/ovim.py @@ -43,8 +43,8 @@ import openflow_conn __author__ = "Alfonso Tierno, Leonardo Mirabal" __date__ = "$06-Feb-2017 12:07:15$" -__version__ = "0.5.22-r538" -version_date = "Nov 2017" +__version__ = "0.5.23-r539" +version_date = "Jan 2018" database_version = 22 #needed database schema version HTTP_Bad_Request = 400