[PATCH]: Print a better error message if the disk path doesn't exist

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

 



All,
     Currently with virt-install, if you specify a path for the disk image, and
the subdirectories don't exist, like so:

virt-install -n chris -r 512 -f /var/lib/xen/images/foo/x.img -s 1 --nonsparse
--nographics -p -l nfs:server:/path/to/tree

(where /var/lib/xen/images/foo subdir doesn't exist), you get a traceback like so:

Starting install...
Creating storage file...  100% |=========================| 1.0 GB    00:00
Traceback (most recent call last):
  File "/usr/sbin/virt-install", line 633, in ?
    main()
  File "/usr/sbin/virt-install", line 578, in main
    dom = guest.start_install(conscb,progresscb)
  File "/usr/lib/python2.4/site-packages/virtinst/Guest.py", line 649, in
start_install
    return self._do_install(consolecb, meter)
  File "/usr/lib/python2.4/site-packages/virtinst/Guest.py", line 662, in
_do_install
    self._create_devices(meter)
  File "/usr/lib/python2.4/site-packages/virtinst/Guest.py", line 557, in
_create_devices
    disk.setup(progresscb)
  File "/usr/lib/python2.4/site-packages/virtinst/Guest.py", line 104, in setup
    fd = os.open(self.path, os.O_WRONLY | os.O_CREAT)
OSError: [Errno 2] No such file or directory: '/var/lib/xen/images/foo/x.img'

The attached patch fixes this by adding a try..except inside of the try..finally
block to catch the exception and throw a RuntimeError instead.  Note that I went
the route of nested try..except inside of try..finally to be compatible with
python 2.4.  Also note that the patch as posted is against the RHEL-5.1 version
of virt-install, but should apply pretty easily to upstream virt-install.

Comments?

Thanks,
Chris Lalancette
diff -up virtinst-0.103.0/virtinst/Guest.py.orig virtinst-0.103.0/virtinst/Guest.py
--- virtinst-0.103.0/virtinst/Guest.py.orig	2007-10-04 13:42:48.000000000 -0400
+++ virtinst-0.103.0/virtinst/Guest.py	2007-10-04 13:42:51.000000000 -0400
@@ -101,16 +101,19 @@ class VirtualDisk:
                              text="Creating storage file...")
             fd = None
             try: 
-                fd = os.open(self.path, os.O_WRONLY | os.O_CREAT)
-                if self.sparse:
-                    os.lseek(fd, size_bytes, 0)
-                    os.write(fd, '\x00')
-                    progresscb.update(self.size)
-                else:
-                    buf = '\x00' * 1024 * 1024 # 1 meg of nulls
-                    for i in range(0, long(self.size * 1024L)):
-                        os.write(fd, buf)
-                        progresscb.update(long(i * 1024L * 1024L))
+                try:
+                    fd = os.open(self.path, os.O_WRONLY | os.O_CREAT)
+                    if self.sparse:
+                        os.lseek(fd, size_bytes, 0)
+                        os.write(fd, '\x00')
+                        progresscb.update(self.size)
+                    else:
+                        buf = '\x00' * 1024 * 1024 # 1 meg of nulls
+                        for i in range(0, long(self.size * 1024L)):
+                            os.write(fd, buf)
+                            progresscb.update(long(i * 1024L * 1024L))
+                except OSError:
+                    raise RuntimeError, "Path to diskimage "+self.path+" does not exist"
             finally:
                 if fd is not None:
                     os.close(fd)
_______________________________________________
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