[Kimchi-devel] [PATCH 2/4] Add Kimchi version to objectstore entries.

pvital at linux.vnet.ibm.com pvital at linux.vnet.ibm.com
Thu Nov 5 18:47:16 UTC 2015


From: Paulo Vital <pvital at linux.vnet.ibm.com>

Update all ObjectStore.store() call in Kimchi to add Kimchi version
to objectstore entries. To support this, add a get_kimchi_version()
method into Kimchi's config.py.

Signed-off-by: Paulo Vital <pvital at linux.vnet.ibm.com>
---
 src/wok/plugins/kimchi/config.py.in          |  5 +++++
 src/wok/plugins/kimchi/model/diskutils.py    |  7 +++++--
 src/wok/plugins/kimchi/model/storagepools.py |  4 +++-
 src/wok/plugins/kimchi/model/templates.py    |  4 +++-
 src/wok/plugins/kimchi/model/vms.py          | 20 +++++++++++++-------
 src/wok/plugins/kimchi/tests/test_model.py   |  4 +++-
 6 files changed, 32 insertions(+), 12 deletions(-)

diff --git a/src/wok/plugins/kimchi/config.py.in b/src/wok/plugins/kimchi/config.py.in
index 43e94e1..8b43b4e 100644
--- a/src/wok/plugins/kimchi/config.py.in
+++ b/src/wok/plugins/kimchi/config.py.in
@@ -29,11 +29,16 @@ from wok.xmlutils.utils import xpath_get_text
 kimchiLock = threading.Lock()
 
 __with_spice__ = "@withspice@"
+__version__ = "@kimchiversion@"
 
 # Storage pool constant for read-only pool types
 READONLY_POOL_TYPE = ['iscsi', 'scsi', 'mpath']
 
 
+def get_kimchi_version():
+    return __version__
+
+
 def get_distros_store():
     return os.path.join(PluginPaths('kimchi').conf_dir, 'distros.d')
 
diff --git a/src/wok/plugins/kimchi/model/diskutils.py b/src/wok/plugins/kimchi/model/diskutils.py
index 076b334..b3fe116 100644
--- a/src/wok/plugins/kimchi/model/diskutils.py
+++ b/src/wok/plugins/kimchi/model/diskutils.py
@@ -20,6 +20,7 @@
 from wok.exception import OperationFailed, NotFoundError
 from wok.utils import wok_log
 
+from wok.plugins.kimchi.config import get_kimchi_version
 from wok.plugins.kimchi.model.vms import VMModel, VMsModel
 from wok.plugins.kimchi.xmlutils.disk import get_vm_disk_info, get_vm_disks
 
@@ -49,7 +50,8 @@ def get_disk_used_by(objstore, conn, path):
                             used_by.append(vm)
                 try:
                     session.store('storagevolume', path,
-                                  {'used_by': used_by})
+                                  {'used_by': used_by},
+                                  get_kimchi_version())
                 except Exception as e:
                     # Let the exception be raised. If we allow disks'
                     #   used_by to be out of sync, data corruption could
@@ -71,6 +73,7 @@ def get_disk_used_by(objstore, conn, path):
 def set_disk_used_by(objstore, path, new_used_by):
     try:
         with objstore as session:
-            session.store('storagevolume', path, {'used_by': new_used_by})
+            session.store('storagevolume', path, {'used_by': new_used_by},
+                          get_kimchi_version())
     except Exception as e:
         raise OperationFailed('KCHVOL0017E', {'err': e.message})
diff --git a/src/wok/plugins/kimchi/model/storagepools.py b/src/wok/plugins/kimchi/model/storagepools.py
index a5c5581..cc0bc7c 100644
--- a/src/wok/plugins/kimchi/model/storagepools.py
+++ b/src/wok/plugins/kimchi/model/storagepools.py
@@ -28,6 +28,7 @@ from wok.exception import NotFoundError, OperationFailed
 from wok.utils import add_task, run_command, wok_log
 from wok.xmlutils.utils import xpath_get_text
 
+from wok.plugins.kimchi.config import get_kimchi_version
 from wok.plugins.kimchi.model.config import CapabilitiesModel
 from wok.plugins.kimchi.model.host import DeviceModel
 from wok.plugins.kimchi.model.libvirtstoragepool import StoragePoolDef
@@ -251,7 +252,8 @@ class StoragePoolsModel(object):
         # Record scanning-task/storagepool mapping for future querying
         try:
             with self.objstore as session:
-                session.store('scanning', params['name'], task_id)
+                session.store('scanning', params['name'], task_id,
+                              get_kimchi_version())
             return task_id
         except Exception as e:
             raise OperationFailed('KCHPOOL0037E', {'err': e.message})
diff --git a/src/wok/plugins/kimchi/model/templates.py b/src/wok/plugins/kimchi/model/templates.py
index 2886c87..47b2c9e 100644
--- a/src/wok/plugins/kimchi/model/templates.py
+++ b/src/wok/plugins/kimchi/model/templates.py
@@ -27,6 +27,7 @@ from wok.exception import NotFoundError, OperationFailed
 from wok.utils import probe_file_permission_as_user, run_setfacl_set_attr
 from wok.xmlutils.utils import xpath_get_text
 
+from wok.plugins.kimchi.config import get_kimchi_version
 from wok.plugins.kimchi.kvmusertests import UserTests
 from wok.plugins.kimchi.model.cpuinfo import CPUInfoModel
 from wok.plugins.kimchi.utils import pool_name_from_uri
@@ -98,7 +99,8 @@ class TemplatesModel(object):
             with self.objstore as session:
                 if name in session.get_list('template'):
                     raise InvalidOperation("KCHTMPL0001E", {'name': name})
-                session.store('template', name, t.info)
+                session.store('template', name, t.info,
+                              get_kimchi_version())
         except InvalidOperation:
             raise
         except Exception, e:
diff --git a/src/wok/plugins/kimchi/model/vms.py b/src/wok/plugins/kimchi/model/vms.py
index 63681c7..e91160c 100644
--- a/src/wok/plugins/kimchi/model/vms.py
+++ b/src/wok/plugins/kimchi/model/vms.py
@@ -43,7 +43,7 @@ from wok.xmlutils.utils import dictize
 
 from wok.plugins.kimchi import model
 from wok.plugins.kimchi import vnc
-from wok.plugins.kimchi.config import READONLY_POOL_TYPE
+from wok.plugins.kimchi.config import READONLY_POOL_TYPE, get_kimchi_version
 from wok.plugins.kimchi.kvmusertests import UserTests
 from wok.plugins.kimchi.model.config import CapabilitiesModel
 from wok.plugins.kimchi.model.featuretests import FeatureTests
@@ -138,7 +138,8 @@ class VMsModel(object):
         if icon:
             try:
                 with self.objstore as session:
-                    session.store('vm', vm_uuid, {'icon': icon})
+                    session.store('vm', vm_uuid, {'icon': icon},
+                                  get_kimchi_version())
             except Exception as e:
                 # It is possible to continue Kimchi executions without store
                 # vm icon info
@@ -480,7 +481,8 @@ class VMModel(object):
             # set the new disk's used_by
             with self.objstore as session:
                 session.store('storagevolume', new_vol['path'],
-                              {'used_by': [domain_name]})
+                              {'used_by': [domain_name]},
+                              get_kimchi_version())
             rollback.prependDefer(_delete_disk_from_objstore, new_vol['path'])
 
             # remove the new volume should an error occur later
@@ -502,7 +504,8 @@ class VMModel(object):
             try:
                 vm = session.get('vm', old_uuid)
                 icon = vm['icon']
-                session.store('vm', new_uuid, {'icon': icon})
+                session.store('vm', new_uuid, {'icon': icon},
+                              get_kimchi_version())
             except NotFoundError:
                 # if we cannot find an object store entry for the original VM,
                 # don't store one with an empty value.
@@ -1141,7 +1144,8 @@ class VMModel(object):
                         used_by = session.get('storagevolume', path)['used_by']
                         used_by.remove(name)
                         session.store('storagevolume', path,
-                                      {'used_by': used_by})
+                                      {'used_by': used_by},
+                                      get_kimchi_version())
             except Exception as e:
                 raise OperationFailed('KCHVOL0017E', {'err': e.message})
 
@@ -1400,7 +1404,8 @@ class VMScreenshotModel(object):
         # screenshot info changed after scratch generation
         try:
             with self.objstore as session:
-                session.store('screenshot', vm_uuid, screenshot.info)
+                session.store('screenshot', vm_uuid, screenshot.info,
+                              get_kimchi_version())
         except Exception as e:
             # It is possible to continue Kimchi executions without store
             # screenshots
@@ -1416,7 +1421,8 @@ class VMScreenshotModel(object):
                     params = session.get('screenshot', vm_uuid)
                 except NotFoundError:
                     params = {'uuid': vm_uuid}
-                    session.store('screenshot', vm_uuid, params)
+                    session.store('screenshot', vm_uuid, params,
+                                  get_kimchi_version())
         except Exception as e:
             # The 'except' outside of 'with' is necessary to catch possible
             # exception from '__exit__' when calling 'session.store'
diff --git a/src/wok/plugins/kimchi/tests/test_model.py b/src/wok/plugins/kimchi/tests/test_model.py
index fdbe3b4..dc9fa8c 100644
--- a/src/wok/plugins/kimchi/tests/test_model.py
+++ b/src/wok/plugins/kimchi/tests/test_model.py
@@ -37,6 +37,7 @@ from wok.xmlutils.utils import xpath_get_text
 
 from wok.plugins.kimchi import netinfo
 from wok.plugins.kimchi import osinfo
+from wok.plugins.kimchi.config import get_kimchi_version
 from wok.plugins.kimchi.config import kimchiPaths as paths
 from wok.plugins.kimchi.model import model
 from wok.plugins.kimchi.model.libvirtconnection import LibvirtConnection
@@ -268,7 +269,8 @@ class ModelTests(unittest.TestCase):
                          "storagepool": "/plugins/kimchi/storagepools/default"}
 
             with inst.objstore as session:
-                session.store('template', tmpl_name, tmpl_info)
+                session.store('template', tmpl_name, tmpl_info,
+                              get_kimchi_version())
 
             params = {'name': 'kimchi-vm',
                       'template': '/plugins/kimchi/templates/img-tmpl'}
-- 
2.4.3




More information about the Kimchi-devel mailing list