summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/pybind/rados.py6
-rw-r--r--src/test/pybind/test_rados.py23
2 files changed, 27 insertions, 2 deletions
diff --git a/src/pybind/rados.py b/src/pybind/rados.py
index e543ff79305..34d83c7b353 100644
--- a/src/pybind/rados.py
+++ b/src/pybind/rados.py
@@ -182,7 +182,7 @@ class Rados(object):
raise RadosStateError("You cannot perform that operation on a \
Rados object in state %s." % (self.state))
- def __init__(self, rados_id=None, name='client.admin', clustername='ceph',
+ def __init__(self, rados_id=None, name=None, clustername=None,
conf_defaults=None, conffile=None, conf=None, flags=0):
self.librados = CDLL('librados.so.2')
self.cluster = c_void_p()
@@ -195,6 +195,10 @@ Rados object in state %s." % (self.state))
raise Error("Rados(): can't supply both rados_id and name")
if rados_id:
name = 'client.' + rados_id
+ if name is None:
+ name = 'client.admin'
+ if clustername is None:
+ clustername = 'ceph'
ret = run_in_thread(self.librados.rados_create2,
(byref(self.cluster), c_char_p(clustername),
c_char_p(name), c_uint64(flags)))
diff --git a/src/test/pybind/test_rados.py b/src/test/pybind/test_rados.py
index 5176d6383d5..019a86c2763 100644
--- a/src/test/pybind/test_rados.py
+++ b/src/test/pybind/test_rados.py
@@ -1,10 +1,31 @@
from nose.tools import eq_ as eq, assert_raises
-from rados import (Rados, Object, ObjectExists, ObjectNotFound,
+from rados import (Rados, Error, Object, ObjectExists, ObjectNotFound,
ANONYMOUS_AUID, ADMIN_AUID)
import threading
import json
import errno
+def test_rados_init_error():
+ assert_raises(Error, Rados, conffile='', rados_id='admin',
+ name='client.admin')
+ assert_raises(Error, Rados, conffile='', name='invalid')
+ assert_raises(Error, Rados, conffile='', name='bad.invalid')
+
+def test_rados_init():
+ with Rados(conffile='', rados_id='admin'):
+ pass
+ with Rados(conffile='', name='client.admin'):
+ pass
+ with Rados(conffile='', name='client.admin'):
+ pass
+ with Rados(conffile='', name='client.admin'):
+ pass
+
+def test_ioctx_context_manager():
+ with Rados(conffile='', rados_id='admin') as conn:
+ with conn.open_ioctx('data') as ioctx:
+ pass
+
class TestRados(object):
def setUp(self):