Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ai
configdb
Commits
0b96d47b
Commit
0b96d47b
authored
Aug 26, 2012
by
ale
Browse files
add zookeeper interface tests; fix a few typos and oversights
parent
ee191c04
Changes
3
Hide whitespace changes
Inline
Side-by-side
configdb/db/interface/zookeeper_interface.py
View file @
0b96d47b
...
...
@@ -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
(
D
oo
z
erSession
(
self
))
return
base
.
session_context_manager
(
Z
oo
keep
erSession
(
self
))
def
add_audit
(
self
,
entity_name
,
object_name
,
operation
,
data
,
auth_ctx
,
session
):
...
...
configdb/tests/test_db_api_zookeeper.py
0 → 100644
View file @
0b96d47b
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
)
configdb/tests/test_zookeeper_interface.py
0 → 100644
View file @
0b96d47b
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
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment