Commit 0b96d47b authored by ale's avatar ale
Browse files

add zookeeper interface tests; fix a few typos and oversights

parent ee191c04
......@@ -3,6 +3,7 @@ import urllib
import cPickle as pickle
import kazoo.client
import kazoo.exceptions
from configdb import exceptions
from configdb.db.interface import base
......@@ -39,7 +40,7 @@ class ZookeeperSession(object):
self.db._serialize(obj),
rev)
self.revisions[path] = stat.version
except BadVersionException:
except kazoo.exceptions.BadVersionException:
raise exceptions.IntegrityError('Bad revision')
def delete(self, obj):
......@@ -51,7 +52,7 @@ class ZookeeperSession(object):
try:
rev = self.revisions.pop(path)
self.db.conn.delete(path, rev)
except BadVersionException:
except kazoo.exceptions.BadVersionException:
raise exceptions.IntegrityError('Bad revision')
def _deserialize_if_not_none(self, data):
......@@ -67,9 +68,11 @@ class ZookeeperSession(object):
data, stat = self.db.conn.get(path, rev)
if rev < 0:
self.revisions[path] = stat.version
except BadVersionException:
except kazoo.exceptions.BadVersionException:
data, stat = self.db.conn.get(path)
self.revisions[path] = stat.version
except kazoo.exceptions.NoNodeException:
return None
return self._deserialize_if_not_none(data)
def _find(self, entity_name):
......@@ -77,6 +80,12 @@ class ZookeeperSession(object):
for name in self.db.conn.get_children(path):
yield self._get(entity_name, self._unescape(name))
def commit(self):
pass
def rollback(self):
pass
class ZookeeperInterface(base.DbInterface):
"""Database interface for a Zookeeper-based backend.
......@@ -100,7 +109,7 @@ class ZookeeperInterface(base.DbInterface):
return pickle.loads(data)
def session(self):
return base.session_context_manager(DoozerSession(self))
return base.session_context_manager(ZookeeperSession(self))
def add_audit(self, entity_name, object_name, operation,
data, auth_ctx, session):
......
import os
from configdb.db.interface import zookeeper_interface
from configdb.tests import *
from configdb.tests.db_api_test_base import DbApiTestBase
class ZookeeperInterfaceTest(DbApiTestBase, TestBase):
TESTROOT = '/configdb-test-%d' % os.getpid()
def init_db(self):
return zookeeper_interface.ZookeeperInterface(
'127.0.0.1:2181', self.get_schema(), self.TESTROOT)
import os
from configdb.db.interface import zookeeper_interface
from configdb.tests import *
from configdb.tests.db_interface_test_base import DbInterfaceTestBase
class ZookeeperInterfaceTest(DbInterfaceTestBase, TestBase):
TESTROOT = '/configdb-test-%d' % os.getpid()
def init_db(self):
return zookeeper_interface.ZookeeperInterface(
'127.0.0.1:2181', self.get_schema(), self.TESTROOT)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment