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] 5ff73ff8ff
[2] https://bandit.readthedocs.io/en/latest/plugins/b113_request_without_timeout.html

Closes-bug: #2011573
Change-Id: I341faedbf7e237eed176e0d3ed3586b8d2c2cbb8
This commit is contained in:
Fernando Royo 2023-03-14 12:18:34 +01:00
parent e5d1bd0336
commit 1878eb4c21
2 changed files with 12 additions and 3 deletions

View File

@ -109,3 +109,6 @@ LB_SELECTION_FIELDS_MAP = {
# HM events status # HM events status
HM_EVENT_MEMBER_PORT_ONLINE = ['online'] HM_EVENT_MEMBER_PORT_ONLINE = ['online']
HM_EVENT_MEMBER_PORT_OFFLINE = ['offline'] HM_EVENT_MEMBER_PORT_OFFLINE = ['offline']
# max timeout for request
MAX_TIMEOUT_REQUEST = 5

View File

@ -119,7 +119,8 @@ class OvnProviderHelper():
Stream.ssl_set_ca_cert_file(ca_cert_file) Stream.ssl_set_ca_cert_file(ca_cert_file)
def shutdown(self): 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.helper_thread.join()
self.ovn_nbdb.stop() self.ovn_nbdb.stop()
del self.ovn_nbdb_api del self.ovn_nbdb_api
@ -389,7 +390,12 @@ class OvnProviderHelper():
def request_handler(self): def request_handler(self):
while True: 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'] request_type = request['type']
if request_type == ovn_const.REQ_TYPE_EXIT: if request_type == ovn_const.REQ_TYPE_EXIT:
break break
@ -414,7 +420,7 @@ class OvnProviderHelper():
LOG.exception('Unexpected exception in request_handler') LOG.exception('Unexpected exception in request_handler')
def add_request(self, req): def add_request(self, req):
self.requests.put(req) self.requests.put(req, timeout=ovn_const.MAX_TIMEOUT_REQUEST)
@tenacity.retry( @tenacity.retry(
retry=tenacity.retry_if_exception_type( retry=tenacity.retry_if_exception_type(