Browse Source

Handle unknown operstate with ethtool

Use ethtool if inteface operstate is not up.

Change-Id: I7eef2f9ab542fefacb4fe8ec16c3cab6e3b677b6
Closes-bug: #1618480
Vladimir Kuklin 2 years ago
parent
commit
b9b5633142
1 changed files with 16 additions and 2 deletions
  1. 16
    2
      network_checker/net_check/api.py

+ 16
- 2
network_checker/net_check/api.py View File

@@ -194,8 +194,22 @@ class Actor(object):
194 194
 
195 195
     def _check_iface_ready(self, iface, vid=None):
196 196
         check_iface = self._iface_name(iface, vid)
197
-        output = self._execute(['ip', '-o', 'link', 'show', check_iface])
198
-        return 'state UP' in '\n'.join(output)
197
+        with open('/sys/class/net/{0}/operstate'.format(check_iface)) as f:
198
+            state = f.readline().strip()
199
+        if state.lower() == 'up':
200
+            self.logger.debug('Inteface %s is up', check_iface)
201
+            return True
202
+        elif state.lower == 'unknown':
203
+            self.logger.debug('Inteface %s state is unknown, using ethtool',
204
+                              check_iface)
205
+            ethtool_output = self._execute(['ethtool', check_iface])
206
+            for line in ethtool_output:
207
+                result = re.match(r'Link\s+detected:\s*(\w+)', line.strip())
208
+                if result and result.group(1).lower() == 'yes':
209
+                    self.logger.debug('Link is detected by ethtool for %s',
210
+                                      check_iface)
211
+                    return True
212
+        return False
199 213
 
200 214
     def _ensure_iface_up(self, iface, vid=None):
201 215
         """Ensures interface is with vid up."""

Loading…
Cancel
Save