Change in vdsm[master]: NetReload: netmodels for addNetwork

gvallare at redhat.com gvallare at redhat.com
Mon Apr 29 07:12:47 UTC 2013


Giuseppe Vallarelli has posted comments on this change.

Change subject: NetReload: netmodels for addNetwork
......................................................................


Patch Set 2: (5 inline comments)

....................................................
File lib/vdsm/netinfo.py
Line 132: 
Line 133:     :param mtu: mtu value
Line 134:     :type mtu: integer
Line 135: 
Line 136:     getMaxMtu return the highest value in a connection tree,
Here you can use the directive :returns:  and then describe the returned value as you already did.
Line 137:     it check if a vlan, bond that have a higher mtu value
Line 138:     """
Line 139:     for nic in nics:
Line 140:         mtuval = int(getMtu(nic))


Line 139:     for nic in nics:
Line 140:         mtuval = int(getMtu(nic))
Line 141:         if mtuval > mtu:
Line 142:             mtu = mtuval
Line 143:     return mtu
It can be simplified by using the max builtin see example below:
a = ['12', '42', '3', '99']; max([int(x) for x in a])
Line 144: 
Line 145: 
Line 146: def bridge_stp_state(bridge):
Line 147:     stp = file('/sys/class/net/%s/bridge/stp_state' % bridge).readline()


Line 189:     return addr
Line 190: 
Line 191: 
Line 192: def prefix2netmask(prefix):
Line 193:     if not 0 <= prefix <= 32:
What about assert 0 <= prefix <= 32, 'error_message'
I would use assertions for conditions that should never happen.
Line 194:         raise ValueError('%s is not a valid prefix value. It must be between '
Line 195:                          '0 and 32')
Line 196:     return socket.inet_ntoa(
Line 197:         struct.pack("!I", int('1' * prefix + '0' * (32 - prefix), 2)))


Line 193:     if not 0 <= prefix <= 32:
Line 194:         raise ValueError('%s is not a valid prefix value. It must be between '
Line 195:                          '0 and 32')
Line 196:     return socket.inet_ntoa(
Line 197:         struct.pack("!I", int('1' * prefix + '0' * (32 - prefix), 2)))
The expression within int(...) is a little obscure.
Line 198: 
Line 199: 
Line 200: def netmask2prefix(netmask):
Line 201:     try:


Line 202:         socket.inet_pton(socket.AF_INET, netmask)
Line 203:     except socket.error:
Line 204:         raise ValueError('%s is not a valid netmask.' % netmask)
Line 205:     num = struct.unpack("!I", socket.inet_aton(netmask))[0]
Line 206:     if num & (num - 1) != (num << 1) & 0xffffffff:
if condition is not easy to understand. You can either add a comment or extract a method providing a meaningful name.
Line 207:         raise ValueError("%s is not a valid netmask." % netmask)
Line 208:     return bin(num)[2:].index('0')
Line 209: 
Line 210: 


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

Gerrit-MessageType: comment
Gerrit-Change-Id: Iba5c5b84760e27245cbe34c3b290c54e51278e72
Gerrit-PatchSet: 2
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Antoni Segura Puimedon <asegurap at redhat.com>
Gerrit-Reviewer: Antoni Segura Puimedon <asegurap at redhat.com>
Gerrit-Reviewer: Dan Kenigsberg <danken at redhat.com>
Gerrit-Reviewer: Giuseppe Vallarelli <gvallare at redhat.com>
Gerrit-Reviewer: Mark Wu <wudxw at linux.vnet.ibm.com>
Gerrit-Reviewer: oVirt Jenkins CI Server


More information about the vdsm-patches mailing list