From: Josh Durgin Date: Wed, 14 Aug 2013 22:28:19 +0000 (-0700) Subject: rados.py: fix Rados() backwards compatibility X-Git-Tag: v0.67.1~6 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=dd0df583e2661444287a36acc240a8ac0ec381e8;p=ceph.git 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 Signed-off-by: Josh Durgin Reviewed-by: Sage Weil (cherry picked from commit 34da9cbc33205623cf64aee1989f53dfb2c5bddd) --- diff --git a/src/pybind/rados.py b/src/pybind/rados.py index e543ff793050..34d83c7b3536 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 5176d6383d54..019a86c2763a 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):