From 821b805c18ad7652a79d4f581f4695558f17e943 Mon Sep 17 00:00:00 2001 From: psterdale Date: Wed, 28 Jun 2017 18:16:52 +0530 Subject: [PATCH] #156 On UCSM reboot UcsHandle is not able to establish the connection. Enclosed response_str = self.post_xml(xml_str) in try block and moved self._tx_lock_release_conditional(elem) to fnally block --- ucsmsdk/ucssession.py | 46 +++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/ucsmsdk/ucssession.py b/ucsmsdk/ucssession.py index 1aa0a23b..fec4e9b3 100644 --- a/ucsmsdk/ucssession.py +++ b/ucsmsdk/ucssession.py @@ -293,32 +293,36 @@ def post_elem(self, elem): from . import ucsxmlcodec as xc self._tx_lock_acquire_conditional(elem) - if self._is_stale_cookie(elem): - elem.attrib['cookie'] = self.cookie - - self.dump_xml_request(elem) - xml_str = xc.to_xml_str(elem) - - response_str = self.post_xml(xml_str) - self.dump_xml_response(response_str) - try: - if response_str: - response = xc.from_xml_str(response_str, self) + if self._is_stale_cookie(elem): + elem.attrib['cookie'] = self.cookie - # Cookie update should happen with-in the lock - # this ensures that the next packet goes out - # with the new cookie - if elem.tag == "aaaRefresh": - self._update_cookie(response) + self.dump_xml_request(elem) + xml_str = xc.to_xml_str(elem) + response_str = self.post_xml(xml_str) + self.dump_xml_response(response_str) + + try: + if response_str: + response = xc.from_xml_str(response_str, self) + + # Cookie update should happen with-in the lock + # this ensures that the next packet goes out + # with the new cookie + if elem.tag == "aaaRefresh": + self._update_cookie(response) + + # self._tx_lock_release_conditional(elem) + # Moved to finally block + return response + except: + # self._tx_lock_release_conditional(elem) + # Moved to finally block + raise + finally: self._tx_lock_release_conditional(elem) - return response - except: - self._tx_lock_release_conditional(elem) - raise - self._tx_lock_release_conditional(elem) return None def _tx_lock_acquire_conditional(self, elem):