[Kimchi-devel] [PATCHv4 4/6] Make sure path and volume will not be specified at same time

lvroyce at linux.vnet.ibm.com lvroyce at linux.vnet.ibm.com
Fri Jun 27 12:18:07 UTC 2014


From: Royce Lv <lvroyce at linux.vnet.ibm.com>

When adding vm storage, volume and path cannot be specified
at the same time. Fix it.

Signed-off-by: Royce Lv <lvroyce at linux.vnet.ibm.com>
---
 src/kimchi/i18n.py             | 1 +
 src/kimchi/mockmodel.py        | 2 ++
 src/kimchi/model/vmstorages.py | 2 ++
 3 files changed, 5 insertions(+)

diff --git a/src/kimchi/i18n.py b/src/kimchi/i18n.py
index 90ecc17..91684b6 100644
--- a/src/kimchi/i18n.py
+++ b/src/kimchi/i18n.py
@@ -246,6 +246,7 @@ messages = {
     "KCHVMSTOR0014E": _("Controller type %(type)s limitation of %(limit)s devices reached"),
     "KCHVMSTOR0015E": _("Cannot lookup disk path information by given pool/volume: %(error)s"),
     "KCHVMSTOR0016E": _("Volume already been used by other vm"),
+    "KCHVMSTOR0017E": _("Only one of path or pool/volume can be specified to add a new virtual machine disk"),
 
     "KCHREPOS0001E": _("YUM Repository ID must be one word only string."),
     "KCHREPOS0002E": _("Repository URL must be an http://, ftp:// or file:// URL."),
diff --git a/src/kimchi/mockmodel.py b/src/kimchi/mockmodel.py
index aecc2a1..a0920e0 100644
--- a/src/kimchi/mockmodel.py
+++ b/src/kimchi/mockmodel.py
@@ -665,6 +665,8 @@ class MockModel(object):
         path = params.get('path')
         if path and path.startswith('/') and not os.path.exists(path):
             raise InvalidParameter("KCHVMSTOR0003E", {'value': path})
+        if path and params.get('pool'):
+            raise InvalidParameter("KCHVMSTOR0017E")
         elif params.get('pool'):
             try:
                 self.storagevolume_lookup(params['pool'], params['vol'])
diff --git a/src/kimchi/model/vmstorages.py b/src/kimchi/model/vmstorages.py
index 8c51716..cd985fa 100644
--- a/src/kimchi/model/vmstorages.py
+++ b/src/kimchi/model/vmstorages.py
@@ -154,6 +154,8 @@ class VMStoragesModel(object):
         # Path will never be blank due to API.json verification.
         # There is no need to cover this case here.
         params['format'] = 'raw'
+        if not ('vol' in params) ^ ('path' in params):
+            raise InvalidParameter("KCHVMSTOR0017E")
         if params.get('vol'):
             try:
                 pool = params['pool']
-- 
1.8.3.2




More information about the Kimchi-devel mailing list