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

Cole Robinson crobinso at redhat.com
Thu Oct 4 18:26:34 UTC 2007


Chris Lalancette wrote:
> 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
> 

Hi Chris,

Actually just yesterday I committed some validation cases to virtinst which
catch this problem, though in a different location.

http://hg.et.redhat.com/virt/applications/virtinst--devel?cs=c0b20d1eaaf2

It catches it prior to the setup() portion of the code: when
the disk path is passed to the VirtualDisk constructor, it now checks
to ensure the directory exists, and if not throws a ValueError. This
way virt-install can catch this and recover, then prompt the user for
a corrected path.

Not sure if the relevant portion of that patch fits your needs
though.

- Cole

-- 
Cole Robinson
crobinso at redhat.com




More information about the et-mgmt-tools mailing list