[Kimchi-devel] [PATCH] [Kimchi] Update Kimchi objectstore versioning.
pvital at linux.vnet.ibm.com
pvital at linux.vnet.ibm.com
Mon Dec 14 13:46:30 UTC 2015
From: Paulo Vital <pvital at linux.vnet.ibm.com>
With the new structure of the objectstore changed in Wok 2.0.0, the schema of
the objectstore file needs to be checked and, if necessary, updated to reflect
the new structure.
This patch removes from Kimchi the methods used to check the objectstore schema
and upgrade it if necessary. These methods are now present in wok.plugins and
are common to any Wok plugin.
Signed-off-by: Paulo Vital <pvital at linux.vnet.ibm.com>
---
root.py | 4 ++--
utils.py | 40 ----------------------------------------
2 files changed, 2 insertions(+), 42 deletions(-)
diff --git a/root.py b/root.py
index 4fbe0fc..cee30f6 100644
--- a/root.py
+++ b/root.py
@@ -26,9 +26,9 @@ from wok.plugins.kimchi.i18n import messages
from wok.plugins.kimchi.control import sub_nodes
from wok.plugins.kimchi.model import model as kimchiModel
from wok.plugins.kimchi.utils import upgrade_objectstore_data
-from wok.plugins.kimchi.utils import upgrade_objectstore_schema
from wok.plugins.kimchi.utils import upgrade_objectstore_template_disks
from wok.root import WokRoot
+from wok.utils import upgrade_objectstore_schema
class KimchiRoot(WokRoot):
@@ -68,7 +68,7 @@ class KimchiRoot(WokRoot):
# Some paths or URI's present in the objectstore have changed after
# Kimchi 2.0.0 release. Check here if an upgrade in the schema and data
# are necessary.
- if upgrade_objectstore_schema('version'):
+ if upgrade_objectstore_schema(config.get_object_store(), 'version'):
upgrade_objectstore_data('icon', 'images', 'plugins/kimchi/')
upgrade_objectstore_data('storagepool', '/storagepools',
'/plugins/kimchi')
diff --git a/utils.py b/utils.py
index 0997faa..5a3f209 100644
--- a/utils.py
+++ b/utils.py
@@ -101,46 +101,6 @@ def validate_repo_url(url):
raise InvalidParameter("KCHREPOS0002E")
-def get_objectstore_fields():
- """
- Return a list with all fields of the objectstore.
- """
- conn = sqlite3.connect(config.get_object_store(), timeout=10)
- cursor = conn.cursor()
- schema_fields = []
- sql = "PRAGMA table_info('objects')"
- cursor.execute(sql)
- for row in cursor.fetchall():
- schema_fields.append(row[1])
- return schema_fields
-
-
-def upgrade_objectstore_schema(field=None):
- """
- Add a new column (of type TEXT) in the objectstore schema.
- """
- if field is None:
- wok_log.error("Cannot upgrade objectstore schema.")
- return False
-
- if field in get_objectstore_fields():
- return False
- try:
- conn = sqlite3.connect(config.get_object_store(), timeout=10)
- cursor = conn.cursor()
- sql = "ALTER TABLE objects ADD COLUMN %s TEXT" % field
- cursor.execute(sql)
- wok_log.info("Objectstore schema sucessfully upgraded.")
- conn.close()
- except sqlite3.Error, e:
- if conn:
- conn.rollback()
- conn.close()
- wok_log.error("Cannot upgrade objectstore schema: ", e.args[0])
- return False
- return True
-
-
def upgrade_objectstore_data(item, old_uri, new_uri):
"""
Upgrade the value of a given JSON's item of all Template and VM entries
--
2.5.0
More information about the Kimchi-devel
mailing list