Re: [PATCH] reworked virtinst validation fixes

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

 



Daniel P. Berrange wrote:
> On Fri, Sep 28, 2007 at 01:16:27PM -0400, Cole Robinson wrote:
>> Hi all,
>>
>> This patch fixes some validation errors in virtinst uncovered by the
>> tests I just sent. I sent this a couple months ago but it must have just
>> fallen through the cracks, so I reworked it against the current tip.
>> This stuff is pretty simple and handy for useful error reporting.
> 
> Looks ok, except for this part:
> 
> -        if path != None:
> -            self.path = os.path.abspath(path)
> -        else:
> -            self.path = None
> -            type  = VirtualDisk.TYPE_FILE # Arbitrary choice but avoids the null-path null-type case
> -
> +        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)
> +
> 
> And a few places following it which don't cope with fact that self.path
> is allowed to be None. Path is allowed to be None for CDROMs so we can
> setup a disk whichout any media inserted.

I reworked this patch accommodating the case you stated above. In doing
so I also worked out a few bugs in the rest of the disk validating code.
As a result the patch changes the xml test code to use a path of
/etc/test.img instead of /xen/test.img for disk testing, since I added
a case to throw an exception if the root directory of the
path doesn't exist.

> 
> BTW, can you fix your Thunderbird so it either sends patches as text/plain,
> or just inlines them.
> 
>   http://lwn.net/Articles/249669/
> 
> Using text/x-patch as a type makes quoting & replying harder.
> 
> Regards,
> Dan.

Thanks for the tip. The attachment should be text/plain now. Let me know
if there is still an issue.

Thanks,
Cole

-- 
Cole Robinson
crobinso@xxxxxxxxxx
diff -r 219bd66150dd tests/boot-fullyvirt-disk-file.xml
--- a/tests/boot-fullyvirt-disk-file.xml	Fri Sep 28 12:33:09 2007 -0400
+++ b/tests/boot-fullyvirt-disk-file.xml	Wed Oct 03 10:00:28 2007 -0400
@@ -19,7 +19,7 @@
     <emulator>/usr/lib/xen/bin/qemu-dm</emulator>
     <console device='pty'/>
     <disk type='file' device='disk'>
-      <source file='/xen/test.img'/>
+      <source file='/etc/test.img'/>
       <target dev='hda'/>
     </disk>
     <disk type='block' device='cdrom'>
diff -r 219bd66150dd tests/boot-paravirt-disk-drv-file.xml
--- a/tests/boot-paravirt-disk-drv-file.xml	Fri Sep 28 12:33:09 2007 -0400
+++ b/tests/boot-paravirt-disk-drv-file.xml	Wed Oct 03 10:00:28 2007 -0400
@@ -11,7 +11,7 @@
   <devices>
     <disk type='file' device='disk'>
       <driver name='file'/>
-      <source file='/xen/test.img'/>
+      <source file='/etc/test.img'/>
       <target dev='xvda'/>
     </disk>
 
diff -r 219bd66150dd tests/boot-paravirt-disk-drv-tap-qcow.xml
--- a/tests/boot-paravirt-disk-drv-tap-qcow.xml	Fri Sep 28 12:33:09 2007 -0400
+++ b/tests/boot-paravirt-disk-drv-tap-qcow.xml	Wed Oct 03 10:00:28 2007 -0400
@@ -11,7 +11,7 @@
   <devices>
     <disk type='file' device='disk'>
       <driver name='tap' type='qcow'/>
-      <source file='/xen/test.img'/>
+      <source file='/etc/test.img'/>
       <target dev='xvda'/>
     </disk>
 
diff -r 219bd66150dd tests/boot-paravirt-disk-drv-tap.xml
--- a/tests/boot-paravirt-disk-drv-tap.xml	Fri Sep 28 12:33:09 2007 -0400
+++ b/tests/boot-paravirt-disk-drv-tap.xml	Wed Oct 03 10:00:28 2007 -0400
@@ -11,7 +11,7 @@
   <devices>
     <disk type='file' device='disk'>
       <driver name='tap'/>
-      <source file='/xen/test.img'/>
+      <source file='/etc/test.img'/>
       <target dev='xvda'/>
     </disk>
 
diff -r 219bd66150dd tests/boot-paravirt-disk-file.xml
--- a/tests/boot-paravirt-disk-file.xml	Fri Sep 28 12:33:09 2007 -0400
+++ b/tests/boot-paravirt-disk-file.xml	Wed Oct 03 10:00:28 2007 -0400
@@ -10,7 +10,7 @@
   <vcpu>5</vcpu>
   <devices>
     <disk type='file' device='disk'>
-      <source file='/xen/test.img'/>
+      <source file='/etc/test.img'/>
       <target dev='xvda'/>
     </disk>
 
diff -r 219bd66150dd tests/boot-paravirt-many-disks.xml
--- a/tests/boot-paravirt-many-disks.xml	Fri Sep 28 12:33:09 2007 -0400
+++ b/tests/boot-paravirt-many-disks.xml	Wed Oct 03 10:00:28 2007 -0400
@@ -10,12 +10,12 @@
   <vcpu>5</vcpu>
   <devices>
     <disk type='file' device='disk'>
-      <source file='/xen/test1.img'/>
+      <source file='/etc/test1.img'/>
       <target dev='xvda'/>
     </disk>
     <disk type='file' device='disk'>
       <driver name='tap' type='qcow'/>
-      <source file='/xen/test2.img'/>
+      <source file='/etc/test2.img'/>
       <target dev='xvdb'/>
     </disk>
     <disk type='block' device='disk'>
diff -r 219bd66150dd tests/install-fullyvirt-disk-file.xml
--- a/tests/install-fullyvirt-disk-file.xml	Fri Sep 28 12:33:09 2007 -0400
+++ b/tests/install-fullyvirt-disk-file.xml	Wed Oct 03 10:00:29 2007 -0400
@@ -19,7 +19,7 @@
     <emulator>/usr/lib/xen/bin/qemu-dm</emulator>
     <console device='pty'/>
     <disk type='file' device='disk'>
-      <source file='/xen/test.img'/>
+      <source file='/etc/test.img'/>
       <target dev='hda'/>
     </disk>
     <disk type='block' device='cdrom'>
diff -r 219bd66150dd tests/install-paravirt-disk-drv-file.xml
--- a/tests/install-paravirt-disk-drv-file.xml	Fri Sep 28 12:33:09 2007 -0400
+++ b/tests/install-paravirt-disk-drv-file.xml	Wed Oct 03 10:00:29 2007 -0400
@@ -16,7 +16,7 @@
   <devices>
     <disk type='file' device='disk'>
       <driver name='file'/>
-      <source file='/xen/test.img'/>
+      <source file='/etc/test.img'/>
       <target dev='xvda'/>
     </disk>
 
diff -r 219bd66150dd tests/install-paravirt-disk-drv-tap-qcow.xml
--- a/tests/install-paravirt-disk-drv-tap-qcow.xml	Fri Sep 28 12:33:09 2007 -0400
+++ b/tests/install-paravirt-disk-drv-tap-qcow.xml	Wed Oct 03 10:00:29 2007 -0400
@@ -16,7 +16,7 @@
   <devices>
     <disk type='file' device='disk'>
       <driver name='tap' type='qcow'/>
-      <source file='/xen/test.img'/>
+      <source file='/etc/test.img'/>
       <target dev='xvda'/>
     </disk>
 
diff -r 219bd66150dd tests/install-paravirt-disk-drv-tap.xml
--- a/tests/install-paravirt-disk-drv-tap.xml	Fri Sep 28 12:33:09 2007 -0400
+++ b/tests/install-paravirt-disk-drv-tap.xml	Wed Oct 03 10:00:29 2007 -0400
@@ -16,7 +16,7 @@
   <devices>
     <disk type='file' device='disk'>
       <driver name='tap'/>
-      <source file='/xen/test.img'/>
+      <source file='/etc/test.img'/>
       <target dev='xvda'/>
     </disk>
 
diff -r 219bd66150dd tests/install-paravirt-disk-file.xml
--- a/tests/install-paravirt-disk-file.xml	Fri Sep 28 12:33:09 2007 -0400
+++ b/tests/install-paravirt-disk-file.xml	Wed Oct 03 10:00:29 2007 -0400
@@ -15,7 +15,7 @@
   <vcpu>5</vcpu>
   <devices>
     <disk type='file' device='disk'>
-      <source file='/xen/test.img'/>
+      <source file='/etc/test.img'/>
       <target dev='xvda'/>
     </disk>
 
diff -r 219bd66150dd tests/install-paravirt-many-disks.xml
--- a/tests/install-paravirt-many-disks.xml	Fri Sep 28 12:33:09 2007 -0400
+++ b/tests/install-paravirt-many-disks.xml	Wed Oct 03 10:00:29 2007 -0400
@@ -15,12 +15,12 @@
   <vcpu>5</vcpu>
   <devices>
     <disk type='file' device='disk'>
-      <source file='/xen/test1.img'/>
+      <source file='/etc/test1.img'/>
       <target dev='xvda'/>
     </disk>
     <disk type='file' device='disk'>
       <driver name='tap' type='qcow'/>
-      <source file='/xen/test2.img'/>
+      <source file='/etc/test2.img'/>
       <target dev='xvdb'/>
     </disk>
     <disk type='block' device='disk'>
diff -r 219bd66150dd tests/xmlconfig.py
--- a/tests/xmlconfig.py	Fri Sep 28 12:33:09 2007 -0400
+++ b/tests/xmlconfig.py	Wed Oct 03 09:58:20 2007 -0400
@@ -53,7 +53,7 @@ class TestXMLConfig(unittest.TestCase):
 
     def testBootParavirtDiskFile(self):
         g = self._get_basic_paravirt_guest()
-        g.disks.append(virtinst.VirtualDisk("/xen/test.img", type=virtinst.VirtualDisk.TYPE_FILE,size=5))
+        g.disks.append(virtinst.VirtualDisk("/etc/test.img", type=virtinst.VirtualDisk.TYPE_FILE,size=5))
         self._compare(g, "boot-paravirt-disk-file", False)
 
     def testBootParavirtDiskBlock(self):
@@ -69,27 +69,27 @@ class TestXMLConfig(unittest.TestCase):
 
     def testBootParavirtDiskDrvFile(self):
         g = self._get_basic_paravirt_guest()
-        g.disks.append(virtinst.VirtualDisk("/xen/test.img", type=virtinst.VirtualDisk.TYPE_FILE, \
+        g.disks.append(virtinst.VirtualDisk("/etc/test.img", type=virtinst.VirtualDisk.TYPE_FILE, \
                                        driverName = virtinst.VirtualDisk.DRIVER_FILE,size=5))
         self._compare(g, "boot-paravirt-disk-drv-file", False)
 
     def testBootParavirtDiskDrvTap(self):
         g = self._get_basic_paravirt_guest()
-        g.disks.append(virtinst.VirtualDisk("/xen/test.img", type=virtinst.VirtualDisk.TYPE_FILE, \
+        g.disks.append(virtinst.VirtualDisk("/etc/test.img", type=virtinst.VirtualDisk.TYPE_FILE, \
                                        driverName = virtinst.VirtualDisk.DRIVER_TAP,size=5))
         self._compare(g, "boot-paravirt-disk-drv-tap", False)
 
     def testBootParavirtDiskDrvTapQCow(self):
         g = self._get_basic_paravirt_guest()
-        g.disks.append(virtinst.VirtualDisk("/xen/test.img", type=virtinst.VirtualDisk.TYPE_FILE, \
+        g.disks.append(virtinst.VirtualDisk("/etc/test.img", type=virtinst.VirtualDisk.TYPE_FILE, \
                                        driverName = virtinst.VirtualDisk.DRIVER_TAP, \
                                        driverType = virtinst.VirtualDisk.DRIVER_TAP_QCOW,size=5))
         self._compare(g, "boot-paravirt-disk-drv-tap-qcow", False)
 
     def testBootParavirtManyDisks(self):
         g = self._get_basic_paravirt_guest()
-        g.disks.append(virtinst.VirtualDisk("/xen/test1.img", type=virtinst.VirtualDisk.TYPE_FILE,size=5))
-        g.disks.append(virtinst.VirtualDisk("/xen/test2.img", type=virtinst.VirtualDisk.TYPE_FILE, \
+        g.disks.append(virtinst.VirtualDisk("/etc/test1.img", type=virtinst.VirtualDisk.TYPE_FILE,size=5))
+        g.disks.append(virtinst.VirtualDisk("/etc/test2.img", type=virtinst.VirtualDisk.TYPE_FILE, \
                                        driverName = virtinst.VirtualDisk.DRIVER_TAP, \
                                        driverType = virtinst.VirtualDisk.DRIVER_TAP_QCOW,size=5))
         g.disks.append(virtinst.VirtualDisk("/dev/root", type=virtinst.VirtualDisk.TYPE_BLOCK))
@@ -97,7 +97,7 @@ class TestXMLConfig(unittest.TestCase):
 
     def testBootFullyvirtDiskFile(self):
         g = self._get_basic_fullyvirt_guest()
-        g.disks.append(virtinst.VirtualDisk("/xen/test.img", type=virtinst.VirtualDisk.TYPE_FILE,size=5))
+        g.disks.append(virtinst.VirtualDisk("/etc/test.img", type=virtinst.VirtualDisk.TYPE_FILE,size=5))
         self._compare(g, "boot-fullyvirt-disk-file", False)
 
     def testBootFullyvirtDiskBlock(self):
@@ -110,7 +110,7 @@ class TestXMLConfig(unittest.TestCase):
 
     def testInstallParavirtDiskFile(self):
         g = self._get_basic_paravirt_guest()
-        g.disks.append(virtinst.VirtualDisk("/xen/test.img", type=virtinst.VirtualDisk.TYPE_FILE,size=5))
+        g.disks.append(virtinst.VirtualDisk("/etc/test.img", type=virtinst.VirtualDisk.TYPE_FILE,size=5))
         self._compare(g, "install-paravirt-disk-file", True)
 
     def testInstallParavirtDiskBlock(self):
@@ -126,27 +126,27 @@ class TestXMLConfig(unittest.TestCase):
 
     def testInstallParavirtDiskDrvFile(self):
         g = self._get_basic_paravirt_guest()
-        g.disks.append(virtinst.VirtualDisk("/xen/test.img", type=virtinst.VirtualDisk.TYPE_FILE, \
+        g.disks.append(virtinst.VirtualDisk("/etc/test.img", type=virtinst.VirtualDisk.TYPE_FILE, \
                                        driverName = virtinst.VirtualDisk.DRIVER_FILE,size=5))
         self._compare(g, "install-paravirt-disk-drv-file", True)
 
     def testInstallParavirtDiskDrvTap(self):
         g = self._get_basic_paravirt_guest()
-        g.disks.append(virtinst.VirtualDisk("/xen/test.img", type=virtinst.VirtualDisk.TYPE_FILE, \
+        g.disks.append(virtinst.VirtualDisk("/etc/test.img", type=virtinst.VirtualDisk.TYPE_FILE, \
                                        driverName = virtinst.VirtualDisk.DRIVER_TAP,size=5))
         self._compare(g, "install-paravirt-disk-drv-tap", True)
 
     def testInstallParavirtDiskDrvTapQCow(self):
         g = self._get_basic_paravirt_guest()
-        g.disks.append(virtinst.VirtualDisk("/xen/test.img", type=virtinst.VirtualDisk.TYPE_FILE, \
+        g.disks.append(virtinst.VirtualDisk("/etc/test.img", type=virtinst.VirtualDisk.TYPE_FILE, \
                                        driverName = virtinst.VirtualDisk.DRIVER_TAP, \
                                        driverType = virtinst.VirtualDisk.DRIVER_TAP_QCOW,size=5))
         self._compare(g, "install-paravirt-disk-drv-tap-qcow", True)
 
     def testInstallParavirtManyDisks(self):
         g = self._get_basic_paravirt_guest()
-        g.disks.append(virtinst.VirtualDisk("/xen/test1.img", type=virtinst.VirtualDisk.TYPE_FILE,size=5))
-        g.disks.append(virtinst.VirtualDisk("/xen/test2.img", type=virtinst.VirtualDisk.TYPE_FILE, \
+        g.disks.append(virtinst.VirtualDisk("/etc/test1.img", type=virtinst.VirtualDisk.TYPE_FILE,size=5))
+        g.disks.append(virtinst.VirtualDisk("/etc/test2.img", type=virtinst.VirtualDisk.TYPE_FILE, \
                                        driverName = virtinst.VirtualDisk.DRIVER_TAP, \
                                        driverType = virtinst.VirtualDisk.DRIVER_TAP_QCOW,size=5))
         g.disks.append(virtinst.VirtualDisk("/dev/root", type=virtinst.VirtualDisk.TYPE_BLOCK))
@@ -154,7 +154,7 @@ class TestXMLConfig(unittest.TestCase):
 
     def testInstallFullyvirtDiskFile(self):
         g = self._get_basic_fullyvirt_guest()
-        g.disks.append(virtinst.VirtualDisk("/xen/test.img", type=virtinst.VirtualDisk.TYPE_FILE,size=5))
+        g.disks.append(virtinst.VirtualDisk("/etc/test.img", type=virtinst.VirtualDisk.TYPE_FILE,size=5))
         self._compare(g, "install-fullyvirt-disk-file", True)
 
     def testInstallFullyvirtDiskBlock(self):
diff -r 219bd66150dd virtinst/CloneManager.py
--- a/virtinst/CloneManager.py	Fri Sep 28 12:33:09 2007 -0400
+++ b/virtinst/CloneManager.py	Wed Oct 03 09:06:14 2007 -0400
@@ -70,7 +70,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:
@@ -102,7 +102,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:
@@ -117,14 +117,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 219bd66150dd virtinst/Guest.py
--- a/virtinst/Guest.py	Fri Sep 28 12:33:09 2007 -0400
+++ b/virtinst/Guest.py	Wed Oct 03 10:05:02 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,21 +46,24 @@ class VirtualDisk:
         self.size = size
         self.sparse = sparse
         self.transient = transient
-        if path != None:
-            self.path = os.path.abspath(path)
-        else:
-            self.path = None
-            type  = VirtualDisk.TYPE_FILE # Arbitrary choice but avoids the null-path null-type case
-            
-        if self.path != None and os.path.isdir(self.path):
-            raise ValueError, \
-                _("The disk path must be a file or a device, not a directory")
-
-        if self.path != None and not self.path.startswith("/"):
-            raise ValueError, \
-                _("The disk path must be an absolute path location, beginning with '/'")
-
-        if type is None:
+        self.path = path
+       
+        if self.path is not None:
+            if __builtin__.type(self.path) is not __builtin__.type("string"):
+                raise ValueError, _("The disk path must be a string or None.")
+            self.path = os.path.abspath(self.path)
+
+            if self.path != None and os.path.isdir(self.path):
+                raise ValueError, _("The disk path must be a file or a device, not a directory")
+
+            if not os.path.exists(os.path.dirname(self.path)):
+                raise ValueError, _("The specified path's root directory must exist.")
+        else:
+            if device is not self.DEVICE_FLOPPY and \
+               device is not self.DEVICE_CDROM:
+                raise ValueError, _("Disk type '%s' requires a path") % device 
+
+        if type is None and self.path is not None:
             if not os.path.exists(self.path):
                 logging.debug("Disk path not found: Assuming file disk type.");
                 self._type = VirtualDisk.TYPE_FILE
@@ -79,13 +77,16 @@ class VirtualDisk:
         else:
             self._type = type
 
-        if self._type == VirtualDisk.TYPE_FILE and self.path != None:
-            if size is None and not os.path.exists(self.path):
+        if self._type == VirtualDisk.TYPE_FILE and self.path is not None:
+            if self.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:
-                raise ValueError, \
-                    _("The size of the disk image must be greater than 0")
+            if self.size is not None and \
+               (__builtin__.type(self.size) is not __builtin__.type(1) and \
+                __builtin__.type(self.size) is not __builtin__.type(1.0)):
+                raise ValueError, _("Disk size must be an int or a float.")
+            if self.size <= 0 and self.size is not None:
+                raise ValueError, _("Disk size must be 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.")
@@ -123,7 +124,8 @@ class VirtualDisk:
     read_only = property(get_read_only)
 
     def setup(self, progresscb):
-        if self._type == VirtualDisk.TYPE_FILE and not os.path.exists(self.path):
+        if self._type == VirtualDisk.TYPE_FILE and self.path is not None \
+           and not os.path.exists(self.path):
             size_bytes = long(self.size * 1024L * 1024L * 1024L)
             progresscb.start(filename=self.path,size=long(size_bytes), \
                              text=_("Creating storage file..."))
@@ -213,10 +215,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
@@ -411,6 +418,8 @@ class Installer(object):
     def get_cdrom(self):
         return self._cdrom
     def set_cdrom(self, enable):
+        if __builtin__.type(enable) is not __builtin__.type(True):
+            raise ValueError, _("Guest.cdrom must be a boolean type")
         self._cdrom = enable
     cdrom = property(get_cdrom, set_cdrom)
 
@@ -438,6 +447,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
@@ -487,14 +498,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)
 
@@ -503,7 +512,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:
@@ -514,7 +523,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)
@@ -525,6 +534,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)
@@ -533,7 +545,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)
 
@@ -629,9 +641,13 @@ class Guest(object):
     extraargs = property(get_extraargs, set_extraargs)
 
     def get_cdrom(self):
-        return self.location
+        return self._installer.location
     def set_cdrom(self, val):
-        self.location = val
+        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)
         self._installer.cdrom = True
     cdrom = property(get_cdrom, set_cdrom)
 
_______________________________________________
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