Merge ~kissiel/plainbox-provider-checkbox:use-mii-tool-in-network into plainbox-provider-checkbox:master

Proposed by Maciej Kisielewski
Status: Merged
Approved by: Maciej Kisielewski
Approved revision: 7777b1e1abec3f0e17330582f9b1c3f7faae1536
Merged at revision: 582bcf4c69141532e8e7b25f162215b393d442a5
Proposed branch: ~kissiel/plainbox-provider-checkbox:use-mii-tool-in-network
Merge into: plainbox-provider-checkbox:master
Diff against target: 46 lines (+12/-15)
1 file modified
bin/network (+12/-15)
Reviewer Review Type Date Requested Status
Paul Larson Approve
Review via email: mp+314996@code.launchpad.net

Description of the change

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.

To post a comment you must log in.
Revision history for this message
Paul Larson (pwlars) wrote :

nice, +1

review: Approve
Revision history for this message
Maciej Kisielewski (kissiel) wrote :

I've run a series of tests on trusty, xenial, yakkety, zesty to confirm the output of mii-tool is acceptable for the new approach. They all passed.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/bin/network b/bin/network
2index 7ba8ef0..ae9cd38 100755
3--- a/bin/network
4+++ b/bin/network
5@@ -280,29 +280,26 @@ class Interface(socket.socket):
6
7 @property
8 def max_speed(self):
9- # Parse ethtool data for max speed since /sys/class/net/DEV/speed only
10- # reports link speed.
11-
12- # Search for things that look like 100baseSX,
13- # 40000baseNX, 10000baseT
14+ # Parse mii-tool data for max speed
15+ # search for numbers in the line starting with 'capabilities'
16+ # return largest number as max_speed
17 try:
18- ethinfo = check_output(['ethtool', self.interface],
19- universal_newlines=True,
20- stderr=STDOUT).split(' ')
21+ info = check_output(['mii-tool', '-v', self.interface],
22+ universal_newlines=True,
23+ stderr=STDOUT).split('\n')
24 except FileNotFoundError:
25- logging.warning('ethtool not found! Unable to get max speed')
26+ logging.warning('mii-tool not found! Unable to get max speed')
27 ethinfo = None
28 except CalledProcessError as e:
29- logging.error('ethtool returned an error!')
30+ logging.error('mii-tool returned an error!')
31 logging.error(e.output)
32 ethinfo = None
33 finally:
34- expression = '(\\d+)(base)([A-Z]+)|(\d+)(Mb/s)'
35- regex = re.compile(expression)
36+ regex = re.compile(r'(\d+)(base)([A-Z]+)')
37 speeds = [0]
38- if ethinfo:
39- for i in ethinfo:
40- hit = regex.search(i)
41+ for line in filter(lambda l: 'capabilities' in l, info):
42+ for s in line.split(' '):
43+ hit = regex.search(s)
44 if hit:
45 speeds.append(int(re.sub("\D", "", hit.group(0))))
46 return max(speeds)

Subscribers

People subscribed via source and target branches