summaryrefslogtreecommitdiff
diff options
authorMaciej Kisielewski <maciej.kisielewski@canonical.com>2017-01-18 11:00:37 +0100
committerMaciej Kisielewski <maciej.kisielewski@canonical.com>2017-01-18 11:00:37 +0100
commitd3d14a2e7a8c4d2c849b2673b2498eab1f26aff4 (patch)
tree9254d01c97c216862ecf0a21e711a491017d3fdc
parenta3e460b7a10f6af6b91b090c1e4a4709c035625b (diff)
network: use mii-tool instead of ethtool to determine max speed
On some systems, ethtool returns such output: >>> Supported link modes: 10baseT/Half 10baseT/Full 100baseT/Half 100baseT/Full 1000baseT/Half 1000baseT/Full Supported pause frame use: No Supports auto-negotiation: Yes Advertised link modes: 10baseT/Half 10baseT/Full 100baseT/Half 100baseT/Full Advertised pause frame use: Symmetric Receive-only Advertised auto-negotiation: Yes Link partner advertised link modes: 10baseT/Half 10baseT/Full 100baseT/Half 100baseT/Full <<< previous version of the `network` script parsed for any number followed by the 'baseT' string and picked the largest one found as max_speed. Which for this system is wrong. This patch makes the script parse output of mii-tool and look for 'capabilities' line. It parses modes only from that line. In case of that system it returns 100. Signed-off-by: Maciej Kisielewski <maciej.kisielewski@canonical.com>
-rwxr-xr-xbin/network27
1 files changed, 12 insertions, 15 deletions
diff --git a/bin/network b/bin/network
index 7ba8ef0..ae9cd38 100755
--- a/bin/network
+++ b/bin/network
@@ -280,29 +280,26 @@ class Interface(socket.socket):
@property
def max_speed(self):
- # Parse ethtool data for max speed since /sys/class/net/DEV/speed only
- # reports link speed.
-
- # Search for things that look like 100baseSX,
- # 40000baseNX, 10000baseT
+ # Parse mii-tool data for max speed
+ # search for numbers in the line starting with 'capabilities'
+ # return largest number as max_speed
try:
- ethinfo = check_output(['ethtool', self.interface],
- universal_newlines=True,
- stderr=STDOUT).split(' ')
+ info = check_output(['mii-tool', '-v', self.interface],
+ universal_newlines=True,
+ stderr=STDOUT).split('\n')
except FileNotFoundError:
- logging.warning('ethtool not found! Unable to get max speed')
+ logging.warning('mii-tool not found! Unable to get max speed')
ethinfo = None
except CalledProcessError as e:
- logging.error('ethtool returned an error!')
+ logging.error('mii-tool returned an error!')
logging.error(e.output)
ethinfo = None
finally:
- expression = '(\\d+)(base)([A-Z]+)|(\d+)(Mb/s)'
- regex = re.compile(expression)
+ regex = re.compile(r'(\d+)(base)([A-Z]+)')
speeds = [0]
- if ethinfo:
- for i in ethinfo:
- hit = regex.search(i)
+ for line in filter(lambda l: 'capabilities' in l, info):
+ for s in line.split(' '):
+ hit = regex.search(s)
if hit:
speeds.append(int(re.sub("\D", "", hit.group(0))))
return max(speeds)