Change in vdsm[master]: netinfo:nicSpeed(): fix nicSpeed condition

phoracek at redhat.com phoracek at redhat.com
Fri Oct 31 11:53:53 UTC 2014


Petr Horáček has uploaded a new change for review.

Change subject: netinfo:nicSpeed(): fix nicSpeed condition
......................................................................

netinfo:nicSpeed(): fix nicSpeed condition

In `if s not in (2 ** 16 - 1, 2 ** 32 - 1) or s > 0` first
part doesnt make sense with OR. Changed to AND.

I changed conditions to make the function more readable.

Change-Id: I34cfca16909f9695441e26d3ddd508e7a4210c12
Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1157224
Signed-off-by: Petr Horáček <phoracek at redhat.com>
---
M lib/vdsm/netinfo.py
1 file changed, 9 insertions(+), 12 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/94/34694/1

diff --git a/lib/vdsm/netinfo.py b/lib/vdsm/netinfo.py
index d2ef90b..780f4e5 100644
--- a/lib/vdsm/netinfo.py
+++ b/lib/vdsm/netinfo.py
@@ -247,19 +247,16 @@
 
 
 def nicSpeed(nicName):
-    """Returns the nic speed if it is a legal value and nicName refers to a
-    nic, 0 otherwise."""
+    """Returns the nic speed if it is a legal value, nicName refers to a
+    nic and nic is UP, 0 otherwise."""
     try:
-        # if the device is not up we must report 0
-        if operstate(nicName) != OPERSTATE_UP:
-            return 0
-        with open('/sys/class/net/%s/speed' % nicName) as speedFile:
-            s = int(speedFile.read())
-        # the device may have been disabled/downed after checking
-        # so we validate the return value as sysfs may return
-        # special values to indicate the device is down/disabled
-        if s not in (2 ** 16 - 1, 2 ** 32 - 1) or s > 0:
-            return s
+        if operstate(nicName) == OPERSTATE_UP:
+            with open('/sys/class/net/%s/speed' % nicName) as speedFile:
+                s = int(speedFile.read())
+            # the device may have been disabled/downed after checking
+            # so we validate the return value as sysfs may return
+            # special values to indicate the device is down/disabled
+            return s if s not in (2 ** 16 - 1, 2 ** 32 - 1) and s > 0 else 0
     except IOError as ose:
         if ose.errno == errno.EINVAL:
             return _ibHackedSpeed(nicName)


-- 
To view, visit http://gerrit.ovirt.org/34694
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I34cfca16909f9695441e26d3ddd508e7a4210c12
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Petr Horáček <phoracek at redhat.com>


More information about the vdsm-patches mailing list