Skip to content

Commit a737f67

Browse files
committed
ovn-tester: Allow tests to manually end iterations.
Until this point, when running a qps_test, the ovn_context code would automatically take care of marking an iteration as started or ended. This is a problem, though, for tests that wait until all iterations have completed to determine if ports came up within the configured time limit. The issue is that the ovn_context will mark the iteration as completed, potentially logging the iteration as successful. However, after this has been logged, the test could mark the iteration as failed if it turns out the port did not come up within the configured time limit. The solution here is to allow for tests to override the default behavior by letting them mark the iteration as completed. To do this, the qps_test() function now accepts a kwargs parameter, and setting end_iteration=False will allow for the individual test to mark iterations as complete instead of having it done automatically by the ovn_context code. For convenience, a new all_iterations_completed() method is added to ovn_context so the tests don't have to keep track of iterations to mark them as complete. Signed-off-by: Mark Michelson <[email protected]>
1 parent aa2ce69 commit a737f67

File tree

5 files changed

+31
-9
lines changed

5 files changed

+31
-9
lines changed

ovn-tester/ovn_context.py

+20-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import ovn_stats
33
import time
44
import asyncio
5+
from collections import Counter
56

67
log = logging.getLogger(__name__)
78

@@ -49,7 +50,8 @@ def iteration_completed(self, iteration):
4950
asynchronously since task starts and ends can overlap.'''
5051
iteration.end()
5152
duration = iteration.end_time - iteration.start_time
52-
ovn_stats.add(ITERATION_STAT_NAME, duration, iteration.failed)
53+
ovn_stats.add(ITERATION_STAT_NAME, duration, iteration.failed,
54+
iteration)
5355
self.iterations = {task_name: it for task_name, it in
5456
self.iterations.items() if it != iteration}
5557
if self.test:
@@ -58,6 +60,18 @@ def iteration_completed(self, iteration):
5860
f'Context {self.test_name}, Iteration {iteration.num}, '
5961
f'Result: {"FAILURE" if iteration.failed else "SUCCESS"}')
6062

63+
def all_iterations_completed(self):
64+
if self.iteration_singleton is not None:
65+
# Weird, but you do you man.
66+
self.iteration_completed(self.iteration_singleton)
67+
return
68+
69+
# self.iterations may have the same iteration value for multiple
70+
# keys. We need to first get the unique list of iterations.
71+
iter_list = Counter(self.iterations.values())
72+
for iteration in iter_list:
73+
self.iteration_completed(iteration)
74+
6175
def create_task(self, coro, iteration=None):
6276
'''Create a task to run in this context.'''
6377
if iteration is None:
@@ -66,23 +80,24 @@ def create_task(self, coro, iteration=None):
6680
self.iterations[task.get_name()] = iteration
6781
return task
6882

69-
async def qps_test(self, qps, coro, *args):
83+
async def qps_test(self, qps, coro, *args, **kwargs):
7084
tasks = []
7185
for i in range(self.max_iterations):
7286
iteration = ContextIteration(i, self)
7387
tasks.append(self.create_task(
74-
self.qps_task(iteration, coro, *args), iteration)
88+
self.qps_task(iteration, coro, *args, **kwargs), iteration)
7589
)
7690
# Use i+1 so that we don't sleep on task 0 and so that
7791
# we sleep after 20 iterations instead of 21.
7892
if (i + 1) % qps == 0:
7993
await asyncio.sleep(1)
8094
await asyncio.gather(*tasks)
8195

82-
async def qps_task(self, iteration, coro, *args):
96+
async def qps_task(self, iteration, coro, *args, **kwargs):
8397
await self.iteration_started(iteration)
8498
await coro(*args)
85-
self.iteration_completed(iteration)
99+
if kwargs.get('end_iteration', True):
100+
self.iteration_completed(iteration)
86101

87102

88103
def get_current_iteration():

ovn-tester/ovn_tester.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,10 @@ async def run(self, ovn, bringup_cfg):
242242
await ovn.create_cluster_join_switch("ls-join")
243243
await ovn.create_cluster_load_balancer("lb-cluster")
244244
await ctx.qps_test(bringup_cfg.queries_per_second,
245-
self.provisioner, ovn, bringup_cfg)
245+
self.provisioner, ovn, bringup_cfg,
246+
end_iteration=False)
246247
await ovn.wait_for_ports_up(self.port_iters)
248+
ctx.all_iterations_completed()
247249

248250

249251
async def main(global_cfg, cluster_cfg, brex_cfg, bringup_cfg):

ovn-tester/tests/cluster_density.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,9 @@ async def run(self, ovn, global_cfg):
5858
(self.config.n_runs - self.config.n_startup) //
5959
self.batch_ratio, test=self) as ctx:
6060
await ctx.qps_test(self.config.queries_per_second,
61-
self.tester, ovn, all_ns)
61+
self.tester, ovn, all_ns, end_iteration=False)
6262
await ovn.wait_for_ports_up(self.test_port_iters)
63+
ctx.all_iterations_completed()
6364

6465
if not global_cfg.cleanup:
6566
return

ovn-tester/tests/density_heavy.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,10 @@ async def run(self, ovn, global_cfg):
8080
(self.config.n_pods - self.config.n_startup) //
8181
self.config.batch, test=self) as ctx:
8282
await ctx.qps_test(self.config.queries_per_second,
83-
self.provisioner, ns, ovn)
83+
self.provisioner, ns, ovn,
84+
end_iteration=False)
8485
await ovn.wait_for_ports_up(self.test_port_iters)
86+
ctx.all_iterations_completed()
8587

8688
if not global_cfg.cleanup:
8789
return

ovn-tester/tests/density_light.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@ async def run(self, ovn, global_cfg):
3434
n_iterations = self.config.n_pods - self.config.n_startup
3535
with Context('density_light', n_iterations, test=self) as ctx:
3636
await ctx.qps_test(self.config.queries_per_second,
37-
self.provisioner, ns, ovn)
37+
self.provisioner, ns, ovn,
38+
end_iteration=False)
3839
await ovn.wait_for_ports_up(self.test_port_iters)
40+
ctx.all_iterations_completed()
3941

4042
if not global_cfg.cleanup:
4143
return

0 commit comments

Comments
 (0)