From 79cad066ab849bdb773f1716c54acf61e601f0e8 Mon Sep 17 00:00:00 2001 From: Sugandha Gupta Date: Thu, 2 Aug 2018 14:48:12 -0700 Subject: e320: bist: Add link_up test - Returns true if the link of sfp0 is up (1G/10G) --- mpm/python/e320_bist | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'mpm/python') diff --git a/mpm/python/e320_bist b/mpm/python/e320_bist index 99da3cd74..c9664ce00 100755 --- a/mpm/python/e320_bist +++ b/mpm/python/e320_bist @@ -797,6 +797,32 @@ class E320BIST(object): } return len(result) == 1, result + def bist_link_up(self): + """ + BIST test for SFP link + Description: Checks if SFP link is up + External Equipment: 1G/10G cable connected to SFP port + Return dictionary: + - sfp0: status of link + Return status: True if link is UP + """ + assert 'link_up' in self.tests_to_run + if self.args.dry_run: + return True, {'sfp0': 'UP'} + from pyroute2 import IPRoute + result = {} + with IPRoute() as ipr: + links = ipr.link_lookup(ifname='sfp0') + if not links: + return False, {'error_msg': "No interface found"} + link_info = next(iter(ipr.get_links(links)), None) + if link_info == None: + return False, {'error_msg': "Error on get_links for sfp0"} + result['sfp0'] = link_info.get_attr('IFLA_OPERSTATE') + if result['sfp0'] != 'UP': + result['error_msg'] = "Link not up for interface" + return 'error_msg' not in result, result + def gpio_set_all(gpio_bank, value, gpio_size, ddr_mask): """Helper function for set gpio. -- cgit v1.2.3