Skip to content

Commit

Permalink
Add IPv6 tests (#328)
Browse files Browse the repository at this point in the history
* Update IPv6 verify_dut_addrs function

Allow the function to match multiple keys in links/addrs.

Signed-off-by: Serhiy Boiko <[email protected]>

* Update IPv6 verify_dut_neighbors function

Add ability to match multiple fields and specify whether
an entry should exist or not.

Signed-off-by: Serhiy Boiko <[email protected]>

* Update IPv6 wait_for_nei_state function

Use common verify_dut_neighbors function.

Signed-off-by: Serhiy Boiko <[email protected]>

* Update IPv6 neighbor ageing test

Provide more context to the test by adding comments.
Update sleep values.

Signed-off-by: Serhiy Boiko <[email protected]>

* Add IPv6 tests

- test_ipv6_flags
- test_ipv6_secondary_addr
- test_ipv6_nei_change

Signed-off-by: Serhiy Boiko <[email protected]>

---------

Signed-off-by: Serhiy Boiko <[email protected]>
  • Loading branch information
SerhiyBoikoPLV authored May 18, 2023
1 parent 138c692 commit 9a1c6ab
Show file tree
Hide file tree
Showing 5 changed files with 777 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,56 +48,53 @@ async def verify_dut_neighbors(dent, expected_neis):

for expected_nei in expected_neis:
for nei in neighbors:
for key in expected_nei: # find matching neighbor
if key == 'states':
continue
if expected_nei[key] != nei[key]:
break
else: # neighbor found
assert 'offload' in nei, f'Neighbor {nei} should be offloaded'
assert nei['state'][0] in expected_nei['states'], \
f'Neighbor {nei} should have one of {expected_nei["states"]} states'
break
if not all(expected_nei[key] == nei.get(key)
for key in expected_nei
if key not in ['states', 'offload', 'should_exist']):
# if some keys do not match go to the next neighbor
continue
# neighbor found
assert expected_nei['should_exist'], f'Neighbor {nei} found, but not expected'
assert nei['state'][0] in expected_nei['states'], \
f'Neighbor {nei} should have one of {expected_nei["states"]} states'
if 'offload' in expected_nei:
# neighbor is offloaded when the entry has the 'offload' key (the value does not matter)
assert ('offload' in nei) == expected_nei['offload'], \
f'Expected offload state {expected_nei["offload"]}, but neighbor has {nei}'
break
else: # neighbor not found
raise LookupError(f'Neighbor {expected_nei} expected, but not found')
if expected_nei['should_exist']:
raise LookupError(f'Neighbor {expected_nei} expected, but not found')

learned_macs = {}
for nei in neighbors:
if nei['dev'] not in learned_macs:
learned_macs[nei['dev']] = []
learned_macs[nei['dev']].append(nei['lladdr'])
if 'lladdr' in nei:
learned_macs[nei['dev']].append(nei['lladdr'])
return learned_macs


async def verify_dut_addrs(dent, expected_addrs, expect_family=('inet', 'inet6')):
async def verify_dut_addrs(dent, expected_addrs):
out = await IpAddress.show(input_data=[{dent: [
{'cmd_options': '-j -4'}
{'cmd_options': '-j'}
]}], parse_output=True)
assert out[0][dent]['rc'] == 0, 'Failed to get IPv4 addr'
links = out[0][dent]['parsed_output']

out = await IpAddress.show(input_data=[{dent: [
{'cmd_options': '-j -6'}
]}], parse_output=True)
assert out[0][dent]['rc'] == 0, 'Failed to get IPv6 addr'
links += out[0][dent]['parsed_output']

for swp, ip, plen in expected_addrs:
for link in links:
if swp != link['ifname']:
for expected_addr in expected_addrs:
for link in out[0][dent]['parsed_output']:
if not all(expected_addr[key] == link.get(key)
for key in expected_addr
if key not in ['addr_info', 'should_exist']):
# if some keys do not match go to the next link
continue
# link found
for addr in link['addr_info']:
if ip != addr['local']:
continue
# IP addr found
assert addr['family'] in expect_family, f'Expected {addr} to be {expect_family}'
assert addr['prefixlen'] == plen, f'Expected {addr} prefix length to be {plen}'
if any(all(expected_addr['addr_info'][key] == addr.get(key)
for key in expected_addr['addr_info'])
for addr in link['addr_info']):
# addr in link found
assert expected_addr['should_exist'], f'Link {link} found, but not expected'
break
else: # IP addr not found
# `links` list might have duplicate entries (for ipv4 and ipv6),
# thus we need to look through all of the entries.
continue
break
else: # `swp` with `ip` addr not found
raise LookupError(f'IP addr {swp, addr} expected, but not found')
else: # link with addr not found
if expected_addr['should_exist']:
raise LookupError(f'IP addr {expected_addr} expected, but not found')
Loading

0 comments on commit 9a1c6ab

Please sign in to comment.