[PATCH] virtinst validation fixes

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The attached patch fixes some validation errors in virtinst uncovered by
the recently submitted validation tests.

Signed-off-by: Cole Robinson <crobinso@xxxxxxxxxx>

Thanks,
Cole

-- 
Cole Robinson
crobinso@xxxxxxxxxx
diff -r 5ca9f240b398 virtinst/CloneManager.py
--- a/virtinst/CloneManager.py	Thu Jul 12 17:17:50 2007 -0400
+++ b/virtinst/CloneManager.py	Tue Jul 10 14:55:24 2007 -0400
@@ -69,7 +69,7 @@ class CloneDesign(object):
     def get_original_guest(self):
         return self._original_guest
     def set_original_guest(self, original_guest):
-        if len(original_guest) == 0:
+        if type(original_guest) is not type("str") or len(original_guest)==0:
            raise ValueError, _("Name or UUID of guest to clone is required")
 
         try:
@@ -101,7 +101,7 @@ class CloneDesign(object):
         self._clone_uuid = uuid
     def get_clone_uuid(self):
         return self._clone_uuid
-    clone_uuid = property(get_clone_uuid)
+    clone_uuid = property(get_clone_uuid, set_clone_uuid)
 
     def set_clone_devices(self, devices):
         if len(devices) == 0:
@@ -109,14 +109,14 @@ class CloneDesign(object):
         self._clone_devices.append(devices)
     def get_clone_devices(self):
         return self._clone_devices
-    clone_devices = property(get_clone_devices)
+    clone_devices = property(get_clone_devices, set_clone_devices)
 
     def set_clone_mac(self, mac):
         Guest.VirtualNetworkInterface(mac)
         self._clone_mac.append(mac)
     def get_clone_mac(self):
         return self._clone_mac
-    clone_mac = property(get_clone_mac)
+    clone_mac = property(get_clone_mac, set_clone_mac)
 
     def get_clone_bs(self):
         return self._clone_bs
diff -r 5ca9f240b398 virtinst/Guest.py
--- a/virtinst/Guest.py	Thu Jul 12 17:17:50 2007 -0400
+++ b/virtinst/Guest.py	Tue Jul 10 16:01:22 2007 -0400
@@ -19,15 +19,10 @@ import urlgrabber.progress as progress
 import urlgrabber.progress as progress
 import util
 import libvirt
+import __builtin__
 from virtinst import _virtinst as _
 
 import logging
-
-
-#print "YO %s" % (virtinst.gettext_virtinst("YO"))
-
-#def _(msg):
-#    gettext_virtinst(msg)
 
 class VirtualDisk:
     DRIVER_FILE = "file"
@@ -51,15 +46,16 @@ class VirtualDisk:
         self.size = size
         self.sparse = sparse
         self.transient = transient
-        self.path = os.path.abspath(path)
+        self.path = path
+
+        if __builtin__.type(self.path) is not __builtin__.type("string"): 
+            raise ValueError, \
+                _("The disk path must be a string.")
+        self.path = os.path.abspath(self.path)
 
         if os.path.isdir(self.path):
             raise ValueError, \
                 _("The disk path must be a file or a device, not a directory")
-
-        if not self.path.startswith("/"):
-            raise ValueError, \
-                _("The disk path must be an absolute path location, beginning with '/'")
 
         if type is None:
             if not os.path.exists(self.path):
@@ -79,9 +75,11 @@ class VirtualDisk:
             if size is None and not os.path.exists(self.path):
                 raise ValueError, \
                     _("A size must be provided for non-existent disks")
-            if size is not None and size <= 0:
+            if size is not None and \
+               (__builtin__.type(size) is not __builtin__.type(1) or \
+               size <= 0):
                 raise ValueError, \
-                    _("The size of the disk image must be greater than 0")
+                    _("Disk size must be an integer greater than 0.")
         elif self._type == VirtualDisk.TYPE_BLOCK:
             if not os.path.exists(self.path):
                 raise ValueError, _("The specified block device does not exist.")
@@ -208,10 +206,15 @@ class VirtualNetworkInterface:
 class VirtualNetworkInterface:
     def __init__(self, macaddr = None, type="bridge", bridge = None, network=None):
 
+        if macaddr is not None and \
+           __builtin__.type(macaddr) is not __builtin__.type("string"):
+            raise ValueError, "MAC address must be a string."
+
         if macaddr is not None:
             form = re.match("^([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$",macaddr)
             if form is None:
-                raise ValueError(_("MAC address must be of the format AA:BB:CC:DD:EE:FF"))
+                raise ValueError, \
+                    _("MAC address must be of the format AA:BB:CC:DD:EE:FF")
         self.macaddr = macaddr
         self.type = type
         self.bridge = bridge
@@ -425,6 +428,8 @@ class Installer(object):
             if len(val) != 2:
                 raise ValueError, _("Must pass both a kernel and initrd")
             self._boot = {"kernel": val[0], "initrd": val[1]}
+        else:
+            raise ValueError, _("Kernel and initrd must be specified by a list, dict, or tuple.")
     boot = property(get_boot, set_boot)
 
     # extra arguments to pass to the guest installer
@@ -446,6 +451,7 @@ class Guest(object):
         self._vcpus = None
         self._graphics = { "enabled": False }
         self._keymap = None
+        self._URI = hypervisorURI
 
         self.domain = None
         self.conn = connection
@@ -472,14 +478,12 @@ class Guest(object):
     def get_name(self):
         return self._name
     def set_name(self, val):
-        if len(val) > 50 or len(val) == 0:
-            raise ValueError, _("System name must be greater than 0 and no more than 50 characters")
+        if type(val) is not type("string") or len(val) > 50 or len(val) == 0:
+            raise ValueError, _("System name must be a string greater than 0 and no more than 50 characters")
         if re.match("^[0-9]+$", val):
             raise ValueError, _("System name must not be only numeric characters")
         if re.match("^[a-zA-Z0-9._-]+$", val) == None:
             raise ValueError, _("System name can only contain alphanumeric, '_', '.', or '-' characters")
-        if type(val) != type("string"):
-            raise ValueError, _("System name must be a string")
         self._name = val
     name = property(get_name, set_name)
 
@@ -488,7 +492,7 @@ class Guest(object):
     def get_memory(self):
         return self._memory
     def set_memory(self, val):
-        if (type(val) is not type(1) or val < 0):
+        if (type(val) is not type(1) or val <= 0):
             raise ValueError, _("Memory value must be an integer greater than 0")
         self._memory = val
         if self._maxmemory is None or self._maxmemory < val:
@@ -499,7 +503,7 @@ class Guest(object):
     def get_maxmemory(self):
         return self._maxmemory
     def set_maxmemory(self, val):
-        if (type(val) is not type(1) or val < 0):
+        if (type(val) is not type(1) or val <= 0):
             raise ValueError, _("Max Memory value must be an integer greater than 0")
         self._maxmemory = val
     maxmemory = property(get_maxmemory, set_maxmemory)
@@ -510,6 +514,9 @@ class Guest(object):
         return self._uuid
     def set_uuid(self, val):
         # need better validation
+        if type(val) is not type("string"):
+            raise ValueError, _("UUID must be a string.")
+
         form = re.match("[a-fA-F0-9]{8}[-]([a-fA-F0-9]{4}[-]){3}[a-fA-F0-9]{12}$", val)
         if form is None:
             form = re.match("[a-fA-F0-9]{32}$", val)
@@ -518,7 +525,7 @@ class Guest(object):
 
             else:   # UUID had no dashes, so add them in
                 val=val[0:8] + "-" + val[8:12] + "-" + val[12:16] + \
-                "-" + val[16:20] + "-" + val[20:32]
+                    "-" + val[16:20] + "-" + val[20:32]
         self._uuid = val
     uuid = property(get_uuid, set_uuid)
 
@@ -619,8 +626,8 @@ class Guest(object):
             return self._installer.location
         return None
     def set_cdrom(self, val):
-        if val is None or len(val) == 0:
-            raise ValueError, _("You must specify an ISO or CD-ROM location for the installation")
+        if val is None or type(val) is not type("string") or len(val) == 0:
+            raise ValueError, _("You must specify a valid ISO or CD-ROM location for the installation")
         if not os.path.exists(val):
             raise ValueError, _("The specified media path does not exist.")
         self._installer.location = os.path.abspath(val)
diff -r 5ca9f240b398 virtinst/__init__.py.in
--- a/virtinst/__init__.py.in	Thu Jul 12 17:17:50 2007 -0400
+++ b/virtinst/__init__.py.in	Tue Jul 10 14:51:32 2007 -0400
@@ -14,3 +14,4 @@ from ParaVirtGuest import ParaVirtGuest
 from ParaVirtGuest import ParaVirtGuest
 from DistroManager import DistroInstaller
 from LiveCDInstaller import LiveCDInstaller
+from CloneManager import CloneDesign
_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/et-mgmt-tools

[Index of Archives]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux