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 16:11:00 -0700
commitdd0df583e2661444287a36acc240a8ac0ec381e8 (patch)
tree967d490ba5101c55ce8f41251034b21e58ad4265
parentb9d1bf51610159a88ad257f29a81691e6b178e17 (diff)
downloadceph-dd0df583e2661444287a36acc240a8ac0ec381e8.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> Reviewed-by: Sage Weil <sage.weil@inktank.com> (cherry picked from commit 34da9cbc33205623cf64aee1989f53dfb2c5bddd)
-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):