[PATCH] Change function that verifies network interface status

LTC Bugzilla #115031 - LTCTest: build-8: List interfaces which are active The old way does just consider if the interface has connectivity, not the interface status. The new file can determine if the interface is up or down and if cable is connected or not. Signed-off-by: Ramon Medeiros <ramonn@linux.vnet.ibm.com> --- src/kimchi/netinfo.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/kimchi/netinfo.py b/src/kimchi/netinfo.py index 5fd6130..276c0b7 100644 --- a/src/kimchi/netinfo.py +++ b/src/kimchi/netinfo.py @@ -29,7 +29,7 @@ BONDING_PATH = '/sys/class/net/*/bonding' WLAN_PATH = '/sys/class/net/*/wireless' NET_BRPORT = '/sys/class/net/%s/brport' NET_MASTER = '/sys/class/net/%s/master' -NET_STATE = '/sys/class/net/%s/operstate' +NET_STATE = '/sys/class/net/%s/carrier' PROC_NET_VLAN = '/proc/net/vlan/' BONDING_SLAVES = '/sys/class/net/%s/bonding/slaves' BRIDGE_PORTS = '/sys/class/net/%s/brif' @@ -101,8 +101,21 @@ def is_bondlave(nic): def operstate(dev): - return open(NET_STATE % dev).readline().strip() + status = None + + # try to read interface status + try: + status = open(NET_STATE % dev).readline().strip() + except IOError: + pass + + # when IOError is raised, interface is down + if status == None: + return "down" + # if value is 1, cable is connected + # 0 corresponds to no interface up with no cable + return "up" def get_vlan_device(vlan): """ Return the device of the given VLAN. """ -- 1.8.3.1

On 20-08-2014 11:58, Ramon Medeiros wrote:
LTC Bugzilla #115031 - LTCTest: build-8: List interfaces which are active
The old way does just consider if the interface has connectivity, not the interface status. The new file can determine if the interface is up or down and if cable is connected or not.
Signed-off-by: Ramon Medeiros <ramonn@linux.vnet.ibm.com>
There are trailing white spaces in your patch. Please remove them.
+ # try to read interface status + try: + status = open(NET_STATE % dev).readline().strip() + except IOError: + pass + + # when IOError is raised, interface is down + if status == None: + return "down"
If you want to return "down" when IOError is raised, do it inside the "except IOError" block (which actually exists but does nothing). I know both codes are similar, but the one in this patch is less clear.

On 08/21/2014 10:54 AM, Crístian Viana wrote:
On 20-08-2014 11:58, Ramon Medeiros wrote:
LTC Bugzilla #115031 - LTCTest: build-8: List interfaces which are active
The old way does just consider if the interface has connectivity, not the interface status. The new file can determine if the interface is up or down and if cable is connected or not.
Signed-off-by: Ramon Medeiros <ramonn@linux.vnet.ibm.com>
There are trailing white spaces in your patch. Please remove them.
+ # try to read interface status + try: + status = open(NET_STATE % dev).readline().strip() + except IOError: + pass + + # when IOError is raised, interface is down + if status == None: + return "down"
If you want to return "down" when IOError is raised, do it inside the "except IOError" block (which actually exists but does nothing). I know both codes are similar, but the one in this patch is less clear.
ok, i resent the patch -- Ramon Nunes Medeiros RHEV-H Blue for Troy & Sparta Focal Point Software Engineer - Linux Technology Center Brazil IBM Systems & Technology Group Phone : +55 19 2132 7878 ramonn@br.ibm.com
participants (2)
-
Crístian Viana
-
Ramon Medeiros