[DTS][V2] framework/crb: Add functions of check and wait specified link status
DongJunX
junx.dong at intel.com
Tue Jan 25 08:08:09 CET 2022
Signed-off-by: DongJunX <junx.dong at intel.com>
---
framework/crb.py | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git a/framework/crb.py b/framework/crb.py
index bd4f565d..7875510f 100755
--- a/framework/crb.py
+++ b/framework/crb.py
@@ -907,3 +907,33 @@ class Crb(object):
else:
self.logger.info("NIC %s may be not find %s" % (intf, flag))
return False
+
+ def is_interface_up(self, intf, timeout=15):
+ """
+ check and wait port link status up until timeout
+ """
+ for i in range(timeout):
+ link_status = self.get_interface_link_status(intf)
+ if link_status == 'Up':
+ return True
+ time.sleep(1)
+ self.logger.error(f"check and wait {intf} link up timeout")
+ return False
+
+ def is_interface_down(self, intf, timeout=15):
+ """
+ check and wait port link status down until timeout
+ """
+ for i in range(timeout):
+ link_status = self.get_interface_link_status(intf)
+ if link_status == 'Down':
+ return True
+ time.sleep(1)
+ self.logger.error(f"check and wait {intf} link down timeout")
+ return False
+
+ def get_interface_link_status(self, intf):
+ out = self.send_expect(f"ethtool {intf}", "#")
+ link_status_matcher = r'Link detected: (\w+)'
+ link_status = re.search(link_status_matcher, out).groups()[0]
+ return 'Up' if link_status == 'yes' else 'Down'
--
2.33.1.windows.1
More information about the dts
mailing list