summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosh Durgin <josh.durgin@inktank.com>2013-08-14 15:28:19 -0700
committerJosh Durgin <josh.durgin@inktank.com>2013-08-14 15:39:30 -0700
commitb6a9b6dcf2f4de3ac22e6a7e3756c7e94c791b09 (patch)
treeb35c5f2cbb2d69d6c6ef22c34037bbeddb68db3a
parent16ed0b9af8bc08c7dabead1c1a7c1a22b1fb02fb (diff)
downloadceph-b6a9b6dcf2f4de3ac22e6a7e3756c7e94c791b09.tar.gz
rados.py: fix Rados() backwards compatibility
Previously it had no name parameter, so the default will be used by old clients. However, if an old client set rados_id, a new check that both rados_id and name are set would result in an error. Fix this by only applying the default names after the check, and add tests of this behavior. This was introduced in 783b7ec847c7f987ac1814c9c41c91921cac4eba, so it does not affect cuttlefish. Fixes: #5970 Reported-by: Michael Morgan <mmorgan@dca.net> Signed-off-by: Josh Durgin <josh.durgin@inktank.com>
-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):