From 531d9498c761ac3c7e8194122f03569c34adfb37 Mon Sep 17 00:00:00 2001 From: Amit Bawer Date: Aug 24 2020 15:41:06 +0000 Subject: python: Remove init_resource() deprecated API write_resource() is used to replace init_resource() functionality as far back as in commit: commit 3e17957 Author: Federico Simoncelli Date: Wed Apr 10 12:09:43 2013 -0400 python: use the write commands in example.py The init_lockspace/resource commands have been obsoleted, the new ones are write_lockspace/resource. The old API was kept to support legacy python2-sanlock consuming code. Now that python 2 is officialy retired this API can be removed. Signed-off-by: Amit Bawer --- diff --git a/python/sanlock.c b/python/sanlock.c index b0dfb57..d616008 100644 --- a/python/sanlock.c +++ b/python/sanlock.c @@ -420,60 +420,6 @@ convert_to_pybytes(PyObject* arg, void *addr) return 0; } -/* init_resource */ -PyDoc_STRVAR(pydoc_init_resource, "\ -init_resource(lockspace, resource, disks, max_hosts=0, num_hosts=0, \ -use_aio=True)\n\ -*DEPRECATED* use write_resource instead.\n\ -Initialize a device to be used as sanlock resource.\n\ -The disks must be in the format: [(path, offset), ... ]"); - -static PyObject * -py_init_resource(PyObject *self __unused, PyObject *args, PyObject *keywds) -{ - int rv = -1, max_hosts = 0, num_hosts = 0, use_aio = 1; - PyObject *lockspace = NULL, *resource = NULL; - struct sanlk_resource *res = NULL; - PyObject *disks; - - static char *kwlist[] = {"lockspace", "resource", "disks", "max_hosts", - "num_hosts", "use_aio", NULL}; - - /* parse python tuple */ - if (!PyArg_ParseTupleAndKeywords(args, keywds, "O&O&O!|iii", - kwlist, convert_to_pybytes, &lockspace, convert_to_pybytes, &resource, - &PyList_Type, &disks, &max_hosts, &num_hosts, &use_aio)) { - goto finally; - } - - /* parse and check sanlock resource */ - if (parse_disks(disks, &res) < 0) { - goto finally; - } - - /* prepare sanlock names */ - strncpy(res->lockspace_name, PyBytes_AsString(lockspace), SANLK_NAME_LEN); - strncpy(res->name, PyBytes_AsString(resource), SANLK_NAME_LEN); - - /* init sanlock resource (gil disabled) */ - Py_BEGIN_ALLOW_THREADS - rv = sanlock_direct_init(NULL, res, max_hosts, num_hosts, use_aio); - Py_END_ALLOW_THREADS - - if (rv != 0) { - set_sanlock_error(rv, "Sanlock resource init failure"); - goto finally; - } - -finally: - Py_XDECREF(lockspace); - Py_XDECREF(resource); - free(res); - if (rv != 0) - return NULL; - Py_RETURN_NONE; -} - /* write_lockspace */ PyDoc_STRVAR(pydoc_write_lockspace, "\ write_lockspace(lockspace, path, offset=0, max_hosts=0, iotimeout=0, \ @@ -1645,8 +1591,6 @@ static PyMethodDef sanlock_methods[] = { {"register", py_register, METH_NOARGS, pydoc_register}, {"get_alignment", py_get_alignment, METH_VARARGS, pydoc_get_alignment}, - {"init_resource", (PyCFunction) py_init_resource, - METH_VARARGS|METH_KEYWORDS, pydoc_init_resource}, {"write_lockspace", (PyCFunction) py_write_lockspace, METH_VARARGS|METH_KEYWORDS, pydoc_write_lockspace}, {"write_resource", (PyCFunction) py_write_resource, diff --git a/tests/python_test.py b/tests/python_test.py index 965bc06..abd459e 100644 --- a/tests/python_test.py +++ b/tests/python_test.py @@ -689,28 +689,6 @@ def test_set_event_parse_args(no_sanlock_daemon, name): sanlock.set_event(name, 1, 1, 1) -@pytest.mark.parametrize("name", LOCKSPACE_OR_RESOURCE_NAMES) -@pytest.mark.parametrize("filename,encoding", FILE_NAMES) -def test_init_resource_parse_args(no_sanlock_daemon, name, filename, encoding): - path = util.generate_path("/tmp/", filename, encoding) - disks = [(path, 0)] - with raises_sanlock_errno(errno.ENOENT): - sanlock.init_resource(b"ls_name", name, disks) - with raises_sanlock_errno(errno.ENOENT): - sanlock.init_resource(name, b"res_name", disks) - - -def test_init_resource_path_length(no_sanlock_daemon): - path = "x" * constants.SANLK_PATH_LEN - with pytest.raises(ValueError): - sanlock.init_resource(b"ls_name", b"res_name", [(path, 0)]) - - # init_resource access storage directly. - path = "x" * (constants.SANLK_PATH_LEN - 1) - with raises_sanlock_errno(errno.ENAMETOOLONG): - sanlock.init_resource(b"ls_name", b"res_name", [(path, 0)]) - - @pytest.mark.parametrize("filename,encoding", FILE_NAMES) def test_get_alignment_parse_args(no_sanlock_daemon, filename, encoding): path = util.generate_path("/tmp/", filename, encoding)