diff --git a/.gitmodules b/.gitmodules index cda5bb2cb..e69de29bb 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +0,0 @@ -[submodule "modules/aerospike-lua-core"] - path = modules/aerospike-lua-core - url = https://github.com/aerospike/aerospike-lua-core diff --git a/VERSION b/VERSION index 47b322c97..4d9d11cf5 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.4.1 +3.4.2 diff --git a/doc/scan.rst b/doc/scan.rst index 59d0a3ce1..40711f19c 100644 --- a/doc/scan.rst +++ b/doc/scan.rst @@ -36,7 +36,7 @@ Scan Class --- :class:`Scan` :class:`list` of records. :param dict policy: optional :ref:`aerospike_scan_policies`. - :param str nodename: optional name of node used to limit the scan to a single node. + :param str nodename: optional Node ID of node used to limit the scan to a single node. :return: a :class:`list` of :ref:`aerospike_record_tuple`. @@ -89,7 +89,7 @@ Scan Class --- :class:`Scan` :param callable callback: the function to invoke for each record. :param dict policy: optional :ref:`aerospike_scan_policies`. :param dict options: the :ref:`aerospike_scan_options` that will apply to the scan. - :param str nodename: optional name of node used to limit the scan to a single node. + :param str nodename: optional Node ID of node used to limit the scan to a single node. .. note:: A :ref:`aerospike_record_tuple` is passed as the argument to the callback function. diff --git a/modules/aerospike-lua-core b/modules/aerospike-lua-core deleted file mode 160000 index acb9eb1ec..000000000 --- a/modules/aerospike-lua-core +++ /dev/null @@ -1 +0,0 @@ -Subproject commit acb9eb1ec2dda2c64375b28c7fb08a0518aadd27 diff --git a/setup.py b/setup.py index 969779de7..2f1f2a8d2 100644 --- a/setup.py +++ b/setup.py @@ -16,53 +16,11 @@ ################################################################################ from __future__ import print_function -import errno +from subprocess import Popen import os import platform import sys -from distutils.command.build import build -from setuptools.command.install import install -from distutils.sysconfig import get_config_vars from setuptools import setup, Extension -from shutil import copytree, copy2 -from subprocess import Popen - - -class InstallCommand(install): - user_options = install.user_options + [ - ('lua-system-path=', None, 'Path to the lua system files') - ] - - def initialize_options(self): - install.initialize_options(self) - self.lua_system_path = None - - def finalize_options(self): - install.finalize_options(self) - - def run(self): - global lua_system_path - lua_system_path = self.lua_system_path - install.run(self) - - -class BuildCommand(build): - user_options = build.user_options + [ - ('lua-system-path=', None, 'Path to the lua system files') - ] - - def initialize_options(self): - build.initialize_options(self) - self.lua_system_path = None - - def finalize_options(self): - build.finalize_options(self) - - def run(self): - global lua_system_path - lua_system_path = self.lua_system_path - build.run(self) - ################################################################################ # ENVIRONMENT VARIABLES @@ -72,7 +30,7 @@ def run(self): os.environ['ARCHFLAGS'] = '-arch x86_64' AEROSPIKE_C_VERSION = os.getenv('AEROSPIKE_C_VERSION') if not AEROSPIKE_C_VERSION: - AEROSPIKE_C_VERSION = '4.3.14' + AEROSPIKE_C_VERSION = '4.3.17' DOWNLOAD_C_CLIENT = os.getenv('DOWNLOAD_C_CLIENT') AEROSPIKE_C_HOME = os.getenv('AEROSPIKE_C_HOME') PREFIX = None @@ -86,7 +44,7 @@ def run(self): ################################################################################ -def resolve_c_client(lua_src_path): +def resolve_c_client(): global PREFIX, AEROSPIKE_C_VERSION, DOWNLOAD_C_CLIENT global extra_objects, include_dirs @@ -210,43 +168,24 @@ def resolve_c_client(lua_src_path): sys.exit(8) ################################################################################ -# RESOLVE C CLIENT DEPENDENCY AND LUA SYSTEM PATH +# RESOLVE C CLIENT DEPENDENCY ################################################################################ -lua_system_path = '' # If the C client is packaged elsewhere, assume the libraries are available -lua_src_path = "modules/aerospike-lua-core/src" if os.environ.get('NO_RESOLVE_C_CLIENT_DEP', None): has_c_client = True libraries = libraries + ['aerospike'] - lua_src_path = os.environ.get('AEROSPIKE_LUA_PATH', lua_src_path) else: has_c_client = False -lua_files = [ - lua_src_path + '/aerospike.lua', - lua_src_path + '/as.lua', - lua_src_path + '/stream_ops.lua' - ] - -for file in lua_files: - if not os.path.isfile(file): - print("Warning: lua file {} not found, exiting".format(file), file=sys.stderr) - sys.exit(4) - - -# If system-path isn't specified this will install relative to sys.exec_prefix -data_files = [ - ('aerospike/lua', lua_files) -] if not has_c_client: if (('build' in sys.argv or 'build_ext' in sys.argv or 'install' in sys.argv or 'bdist_wheel' in sys.argv)): - resolve_c_client(lua_src_path) + resolve_c_client() ################################################################################ # SETUP @@ -261,10 +200,6 @@ def resolve_c_client(lua_src_path): version = f.read() setup( - cmdclass={ - 'build': BuildCommand, - 'install': InstallCommand, - }, name='aerospike', version=version.strip(), description='Aerospike Client Library for Python', @@ -288,14 +223,8 @@ def resolve_c_client(lua_src_path): # Package Data Files zip_safe=False, include_package_data=True, - package_data={ - 'aerospike': [ - lua_src_path + '/*.lua', - ] - }, # Data files - data_files=data_files, ext_modules=[ Extension( # Extension Name diff --git a/src/main/aerospike.c b/src/main/aerospike.c index c49556f33..dab15cefa 100644 --- a/src/main/aerospike.c +++ b/src/main/aerospike.c @@ -93,7 +93,7 @@ AerospikeConstants operator_constants[] = { MOD_INIT(aerospike) { - const char version[8] = "3.4.1"; + const char version[8] = "3.4.2"; // Makes things "thread-safe" PyEval_InitThreads(); int i = 0; diff --git a/src/main/client/sec_index.c b/src/main/client/sec_index.c index 98b03b613..c67ada827 100644 --- a/src/main/client/sec_index.c +++ b/src/main/client/sec_index.c @@ -30,6 +30,15 @@ #include "exceptions.h" #include "policy.h" +static bool getDataTypeFromPyObject(PyObject* py_datatype, as_index_datatype* idx_datatype, as_error* err); + +static PyObject* createIndexWithCollectionType(AerospikeClient* self, PyObject* py_policy, PyObject* py_ns, PyObject* py_set, + PyObject* py_bin, PyObject* py_name, PyObject* py_datatype, as_index_type index_type); + +static PyObject* +createIndexWithDataAndCollectionType(AerospikeClient* self, PyObject* py_policy, PyObject* py_ns, PyObject* py_set, + PyObject* py_bin, PyObject* py_name, as_index_type index_type, as_index_datatype data_type); + /** ******************************************************************************************************* * Creates an integer index for a bin in the Aerospike DB. @@ -55,12 +64,6 @@ PyObject * AerospikeClient_Index_Integer_Create(AerospikeClient * self, PyObject PyObject * py_set = NULL; PyObject * py_bin = NULL; PyObject * py_name = NULL; - PyObject * py_ustr_set = NULL; - PyObject * py_ustr_bin = NULL; - PyObject * py_ustr_name = NULL; - as_policy_info info_policy; - as_policy_info *info_policy_p = NULL; - as_index_task task; // Python Function Keyword Arguments static char * kwlist[] = {"ns", "set", "bin", "name", "policy", NULL}; @@ -71,104 +74,8 @@ PyObject * AerospikeClient_Index_Integer_Create(AerospikeClient * self, PyObject return NULL; } - if (!self || !self->as) { - as_error_update(&err, AEROSPIKE_ERR_PARAM, "Invalid aerospike object"); - goto CLEANUP; - } - - if (!self->is_conn_16) { - as_error_update(&err, AEROSPIKE_ERR_CLUSTER, "No connection to aerospike cluster"); - goto CLEANUP; - } - - // Convert python object to policy_info - pyobject_to_policy_info( &err, py_policy, &info_policy, &info_policy_p, - &self->as->config.policies.info); - if (err.code != AEROSPIKE_OK) { - goto CLEANUP; - } - - // Convert python object into namespace string - if( !PyString_Check(py_ns) ) { - as_error_update(&err, AEROSPIKE_ERR_PARAM, "Namespace should be a string"); - goto CLEANUP; - } - char *namespace = PyString_AsString(py_ns); - - // Convert python object into set string - char *set_ptr = NULL; - if (PyUnicode_Check(py_set)) { - py_ustr_set = PyUnicode_AsUTF8String(py_set); - set_ptr = PyBytes_AsString(py_ustr_set); - } else if (PyString_Check(py_set)) { - set_ptr = PyString_AsString(py_set); - } else if(py_set != Py_None) { - as_error_update(&err, AEROSPIKE_ERR_PARAM, "Set should be string, unicode or None"); - goto CLEANUP; - } - - // Convert python object into bin string - char *bin_ptr = NULL; - if (PyUnicode_Check(py_bin)) { - py_ustr_bin = PyUnicode_AsUTF8String(py_bin); - bin_ptr = PyBytes_AsString(py_ustr_bin); - } else if (PyString_Check(py_bin)) { - bin_ptr = PyString_AsString(py_bin); - } else if (PyByteArray_Check(py_bin)) { - bin_ptr = PyByteArray_AsString(py_bin); - } else { - as_error_update(&err, AEROSPIKE_ERR_PARAM, "Bin should be a string"); - goto CLEANUP; - } - - // Convert PyObject into the name of the index - char *name = NULL; - if (PyUnicode_Check(py_name)) { - py_ustr_name = PyUnicode_AsUTF8String(py_name); - name = PyBytes_AsString(py_ustr_name); - } else if (PyString_Check(py_name)) { - name = PyString_AsString(py_name); - } else { - as_error_update(&err, AEROSPIKE_ERR_PARAM, "Index name should be string or unicode"); - goto CLEANUP; - } - - // Invoke operation - Py_BEGIN_ALLOW_THREADS - aerospike_index_create_complex(self->as, &err, &task, info_policy_p, namespace, set_ptr, bin_ptr, name, AS_INDEX_TYPE_DEFAULT, AS_INDEX_NUMERIC); - Py_END_ALLOW_THREADS - if (err.code != AEROSPIKE_OK) { - as_error_update(&err, err.code, NULL); - goto CLEANUP; - } else { - Py_BEGIN_ALLOW_THREADS - aerospike_index_create_wait(&err, &task, 2000); - Py_END_ALLOW_THREADS - } - -CLEANUP: - if(py_ustr_set) { - Py_DECREF(py_ustr_set); - } - if(py_ustr_bin) { - Py_DECREF(py_ustr_bin); - } - if(py_ustr_name) { - Py_DECREF(py_ustr_name); - } - if (err.code != AEROSPIKE_OK) { - PyObject * py_err = NULL; - error_to_pyobject(&err, &py_err); - PyObject *exception_type = raise_exception(&err); - if(PyObject_HasAttrString(exception_type, "name")) { - PyObject_SetAttrString(exception_type, "name", py_name); - } - PyErr_SetObject(exception_type, py_err); - Py_DECREF(py_err); - return NULL; - } + return createIndexWithDataAndCollectionType(self, py_policy, py_ns, py_set, py_bin, py_name, AS_INDEX_TYPE_DEFAULT, AS_INDEX_NUMERIC); - return PyLong_FromLong(0); } /** @@ -196,13 +103,6 @@ PyObject * AerospikeClient_Index_String_Create(AerospikeClient * self, PyObject PyObject * py_set = NULL; PyObject * py_bin = NULL; PyObject * py_name = NULL; - PyObject *py_ustr_set = NULL; - PyObject *py_ustr_bin = NULL; - PyObject *py_ustr_name = NULL; - - as_policy_info info_policy; - as_policy_info *info_policy_p = NULL; - as_index_task task; // Python Function Keyword Arguments static char * kwlist[] = {"ns", "set", "bin", "name", "policy", NULL}; @@ -213,105 +113,7 @@ PyObject * AerospikeClient_Index_String_Create(AerospikeClient * self, PyObject return NULL; } - if (!self || !self->as) { - as_error_update(&err, AEROSPIKE_ERR_PARAM, "Invalid aerospike object"); - goto CLEANUP; - } - - if (!self->is_conn_16) { - as_error_update(&err, AEROSPIKE_ERR_CLUSTER, "No connection to aerospike cluster"); - goto CLEANUP; - } - - // Convert python object to policy_info - pyobject_to_policy_info( &err, py_policy, &info_policy, &info_policy_p, - &self->as->config.policies.info); - if (err.code != AEROSPIKE_OK) { - goto CLEANUP; - } - - // Convert python object into namespace string - if( !PyString_Check(py_ns) ) { - as_error_update(&err, AEROSPIKE_ERR_PARAM, "Namespace should be a string"); - goto CLEANUP; - } - char *namespace = PyString_AsString(py_ns); - - // Convert python object into set string - char *set_ptr = NULL; - if (PyUnicode_Check(py_set)) { - py_ustr_set = PyUnicode_AsUTF8String(py_set); - set_ptr = PyBytes_AsString(py_ustr_set); - } else if (PyString_Check(py_set)) { - set_ptr = PyString_AsString(py_set); - } else if(py_set != Py_None) { - as_error_update(&err, AEROSPIKE_ERR_PARAM, "Set should be string, unicode or None"); - goto CLEANUP; - } - - // Convert python object into bin string - char *bin_ptr = NULL; - if (PyUnicode_Check(py_bin)) { - py_ustr_bin = PyUnicode_AsUTF8String(py_bin); - bin_ptr = PyBytes_AsString(py_ustr_bin); - } else if (PyString_Check(py_bin)) { - bin_ptr = PyString_AsString(py_bin); - } else if (PyByteArray_Check(py_bin)) { - bin_ptr = PyByteArray_AsString(py_bin); - } else { - as_error_update(&err, AEROSPIKE_ERR_PARAM, "Bin should be a string"); - goto CLEANUP; - } - - // Convert PyObject into the name of the index - char *name = NULL; - if (PyUnicode_Check(py_name)) { - py_ustr_name = PyUnicode_AsUTF8String(py_name); - name = PyBytes_AsString(py_ustr_name); - } else if (PyString_Check(py_name)) { - name = PyString_AsString(py_name); - } else { - as_error_update(&err, AEROSPIKE_ERR_PARAM, "Index name should be string or unicode"); - goto CLEANUP; - } - - // Invoke operation - Py_BEGIN_ALLOW_THREADS - aerospike_index_create_complex(self->as, &err, &task, info_policy_p, namespace, set_ptr, bin_ptr, name, AS_INDEX_TYPE_DEFAULT, AS_INDEX_STRING); - Py_END_ALLOW_THREADS - - if (err.code != AEROSPIKE_OK) { - as_error_update(&err, err.code, NULL); - goto CLEANUP; - } else { - Py_BEGIN_ALLOW_THREADS - aerospike_index_create_wait(&err, &task, 2000); - Py_END_ALLOW_THREADS - } - -CLEANUP: - if(py_ustr_set) { - Py_DECREF(py_ustr_set); - } - if(py_ustr_bin) { - Py_DECREF(py_ustr_bin); - } - if(py_ustr_name) { - Py_DECREF(py_ustr_name); - } - if (err.code != AEROSPIKE_OK) { - PyObject * py_err = NULL; - error_to_pyobject(&err, &py_err); - PyObject *exception_type = raise_exception(&err); - if(PyObject_HasAttrString(exception_type, "name")) { - PyObject_SetAttrString(exception_type, "name", py_name); - } - PyErr_SetObject(exception_type, py_err); - Py_DECREF(py_err); - return NULL; - } - - return PyLong_FromLong(0); + return createIndexWithDataAndCollectionType(self, py_policy, py_ns, py_set, py_bin, py_name, AS_INDEX_TYPE_DEFAULT, AS_INDEX_STRING); } /** @@ -429,13 +231,7 @@ PyObject * AerospikeClient_Index_List_Create(AerospikeClient * self, PyObject *a PyObject * py_bin = NULL; PyObject * py_name = NULL; PyObject * py_datatype = NULL; - PyObject *py_ustr_set = NULL; - PyObject *py_ustr_bin = NULL; - PyObject *py_ustr_name = NULL; - as_policy_info info_policy; - as_policy_info *info_policy_p = NULL; - as_index_task task; // Python Function Keyword Arguments static char * kwlist[] = {"ns", "set", "bin", "index_datatype", "name", "policy", NULL}; @@ -446,260 +242,64 @@ PyObject * AerospikeClient_Index_List_Create(AerospikeClient * self, PyObject *a return NULL; } - if (!self || !self->as) { - as_error_update(&err, AEROSPIKE_ERR_PARAM, "Invalid aerospike object"); - goto CLEANUP; - } + return createIndexWithCollectionType(self, py_policy, py_ns, py_set, py_bin, py_name, py_datatype, AS_INDEX_TYPE_LIST); +} - if (!self->is_conn_16) { - as_error_update(&err, AEROSPIKE_ERR_CLUSTER, "No connection to aerospike cluster"); - goto CLEANUP; - } +PyObject * AerospikeClient_Index_Map_Keys_Create(AerospikeClient * self, PyObject *args, PyObject * kwds) +{ + // Initialize error + as_error err; + as_error_init(&err); - // Convert python object to policy_info - pyobject_to_policy_info( &err, py_policy, &info_policy, &info_policy_p, &self->as->config.policies.info); - if (err.code != AEROSPIKE_OK) { - goto CLEANUP; - } + // Python Function Arguments + PyObject * py_policy = NULL; + PyObject * py_ns = NULL; + PyObject * py_set = NULL; + PyObject * py_bin = NULL; + PyObject * py_name = NULL; + PyObject * py_datatype = NULL; - // Convert python object into namespace string - if( !PyString_Check(py_ns) ) { - as_error_update(&err, AEROSPIKE_ERR_PARAM, "Namespace should be a string"); - goto CLEANUP; + + // Python Function Keyword Arguments + static char * kwlist[] = {"ns", "set", "bin", "index_datatype", "name", "policy", NULL}; + + // Python Function Argument Parsing + if (PyArg_ParseTupleAndKeywords(args, kwds, "OOOOO|O:index_map_keys_create", kwlist, + &py_ns, &py_set, &py_bin, &py_datatype, &py_name, &py_policy) == false) { + return NULL; } - char *namespace = PyString_AsString(py_ns); - // Convert python object into set string - char *set_ptr = NULL; - if (PyUnicode_Check(py_set)) { - py_ustr_set = PyUnicode_AsUTF8String(py_set); - set_ptr = PyBytes_AsString(py_ustr_set); - } else if (PyString_Check(py_set)) { - set_ptr = PyString_AsString(py_set); - } else if( py_set != Py_None) { - as_error_update(&err, AEROSPIKE_ERR_PARAM, "Set should be string, unicode or None"); - goto CLEANUP; - } - - // Convert python object into bin string - char *bin_ptr = NULL; - if (PyUnicode_Check(py_bin)) { - py_ustr_bin = PyUnicode_AsUTF8String(py_bin); - bin_ptr = PyBytes_AsString(py_ustr_bin); - } else if (PyString_Check(py_bin)) { - bin_ptr = PyString_AsString(py_bin); - } else if (PyByteArray_Check(py_bin)) { - bin_ptr = PyByteArray_AsString(py_bin); - } else { - as_error_update(&err, AEROSPIKE_ERR_PARAM, "Bin should be a string"); - goto CLEANUP; - } - - // Convert PyObject into the name of the index - char *name = NULL; - if (PyUnicode_Check(py_name)) { - py_ustr_name = PyUnicode_AsUTF8String(py_name); - name = PyBytes_AsString(py_ustr_name); - } else if (PyString_Check(py_name)) { - name = PyString_AsString(py_name); - } else { - as_error_update(&err, AEROSPIKE_ERR_PARAM, "Index name should be string or unicode"); - goto CLEANUP; - } - - long type = 0; - if (PyInt_Check(py_datatype)) { - type = PyInt_AsLong(py_datatype); - } else if (PyLong_Check(py_datatype)) { - type = PyLong_AsLong(py_datatype); - if (type == -1 && PyErr_Occurred()) { - if (PyErr_ExceptionMatches(PyExc_OverflowError)) { - as_error_update(&err, AEROSPIKE_ERR_PARAM, "integer value exceeds sys.maxsize"); - } - } - } + return createIndexWithCollectionType(self, py_policy, py_ns, py_set, py_bin, py_name, py_datatype, AS_INDEX_TYPE_MAPKEYS); - // Invoke operation - Py_BEGIN_ALLOW_THREADS - aerospike_index_create_complex(self->as, &err, &task, info_policy_p, namespace, set_ptr, bin_ptr, name, AS_INDEX_TYPE_LIST, type); - Py_END_ALLOW_THREADS - if (err.code != AEROSPIKE_OK) { - as_error_update(&err, err.code, NULL); - goto CLEANUP; - } else { - Py_BEGIN_ALLOW_THREADS - aerospike_index_create_wait(&err, &task, 2000); - Py_END_ALLOW_THREADS - } - -CLEANUP: - if(py_ustr_set) { - Py_DECREF(py_ustr_set); - } - if(py_ustr_bin) { - Py_DECREF(py_ustr_bin); - } - if(py_ustr_name) { - Py_DECREF(py_ustr_name); - } - if (err.code != AEROSPIKE_OK) { - PyObject * py_err = NULL; - error_to_pyobject(&err, &py_err); - PyObject *exception_type = raise_exception(&err); - if(PyObject_HasAttrString(exception_type, "name")) { - PyObject_SetAttrString(exception_type, "name", py_name); - } - PyErr_SetObject(exception_type, py_err); - Py_DECREF(py_err); - return NULL; - } - - return PyLong_FromLong(0); } -PyObject * AerospikeClient_Index_Map_Keys_Create(AerospikeClient * self, PyObject *args, PyObject * kwds) +PyObject * AerospikeClient_Index_Map_Values_Create(AerospikeClient * self, PyObject *args, PyObject * kwds) { // Initialize error as_error err; as_error_init(&err); // Python Function Arguments - PyObject * py_policy = NULL; + PyObject* py_policy = NULL; PyObject * py_ns = NULL; PyObject * py_set = NULL; PyObject * py_bin = NULL; PyObject * py_name = NULL; PyObject * py_datatype = NULL; - PyObject *py_ustr_set = NULL; - PyObject *py_ustr_bin = NULL; - PyObject *py_ustr_name = NULL; - - as_policy_info info_policy; - as_policy_info *info_policy_p = NULL; - as_index_task task; // Python Function Keyword Arguments static char * kwlist[] = {"ns", "set", "bin", "index_datatype", "name", "policy", NULL}; // Python Function Argument Parsing - if (PyArg_ParseTupleAndKeywords(args, kwds, "OOOOO|O:index_map_keys_create", kwlist, + if (PyArg_ParseTupleAndKeywords(args, kwds, "OOOOO|O:index_map_values_create", kwlist, &py_ns, &py_set, &py_bin, &py_datatype, &py_name, &py_policy) == false) { return NULL; } - if (!self || !self->as) { - as_error_update(&err, AEROSPIKE_ERR_PARAM, "Invalid aerospike object"); - goto CLEANUP; - } - - if (!self->is_conn_16) { - as_error_update(&err, AEROSPIKE_ERR_CLUSTER, "No connection to aerospike cluster"); - goto CLEANUP; - } - - // Convert python object to policy_info - pyobject_to_policy_info( &err, py_policy, &info_policy, &info_policy_p, &self->as->config.policies.info); - if (err.code != AEROSPIKE_OK) { - goto CLEANUP; - } - - // Convert python object into namespace string - if( !PyString_Check(py_ns) ) { - as_error_update(&err, AEROSPIKE_ERR_PARAM, "Namespace should be a string"); - goto CLEANUP; - } - char *namespace = PyString_AsString(py_ns); - - // Convert python object into set string - char *set_ptr = NULL; - if (PyUnicode_Check(py_set)) { - py_ustr_set = PyUnicode_AsUTF8String(py_set); - set_ptr = PyBytes_AsString(py_ustr_set); - } else if (PyString_Check(py_set)) { - set_ptr = PyString_AsString(py_set); - } else if(py_set != Py_None) { - as_error_update(&err, AEROSPIKE_ERR_PARAM, "Set should be string, unicode or None"); - goto CLEANUP; - } - - // Convert python object into bin string - char *bin_ptr = NULL; - if (PyUnicode_Check(py_bin)) { - py_ustr_bin = PyUnicode_AsUTF8String(py_bin); - bin_ptr = PyBytes_AsString(py_ustr_bin); - } else if (PyString_Check(py_bin)) { - bin_ptr = PyString_AsString(py_bin); - } else if (PyByteArray_Check(py_bin)) { - bin_ptr = PyByteArray_AsString(py_bin); - } else { - as_error_update(&err, AEROSPIKE_ERR_PARAM, "Bin should be a string"); - goto CLEANUP; - } - - // Convert PyObject into the name of the index - char *name = NULL; - if (PyUnicode_Check(py_name)) { - py_ustr_name = PyUnicode_AsUTF8String(py_name); - name = PyBytes_AsString(py_ustr_name); - } else if (PyString_Check(py_name)) { - name = PyString_AsString(py_name); - } else { - as_error_update(&err, AEROSPIKE_ERR_PARAM, "Index name should be string or unicode"); - goto CLEANUP; - } - - long type = 0; - if (PyInt_Check(py_datatype)) { - type = PyInt_AsLong(py_datatype); - } else if (PyLong_Check(py_datatype)) { - type = PyLong_AsLong(py_datatype); - if (type == -1 && PyErr_Occurred()) { - if (PyErr_ExceptionMatches(PyExc_OverflowError)) { - as_error_update(&err, AEROSPIKE_ERR_PARAM, "integer value exceeds sys.maxsize"); - goto CLEANUP; - } - } - } - - // Invoke operation - Py_BEGIN_ALLOW_THREADS - aerospike_index_create_complex(self->as, &err, &task, info_policy_p, namespace, set_ptr, bin_ptr, name, AS_INDEX_TYPE_MAPKEYS, type); - Py_END_ALLOW_THREADS - if (err.code != AEROSPIKE_OK) { - as_error_update(&err, err.code, NULL); - goto CLEANUP; - } else { - Py_BEGIN_ALLOW_THREADS - aerospike_index_create_wait(&err, &task, 2000); - Py_END_ALLOW_THREADS - } - -CLEANUP: - if(py_ustr_set) { - Py_DECREF(py_ustr_set); - } - if(py_ustr_bin) { - Py_DECREF(py_ustr_bin); - } - if(py_ustr_name) { - Py_DECREF(py_ustr_name); - } - if (err.code != AEROSPIKE_OK) { - PyObject * py_err = NULL; - error_to_pyobject(&err, &py_err); - PyObject *exception_type = raise_exception(&err); - if(PyObject_HasAttrString(exception_type, "name")) { - PyObject_SetAttrString(exception_type, "name", py_name); - } - PyErr_SetObject(exception_type, py_err); - Py_DECREF(py_err); - return NULL; - } - - return PyLong_FromLong(0); + return createIndexWithCollectionType(self, py_policy, py_ns, py_set, py_bin, py_name, py_datatype, AS_INDEX_TYPE_MAPVALUES); } -PyObject * AerospikeClient_Index_Map_Values_Create(AerospikeClient * self, PyObject *args, PyObject * kwds) +PyObject * AerospikeClient_Index_2dsphere_Create(AerospikeClient * self, PyObject *args, PyObject * kwds) { // Initialize error as_error err; @@ -711,148 +311,92 @@ PyObject * AerospikeClient_Index_Map_Values_Create(AerospikeClient * self, PyObj PyObject * py_set = NULL; PyObject * py_bin = NULL; PyObject * py_name = NULL; - PyObject * py_datatype = NULL; - PyObject *py_ustr_set = NULL; - PyObject *py_ustr_bin = NULL; - PyObject *py_ustr_name = NULL; - - as_policy_info info_policy; - as_policy_info *info_policy_p = NULL; - as_index_task task; // Python Function Keyword Arguments - static char * kwlist[] = {"ns", "set", "bin", "index_datatype", "name", "policy", NULL}; + static char * kwlist[] = {"ns", "set", "bin", "name", "policy", NULL}; // Python Function Argument Parsing - if (PyArg_ParseTupleAndKeywords(args, kwds, "OOOOO|O:index_map_values_create", kwlist, - &py_ns, &py_set, &py_bin, &py_datatype, &py_name, &py_policy) == false) { + if (PyArg_ParseTupleAndKeywords(args, kwds, "OOOO|O:index_geo2dsphere_create", kwlist, + &py_ns, &py_set, &py_bin, &py_name, &py_policy) == false) { return NULL; } - if (!self || !self->as) { - as_error_update(&err, AEROSPIKE_ERR_PARAM, "Invalid aerospike object"); - //raise_exception(&err, -2, "Invalid aerospike object"); - goto CLEANUP; - } - - if (!self->is_conn_16) { - as_error_update(&err, AEROSPIKE_ERR_CLUSTER, "No connection to aerospike cluster"); - goto CLEANUP; - } + return createIndexWithDataAndCollectionType(self, py_policy, py_ns, py_set, py_bin, py_name, AS_INDEX_TYPE_DEFAULT, AS_INDEX_GEO2DSPHERE); - // Convert python object to policy_info - pyobject_to_policy_info( &err, py_policy, &info_policy, &info_policy_p, &self->as->config.policies.info); - if (err.code != AEROSPIKE_OK) { - goto CLEANUP; - } +} - // Convert python object into namespace string - if( !PyString_Check(py_ns) ) { - as_error_update(&err, AEROSPIKE_ERR_PARAM, "Namespace should be a string"); - goto CLEANUP; - } - char *namespace = PyString_AsString(py_ns); - // Convert python object into set string - char *set_ptr = NULL; - if (PyUnicode_Check(py_set)) { - py_ustr_set = PyUnicode_AsUTF8String(py_set); - set_ptr = PyBytes_AsString(py_ustr_set); - } else if (PyString_Check(py_set)) { - set_ptr = PyString_AsString(py_set); - } else if(py_set != Py_None) { - as_error_update(&err, AEROSPIKE_ERR_PARAM, "Set should be string, unicode or None"); - goto CLEANUP; - } - - // Convert python object into bin string - char *bin_ptr = NULL; - if (PyUnicode_Check(py_bin)) { - py_ustr_bin = PyUnicode_AsUTF8String(py_bin); - bin_ptr = PyBytes_AsString(py_ustr_bin); - } else if (PyString_Check(py_bin)) { - bin_ptr = PyString_AsString(py_bin); - } else if (PyByteArray_Check(py_bin)) { - bin_ptr = PyByteArray_AsString(py_bin); - } else { - as_error_update(&err, AEROSPIKE_ERR_PARAM, "Bin should be a string"); - goto CLEANUP; - } - - // Convert PyObject into the name of the index - char *name = NULL; - if (PyUnicode_Check(py_name)) { - py_ustr_name = PyUnicode_AsUTF8String(py_name); - name = PyBytes_AsString(py_ustr_name); - } else if (PyString_Check(py_name)) { - name = PyString_AsString(py_name); - } else { - as_error_update(&err, AEROSPIKE_ERR_PARAM, "Index name should be string or unicode"); - goto CLEANUP; - } +/* + * Convert a PyObject into an as_index_datatype, return False if the conversion fails for any reason. + */ +static bool +getDataTypeFromPyObject(PyObject* py_datatype, as_index_datatype* idx_datatype, as_error* err) { - int type = 0; + long type = 0; if (PyInt_Check(py_datatype)) { type = PyInt_AsLong(py_datatype); } else if (PyLong_Check(py_datatype)) { - type = PyLong_AsLongLong(py_datatype); + type = PyLong_AsLong(py_datatype); if (type == -1 && PyErr_Occurred()) { if (PyErr_ExceptionMatches(PyExc_OverflowError)) { - as_error_update(&err, AEROSPIKE_ERR_PARAM, "integer value exceeds sys.maxsize"); + as_error_update(err, AEROSPIKE_ERR_PARAM, "integer value exceeds sys.maxsize"); goto CLEANUP; } } - } - - // Invoke operation - Py_BEGIN_ALLOW_THREADS - aerospike_index_create_complex(self->as, &err, &task, info_policy_p, namespace, set_ptr, bin_ptr, name, AS_INDEX_TYPE_MAPVALUES, type); - Py_END_ALLOW_THREADS - if (err.code != AEROSPIKE_OK) { - as_error_update(&err, err.code, NULL); - goto CLEANUP; } else { - Py_BEGIN_ALLOW_THREADS - aerospike_index_create_wait(&err, &task, 2000); - Py_END_ALLOW_THREADS + as_error_update(err, AEROSPIKE_ERR_PARAM, "Index type must be an integer"); + goto CLEANUP; } -CLEANUP: - if(py_ustr_set) { - Py_DECREF(py_ustr_set); - } - if(py_ustr_bin) { - Py_DECREF(py_ustr_bin); - } - if(py_ustr_name) { - Py_DECREF(py_ustr_name); - } - if (err.code != AEROSPIKE_OK) { + *idx_datatype = type; + + CLEANUP: + if (err->code != AEROSPIKE_OK) { PyObject * py_err = NULL; - error_to_pyobject(&err, &py_err); - PyObject *exception_type = raise_exception(&err); - if(PyObject_HasAttrString(exception_type, "name")) { - PyObject_SetAttrString(exception_type, "name", py_name); - } + error_to_pyobject(err, &py_err); + PyObject *exception_type = raise_exception(err); PyErr_SetObject(exception_type, py_err); Py_DECREF(py_err); + return false; + } + return true; + +} + +/* + * Figure out the data_type from a PyObject and call createIndexWithDataAndCollectionType. + */ +static PyObject* +createIndexWithCollectionType(AerospikeClient* self, PyObject* py_policy, PyObject* py_ns, PyObject* py_set, + PyObject* py_bin, PyObject* py_name, PyObject* py_datatype, as_index_type index_type) { + + as_index_datatype data_type = AS_INDEX_STRING; + + as_error err; + as_error_init(&err); + + if (!getDataTypeFromPyObject(py_datatype, &data_type, &err)) { return NULL; } - return PyLong_FromLong(0); + return createIndexWithDataAndCollectionType(self, py_policy, py_ns, py_set, py_bin, py_name, index_type, data_type); + } -PyObject * AerospikeClient_Index_2dsphere_Create(AerospikeClient * self, PyObject *args, PyObject * kwds) -{ + + +/* + * Create a complex index on the specified ns/set/bin with the given name and index and data_type. Return PyObject(0) on success + * else return NULL with an error raised. + */ + +static PyObject* +createIndexWithDataAndCollectionType(AerospikeClient* self, PyObject* py_policy, PyObject* py_ns, PyObject* py_set, + PyObject* py_bin, PyObject* py_name, as_index_type index_type, as_index_datatype data_type) { + // Initialize error as_error err; as_error_init(&err); - // Python Function Arguments - PyObject * py_policy = NULL; - PyObject * py_ns = NULL; - PyObject * py_set = NULL; - PyObject * py_bin = NULL; - PyObject * py_name = NULL; PyObject *py_ustr_set = NULL; PyObject *py_ustr_bin = NULL; PyObject *py_ustr_name = NULL; @@ -861,17 +405,9 @@ PyObject * AerospikeClient_Index_2dsphere_Create(AerospikeClient * self, PyObjec as_policy_info *info_policy_p = NULL; as_index_task task; - // Python Function Keyword Arguments - static char * kwlist[] = {"ns", "set", "bin", "name", "policy", NULL}; - - // Python Function Argument Parsing - if (PyArg_ParseTupleAndKeywords(args, kwds, "OOOO|O:index_geo2dsphere_create", kwlist, - &py_ns, &py_set, &py_bin, &py_name, &py_policy) == false) { - return NULL; - } - if (!self || !self->as) { as_error_update(&err, AEROSPIKE_ERR_PARAM, "Invalid aerospike object"); + //raise_exception(&err, -2, "Invalid aerospike object"); goto CLEANUP; } @@ -880,11 +416,6 @@ PyObject * AerospikeClient_Index_2dsphere_Create(AerospikeClient * self, PyObjec goto CLEANUP; } - if (!aerospike_has_geo(self->as)) { - as_error_update(&err, AEROSPIKE_ERR_CLUSTER, "Server does not support geospatial indexes"); - goto CLEANUP; - } - // Convert python object to policy_info pyobject_to_policy_info( &err, py_policy, &info_policy, &info_policy_p, &self->as->config.policies.info); if (err.code != AEROSPIKE_OK) { @@ -938,7 +469,7 @@ PyObject * AerospikeClient_Index_2dsphere_Create(AerospikeClient * self, PyObjec // Invoke operation Py_BEGIN_ALLOW_THREADS - aerospike_index_create_complex(self->as, &err, &task, info_policy_p, namespace, set_ptr, bin_ptr, name, AS_INDEX_TYPE_DEFAULT, AS_INDEX_GEO2DSPHERE); + aerospike_index_create_complex(self->as, &err, &task, info_policy_p, namespace, set_ptr, bin_ptr, name, index_type, data_type); Py_END_ALLOW_THREADS if (err.code != AEROSPIKE_OK) { as_error_update(&err, err.code, NULL); @@ -963,9 +494,6 @@ PyObject * AerospikeClient_Index_2dsphere_Create(AerospikeClient * self, PyObjec PyObject * py_err = NULL; error_to_pyobject(&err, &py_err); PyObject *exception_type = raise_exception(&err); - if(PyObject_HasAttrString(exception_type, "name")) { - PyObject_SetAttrString(exception_type, "name", py_name); - } PyErr_SetObject(exception_type, py_err); Py_DECREF(py_err); return NULL; diff --git a/src/main/client/type.c b/src/main/client/type.c index e7f069c18..ad0b923e3 100644 --- a/src/main/client/type.c +++ b/src/main/client/type.c @@ -874,23 +874,11 @@ static int AerospikeClient_Type_Init(AerospikeClient * self, PyObject * args, Py as_config config; as_config_init(&config); - bool lua_system_path = false; bool lua_user_path = false; PyObject * py_lua = PyDict_GetItemString(py_config, "lua"); if (py_lua && PyDict_Check(py_lua)) { - PyObject * py_lua_system_path = PyDict_GetItemString(py_lua, "system_path"); - if (py_lua_system_path && PyString_Check(py_lua_system_path)) { - lua_system_path = true; - if (strnlen(PyString_AsString(py_lua_system_path), AS_CONFIG_PATH_MAX_SIZE) > - AS_CONFIG_PATH_MAX_LEN) { - error_code = INIT_LUA_SYS_ERR; - goto CONSTRUCTOR_ERROR; - - } - strcpy(config.lua.system_path, PyString_AsString(py_lua_system_path)); - } PyObject * py_lua_user_path = PyDict_GetItemString(py_lua, "user_path"); if (py_lua_user_path && PyString_Check(py_lua_user_path)) { @@ -904,19 +892,6 @@ static int AerospikeClient_Type_Init(AerospikeClient * self, PyObject * args, Py } } - if (!lua_system_path) { - char system_path[AS_CONFIG_PATH_MAX_LEN]; - strcpy(system_path, "/usr/local/aerospike/lua"); - - struct stat info; - if (stat(system_path, &info) == 0 && (info.st_mode & S_IFDIR) && (access(system_path, R_OK)) == 0) { - strcpy(config.lua.system_path, system_path); - } - else { - config.lua.system_path[0] = '\0'; - } - } - if (!lua_user_path) { strcpy(config.lua.user_path, "."); } else { diff --git a/src/main/conversions.c b/src/main/conversions.c index 571f0a2be..83a6c166c 100644 --- a/src/main/conversions.c +++ b/src/main/conversions.c @@ -1070,8 +1070,11 @@ as_status do_val_to_pyobject(AerospikeClient * self, as_error * err, const as_va char * locstr = as_geojson_get(gp); PyObject *py_locstr = PyString_FromString(locstr); PyObject *py_loads = AerospikeGeospatial_DoLoads(py_locstr, err); - *py_val = AerospikeGeospatial_New(err, py_loads); Py_DECREF(py_locstr); + if (err->code != AEROSPIKE_OK) { + break; + } + *py_val = AerospikeGeospatial_New(err, py_loads); if (py_loads) { Py_DECREF(py_loads); } @@ -1905,4 +1908,4 @@ string_and_pyuni_from_pystring(PyObject* py_string, PyObject** pyuni_r, char** c return AEROSPIKE_OK; } return as_error_update(err, AEROSPIKE_ERR_PARAM, "String value required"); -} \ No newline at end of file +} diff --git a/src/main/geospatial/loads.c b/src/main/geospatial/loads.c index 9f905fade..17ff667c9 100644 --- a/src/main/geospatial/loads.c +++ b/src/main/geospatial/loads.c @@ -45,7 +45,9 @@ PyObject * AerospikeGeospatial_DoLoads(PyObject *py_geodata, as_error *err) Py_INCREF(json_module); initresult = PyObject_CallMethodObjArgs(json_module, py_funcname, py_geodata, NULL); - + if (!initresult) { + as_error_update(err, AEROSPIKE_ERR_CLIENT, "Unable to load GeoJSON"); + } Py_DECREF(json_module); Py_DECREF(py_funcname); } diff --git a/src/main/scan/type.c b/src/main/scan/type.c index 0e03d9535..4c6d449f3 100644 --- a/src/main/scan/type.c +++ b/src/main/scan/type.c @@ -35,9 +35,10 @@ ******************************************************************************/ PyDoc_STRVAR(foreach_doc, -"foreach(callback[, policy[, options]])\n\ +"foreach(callback[, policy[, options [, nodename]])\n\ \n\ -Invoke the callback function for each of the records streaming back from the scan."); +Invoke the callback function for each of the records streaming back from the scan. If provided \ +nodename should be the Node ID of a node to limit the scan to."); PyDoc_STRVAR(select_doc, "select(bin1[, bin2[, bin3..]])\n\ @@ -46,9 +47,10 @@ Set a filter on the record bins resulting from results() or foreach(). \ If a selected bin does not exist in a record it will not appear in the bins portion of that record tuple."); PyDoc_STRVAR(results_doc, -"results([policy]) -> list of (key, meta, bins)\n\ +"results([policy [, nodename]) -> list of (key, meta, bins)\n\ \n\ -Buffer the records resulting from the scan, and return them as a list of records."); +Buffer the records resulting from the scan, and return them as a list of records.If provided \ +nodename should be the Node ID of a node to limit the scan to."); /******************************************************************************* diff --git a/test/new_tests/conftest.py b/test/new_tests/conftest.py index aff85af6b..0a4f14492 100644 --- a/test/new_tests/conftest.py +++ b/test/new_tests/conftest.py @@ -35,9 +35,8 @@ def wait_for_port(address, port, interval=0.1, timeout=60): def as_connection(request): hostlist, user, password = TestBaseClass.get_hosts() tls_info = TestBaseClass.get_tls_info() - lua_system_path = os.path.join(sys.exec_prefix, "aerospike", "lua") lua_user_path = os.path.join(sys.exec_prefix, "aerospike", "usr-lua") - lua_info = {'system_path': lua_system_path, 'user_path': lua_user_path} + lua_info = {'user_path': lua_user_path} config = {'hosts': hostlist, 'tls': tls_info, 'lua': lua_info} as_client = None if len(hostlist) == 2: diff --git a/test/new_tests/test_admin_change_password.py b/test/new_tests/test_admin_change_password.py index 9a6ad497f..cc0b391b4 100644 --- a/test/new_tests/test_admin_change_password.py +++ b/test/new_tests/test_admin_change_password.py @@ -16,7 +16,7 @@ class TestChangePassword(TestBaseClass): pytestmark = pytest.mark.skipif( - TestBaseClass().get_hosts()[1] is None, + not TestBaseClass.auth_in_use(), reason="No user specified, may be not secured cluster.") def setup_method(self, method): @@ -65,15 +65,14 @@ def test_change_password_with_proper_parameters(self): config = { "hosts": TestChangePassword.hostlist } - try: + + # Assert that connecting to the server with the old password fails + with pytest.raises( + (aerospike.exception.InvalidPassword, + aerospike.exception.InvalidCredential)): self.clientreaduserwrong = aerospike.client( config).connect(user, "aerospike") - except aerospike.exception.InvalidPassword as exception: - assert exception.code == 62 - except aerospike.exception.ClientError as exception: - assert exception.code == -1 - self.clientreaduserright = aerospike.client(config).connect( user, "newpassword") @@ -114,15 +113,12 @@ def test_change_password_with_proper_timeout_policy_value(self): "hosts": TestChangePassword.hostlist } - try: + with pytest.raises( + (aerospike.exception.InvalidPassword, + aerospike.exception.InvalidCredential)): self.clientreaduserwrong = aerospike.client( config).connect(user, "aerospike") - except aerospike.exception.InvalidPassword as exception: - assert exception.code == 62 - except aerospike.exception.ClientError as exception: - assert exception.code == -1 - self.clientreaduserright = aerospike.client(config).connect( user, "newpassword") diff --git a/test/new_tests/test_admin_create_role.py b/test/new_tests/test_admin_create_role.py index 22ca36b5e..4bbbb4e75 100644 --- a/test/new_tests/test_admin_create_role.py +++ b/test/new_tests/test_admin_create_role.py @@ -17,7 +17,7 @@ class TestCreateRole(TestBaseClass): pytestmark = pytest.mark.skipif( - TestBaseClass().get_hosts()[1] == None, + not TestBaseClass.auth_in_use(), reason="No user specified, may be not secured cluster.") def setup_method(self, method): @@ -95,6 +95,8 @@ def test_create_role_positive(self): self.client.admin_query_role("usr-sys-admin-test") # role exists, clear it out. self.client.admin_drop_role("usr-sys-admin-test") + # Give some time for the role removal to take place + time.sleep(2) except e.InvalidRole: pass # we are good, no such role exists diff --git a/test/new_tests/test_admin_create_user.py b/test/new_tests/test_admin_create_user.py index fcfaf1f98..045b1809b 100644 --- a/test/new_tests/test_admin_create_user.py +++ b/test/new_tests/test_admin_create_user.py @@ -17,7 +17,7 @@ class TestCreateUser(TestBaseClass): pytestmark = pytest.mark.skipif( - TestBaseClass().get_hosts()[1] is None, + not TestBaseClass.auth_in_use(), reason="No user specified, may be not secured cluster.") def setup_method(self, method): @@ -363,7 +363,6 @@ def test_create_user_with_invalid_roles_types(self, list_item): user = "user7" password = "user7" roles = ['read-write', list_item] - print(roles) try: self.client.admin_drop_user(user, policy) except: @@ -378,7 +377,6 @@ def test_create_user_with_very_long_role_name(self): user = "user7" password = "user7" roles = ['read-write', "abc" * 50] - print(roles) try: self.client.admin_drop_user(user, policy) except: diff --git a/test/new_tests/test_admin_drop_role.py b/test/new_tests/test_admin_drop_role.py index 9f520da8c..6efe36823 100644 --- a/test/new_tests/test_admin_drop_role.py +++ b/test/new_tests/test_admin_drop_role.py @@ -17,7 +17,7 @@ class TestDropRole(TestBaseClass): pytestmark = pytest.mark.skipif( - TestBaseClass().get_hosts()[1] == None, + not TestBaseClass.auth_in_use(), reason="No user specified, may be not secured cluster.") def setup_method(self, method): diff --git a/test/new_tests/test_admin_drop_user.py b/test/new_tests/test_admin_drop_user.py index 4226775e3..93e9d7839 100644 --- a/test/new_tests/test_admin_drop_user.py +++ b/test/new_tests/test_admin_drop_user.py @@ -22,7 +22,7 @@ class SomeClass(object): class TestDropUser(TestBaseClass): pytestmark = pytest.mark.skipif( - TestBaseClass().get_hosts()[1] == None, + not TestBaseClass.auth_in_use(), reason="No user specified, may be not secured cluster.") def setup_method(self, method): diff --git a/test/new_tests/test_admin_grant_privileges.py b/test/new_tests/test_admin_grant_privileges.py index c578378a7..ad36a51cb 100644 --- a/test/new_tests/test_admin_grant_privileges.py +++ b/test/new_tests/test_admin_grant_privileges.py @@ -17,7 +17,7 @@ class TestGrantPrivileges(TestBaseClass): pytestmark = pytest.mark.skipif( - TestBaseClass().get_hosts()[1] == None, + not TestBaseClass.auth_in_use(), reason="No user specified, may be not secured cluster.") def setup_method(self, method): diff --git a/test/new_tests/test_admin_grant_roles.py b/test/new_tests/test_admin_grant_roles.py index 6c4c9a1a0..0b36b0441 100644 --- a/test/new_tests/test_admin_grant_roles.py +++ b/test/new_tests/test_admin_grant_roles.py @@ -17,7 +17,7 @@ class TestGrantRoles(TestBaseClass): pytestmark = pytest.mark.skipif( - TestBaseClass().get_hosts()[1] is None, + not TestBaseClass.auth_in_use(), reason="No user specified, may be not secured cluster.") def setup_method(self, method): diff --git a/test/new_tests/test_admin_query_role.py b/test/new_tests/test_admin_query_role.py index 40c5bec5c..db3c91a43 100644 --- a/test/new_tests/test_admin_query_role.py +++ b/test/new_tests/test_admin_query_role.py @@ -17,7 +17,7 @@ class TestQueryRole(TestBaseClass): pytestmark = pytest.mark.skipif( - TestBaseClass().get_hosts()[1] == None, + not TestBaseClass.auth_in_use(), reason="No user specified, may be not secured cluster.") def setup_method(self, method): diff --git a/test/new_tests/test_admin_query_roles.py b/test/new_tests/test_admin_query_roles.py index bfb76ba55..31dad5b31 100644 --- a/test/new_tests/test_admin_query_roles.py +++ b/test/new_tests/test_admin_query_roles.py @@ -17,7 +17,7 @@ class TestQueryRoles(TestBaseClass): pytestmark = pytest.mark.skipif( - TestBaseClass().get_hosts()[1] == None, + not TestBaseClass.auth_in_use(), reason="No user specified, may be not secured cluster.") def setup_method(self, method): diff --git a/test/new_tests/test_admin_query_user.py b/test/new_tests/test_admin_query_user.py index 6d6d3a4fd..6b2437404 100644 --- a/test/new_tests/test_admin_query_user.py +++ b/test/new_tests/test_admin_query_user.py @@ -17,7 +17,7 @@ class TestQueryUser(TestBaseClass): pytestmark = pytest.mark.skipif( - TestBaseClass().get_hosts()[1] == None, + not TestBaseClass.auth_in_use(), reason="No user specified, may be not secured cluster.") def setup_method(self, method): diff --git a/test/new_tests/test_admin_query_users.py b/test/new_tests/test_admin_query_users.py index 94a6d8934..233c12b8c 100644 --- a/test/new_tests/test_admin_query_users.py +++ b/test/new_tests/test_admin_query_users.py @@ -17,7 +17,7 @@ class TestQueryUsers(TestBaseClass): pytestmark = pytest.mark.skipif( - TestBaseClass().get_hosts()[1] == None, + not TestBaseClass.auth_in_use(), reason="No user specified, may be not secured cluster.") def setup_method(self, method): diff --git a/test/new_tests/test_admin_revoke_privileges.py b/test/new_tests/test_admin_revoke_privileges.py index b622a4afc..d36555d7d 100644 --- a/test/new_tests/test_admin_revoke_privileges.py +++ b/test/new_tests/test_admin_revoke_privileges.py @@ -17,7 +17,7 @@ class TestRevokePrivilege(TestBaseClass): pytestmark = pytest.mark.skipif( - TestBaseClass().get_hosts()[1] == None, + not TestBaseClass.auth_in_use(), reason="No user specified, may be not secured cluster.") def setup_method(self, method): diff --git a/test/new_tests/test_admin_revoke_roles.py b/test/new_tests/test_admin_revoke_roles.py index 199c9f193..e8c748d01 100644 --- a/test/new_tests/test_admin_revoke_roles.py +++ b/test/new_tests/test_admin_revoke_roles.py @@ -17,7 +17,7 @@ class TestRevokeRoles(TestBaseClass): pytestmark = pytest.mark.skipif( - TestBaseClass().get_hosts()[1] is None, + not TestBaseClass.auth_in_use(), reason="No user specified, may be not secured cluster.") def setup_method(self, method): diff --git a/test/new_tests/test_admin_set_password.py b/test/new_tests/test_admin_set_password.py index 73ece3ee5..ba0abfa15 100644 --- a/test/new_tests/test_admin_set_password.py +++ b/test/new_tests/test_admin_set_password.py @@ -16,7 +16,7 @@ class TestSetPassword(TestBaseClass): pytestmark = pytest.mark.skipif( - TestBaseClass().get_hosts()[1] == None, + not TestBaseClass.auth_in_use(), reason="No user specified, may be not secured cluster.") def setup_method(self, method): diff --git a/test/new_tests/test_base_class.py b/test/new_tests/test_base_class.py index b891a758e..6579990d0 100644 --- a/test/new_tests/test_base_class.py +++ b/test/new_tests/test_base_class.py @@ -30,11 +30,16 @@ def get_hosts(): if config.has_option('enterprise-edition', 'password'): TestBaseClass.password = config.get( 'enterprise-edition', 'password') - TestBaseClass.using_auth = True + + # If the password is empty, assume we aren't using authentication + if not TestBaseClass.password.strip(): + TestBaseClass.password = None + TestBaseClass.user = None + else: + TestBaseClass.using_auth = True else: TestBaseClass.hostlist = TestBaseClass.parse_hosts( config.get('community-edition', 'hosts')) - print(TestBaseClass.using_auth) return TestBaseClass.hostlist, TestBaseClass.user, TestBaseClass.password @staticmethod diff --git a/test/new_tests/test_get_put.py b/test/new_tests/test_get_put.py index fd140e9a7..c147b2da8 100644 --- a/test/new_tests/test_get_put.py +++ b/test/new_tests/test_get_put.py @@ -745,25 +745,12 @@ def test_edge_put_record_with_bin_name_exceeding_max_limit(self): """ key = ('test', 'demo', 'put_rec') put_record = { - 'containers_free': [], - 'containers_used': [ - {'cluster_id': 'bob', - 'container_id': 1, - 'port': 4000} - ], - 'list_of_map': [{'test': 'bar'}], - 'map_of_list': {'fizz': ['b', 'u', 'z', 'z']}, - 'ports_free': [], - 'ports_unused': [4100, 4200, 4300], - 'provider_id': u'i-f01fc206' + 'a' * 50: "unimportant" } - try: + with pytest.raises(e.BinNameError): self.as_connection.put(key, put_record) - except e.BinNameError as exception: - assert exception.code == 21 - def test_edge_put_with_integer_greater_than_maxisze(self): """ Invoke put() for a record with integer greater than max size diff --git a/test/new_tests/test_invalid_conf.py b/test/new_tests/test_invalid_conf.py index 356d8f45e..9fc783493 100644 --- a/test/new_tests/test_invalid_conf.py +++ b/test/new_tests/test_invalid_conf.py @@ -52,16 +52,6 @@ def test_lua_user_path_too_long(self): }) assert "Lua user path too long" in err.value.msg - def test_lua_sys_path_too_long(self): - with pytest.raises(e.ParamError) as err: - client = aerospike.client( - { - 'hosts': [ - ("localhost", 3000)], - 'lua': {'system_path': 'a' * 256} - }) - assert "Lua system path too long" in err.value.msg - def test_non_callable_serializer(self): with pytest.raises(e.ParamError) as err: client = aerospike.client( diff --git a/test/new_tests/test_mapkeys_index.py b/test/new_tests/test_mapkeys_index.py index 2ca55dfcc..efcba86b5 100644 --- a/test/new_tests/test_mapkeys_index.py +++ b/test/new_tests/test_mapkeys_index.py @@ -212,17 +212,16 @@ def test_mapkeysindex_on_nonexistent_bin(self): 'test_string_map_index', {}), ('test', 'demo', None, aerospike.INDEX_STRING, 'test_string_map_index', {}), - # These 3 invalid index types, end up getting - # translated to strings - pytest.mark.xfail( - ('test', 'demo', 'string_map', None, - 'test_string_map_index', {})), - pytest.mark.xfail( - ('test', 'demo', 'string_map', 100, - 'test_string_map_index', {})), - pytest.mark.xfail( - ('test', 'demo', 'string_map', 'numeric', - 'test_string_map_index', {})), + + ('test', 'demo', 'string_map', None, + 'test_string_map_index', {}), + + ('test', 'demo', 'string_map', (), + 'test_string_map_index', {}), + + ('test', 'demo', 'string_map', 'numeric', + 'test_string_map_index', {}), + ('test', 'demo', 'string_map', aerospike.INDEX_STRING, None, {}), ('test', 'demo', 'string_map', aerospike.INDEX_STRING, 15, {}), ('test', 'demo', 'string_map', aerospike.INDEX_STRING, @@ -236,7 +235,7 @@ def test_mapkeysindex_on_nonexistent_bin(self): 'Set is int', 'Bin is None', 'Index type is None', - 'Index value is invalid', + 'Index value is tuple', 'Index type is string', 'index name is None', 'Index name is wrong type', diff --git a/test/new_tests/test_mapvalues_index.py b/test/new_tests/test_mapvalues_index.py index 6da16b683..d09595786 100644 --- a/test/new_tests/test_mapvalues_index.py +++ b/test/new_tests/test_mapvalues_index.py @@ -193,7 +193,6 @@ def test_mapvaluesindex_with_invalid_params(self, test_ns, test_set, err_code = err_info.value.code assert err_code == AerospikeStatus.AEROSPIKE_ERR_PARAM - @pytest.mark.xfail() @pytest.mark.parametrize("idx_val", (None, "a", ())) def test_mapvaluesindex_with_invalid_idx_values(self, idx_val): diff --git a/test/new_tests/test_query_predexp.py b/test/new_tests/test_query_predexp.py index 79e088fee..d9f69b025 100644 --- a/test/new_tests/test_query_predexp.py +++ b/test/new_tests/test_query_predexp.py @@ -292,6 +292,7 @@ def test_not(self): ] self.query.predexp(predexps) results = self.query.results() + assert len(results) == 99 assert_each_record_bins(results, lambda b: b['positive_i'] != 5)