From 1878eb4c21040ee34cde8a1aae6d1fb8993ae332 Mon Sep 17 00:00:00 2001 From: Fernando Royo Date: Tue, 14 Mar 2023 12:18:34 +0100 Subject: [PATCH] Fix broken pep8 jobs due to bandit 1.7.5 updated version With the latest version of bandit (1.7.5), a new lint rule has been introduced that checks the inclusion of the timeout parameter for every "requests" call [1]. So B113 lint rule[2] needs to be skipped or code adapted, this patch add the timeout parameter to the put/get requests. [1] https://github.com/PyCQA/bandit/commit/5ff73ff8ff956df7d63fde49c3bd671db8e821eb [2] https://bandit.readthedocs.io/en/latest/plugins/b113_request_without_timeout.html Closes-bug: #2011573 Change-Id: I341faedbf7e237eed176e0d3ed3586b8d2c2cbb8 --- ovn_octavia_provider/common/constants.py | 3 +++ ovn_octavia_provider/helper.py | 12 +++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/ovn_octavia_provider/common/constants.py b/ovn_octavia_provider/common/constants.py index 63f66d9d..52dc060e 100644 --- a/ovn_octavia_provider/common/constants.py +++ b/ovn_octavia_provider/common/constants.py @@ -109,3 +109,6 @@ LB_SELECTION_FIELDS_MAP = { # HM events status HM_EVENT_MEMBER_PORT_ONLINE = ['online'] HM_EVENT_MEMBER_PORT_OFFLINE = ['offline'] + +# max timeout for request +MAX_TIMEOUT_REQUEST = 5 diff --git a/ovn_octavia_provider/helper.py b/ovn_octavia_provider/helper.py index 29c313f6..35b974d1 100644 --- a/ovn_octavia_provider/helper.py +++ b/ovn_octavia_provider/helper.py @@ -119,7 +119,8 @@ class OvnProviderHelper(): Stream.ssl_set_ca_cert_file(ca_cert_file) def shutdown(self): - self.requests.put({'type': ovn_const.REQ_TYPE_EXIT}) + self.requests.put({'type': ovn_const.REQ_TYPE_EXIT}, + timeout=ovn_const.MAX_TIMEOUT_REQUEST) self.helper_thread.join() self.ovn_nbdb.stop() del self.ovn_nbdb_api @@ -389,7 +390,12 @@ class OvnProviderHelper(): def request_handler(self): while True: - request = self.requests.get() + try: + request = self.requests.get( + timeout=ovn_const.MAX_TIMEOUT_REQUEST) + except queue.Empty: + continue + request_type = request['type'] if request_type == ovn_const.REQ_TYPE_EXIT: break @@ -414,7 +420,7 @@ class OvnProviderHelper(): LOG.exception('Unexpected exception in request_handler') def add_request(self, req): - self.requests.put(req) + self.requests.put(req, timeout=ovn_const.MAX_TIMEOUT_REQUEST) @tenacity.retry( retry=tenacity.retry_if_exception_type(