The current template code checks whether an ISO path is a regular file
(i.e. not a directory, not a char device, not a link). However, a block
device may also be a valid ISO path because storage volumes belonging
to logical pools are always block devices (e.g. /dev/mypool/myvol.iso),
and they should also be used to create templates.
Instead of allowing only regular files to be used as template ISOs,
allow block devices as well.
Fix issue #565 (Allow creating templates with device files).
Signed-off-by: Crístian Viana <vianac(a)linux.vnet.ibm.com>
---
src/kimchi/isoinfo.py | 7 +++++--
src/kimchi/model/templates.py | 17 ++++++++++-------
src/kimchi/vmtemplate.py | 10 ++++++++--
3 files changed, 23 insertions(+), 11 deletions(-)
diff --git a/src/kimchi/isoinfo.py b/src/kimchi/isoinfo.py
index b5a1769..badb002 100644
--- a/src/kimchi/isoinfo.py
+++ b/src/kimchi/isoinfo.py
@@ -22,6 +22,7 @@ import glob
import platform
import os
import re
+import stat
import struct
import sys
import urllib2
@@ -151,8 +152,10 @@ class IsoImage(object):
self._scan()
def _is_iso_remote(self):
- if os.path.isfile(self.path):
- return False
+ if os.path.exists(self.path):
+ st_mode = os.stat(self.path).st_mode
+ if stat.S_ISREG(st_mode) or stat.S_ISBLK(st_mode):
+ return False
if check_url_path(self.path):
return True
diff --git a/src/kimchi/model/templates.py b/src/kimchi/model/templates.py
index e91636b..4ea1c0e 100644
--- a/src/kimchi/model/templates.py
+++ b/src/kimchi/model/templates.py
@@ -19,6 +19,7 @@
import copy
import os
+import stat
import libvirt
@@ -41,13 +42,15 @@ class TemplatesModel(object):
name = params.get('name', '').strip()
iso = params.get('cdrom')
# check search permission
- if iso and iso.startswith('/') and os.path.isfile(iso):
- user = UserTests().probe_user()
- ret, excp = probe_file_permission_as_user(iso, user)
- if ret is False:
- raise InvalidParameter('KCHISO0008E',
- {'filename': iso, 'user': user,
- 'err': excp})
+ if iso and iso.startswith('/') and os.path.exists(iso):
+ st_mode = os.stat(iso).st_mode
+ if stat.S_ISREG(st_mode) or stat.S_ISBLK(st_mode):
+ user = UserTests().probe_user()
+ ret, excp = probe_file_permission_as_user(iso, user)
+ if ret is False:
+ raise InvalidParameter('KCHISO0008E',
+ {'filename': iso, 'user':
user,
+ 'err': excp})
cpu_info = params.get('cpu_info')
if cpu_info:
diff --git a/src/kimchi/vmtemplate.py b/src/kimchi/vmtemplate.py
index ef41d0a..ec477dd 100644
--- a/src/kimchi/vmtemplate.py
+++ b/src/kimchi/vmtemplate.py
@@ -19,6 +19,7 @@
import os
import socket
+import stat
import time
import urlparse
import uuid
@@ -403,8 +404,13 @@ class VMTemplate(object):
# validate iso integrity
# FIXME when we support multiples cdrom devices
iso = self.info.get('cdrom')
- if iso and not (os.path.isfile(iso) or check_url_path(iso)):
- invalid['cdrom'] = [iso]
+ if iso:
+ if os.path.exists(iso):
+ st_mode = os.stat(iso).st_mode
+ if not (stat.S_ISREG(st_mode) or stat.S_ISBLK(st_mode)):
+ invalid['cdrom'] = [iso]
+ elif not check_url_path(iso):
+ invalid['cdrom'] = [iso]
self.info['invalid'] = invalid
--
2.1.0