From b8a610ab5c86faaa114b4ddeeb0e55c34bb798a3 Mon Sep 17 00:00:00 2001 From: Thanh Ha Date: Mon, 16 Mar 2015 00:24:32 -0400 Subject: [PATCH] Fix pep8 violations in libconfig.py Change-Id: Ia7e49f22e4526b9737880a99b80da2c29446d61e Signed-off-by: Thanh Ha --- .../libconfig.py | 52 ++++++++++--------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/test/tools/OF_Test/robot_suites/998__Independent_OF_Tests_ovs/libconfig.py b/test/tools/OF_Test/robot_suites/998__Independent_OF_Tests_ovs/libconfig.py index 8cbc75e550..591a835ebc 100644 --- a/test/tools/OF_Test/robot_suites/998__Independent_OF_Tests_ovs/libconfig.py +++ b/test/tools/OF_Test/robot_suites/998__Independent_OF_Tests_ovs/libconfig.py @@ -2,11 +2,12 @@ import requests import time from threading import Thread from functools import wraps -#from multiprocessing import Process +# from multiprocessing import Process __all__ = ['configure_flows', 'wait_until', 'deconfigure_flows'] -#class KeyWord(Process): + +# class KeyWord(Process): class KeyWord(Thread): def __init__(self, *args, **kwargs): super(KeyWord, self).__init__(*args, **kwargs) @@ -19,15 +20,16 @@ class KeyWord(Thread): def result(self): return self._kw_result + def async_task(func): """Taken from http://code.activestate.com/recipes/576684-simple-threading-decorator/ and modified """ @wraps(func) def async_func(*args, **kwargs): - func_hl = KeyWord(target = func, args = args, kwargs = kwargs) + func_hl = KeyWord(target=func, args=args, kwargs=kwargs) func_hl._Thread__args = (func_hl,) + func_hl._Thread__args - #func_hl._args = (func_hl,) + func_hl._args + # func_hl._args = (func_hl,) + func_hl._args func_hl.start() return func_hl @@ -42,10 +44,10 @@ def wait_until(*tasks, **kwargs): timeout = int(kwargs['timeout']) cnt = len(tasks) - while time.time() < (timeout+tstart): + while time.time() < (timeout + tstart): tfinished = 0 for t in tasks: - if t.is_alive() == False: + if t.is_alive() is False: tfinished += 1 continue t.join(timeout=0.2) @@ -53,19 +55,20 @@ def wait_until(*tasks, **kwargs): return (time.time()-tstart) for t in tasks: - if t.is_alive() == True: + if t.is_alive() is True: t.stop() - #t.terminate() + # t.terminate() t.join() return (time.time()-tstart) + @async_task def Example_of_robot_keyword(self, a, b, c): """be carefull, when calling this kw from robot, do not count on self, it is a thread object itself injected by decorator. The purpose is to make - possibility to exit from thread on demand by + possibility to exit from thread on demand by wait until keywork which makes thread.stop() if needed. In your fw you should use self._stop variable. @@ -75,11 +78,10 @@ def Example_of_robot_keyword(self, a, b, c): ${thread}= Example Of Robot Keyword a b c """ while True: - if self._stop == True: + if self._stop is True: break - @async_task def configure_flows(self, host, port, switchid, tableid, minid, maxid): flow_template = ''' @@ -118,20 +120,20 @@ def configure_flows(self, host, port, switchid, tableid, minid, maxid): ses = requests.Session() - for i in range(int(minid),int(maxid)+1): - if self._stop == True: + for i in range(int(minid), int(maxid) + 1): + if self._stop is True: break fid = str(i) - flow = flow_template.format(tableid,fid,fid,fid) - url = 'http://{}:{}/restconf/config/opendaylight-inventory:nodes/node/openflow:{}/table/{}/flow/{}'.format(host, - port, switchid, tableid, fid) + flow = flow_template.format(tableid, fid, fid, fid) + url = 'http://{}:{}/restconf/config/opendaylight-inventory:nodes/node/openflow:{}/table/{}/flow/{}'.format( + host, port, switchid, tableid, fid) try: - rsp = ses.put(url, headers={'Content-Type':'application/xml'}, data=flow, timeout=3) + rsp = ses.put(url, headers={'Content-Type': 'application/xml'}, data=flow, timeout=3) if rsp.status_code == 200: self._kw_result += 1 - except Exception as e: + except Exception: pass @@ -141,15 +143,15 @@ def deconfigure_flows(self, host, port, switchid, tableid, minid, maxid): self._kw_result = 0 ses = requests.Session() - for fid in range(int(minid),int(maxid)): - if self._stop == True: - break; - url = 'http://{}:{}/restconf/config/opendaylight-inventory:nodes/node/openflow:{}/table/{}/flow/{}'.format(host, - port, switchid, tableid, fid) + for fid in range(int(minid), int(maxid)): + if self._stop is True: + break + url = 'http://{}:{}/restconf/config/opendaylight-inventory:nodes/node/openflow:{}/table/{}/flow/{}'.format( + host, port, switchid, tableid, fid) try: - rsp = ses.delete(url, headers={'Content-Type':'application/xml'}, timeout=3) + rsp = ses.delete(url, headers={'Content-Type': 'application/xml'}, timeout=3) if rsp.status_code == 200: self._kw_result += 1 - except Exception as e: + except Exception: pass -- 2.36.6