Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
543 changes: 543 additions & 0 deletions ansible/roles/test/files/ptftests/py3/generic_hash_test.py

Large diffs are not rendered by default.

46 changes: 46 additions & 0 deletions tests/common/devices/sonic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2317,6 +2317,17 @@ def links_status_up(self, ports):
logging.info("Interface {} is up on {}".format(output_port, self.hostname))
return True

def is_interface_status_up(self, interface):
"""
Check if the status of a single interface is oper and admin up.
Args:
interface: the interface to check
Returns:
True if the interface is oper and admin up
"""
output = self.shell('show interface status {}'.format(interface))
return re.search('up +up', output['stdout_lines'][-1])

def get_port_fec(self, portname):
out = self.shell('redis-cli -n 4 HGET "PORT|{}" "fec"'.format(portname))
assert_exit_non_zero(out)
Expand All @@ -2343,6 +2354,41 @@ def get_sfp_type(self, portname):
sfp_type = re.search(r'[QO]?SFP-?[\d\w]{0,3}', out["stdout_lines"][0]).group()
return sfp_type

def get_switch_hash_capabilities(self):
out = self.shell('show switch-hash capabilities')
assert_exit_non_zero(out)
return SonicHost._parse_hash_fields(out)

def get_switch_hash_configurations(self):
out = self.shell('show switch-hash global')
assert_exit_non_zero(out)
return SonicHost._parse_hash_fields(out)

def set_switch_hash_global(self, hash_type, fields, validate=True):
cmd = 'config switch-hash global {}-hash'.format(hash_type)
for field in fields:
cmd += ' ' + field
out = self.shell(cmd, module_ignore_errors=True)
if validate:
assert_exit_non_zero(out)
return out

@staticmethod
def _parse_hash_fields(cli_output):
ecmp_hash_fields = []
lag_hash_fields = []
for line in cli_output['stdout'].splitlines()[2:]:
ecmp_hash_field = line.split(' ')[0]
if ' ' in line:
lag_hash_field = line.split(' ')[-1]
else:
lag_hash_field = ''
if ecmp_hash_field != 'N/A' and ecmp_hash_field != '':
ecmp_hash_fields.append(ecmp_hash_field)
if lag_hash_field != 'N/A' and lag_hash_field != '':
lag_hash_fields.append(lag_hash_field)
return {'ecmp': ecmp_hash_fields, 'lag': lag_hash_fields}


def assert_exit_non_zero(shell_output):
if shell_output['rc'] != 0:
Expand Down
21 changes: 21 additions & 0 deletions tests/hash/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""
Pytest configuration used by the read generic hash tests.
"""
from generic_hash_helper import HASH_FIELDS_SUPPORTED_BY_TEST


def pytest_addoption(parser):
parser.addoption("--hash_field", action="store", default="random",
choices=['all', 'random'] + HASH_FIELDS_SUPPORTED_BY_TEST,
help="The hash field to test, can be 'all', 'random' or a designated one")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible to list all the available ones?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

parser.addoption("--ip_version", action="store", default="random", choices=('all', 'random', 'ipv4', 'ipv6'),
help="The outer ip version to test.")
parser.addoption("--inner_ip_version", action="store", default="random", choices=('all', 'random', 'ipv4', 'ipv6'),
help="The inner ip version to test, only needed when hash field is an inner field.")
parser.addoption("--encap_type", action="store", default="random",
choices=('random', 'all', 'ipinip', 'vxlan', 'nvgre'),
help="The encapsulation type for the inner fields, "
"only needed when hash field is an inner field.")
parser.addoption("--reboot", action="store", default="random",
choices=('random', 'all', 'cold', 'fast', 'warm', 'reload'),
help="The reboot type for the reboot test, only needed for the reboot test case.")
Loading