Change in vdsm[master]: Raise ValueError when passed invalid prefix

asegurap at redhat.com asegurap at redhat.com
Fri May 17 11:28:12 UTC 2013


Antoni Segura Puimedon has uploaded a new change for review.

Change subject: Raise ValueError when passed invalid prefix
......................................................................

Raise ValueError when passed invalid prefix

We should give meaningful Python errors to assist with user-input
checking. This patch is one step in this direction.

Change-Id: I95ef423bdc1fcbe1d0e9c3b0395f39a11e3c4ed2
Signed-off-by: Antoni S. Puimedon <asegurap at redhat.com>
---
M lib/vdsm/netinfo.py
M vdsm/configNetwork.py
2 files changed, 7 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/33/14833/1

diff --git a/lib/vdsm/netinfo.py b/lib/vdsm/netinfo.py
index b0cc844..af3262d 100644
--- a/lib/vdsm/netinfo.py
+++ b/lib/vdsm/netinfo.py
@@ -178,6 +178,9 @@
 
 
 def prefix2netmask(prefix):
+    if not 0 <= prefix <= 32:
+        raise ValueError('%s is not a valid prefix value. It must be between '
+                         '0 and 32')
     return socket.inet_ntoa(
         struct.pack("!I", int('1' * prefix + '0' * (32 - prefix), 2)))
 
diff --git a/vdsm/configNetwork.py b/vdsm/configNetwork.py
index c604ba2..a78cad2 100755
--- a/vdsm/configNetwork.py
+++ b/vdsm/configNetwork.py
@@ -270,7 +270,10 @@
     prefix = options.get('prefix')
     if prefix is not None:
         if netmask is None:
-            netmask = netinfo.prefix2netmask(int(prefix))
+            try:
+                netmask = netinfo.prefix2netmask(int(prefix))
+            except ValueError as ve:
+                raise ConfigNetworkError(ne.ERR_BAD_PARAMS, ve.message)
             del options['prefix']
         else:
             raise ConfigNetworkError(ne.ERR_BAD_PARAMS,


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I95ef423bdc1fcbe1d0e9c3b0395f39a11e3c4ed2
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Antoni Segura Puimedon <asegurap at redhat.com>


More information about the vdsm-patches mailing list