Merge ~kissiel/plainbox-provider-checkbox:revive-ethtool into plainbox-provider-checkbox:master

Proposed by Maciej Kisielewski
Status: Merged
Approved by: Jeff Lane 
Approved revision: 47684a3effff731c20190f940fda4a635d633138
Merged at revision: 9d88c5ca0c733f458f2af38615a80975b539abea
Proposed branch: ~kissiel/plainbox-provider-checkbox:revive-ethtool
Merge into: plainbox-provider-checkbox:master
Diff against target: 71 lines (+37/-20)
1 file modified
bin/network (+37/-20)
Reviewer Review Type Date Requested Status
Sylvain Pineau Approve
Review via email: mp+317093@code.launchpad.net

Description of the change

bring back ethtool and use it as the main tool for determining NIC's speed. If it's not available try mii-tool. This should give us maximum resilience.

To post a comment you must log in.
Revision history for this message
Sylvain Pineau (sylvain-pineau) wrote :

I'd rather fix https://git.launchpad.net/checkbox-support/tree/checkbox_support/scripts/network.py instead and make changes to the checkbox provider only to use checkbox-support-network

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

> I'd rather fix https://git.launchpad.net/checkbox-
> support/tree/checkbox_support/scripts/network.py instead and make changes to
> the checkbox provider only to use checkbox-support-network

Yeah, I gave it some thought and decided my sequence of actions would be as follows:
1) patch bin/network here
2) propagate to checkbox-support
2.5) release c-s
3) patch *.pxus here to use checkbox-support-network

Revision history for this message
Sylvain Pineau (sylvain-pineau) wrote :

I'm fine with the plan above if we add 4) drop the network script from the provider

review: Approve
Revision history for this message
Jeff Lane  (bladernr) wrote :

Ummm... what is checkbox-support? are scripts moving there?
I started to work on this and fix the network script, but saw Maciej started working on it before I got to it.

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

> Ummm... what is checkbox-support? are scripts moving there?
> I started to work on this and fix the network script, but saw Maciej started
> working on it before I got to it.
We've started moving scripts that are used in more than one provider to checkbox-support, to not have to pull changes by hand, every time something changes. I see another benefit of having them available in checkbox-support-* _namespace_ ;)

Revision history for this message
Jeff Lane  (bladernr) wrote :

Sylvain approved the code, so I'm setting the branch to Approve to get it into Dev.

It's affecting our regression testing.

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 ae9cd38..88fd931 100755
3--- a/bin/network
4+++ b/bin/network
5@@ -280,29 +280,46 @@ class Interface(socket.socket):
6
7 @property
8 def max_speed(self):
9- # Parse mii-tool data for max speed
10- # search for numbers in the line starting with 'capabilities'
11- # return largest number as max_speed
12+ speeds = [0]
13+ # parse ethtool output, look for things like:
14+ # 100baseSX, 40000baseNX, 10000baseT
15 try:
16- info = check_output(['mii-tool', '-v', self.interface],
17- universal_newlines=True,
18- stderr=STDOUT).split('\n')
19- except FileNotFoundError:
20- logging.warning('mii-tool not found! Unable to get max speed')
21- ethinfo = None
22- except CalledProcessError as e:
23- logging.error('mii-tool returned an error!')
24- logging.error(e.output)
25- ethinfo = None
26- finally:
27- regex = re.compile(r'(\d+)(base)([A-Z]+)')
28- speeds = [0]
29- for line in filter(lambda l: 'capabilities' in l, info):
30- for s in line.split(' '):
31- hit = regex.search(s)
32+ ethinfo = check_output(['ethtool', self.interface],
33+ universal_newlines=True,
34+ stderr=STDOUT).split(' ')
35+ expression = '(\\d+)(base)([A-Z]+)|(\d+)(Mb/s)'
36+
37+ regex = re.compile(expression)
38+ if ethinfo:
39+ for i in ethinfo:
40+ hit = regex.search(i)
41 if hit:
42 speeds.append(int(re.sub("\D", "", hit.group(0))))
43- return max(speeds)
44+ except CalledProcessError as e:
45+ logging.error('ethtool returned an error!')
46+ logging.error(e.output)
47+ except FileNotFoundError:
48+ logging.warning('ethtool not found! Trying mii-tool')
49+ # Parse mii-tool data for max speed
50+ # search for numbers in the line starting with 'capabilities'
51+ # return largest number as max_speed
52+ try:
53+ info = check_output(['mii-tool', '-v', self.interface],
54+ universal_newlines=True,
55+ stderr=STDOUT).split('\n')
56+ regex = re.compile(r'(\d+)(base)([A-Z]+)')
57+ speeds = [0]
58+ for line in filter(lambda l: 'capabilities' in l, info):
59+ for s in line.split(' '):
60+ hit = regex.search(s)
61+ if hit:
62+ speeds.append(int(re.sub("\D", "", hit.group(0))))
63+ except FileNotFoundError:
64+ logging.warning('mii-tool not found! Unable to get max speed')
65+ except CalledProcessError as e:
66+ logging.error('mii-tool returned an error!')
67+ logging.error(e.output)
68+ return max(speeds)
69
70 @property
71 def macaddress(self):

Subscribers

People subscribed via source and target branches