-
Notifications
You must be signed in to change notification settings - Fork 714
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[link flap] add link flap pytest #1573
Changes from 4 commits
7f23687
28566d9
e204aad
cf42fb7
646ad74
61ea23b
1d2127d
83f5f53
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
""" | ||
Helper script for fanout switch operations | ||
""" | ||
|
||
def fanout_switch_port_lookup(fanout_switches, dut_port): | ||
""" | ||
look up the fanout switch instance and the fanout switch port | ||
connecting to the dut_port | ||
|
||
Args: | ||
fanout_switches (list FanoutHost): list of fanout switch | ||
instaances. | ||
dut_port (str): port name on the DUT | ||
|
||
Returns: | ||
None, None if fanout switch instance and port is not found | ||
FanoutHost, Portname(str) if found | ||
""" | ||
for _, fanout in fanout_switches.items(): | ||
if dut_port in fanout.host_to_fanout_port_map.keys(): | ||
daall marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return fanout, fanout.host_to_fanout_port_map[dut_port] | ||
|
||
return None, None |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import logging | ||
|
||
import pytest | ||
|
||
from common.platform.device_utils import fanout_switch_port_lookup | ||
from common.utilities import wait_until | ||
|
||
class TestLinkFlap: | ||
def __get_dut_if_status(self, dut, ifname=None): | ||
if not ifname: | ||
status = dut.show_interface(command='status')['ansible_facts']['int_status'] | ||
else: | ||
status = dut.show_interface(command='status', interfaces=[ifname])['ansible_facts']['int_status'] | ||
|
||
return status | ||
|
||
|
||
def __check_if_status(self, dut, dut_port, exp_state): | ||
status = self.__get_dut_if_status(dut, dut_port)[dut_port] | ||
return status['oper_state'] == exp_state | ||
|
||
|
||
def __toggle_one_link(self, dut, dut_port, fanout, fanout_port): | ||
logging.info("Testing link flap on {}".format(dut_port)) | ||
|
||
status = self.__get_dut_if_status(dut, dut_port)[dut_port] | ||
logging.debug("Dut port status {}".format(status)) | ||
assert status['oper_state'] == 'up', "Skipping dut port {}: link operational down".format(status) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this could reduced using the above helper function.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. True. Down side is that moving the debug statement into the helper function would cause it come out every second instead of once after waiting is done. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Found a good balance. Changed. |
||
|
||
logging.info("Shutting down fanout switch {} port {} connecting to {}".format(fanout.hostname, fanout_port, dut_port)) | ||
self.ports_shutdown_by_test.add((fanout, fanout_port)) | ||
fanout.shutdown(fanout_port) | ||
wait_until(30, 1, self.__check_if_status, dut, dut_port, 'down') | ||
status = self.__get_dut_if_status(dut, dut_port)[dut_port] | ||
logging.debug("Interface fact : {}".format(status)) | ||
assert status['oper_state'] == 'down', "dut port {} didn't go down as expected".format(dut_port) | ||
|
||
logging.info("Bring up fanout switch {} port {} connecting to {}".format(fanout.hostname, fanout_port, dut_port)) | ||
fanout.no_shutdown(fanout_port) | ||
wait_until(30, 1, self.__check_if_status, dut, dut_port, 'up') | ||
status = self.__get_dut_if_status(dut, dut_port)[dut_port] | ||
logging.debug("Interface fact : {}".format(status)) | ||
assert status['oper_state'] == 'up', "dut port {} didn't come up as expected".format(dut_port) | ||
self.ports_shutdown_by_test.discard((fanout, fanout_port)) | ||
|
||
|
||
def __build_test_candidates(self, dut, fanouthosts): | ||
status = self.__get_dut_if_status(dut) | ||
candidates = [] | ||
daall marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
for dut_port in status.keys(): | ||
fanout, fanout_port = fanout_switch_port_lookup(fanouthosts, dut_port) | ||
|
||
if not fanout or not fanout_port: | ||
logging.info("Skipping port {} that is not found in connection graph".format(dut_port)) | ||
elif status[dut_port]['admin_state'] == 'down': | ||
logging.info("Skipping port {} that is admin down".format(dut_port)) | ||
else: | ||
candidates.append((dut_port, fanout, fanout_port)) | ||
|
||
return candidates | ||
|
||
|
||
def run_link_flap_test(self, dut, fanouthosts): | ||
self.ports_shutdown_by_test = set() | ||
|
||
candidates = self.__build_test_candidates(dut, fanouthosts) | ||
|
||
try: | ||
for dut_port, fanout, fanout_port in candidates: | ||
self.__toggle_one_link(dut, dut_port, fanout, fanout_port) | ||
finally: | ||
logging.info("Restoring fanout switch ports that were shut down by test") | ||
for fanout, fanout_port in self.ports_shutdown_by_test: | ||
logging.debug("Restoring fanout switch {} port {} shut down by test".format(fanout.hostname, fanout_port)) | ||
fanout.no_shutdown(fanout_port) | ||
|
||
|
||
@pytest.mark.topology_any | ||
@pytest.mark.platform_physical | ||
def test_link_flap(duthost, fanouthosts): | ||
tlf = TestLinkFlap() | ||
tlf.run_link_flap_test(duthost, fanouthosts) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for catching it! Fixed now!