[Kimchi-devel] [PATCH 1/4] Add version to objectstore information.
pvital at linux.vnet.ibm.com
pvital at linux.vnet.ibm.com
Thu Nov 5 18:47:15 UTC 2015
From: Paulo Vital <pvital at linux.vnet.ibm.com>
Add support to provide version of Wok (or any other plugin) to objectstore
information. Also add test case to use the new get_object_version() method.
Signed-off-by: Paulo Vital <pvital at linux.vnet.ibm.com>
---
src/wok/objectstore.py | 20 ++++++++++++++++----
tests/test_objectstore.py | 5 +++++
2 files changed, 21 insertions(+), 4 deletions(-)
diff --git a/src/wok/objectstore.py b/src/wok/objectstore.py
index 670a363..089bf80 100644
--- a/src/wok/objectstore.py
+++ b/src/wok/objectstore.py
@@ -63,6 +63,12 @@ class ObjectStoreSession(object):
raise NotFoundError("WOKOBJST0001E", {'item': ident})
return json.loads(jsonstr)
+ def get_object_version(self, obj_type, ident):
+ c = self.conn.cursor()
+ res = c.execute('SELECT version FROM objects WHERE type=? AND id=?',
+ (obj_type, ident))
+ return [x[0] for x in res]
+
def delete(self, obj_type, ident, ignore_missing=False):
c = self.conn.cursor()
c.execute('DELETE FROM objects WHERE type=? AND id=?',
@@ -72,13 +78,18 @@ class ObjectStoreSession(object):
raise NotFoundError("WOKOBJST0001E", {'item': ident})
self.conn.commit()
- def store(self, obj_type, ident, data):
+ def store(self, obj_type, ident, data, version=None):
+ # Get Wok version if none was provided
+ if version is None:
+ version = config.get_version().split('-')[0]
+
jsonstr = json.dumps(data)
c = self.conn.cursor()
c.execute('DELETE FROM objects WHERE type=? AND id=?',
(obj_type, ident))
- c.execute('INSERT INTO objects (id, type, json) VALUES (?,?,?)',
- (ident, obj_type, jsonstr))
+ c.execute('''INSERT INTO objects (id, type, json, version)
+ VALUES (?,?,?,?)''',
+ (ident, obj_type, jsonstr, version))
self.conn.commit()
@@ -100,7 +111,8 @@ class ObjectStore(object):
# are purged every time the daemon startup
if len(res) == 0:
c.execute('''CREATE TABLE objects
- (id TEXT, type TEXT, json TEXT, PRIMARY KEY (id, type))''')
+ (id TEXT, type TEXT, json TEXT, version TEXT,
+ PRIMARY KEY (id, type))''')
conn.commit()
return
diff --git a/tests/test_objectstore.py b/tests/test_objectstore.py
index bce125e..d11e6b7 100644
--- a/tests/test_objectstore.py
+++ b/tests/test_objectstore.py
@@ -26,6 +26,7 @@ import threading
import unittest
from wok import objectstore
+from wok.config import get_version
from wok.exception import NotFoundError
@@ -77,6 +78,10 @@ class ObjectStoreTests(unittest.TestCase):
item = session.get('fǒǒ', 'těst1')
self.assertEquals(2, item[u'α'])
+ # Test get version of object
+ item = session.get_object_version('fǒǒ', 'těst1')
+ self.assertEquals(get_version().split('-')[0], item[0])
+
def test_object_store_threaded(self):
def worker(ident):
with store as session:
--
2.4.3
More information about the Kimchi-devel
mailing list