Skip to content

Commit

Permalink
Fix ethtool show for link partner mode (dentproject#314)
Browse files Browse the repository at this point in the history
Signed-off-by: Stepan Vovk <stepan.vovk@plvision.eu>
  • Loading branch information
StepanVovkPLV committed Apr 30, 2023
1 parent 9e81ea6 commit 71c33c2
Showing 1 changed file with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from dent_os_testbed.lib.ethtool.linux.linux_ethtool import LinuxEthtool

RE_SPACES = re.compile(r'\s+')
RE_SPEEDS = re.compile(r'(10\d*baseT/(Half|Full))')


class LinuxEthtoolImpl(LinuxEthtool):
Expand Down Expand Up @@ -107,16 +106,16 @@ def parse_show(self, command, output, *argv, **kwarg):
records = record.split('\\n')[:-1]
else:
records = record.split('\n')[:-1]
speeds = []
previous_key = None
for line in records:
if ':' not in line and previous_key:
ethtool_info[previous_key] += ' ' + line.strip()
continue
line = RE_SPACES.sub(' ', line).strip().split(':')
key = line[0].replace(' ', '_').lower()
key = line[0].replace(' ', '_').lower().strip()
val = ' '.join(line[1:])
supp_speeds = RE_SPEEDS.findall(val)
if supp_speeds:
speeds.extend(supp_speed[0] for supp_speed in supp_speeds)
ethtool_info[key.strip()] = val.strip()
ethtool_info['supported_speeds'] = speeds
ethtool_info[key] = val.strip()
previous_key = key
return ethtool_info

def format_set(self, command, *argv, **kwarg):
Expand Down

0 comments on commit 71c33c2

Please sign in to comment.