Skip to content

Commit 116d1e1

Browse files
committed
test: fix pylint errors
Signed-off-by: Xiaocheng Dong <[email protected]>
1 parent b8825d2 commit 116d1e1

File tree

2 files changed

+36
-24
lines changed

2 files changed

+36
-24
lines changed

container/ccnp-perf/ccnp_perf.py

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
"""
44

55
import logging
6+
import concurrent
67

78
from concurrent.futures import ThreadPoolExecutor
8-
from concurrent.futures import TimeoutError
99
from multiprocessing import Process, Queue
1010
from threading import Event
1111
import time
@@ -72,7 +72,7 @@ def _timeout_fn(fn, timeout, ev_stop):
7272
future = executor.submit(fn)
7373
try:
7474
r = future.result(timeout)
75-
except TimeoutError:
75+
except concurrent.futures.TimeoutError:
7676
# Timeout expires.
7777
# Now it's time to stop the thread and get the result.
7878
ev_stop.set()
@@ -105,6 +105,7 @@ def _cnt_operations(svc_call, res_queue, timeout):
105105
timeout: time used to repeat the service call.
106106
"""
107107
ev_stop = Event()
108+
# pylint: disable=unnecessary-lambda-assignment
108109
operation = lambda: _repeat_svc_call(svc_call, ev_stop)
109110
cnt = _timeout_fn(operation, timeout, ev_stop)
110111
res_queue.put(cnt) # Pass the total count to the parent process.
@@ -140,7 +141,7 @@ def _start_proc(_perf_wrapper_fn, svc_call, timeout):
140141
be terminated. The result got by the child process will be stored in the ``Queue``.
141142
"""
142143
res_queue = Queue()
143-
p = Process(target=(lambda: _perf_wrapper_fn(svc_call, res_queue, timeout)))
144+
p = Process(target=lambda: _perf_wrapper_fn(svc_call, res_queue, timeout))
144145
p.start()
145146
return p, res_queue
146147

@@ -155,7 +156,7 @@ def _start_proc_and_wait(_perf_wrapper_fn, svc_call):
155156
The result returned by the wrapper function. e.g. the timing result.
156157
"""
157158
res_queue = Queue()
158-
p = Process(target=(lambda: _perf_wrapper_fn(svc_call, res_queue)))
159+
p = Process(target=lambda: _perf_wrapper_fn(svc_call, res_queue))
159160
p.start()
160161
# NOTE: The order matters here. There could be some deadlock if "join" before
161162
# "get" according to the document of Python:
@@ -170,17 +171,17 @@ def _test_throughput(svc_call):
170171
Args:
171172
svc_call: function to invoke the service call.
172173
"""
173-
# 1. Start N processes to simulate N apps (see our design for details).
174+
# 1. Start N processes to simulate N apps (see our design for details).
174175
task_num = THROUGHPUT_TEST_TASK_NUM
175176
time_total = THROUGHPUT_TEST_TASK_TIME
176177
tasks = []
177178
for _ in range(task_num):
178179
# 2. Each process invokes the CCNP API (either via SDK or service directly) repeatedly
179-
# until the timeout T expires (see our design details).
180-
p, res_queue = _start_proc(_cnt_operations, svc_call, time_total)
181-
tasks.append(PerfTask(p, res_queue))
180+
# until the timeout T expires (see our design details).
181+
p, res_queue = _start_proc(_cnt_operations, svc_call, time_total)
182+
tasks.append(PerfTask(p, res_queue))
182183

183-
# 3. Calculate the average ops (total count of completed API calls in N threads divided by T).
184+
# 3. Calculate the average ops (total count of completed API calls in N threads divided by T).
184185
cnt_total = 0
185186
for t in tasks:
186187
cnt = t.queue.get()
@@ -189,6 +190,7 @@ def _test_throughput(svc_call):
189190
ops_avg = cnt_total / time_total
190191

191192
# Log out the result for latter analysis.
193+
# pylint: disable=logging-fstring-interpolation
192194
LOG.info(f"Perf test average throughput is: {ops_avg} ops (operations per second)")
193195

194196
def _test_response(svc_call):
@@ -197,20 +199,22 @@ def _test_response(svc_call):
197199
Args:
198200
svc_call: function to invoke the service call.
199201
"""
200-
# 1. Repeat the steps below M times (M = 20 is the current setting):
202+
# 1. Repeat the steps below M times (M = 20 is the current setting):
201203
repeat_times = RESPONSE_TEST_REPEAT_TIME
202204
t_cost_total = 0
203205
for _ in range(repeat_times):
204-
# Start a new process to simulate an app.​ In the process:​
205-
# Begin timing.​
206-
# Call (one immediately after another) the CCNP API (either via SDK or request to service directly).​
207-
# End timing.​
208-
# Record the time consumption and exit.​
206+
# Start a new process to simulate an app. In the process:
207+
# Begin timing.
208+
# Call (one immediately after another) the CCNP API (either via SDK or
209+
# request to service directly).
210+
# End timing.
211+
# Record the time consumption and exit.
209212
t_cost = _start_proc_and_wait(_timing_response, svc_call)
210213
t_cost_total += t_cost
211214

212215
# 2. Calculate the average response time (total time divided by M).
213216
t_cost_avg = t_cost_total / repeat_times
217+
# pylint: disable=logging-fstring-interpolation
214218
LOG.info(f"Perf test average response time is: {t_cost_avg / 1000000} ms (milliseconds)")
215219

216220
def _sdk_get_cc_measurement():
@@ -257,9 +261,9 @@ def test_ccnp_init():
257261
"""
258262
# TODO:
259263
# Repeat R times (R = 20 is the current setting) and calculate the average time
260-
# (total times divided by R):
261-
# Begin timing.
262-
# Start CCNP deployment (incl. CCNP Device Plugin and CCNP Service).
263-
# Polling the readiness of CCNP service until it's ready.
264-
# End timing.
265-
# Calculate the initialization time using end time subtracted by begin time.
264+
# (total times divided by R):
265+
# Begin timing.
266+
# Start CCNP deployment (incl. CCNP Device Plugin and CCNP Service).
267+
# Polling the readiness of CCNP service until it's ready.
268+
# End timing.
269+
# Calculate the initialization time using end time subtracted by begin time.

test/ci-test/py-test/test_ccnp.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
"""
77

88
import logging
9-
import argparse
109

1110
from ccnp import CcnpSdk
1211

@@ -25,6 +24,9 @@ class TestCCNP:
2524
Tests for CCNP python SDK
2625
'''
2726
def test_eventlog_verify(self):
27+
'''
28+
Replay and verify event logs
29+
'''
2830
evt = CcnpSdk.inst().get_cc_eventlog()
2931
replay = CcnpSdk.inst().replay_cc_eventlog(evt)
3032
for r in replay:
@@ -34,9 +36,15 @@ def test_eventlog_verify(self):
3436
assert m.hash == replay[r][12], "Replay IMR value does not match real IMR."
3537

3638
def test_cc_report(self):
37-
assert CcnpSdk.inst().get_cc_report().dump() is not ""
39+
'''
40+
Test CC report
41+
'''
42+
assert CcnpSdk.inst().get_cc_report().dump() != ""
3843

3944
def test_container_imr(self):
45+
'''
46+
Test container IMR
47+
'''
4048
for i in [0, 1, 3]:
4149
m = CcnpSdk.inst().get_cc_measurement([i, 12])
42-
assert m.hash.hex() is not "", "IMR value should not empty."
50+
assert m.hash.hex() != "", "IMR value should not empty."

0 commit comments

Comments
 (0)