tests: Give more time for interface information to show up - #21278
Conversation
The test failed in upstream CI because the loopback did not have the address as of yet as part of a `show interface`. The `show run` showed that the address was applied, but the interface information in zebra and from `ip ...` commands showed that the data had not finished being sent to the kernel. Give this test more time to converge. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
Greptile SummaryThis PR addresses a CI flakiness issue where the Key changes:
Confidence Score: 3/5
Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[test_topology_setup: Phase 2] --> B[Define expected_loopback_ipv4 = '10.0.0.2']
B --> C[check_leaf2_loopback_ipv4\nclosure]
C --> D{run_and_expect\ncount=20, wait=1s}
D -->|retry| E[vtysh show interface lo]
E --> F{inet addr\nfound?}
F -->|No| G[log: still waiting] --> D
F -->|Yes - any IP| H[ipv4_state nexthop = matched IP\nNOTE: not validated vs expected]
H --> I[return True]
D -->|success=True| J[assert success]
D -->|timeout| K[assert failure\nmessage shows expected_loopback_ipv4]
J --> L[ipv4_nexthop = ipv4_state nexthop]
L --> M[sharp install routes\nusing ipv4_nexthop as nexthop]
Prompt To Fix All With AIThis is a comment left during a code review.
Path: tests/topotests/two_layer_wucmp/test_two_layer_wuecmp.py
Line: 377-402
Comment:
**`expected_loopback_ipv4` defined but never validated**
`expected_loopback_ipv4 = "10.0.0.2"` is only interpolated into the failure message β it is never compared against the IP address actually returned by the regex. The function `check_leaf2_loopback_ipv4` succeeds as soon as *any* `inet x.x.x.x/...` line appears in `show interface lo`. If another address is matched first (e.g. an unexpected loopback address configured before `10.0.0.2` arrives), `ipv4_nexthop` would silently be set to the wrong value and the subsequent sharp-route install would use a bad nexthop, causing downstream test failures that are hard to trace back to this point.
Consider validating the retrieved address against the expected value so the retry keeps waiting until the *correct* address is seen:
```suggestion
def check_leaf2_loopback_ipv4():
lo_output = net["leaf2"].cmd("vtysh -c 'show interface lo'")
ipv4_match = re.search(r"inet (\d+\.\d+\.\d+\.\d+)/\d+", lo_output)
if not ipv4_match:
logger.info("Still waiting for IPv4 address on leaf2 loopback interface")
return False
found_ip = ipv4_match.group(1)
if found_ip != expected_loopback_ipv4:
logger.info(
f"Found {found_ip} on leaf2 loopback, still waiting for {expected_loopback_ipv4}"
)
return False
ipv4_state["nexthop"] = found_ip
return True
```
How can I resolve this? If you propose a fix, please make it concise.Last reviewed commit: "tests: Give more tim..." |
| expected_loopback_ipv4 = "10.0.0.2" | ||
| ipv4_state = {"nexthop": None} | ||
|
|
||
| if not ipv4_match: | ||
| assert False, "Could not find IPv4 address on loopback interface" | ||
| def check_leaf2_loopback_ipv4(): | ||
| lo_output = net["leaf2"].cmd("vtysh -c 'show interface lo'") | ||
| ipv4_match = re.search(r"inet (\d+\.\d+\.\d+\.\d+)/\d+", lo_output) | ||
|
|
||
| ipv4_nexthop = ipv4_match.group(1) | ||
| if not ipv4_match: | ||
| logger.info("Still waiting for IPv4 address on leaf2 loopback interface") | ||
| return False | ||
|
|
||
| ipv4_state["nexthop"] = ipv4_match.group(1) | ||
| return True | ||
|
|
||
| success, result = topotest.run_and_expect( | ||
| check_leaf2_loopback_ipv4, | ||
| True, | ||
| count=20, | ||
| wait=1, | ||
| ) | ||
|
|
||
| assert ( | ||
| success | ||
| ), f"Could not find IPv4 address on loopback interface for node leaf2; expected {expected_loopback_ipv4}" | ||
|
|
||
| ipv4_nexthop = ipv4_state["nexthop"] |
There was a problem hiding this comment.
expected_loopback_ipv4 defined but never validated
expected_loopback_ipv4 = "10.0.0.2" is only interpolated into the failure message β it is never compared against the IP address actually returned by the regex. The function check_leaf2_loopback_ipv4 succeeds as soon as any inet x.x.x.x/... line appears in show interface lo. If another address is matched first (e.g. an unexpected loopback address configured before 10.0.0.2 arrives), ipv4_nexthop would silently be set to the wrong value and the subsequent sharp-route install would use a bad nexthop, causing downstream test failures that are hard to trace back to this point.
Consider validating the retrieved address against the expected value so the retry keeps waiting until the correct address is seen:
| expected_loopback_ipv4 = "10.0.0.2" | |
| ipv4_state = {"nexthop": None} | |
| if not ipv4_match: | |
| assert False, "Could not find IPv4 address on loopback interface" | |
| def check_leaf2_loopback_ipv4(): | |
| lo_output = net["leaf2"].cmd("vtysh -c 'show interface lo'") | |
| ipv4_match = re.search(r"inet (\d+\.\d+\.\d+\.\d+)/\d+", lo_output) | |
| ipv4_nexthop = ipv4_match.group(1) | |
| if not ipv4_match: | |
| logger.info("Still waiting for IPv4 address on leaf2 loopback interface") | |
| return False | |
| ipv4_state["nexthop"] = ipv4_match.group(1) | |
| return True | |
| success, result = topotest.run_and_expect( | |
| check_leaf2_loopback_ipv4, | |
| True, | |
| count=20, | |
| wait=1, | |
| ) | |
| assert ( | |
| success | |
| ), f"Could not find IPv4 address on loopback interface for node leaf2; expected {expected_loopback_ipv4}" | |
| ipv4_nexthop = ipv4_state["nexthop"] | |
| def check_leaf2_loopback_ipv4(): | |
| lo_output = net["leaf2"].cmd("vtysh -c 'show interface lo'") | |
| ipv4_match = re.search(r"inet (\d+\.\d+\.\d+\.\d+)/\d+", lo_output) | |
| if not ipv4_match: | |
| logger.info("Still waiting for IPv4 address on leaf2 loopback interface") | |
| return False | |
| found_ip = ipv4_match.group(1) | |
| if found_ip != expected_loopback_ipv4: | |
| logger.info( | |
| f"Found {found_ip} on leaf2 loopback, still waiting for {expected_loopback_ipv4}" | |
| ) | |
| return False | |
| ipv4_state["nexthop"] = found_ip | |
| return True |
Prompt To Fix With AI
This is a comment left during a code review.
Path: tests/topotests/two_layer_wucmp/test_two_layer_wuecmp.py
Line: 377-402
Comment:
**`expected_loopback_ipv4` defined but never validated**
`expected_loopback_ipv4 = "10.0.0.2"` is only interpolated into the failure message β it is never compared against the IP address actually returned by the regex. The function `check_leaf2_loopback_ipv4` succeeds as soon as *any* `inet x.x.x.x/...` line appears in `show interface lo`. If another address is matched first (e.g. an unexpected loopback address configured before `10.0.0.2` arrives), `ipv4_nexthop` would silently be set to the wrong value and the subsequent sharp-route install would use a bad nexthop, causing downstream test failures that are hard to trace back to this point.
Consider validating the retrieved address against the expected value so the retry keeps waiting until the *correct* address is seen:
```suggestion
def check_leaf2_loopback_ipv4():
lo_output = net["leaf2"].cmd("vtysh -c 'show interface lo'")
ipv4_match = re.search(r"inet (\d+\.\d+\.\d+\.\d+)/\d+", lo_output)
if not ipv4_match:
logger.info("Still waiting for IPv4 address on leaf2 loopback interface")
return False
found_ip = ipv4_match.group(1)
if found_ip != expected_loopback_ipv4:
logger.info(
f"Found {found_ip} on leaf2 loopback, still waiting for {expected_loopback_ipv4}"
)
return False
ipv4_state["nexthop"] = found_ip
return True
```
How can I resolve this? If you propose a fix, please make it concise.There was a problem hiding this comment.
@greptile Why do we need to make a function generic to handle any input when this is specific code to handle a specific test scenario where there will never be other addresses on lo
There was a problem hiding this comment.
You're right. In a controlled test environment where the loopback will only have the configured address, checking for the presence of any IPv4 address is sufficient. The original comment was over-engineering the solution for a test with a known, fixed topology.
The current implementation appropriately waits for the interface information to appear in zebra without adding unnecessary validation logic. Since expected_loopback_ipv4 is only used for the error message, that's fineβit makes the failure message more informative if something does go wrong, but you don't need to validate against it during the check.
|
@Mergifyio backport stable/10.6 |
β Backports have been createdDetails
|
tests: Give more time for interface information to show up (backport #21278)
The test failed in upstream CI because the loopback did not have the address as of yet as part of a
show interface. Theshow runshowed that the address was applied, but the interface information in zebra and fromip ...commands showed that the data had not finished being sent to the kernel. Give this test more time to converge.