Amend check_sg_rules_for_np() method

Move ingress_cidrs_found and egress_cidrs_initialization to
inside the while loop so they're cleared in each iteration.
Move rule match comprobation outside the rules for loop.

Change-Id: I1acba9f407de084f19d9ee12fb6e95de03d578df
This commit is contained in:
Jon Uriarte 2022-01-14 18:07:34 +00:00
parent 5fd8c32c31
commit d9a93bcba9

View File

@ -66,8 +66,6 @@ class TestNetworkPolicyScenario(base.BaseKuryrScenarioTest,
egress_cidrs_should_exist=(),
ingress_cidrs_shouldnt_exist=(),
egress_cidrs_shouldnt_exist=()):
ingress_cidrs_found = set()
egress_cidrs_found = set()
ingress_cidrs_should_exist = set(ingress_cidrs_should_exist)
egress_cidrs_should_exist = set(egress_cidrs_should_exist)
ingress_cidrs_shouldnt_exist = set(ingress_cidrs_shouldnt_exist)
@ -77,6 +75,8 @@ class TestNetworkPolicyScenario(base.BaseKuryrScenarioTest,
start = time.time()
while not rules_match and (time.time() - start) < TIMEOUT_PERIOD:
ingress_cidrs_found = set()
egress_cidrs_found = set()
sg_rules = self.get_sg_rules_for_np(namespace, np)
for rule in sg_rules:
@ -85,17 +85,18 @@ class TestNetworkPolicyScenario(base.BaseKuryrScenarioTest,
elif rule['direction'] == 'egress':
egress_cidrs_found.add(rule['remote_ip_prefix'])
if (ingress_cidrs_should_exist.issubset(ingress_cidrs_found)
and (not ingress_cidrs_shouldnt_exist
or not ingress_cidrs_shouldnt_exist.issubset(
ingress_cidrs_found))
and egress_cidrs_should_exist.issubset(egress_cidrs_found)
and (not egress_cidrs_shouldnt_exist
or not egress_cidrs_shouldnt_exist.issubset(
egress_cidrs_found))):
rules_match = True
else:
time.sleep(10)
if (ingress_cidrs_should_exist.issubset(ingress_cidrs_found)
and (not ingress_cidrs_shouldnt_exist
or not ingress_cidrs_shouldnt_exist.issubset(
ingress_cidrs_found))
and egress_cidrs_should_exist.issubset(egress_cidrs_found)
and (not egress_cidrs_shouldnt_exist
or not egress_cidrs_shouldnt_exist.issubset(
egress_cidrs_found))):
rules_match = True
time.sleep(1)
if not rules_match:
msg = 'Timed out waiting sg rules for np %s to match' % np
raise lib_exc.TimeoutException(msg)