From dd0df583e2661444287a36acc240a8ac0ec381e8 Mon Sep 17 00:00:00 2001 From: Josh Durgin Date: Wed, 14 Aug 2013 15:28:19 -0700 Subject: [PATCH] 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) --- src/pybind/rados.py | 6 +++++- src/test/pybind/test_rados.py | 23 ++++++++++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/pybind/rados.py b/src/pybind/rados.py index e543ff7930505..34d83c7b3536a 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 5176d6383d543..019a86c2763ad 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): -- 2.39.5