tests: fix test_static_timing route removal

On the first step, the test creates 10000 static routes. It passes 10000
to `get_ip_networks` and it generates 10000 /22 routes.

On the fourth step, the test tries to remove 5000 previously created
routes. It passes 5000 to `get_ip_networks` and here starts the problem.
Instead of generating 5000 /22 routes, it generates 5000 /21 routes. And
the whole step is a no-op, we constantly see the following logs:
```
% Refusing to remove a non-existent route
```

To consistently generate same routes, `get_ip_networks` must always use
the same prefix length.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
This commit is contained in:
Igor Ryzhov 2021-10-14 00:13:57 +03:00
parent d759866d5b
commit 925d7f925b

View File

@ -77,8 +77,8 @@ def teardown_module(mod):
tgen.stop_topology() tgen.stop_topology()
def get_ip_networks(super_prefix, count): def get_ip_networks(super_prefix, base_count, count):
count_log2 = math.log(count, 2) count_log2 = math.log(base_count, 2)
if count_log2 != int(count_log2): if count_log2 != int(count_log2):
count_log2 = int(count_log2) + 1 count_log2 = int(count_log2) + 1
else: else:
@ -94,6 +94,7 @@ def test_static_timing():
pytest.skip(tgen.errors) pytest.skip(tgen.errors)
def do_config( def do_config(
base_count,
count, count,
bad_indices, bad_indices,
base_delta, base_delta,
@ -121,7 +122,7 @@ def test_static_timing():
router.logdir, rname, "{}-routes-{}.conf".format(iptype.lower(), optype) router.logdir, rname, "{}-routes-{}.conf".format(iptype.lower(), optype)
) )
with open(config_file, "w") as f: with open(config_file, "w") as f:
for i, net in enumerate(get_ip_networks(super_prefix, count)): for i, net in enumerate(get_ip_networks(super_prefix, base_count, count)):
if i in bad_indices: if i in bad_indices:
if add: if add:
f.write("ip route {} {} bad_input\n".format(net, via)) f.write("ip route {} {} bad_input\n".format(net, via))
@ -170,21 +171,22 @@ def test_static_timing():
bad_indices = [] bad_indices = []
for ipv6 in [False, True]: for ipv6 in [False, True]:
base_delta = do_config( base_delta = do_config(
prefix_count, bad_indices, 0, 0, True, ipv6, prefix_base[ipv6][0] prefix_count, prefix_count, bad_indices, 0, 0, True, ipv6, prefix_base[ipv6][0]
) )
# Another set of same number of prefixes # Another set of same number of prefixes
do_config( do_config(
prefix_count, bad_indices, base_delta, 2, True, ipv6, prefix_base[ipv6][1] prefix_count, prefix_count, bad_indices, base_delta, 2, True, ipv6, prefix_base[ipv6][1]
) )
# Duplicate config # Duplicate config
do_config( do_config(
prefix_count, bad_indices, base_delta, 2, True, ipv6, prefix_base[ipv6][0] prefix_count, prefix_count, bad_indices, base_delta, 2, True, ipv6, prefix_base[ipv6][0]
) )
# Remove 1/2 of duplicate # Remove 1/2 of duplicate
do_config( do_config(
prefix_count,
prefix_count // 2, prefix_count // 2,
bad_indices, bad_indices,
base_delta, base_delta,
@ -196,15 +198,15 @@ def test_static_timing():
# Add all back in so 1/2 replicate 1/2 new # Add all back in so 1/2 replicate 1/2 new
do_config( do_config(
prefix_count, bad_indices, base_delta, 2, True, ipv6, prefix_base[ipv6][0] prefix_count, prefix_count, bad_indices, base_delta, 2, True, ipv6, prefix_base[ipv6][0]
) )
# remove all # remove all
delta = do_config( delta = do_config(
prefix_count, bad_indices, base_delta, 2, False, ipv6, prefix_base[ipv6][0] prefix_count, prefix_count, bad_indices, base_delta, 2, False, ipv6, prefix_base[ipv6][0]
) )
delta += do_config( delta += do_config(
prefix_count, bad_indices, base_delta, 2, False, ipv6, prefix_base[ipv6][1] prefix_count, prefix_count, bad_indices, base_delta, 2, False, ipv6, prefix_base[ipv6][1]
) )