From cbd38062b75add633e44fa4aed4ec3214168fe57 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Thu, 11 Dec 2025 14:30:04 -0800 Subject: [PATCH] Create separate branch to optimize admin tests since QE runs these tests against multinode servers --- test/new_tests/conftest.py | 93 ++++++++++++++- test/new_tests/test_admin_change_password.py | 37 ++++-- test/new_tests/test_admin_create_role.py | 97 ++++++---------- test/new_tests/test_admin_create_user.py | 107 +++++++----------- test/new_tests/test_admin_drop_role.py | 64 ++++++----- test/new_tests/test_admin_drop_user.py | 81 +++++-------- test/new_tests/test_admin_get_role.py | 34 ++++-- test/new_tests/test_admin_get_roles.py | 13 +-- test/new_tests/test_admin_grant_privileges.py | 53 ++++++--- test/new_tests/test_admin_grant_roles.py | 15 +-- test/new_tests/test_admin_query_role.py | 42 ++++--- test/new_tests/test_admin_query_roles.py | 12 +- test/new_tests/test_admin_query_user_info.py | 11 +- test/new_tests/test_admin_query_users_info.py | 27 +++-- .../new_tests/test_admin_revoke_privileges.py | 9 +- test/new_tests/test_admin_revoke_roles.py | 21 ++-- test/new_tests/test_admin_set_password.py | 10 +- test/new_tests/test_admin_set_quotas.py | 9 +- test/new_tests/test_admin_set_whitelist.py | 79 +++++++++---- 19 files changed, 457 insertions(+), 357 deletions(-) diff --git a/test/new_tests/conftest.py b/test/new_tests/conftest.py index 574b7412de..8f3af9ef71 100644 --- a/test/new_tests/conftest.py +++ b/test/new_tests/conftest.py @@ -4,11 +4,13 @@ import sys import pytest - from . import invalid_data from .test_base_class import TestBaseClass import aerospike +from aerospike import exception as e +import logging + # Comment this out because nowhere in the repository is using it ''' @@ -242,6 +244,95 @@ def invalid_key(request): # aerospike.set_log_level(aerospike.LOG_LEVEL_DEBUG) # aerospike.set_log_handler(None) +HARD_LIMIT_SECS = 3 +# Server team states that this time interval is a safe amount +POLL_INTERVAL_SECS = 0.1 + +def poll_until_role_exists(role_name: str, client: aerospike.Client): + start = time.time() + while time.time() - start < HARD_LIMIT_SECS: + try: + client.admin_query_role(role=role_name) + except e.InvalidRole: + time.sleep(POLL_INTERVAL_SECS) + continue + logging.debug("Role now exists. Return early") + return + logging.debug("poll_until_role_exists timeout") + +def poll_until_role_doesnt_exist(role_name: str, client: aerospike.Client): + start = time.time() + try: + while time.time() - start < HARD_LIMIT_SECS: + client.admin_query_role(role=role_name) + time.sleep(POLL_INTERVAL_SECS) + except e.InvalidRole: + logging.debug("Role no longer exists. Return early") + return + logging.debug("poll_until_role_doesnt_exist timeout") + +def poll_until_user_exists(username: str, client: aerospike.Client, roles: list[str]): + start = time.time() + while time.time() - start < HARD_LIMIT_SECS: + try: + user_dict = client.admin_query_user_info(user=username) + if user_dict["roles"] != roles: + continue + except e.InvalidUser: + time.sleep(POLL_INTERVAL_SECS) + continue + logging.debug("User now exists with expected roles.") + return + logging.debug("poll_until_user_exists timeout") + +def poll_until_user_doesnt_exist(username: str, client: aerospike.Client): + start = time.time() + try: + while time.time() - start < HARD_LIMIT_SECS: + client.admin_query_user_info(user=username) + time.sleep(POLL_INTERVAL_SECS) + except e.InvalidUser: + logging.debug("User no longer exists. Return early") + return + logging.debug("poll_until_user_doesnt_exist timeout") + +def wait_for_job_completion(as_connection, job_id, job_module: int = aerospike.JOB_QUERY, time_limit_secs: float = float("inf")): + """ + Blocks until the job has completed + """ + start = time.time() + while time.time() - start < time_limit_secs: + response = as_connection.job_info(job_id, job_module) + if response["status"] != aerospike.JOB_STATUS_INPROGRESS: + break + time.sleep(0.1) + +# Monkeypatching the client class or instance isn't possible since it's immutable + +def admin_create_role_and_poll(client: aerospike.Client, role: str, *args, **kwargs): + retval = client.admin_create_role(role, *args, **kwargs) + poll_until_role_exists(role, client) + return retval + +def admin_create_user_and_poll(client: aerospike.Client, username: str, password: str, roles: list, *args, **kwargs): + retval = client.admin_create_user(username, password, roles, *args, **kwargs) + + # The server creates a user and adds roles to it asynchronously, since security is a type of smd operation + # So client.admin_create_user() can return before all th + poll_until_user_exists(username, client, roles) + + return retval + +def admin_drop_user_and_poll(client: aerospike.Client, username: str, *args, **kwargs): + retval = client.admin_drop_user(username, *args, **kwargs) + poll_until_user_doesnt_exist(username, client) + return retval + +def admin_drop_role_and_poll(client: aerospike.Client, role: str, *args, **kwargs): + retval = client.admin_drop_role(role, *args, **kwargs) + poll_until_role_doesnt_exist(role, client) + return retval + def verify_record_ttl(client: aerospike.Client, key, expected_ttl: int): _, meta = client.exists(key) clock_skew_tolerance_secs = 50 diff --git a/test/new_tests/test_admin_change_password.py b/test/new_tests/test_admin_change_password.py index 82e3cee210..14b9d577cc 100644 --- a/test/new_tests/test_admin_change_password.py +++ b/test/new_tests/test_admin_change_password.py @@ -3,25 +3,32 @@ import pytest import time from .test_base_class import TestBaseClass +from .conftest import admin_drop_user_and_poll, poll_until_user_doesnt_exist import aerospike @pytest.mark.usefixtures("connection_config") -class TestChangePassword(object): +class TestChangePassword: def setup_method(self, method): """ Setup method """ if TestBaseClass.auth_in_use() is False: - pytest.skip("No user specified, may not be a secured cluster", allow_module_level=True) + pytest.skip( + "No user specified, may not be a secured cluster", + allow_module_level=True, + ) config = TestBaseClass.get_connection_config() - self.client = aerospike.client(config).connect(config["user"], config["password"]) + self.client = aerospike.client(config).connect( + config["user"], config["password"] + ) try: - self.client.admin_create_user("testchangepassworduser", "aerospike", ["read"]) - time.sleep(2) + self.client.admin_create_user( + "testchangepassworduser", "aerospike", ["read"] + ) except aerospike.exception.UserExistsError: pass # we are good, no such role exists self.delete_users = [] @@ -32,7 +39,7 @@ def teardown_method(self, method): """ try: - self.client.admin_drop_user("testchangepassworduser") + admin_drop_user_and_poll(self.client, "testchangepassworduser") except Exception: pass @@ -56,13 +63,15 @@ def test_change_password_with_proper_parameters(self): status = self.clientreaduser.admin_change_password(user, password) assert status == 0 - - time.sleep(2) config = self.connection_config # 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") + with pytest.raises( + (aerospike.exception.InvalidPassword, aerospike.exception.InvalidCredential) + ): + self.clientreaduserwrong = aerospike.client(config).connect( + user, "aerospike" + ) self.clientreaduserright = aerospike.client(config).connect(user, "newpassword") @@ -101,8 +110,12 @@ def test_change_password_with_proper_timeout_policy_value(self): time.sleep(2) config = self.connection_config - with pytest.raises((aerospike.exception.InvalidPassword, aerospike.exception.InvalidCredential)): - self.clientreaduserwrong = aerospike.client(config).connect(user, "aerospike") + with pytest.raises( + (aerospike.exception.InvalidPassword, aerospike.exception.InvalidCredential) + ): + self.clientreaduserwrong = aerospike.client(config).connect( + user, "aerospike" + ) 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 4ce5164381..6ff573989c 100644 --- a/test/new_tests/test_admin_create_role.py +++ b/test/new_tests/test_admin_create_role.py @@ -4,6 +4,7 @@ import time from .test_base_class import TestBaseClass from aerospike import exception as e +from .conftest import admin_drop_role_and_poll, admin_drop_user_and_poll, poll_until_role_doesnt_exist, poll_until_user_doesnt_exist, admin_create_user_and_poll, admin_create_role_and_poll import aerospike @@ -24,8 +25,7 @@ def setup_method(self, method): config = self.config self.client = aerospike.client(config).connect(config["user"], config["password"]) try: - self.client.admin_drop_user("testcreaterole") - time.sleep(2) + admin_drop_user_and_poll(self.client, "testcreaterole") except Exception: pass # do nothing, EAFP @@ -38,7 +38,7 @@ def teardown_method(self, method): for user in self.delete_users: try: - self.client.admin_drop_user(user) + admin_drop_user_and_poll(self.client, user) except Exception: pass @@ -58,15 +58,13 @@ def test_create_role_positive_with_policy(self): try: self.client.admin_get_role("usr-sys-admin-test") # role exists, clear it out. - self.client.admin_drop_role("usr-sys-admin-test") - time.sleep(2) + admin_drop_role_and_poll(self.client, "usr-sys-admin-test") except e.InvalidRole: pass # we are good, no such role exists - self.client.admin_create_role( + admin_create_role_and_poll(self.client, "usr-sys-admin-test", [{"code": aerospike.PRIV_READ, "ns": "test", "set": "demo"}], {"timeout": 180000} ) - time.sleep(1) roles = self.client.admin_get_role("usr-sys-admin-test") assert roles == { "privileges": [{"code": 10, "ns": "test", "set": "demo"}], @@ -76,18 +74,17 @@ def test_create_role_positive_with_policy(self): } try: - status = self.client.admin_create_user("testcreaterole", "createrole", ["usr-sys-admin-test"]) + status = admin_create_user_and_poll(self.client, "testcreaterole", "createrole", ["usr-sys-admin-test"]) except e.QuotasNotEnabled: pytest.mark.skip(reason="Got QuotasNotEnabled, skipping quota test.") pytest.skip() assert status == 0 - time.sleep(1) user = self.client.admin_query_user_info("testcreaterole") assert user["roles"] == ["usr-sys-admin-test"] - self.client.admin_drop_user("testcreaterole") + admin_drop_user_and_poll(self.client, "testcreaterole") @pytest.mark.parametrize( "priv_name, privs", @@ -114,31 +111,28 @@ def test_create_role_all_privs_positive(self, priv_name, privs): try: self.client.admin_get_role(role_name) # role exists, clear it out. - self.client.admin_drop_role(role_name) - time.sleep(2) + admin_drop_role_and_poll(self.client, role_name) except e.InvalidRole: pass # we are good, no such role exists - self.client.admin_create_role(role_name, privs) - time.sleep(1) + admin_create_role_and_poll(self.client, role_name, privs) roles = self.client.admin_get_role(role_name) assert roles == {"privileges": privs, "whitelist": [], "read_quota": 0, "write_quota": 0} try: - status = self.client.admin_create_user("testcreaterole", "createrole", [role_name]) + status = admin_create_user_and_poll(self.client, "testcreaterole", "createrole", [role_name]) except e.QuotasNotEnabled: pytest.mark.skip(reason="Got QuotasNotEnabled, skipping quota test.") pytest.skip() assert status == 0 - time.sleep(1) user = self.client.admin_query_user_info("testcreaterole") assert user["roles"] == [role_name] - self.client.admin_drop_user("testcreaterole") + admin_drop_user_and_poll(self.client, "testcreaterole") - self.client.admin_drop_role(role_name) + admin_drop_role_and_poll(self.client, role_name) def test_create_role_positive_with_policy_write(self): """ @@ -147,15 +141,13 @@ def test_create_role_positive_with_policy_write(self): try: self.client.admin_get_role("usr-sys-admin-test") # role exists, clear it out. - self.client.admin_drop_role("usr-sys-admin-test") - time.sleep(2) + admin_drop_role_and_poll(self.client, "usr-sys-admin-test") except e.InvalidRole: pass # we are good, no such role exists - self.client.admin_create_role( + admin_create_role_and_poll(self.client, "usr-sys-admin-test", [{"code": aerospike.PRIV_WRITE, "ns": "test", "set": "demo"}] ) - time.sleep(1) roles = self.client.admin_get_role("usr-sys-admin-test") assert roles == { "privileges": [{"code": 13, "ns": "test", "set": "demo"}], @@ -165,18 +157,17 @@ def test_create_role_positive_with_policy_write(self): } try: - status = self.client.admin_create_user("testcreaterole", "createrole", ["usr-sys-admin-test"]) + status = admin_create_user_and_poll(self.client, "testcreaterole", "createrole", ["usr-sys-admin-test"]) except e.QuotasNotEnabled: pytest.mark.skip(reason="Got QuotasNotEnabled, skipping quota test.") pytest.skip() assert status == 0 - time.sleep(1) user = self.client.admin_query_user_info("testcreaterole") assert user["roles"] == ["usr-sys-admin-test"] - self.client.admin_drop_user("testcreaterole") + admin_drop_user_and_poll(self.client, "testcreaterole") def test_create_role_positive(self): """ @@ -185,16 +176,13 @@ def test_create_role_positive(self): try: self.client.admin_get_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) + admin_drop_role_and_poll(self.client, "usr-sys-admin-test") except e.InvalidRole: pass # we are good, no such role exists - self.client.admin_create_role( + admin_create_role_and_poll(self.client, "usr-sys-admin-test", [{"code": aerospike.PRIV_USER_ADMIN}, {"code": aerospike.PRIV_SYS_ADMIN}] ) - time.sleep(1) roles = self.client.admin_get_role("usr-sys-admin-test") assert roles == { @@ -204,7 +192,7 @@ def test_create_role_positive(self): "write_quota": 0, } - self.client.admin_drop_role("usr-sys-admin-test") + admin_drop_role_and_poll(self.client, "usr-sys-admin-test") def test_create_role_whitelist_quota_positive(self): """ @@ -213,14 +201,12 @@ def test_create_role_whitelist_quota_positive(self): try: self.client.admin_get_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) + admin_drop_role_and_poll(self.client, "usr-sys-admin-test") except e.InvalidRole: pass # we are good, no such role exists try: - self.client.admin_create_role( + admin_create_role_and_poll(self.client, "usr-sys-admin-test", [{"code": aerospike.PRIV_USER_ADMIN}, {"code": aerospike.PRIV_SYS_ADMIN}], whitelist=["127.0.0.1", "10.1.2.0/24"], @@ -231,9 +217,7 @@ def test_create_role_whitelist_quota_positive(self): pytest.mark.skip(reason="Got QuotasNotEnabled, skipping quota test.") pytest.skip() - time.sleep(1) roles = self.client.admin_get_role("usr-sys-admin-test") - assert roles == { "privileges": [ {"code": aerospike.PRIV_USER_ADMIN, "ns": "", "set": ""}, @@ -244,14 +228,14 @@ def test_create_role_whitelist_quota_positive(self): "write_quota": 30, } - self.client.admin_drop_role("usr-sys-admin-test") + admin_drop_role_and_poll(self.client, "usr-sys-admin-test") def test_create_role_incorrect_role_type(self): """ role name not string """ try: - self.client.admin_create_role(1, [{"code": aerospike.PRIV_USER_ADMIN}]) + admin_create_role_and_poll(self.client, 1, [{"code": aerospike.PRIV_USER_ADMIN}]) except e.ParamError as exception: assert exception.code == -2 assert "Role name should be a string" in exception.msg @@ -263,13 +247,12 @@ def test_create_role_unknown_privilege_type(self): try: self.client.admin_get_role("usr-sys-admin-test") # role exists, clear it out. - self.client.admin_drop_role("usr-sys-admin-test") - time.sleep(2) + admin_drop_role_and_poll(self.client, "usr-sys-admin-test") except e.InvalidRole: pass # we are good, no such role exists try: - self.client.admin_create_role("usr-sys-admin-test", [{"code": 64}]) + admin_create_role_and_poll(self.client, "usr-sys-admin-test", [{"code": 64}]) except e.InvalidPrivilege as exception: assert exception.code == 72 @@ -278,7 +261,7 @@ def test_create_role_incorrect_privilege_type(self): privilege type incorrect """ try: - self.client.admin_create_role("usr-sys-admin-test", None) + admin_create_role_and_poll(self.client, "usr-sys-admin-test", None) except e.ParamError as exception: assert exception.code == -2 @@ -291,25 +274,22 @@ def test_create_role_existing_role(self): try: self.client.admin_get_role("usr-sys-admin-test") # role exists, clear it out. - self.client.admin_drop_role("usr-sys-admin-test") - time.sleep(2) + admin_drop_role_and_poll(self.client, "usr-sys-admin-test") except e.InvalidRole: pass # we are good, no such role exists - self.client.admin_create_role( + admin_create_role_and_poll(self.client, "usr-sys-admin-test", [{"code": aerospike.PRIV_USER_ADMIN}, {"code": aerospike.PRIV_SYS_ADMIN}] ) try: - self.client.admin_create_role( + admin_create_role_and_poll(self.client, "usr-sys-admin-test", [{"code": aerospike.PRIV_USER_ADMIN}, {"code": aerospike.PRIV_SYS_ADMIN}] ) - except e.RoleExistsError as exception: assert exception.code == 71 assert exception.msg == "AEROSPIKE_ROLE_ALREADY_EXISTS" - time.sleep(1) - status = self.client.admin_drop_role("usr-sys-admin-test") + status = admin_drop_role_and_poll(self.client, "usr-sys-admin-test") assert status == 0 @@ -319,16 +299,14 @@ def test_create_role_positive_with_special_characters(self): """ role_name = "!#Q#AEQ@#$%&^*((^&*~~~````" try: - self.client.admin_drop_role(role_name) # clear out if it exists - time.sleep(2) + admin_drop_role_and_poll(self.client, role_name) # clear out if it exists except Exception: pass # EAFP - status = self.client.admin_create_role( + status = admin_create_role_and_poll(self.client, role_name, [{"code": aerospike.PRIV_READ, "ns": "test", "set": "demo"}] ) assert status == 0 - time.sleep(1) roles = self.client.admin_get_role(role_name) assert roles == { @@ -340,23 +318,20 @@ def test_create_role_positive_with_special_characters(self): "write_quota": 0, } - status = self.client.admin_create_user("testcreaterole", "createrole", [role_name]) + status = admin_create_user_and_poll(self.client, "testcreaterole", "createrole", [role_name]) assert status == 0 - time.sleep(1) users = self.client.admin_query_user_info("testcreaterole") assert users["roles"] == [role_name] - self.client.admin_drop_role(role_name) - - time.sleep(1) + admin_drop_role_and_poll(self.client, role_name) users = self.client.admin_query_user_info("testcreaterole") assert users["roles"] == [] - self.client.admin_drop_user("testcreaterole") + admin_drop_user_and_poll(self.client, "testcreaterole") def test_create_role_positive_with_too_long_role_name(self): """ @@ -365,7 +340,7 @@ def test_create_role_positive_with_too_long_role_name(self): role_name = "role$" * 1000 try: - self.client.admin_create_role( + admin_create_role_and_poll(self.client, role_name, [{"code": aerospike.PRIV_READ, "ns": "test", "set": "demo"}] ) diff --git a/test/new_tests/test_admin_create_user.py b/test/new_tests/test_admin_create_user.py index 5bb4812155..ee708253e0 100644 --- a/test/new_tests/test_admin_create_user.py +++ b/test/new_tests/test_admin_create_user.py @@ -6,23 +6,24 @@ from aerospike import exception as e from contextlib import nullcontext import aerospike +from .conftest import admin_drop_user_and_poll, poll_until_user_doesnt_exist, admin_create_user_and_poll, poll_until_user_exists @pytest.mark.usefixtures("connection_config") class TestCreateUser(object): user = "user7" - pytestmark = pytest.mark.skipif( - not TestBaseClass.auth_in_use(), reason="No user specified, may be not secured cluster." - ) - def setup_method(self, method): """ Setup method """ config = TestBaseClass.get_connection_config() + if not TestBaseClass.auth_in_use(): + pytest.skip("No user specified, may be not secured cluster.") - self.client = aerospike.client(config).connect(config["user"], config["password"]) + self.client = aerospike.client(config).connect( + config["user"], config["password"] + ) self.delete_users = [] @@ -33,10 +34,9 @@ def teardown_method(self, method): for user in self.delete_users: try: - self.client.admin_drop_user(user) + admin_drop_user_and_poll(self.client, user) except Exception: pass - time.sleep(2) self.client.close() def test_create_user_without_any_parameters(self): @@ -54,14 +54,11 @@ def test_create_user_with_proper_parameters(self): roles = ["read", "read-write", "sys-admin"] try: - self.client.admin_drop_user(user, policy) - time.sleep(2) + admin_drop_user_and_poll(self.client, user, policy) except Exception: pass - status = self.client.admin_create_user(user, password, roles, policy) - - time.sleep(2) + status = admin_create_user_and_poll(self.client, user, password, roles, policy) assert status == 0 @@ -78,14 +75,11 @@ def test_create_user_with_proper_parameters_without_policy(self): roles = ["read", "read-write", "sys-admin"] try: - self.client.admin_drop_user(user) - time.sleep(2) + admin_drop_user_and_poll(self.client, user) except Exception: pass - status = self.client.admin_create_user(user, password, roles) - - time.sleep(2) + status = admin_create_user_and_poll(self.client, user, password, roles) assert status == 0 @@ -103,13 +97,12 @@ def test_create_user_with_invalid_timeout_policy_value(self): roles = ["sys-admin"] try: - self.client.admin_drop_user(user, policy) - time.sleep(2) + admin_drop_user_and_poll(self.client, user, policy) except Exception: pass try: - self.client.admin_create_user(user, password, roles, policy) + admin_create_user_and_poll(self.client, user, password, roles, policy) except e.ParamError as exception: assert exception.code == -2 @@ -123,15 +116,11 @@ def test_create_user_with_proper_timeout_policy_value(self): roles = ["read-write", "sys-admin"] try: - self.client.admin_drop_user(user, policy) - time.sleep(2) + admin_drop_user_and_poll(self.client, user, policy) except Exception: pass - status = self.client.admin_create_user(user, password, roles, policy) - - time.sleep(2) - + status = admin_create_user_and_poll(self.client, user, password, roles, policy) assert status == 0 user = self.client.admin_query_user_info(user) @@ -147,7 +136,7 @@ def test_create_user_with_none_username(self): roles = ["sys-admin"] try: - self.client.admin_create_user(user, password, roles) + admin_create_user_and_poll(self.client, user, password, roles) except e.ParamError as exception: assert exception.code == -2 @@ -160,7 +149,7 @@ def test_create_user_with_empty_username(self): roles = ["read-write"] try: - self.client.admin_create_user(user, password, roles) + admin_create_user_and_poll(self.client, user, password, roles) except e.InvalidUser as exception: assert exception.code == 60 @@ -173,12 +162,11 @@ def test_create_user_with_special_characters_in_username(self): roles = ["read-write"] try: - self.client.admin_drop_user(user) - time.sleep(2) + admin_drop_user_and_poll(self.client, user) except Exception: pass - status = self.client.admin_create_user(user, password, roles) + status = admin_create_user_and_poll(self.client, user, password, roles) assert status == 0 @@ -191,7 +179,7 @@ def test_create_user_with_none_password(self): roles = ["sys-admin"] try: - self.client.admin_create_user(user, password, roles) + admin_create_user_and_poll(self.client, user, password, roles) except e.ParamError as exception: assert exception.code == -2 @@ -204,15 +192,13 @@ def test_create_user_with_empty_string_as_password(self): roles = ["read-write"] try: - self.client.admin_drop_user(user) - time.sleep(2) + admin_drop_user_and_poll(self.client, user) except Exception: pass - status = self.client.admin_create_user(user, password, roles) + status = admin_create_user_and_poll(self.client, user, password, roles) assert status == 0 - time.sleep(2) self.delete_users.append(user) def test_create_user_with_special_characters_in_password(self): @@ -222,12 +208,11 @@ def test_create_user_with_special_characters_in_password(self): roles = ["sys-admin"] try: - self.client.admin_drop_user(user) - time.sleep(2) + admin_drop_user_and_poll(self.client, user) except Exception: pass - status = self.client.admin_create_user(user, password, roles) + status = admin_create_user_and_poll(self.client, user, password, roles) assert status == 0 @@ -240,13 +225,12 @@ def test_create_user_with_too_long_username(self): roles = ["sys-admin"] try: - self.client.admin_drop_user(user) - time.sleep(2) + admin_drop_user_and_poll(self.client, user) except Exception: pass try: - self.client.admin_create_user(user, password, roles) + admin_create_user_and_poll(self.client, user, password, roles) except e.InvalidUser as exception: assert exception.code == 60 @@ -262,13 +246,12 @@ def test_create_user_with_too_long_password(self): roles = ["read-write"] try: - self.client.admin_drop_user(user) - time.sleep(2) + admin_drop_user_and_poll(self.client, user) except Exception: pass with pytest.raises(e.ClientError): - self.client.admin_create_user(user, password, roles) + admin_create_user_and_poll(self.client, user, password, roles) def test_create_user_with_empty_roles_list(self): @@ -277,13 +260,12 @@ def test_create_user_with_empty_roles_list(self): roles = [] try: - self.client.admin_drop_user(user) - time.sleep(2) + admin_drop_user_and_poll(self.client, user) except Exception: pass try: - self.client.admin_create_user(user, password, roles) + admin_create_user_and_poll(self.client, user, password, roles) except e.InvalidRole as exception: assert exception.code == 70 @@ -296,13 +278,11 @@ def test_create_user_with_non_user_admin_user(self): roles = ["read-write"] try: - self.client.admin_drop_user(user) - time.sleep(2) + admin_drop_user_and_poll(self.client, user) except Exception: pass - status = self.client.admin_create_user(user, password, roles) - time.sleep(2) + status = admin_create_user_and_poll(self.client, user, password, roles) assert status == 0 @@ -331,12 +311,12 @@ def test_create_user_with_non_list_roles(self, roles): user = "user7" password = "user7" try: - self.client.admin_drop_user(user) + admin_drop_user_and_poll(self.client, user) except Exception: pass with pytest.raises(e.ParamError): - self.client.admin_create_user(user, password, roles) + admin_create_user_and_poll(self.client, user, password, roles) @pytest.mark.parametrize("list_item", [{}, (), 5, []]) def test_create_user_with_invalid_roles_types(self, list_item): @@ -345,31 +325,29 @@ def test_create_user_with_invalid_roles_types(self, list_item): password = "user7" roles = ["read-write", list_item] try: - self.client.admin_drop_user(user) + admin_drop_user_and_poll(self.client, user) except Exception: pass with pytest.raises(e.ClientError): - self.client.admin_create_user(user, password, roles) + admin_create_user_and_poll(self.client, user, password, roles) def test_create_user_with_very_long_role_name(self): password = "user7" roles = ["read-write", "abc" * 50] try: - self.client.admin_drop_user(self.user) - time.sleep(2) + admin_drop_user_and_poll(self.client, self.user) except Exception: pass with pytest.raises(e.ClientError): - self.client.admin_create_user(self.user, password, roles) + admin_create_user_and_poll(self.client, self.user, password, roles) # Need as_connection to get server version def test_create_pki_user(self, as_connection): try: - self.client.admin_drop_user(self.user) - time.sleep(2) + admin_drop_user_and_poll(self.client, self.user) except Exception: pass @@ -391,10 +369,13 @@ def test_create_pki_user(self, as_connection): roles = ["read-write"] admin_policy = {} with context: - self.client.admin_create_pki_user(user=self.user, roles=roles, policy=admin_policy) + self.client.admin_create_pki_user( + user=self.user, roles=roles, policy=admin_policy + ) if type(context) == nullcontext: + poll_until_user_exists(self.user, self.client, roles) + print("Check that the PKI user was created.") - time.sleep(2) userDict = self.client.admin_query_user_info(self.user) assert userDict["roles"] == ["read-write"] diff --git a/test/new_tests/test_admin_drop_role.py b/test/new_tests/test_admin_drop_role.py index b32bb0d286..0210decf69 100644 --- a/test/new_tests/test_admin_drop_role.py +++ b/test/new_tests/test_admin_drop_role.py @@ -5,6 +5,7 @@ from .test_base_class import TestBaseClass from aerospike import exception as e +from .conftest import admin_drop_user_and_poll, admin_drop_role_and_poll, admin_create_role_and_poll import aerospike @@ -12,7 +13,8 @@ class TestDropRole(object): pytestmark = pytest.mark.skipif( - not TestBaseClass.auth_in_use(), reason="No user specified, may be not secured cluster." + not TestBaseClass.auth_in_use(), + reason="No user specified, may be not secured cluster.", ) def setup_method(self, method): @@ -20,7 +22,9 @@ def setup_method(self, method): Setup method """ config = TestBaseClass.get_connection_config() - self.client = aerospike.client(config).connect(config["user"], config["password"]) + self.client = aerospike.client(config).connect( + config["user"], config["password"] + ) self.delete_users = [] @@ -31,8 +35,7 @@ def teardown_method(self, method): for user in self.delete_users: try: - self.client.admin_drop_user(user) - time.sleep(2) + admin_drop_user_and_poll(self.client, user) except Exception: pass @@ -52,20 +55,19 @@ def test_drop_role_positive_with_policy(self): try: self.client.admin_query_role("usr-sys-admin-test") # role exists, clear it out. - self.client.admin_drop_role("usr-sys-admin-test") - time.sleep(1) + admin_drop_role_and_poll(self.client, "usr-sys-admin-test") except e.InvalidRole: pass # we are good, no such role exists - self.client.admin_create_role( - "usr-sys-admin-test", [{"code": aerospike.PRIV_READ, "ns": "test", "set": "demo"}], {"timeout": 180000} + admin_create_role_and_poll(self.client, + "usr-sys-admin-test", + [{"code": aerospike.PRIV_READ, "ns": "test", "set": "demo"}], + {"timeout": 180000}, ) - time.sleep(1) - status = self.client.admin_drop_role("usr-sys-admin-test", {"timeout": 180000}) + status = admin_drop_role_and_poll(self.client, "usr-sys-admin-test", {"timeout": 180000}) assert status == 0 - time.sleep(1) with pytest.raises(e.InvalidRole): self.client.admin_query_role("usr-sys-admin-test") @@ -77,20 +79,18 @@ def test_drop_role_positive_with_policy_write(self): try: self.client.admin_query_role("usr-sys-admin-test") # role exists, clear it out. - self.client.admin_drop_role("usr-sys-admin-test") - time.sleep(1) + admin_drop_role_and_poll(self.client, "usr-sys-admin-test") except e.InvalidRole: pass # we are good, no such role exists - self.client.admin_create_role( - "usr-sys-admin-test", [{"code": aerospike.PRIV_WRITE, "ns": "test", "set": "demo"}] + admin_create_role_and_poll(self.client, + "usr-sys-admin-test", + [{"code": aerospike.PRIV_WRITE, "ns": "test", "set": "demo"}], ) - time.sleep(1) - status = self.client.admin_drop_role("usr-sys-admin-test") + status = admin_drop_role_and_poll(self.client, "usr-sys-admin-test") assert status == 0 - time.sleep(1) with pytest.raises(e.InvalidRole): self.client.admin_query_role("usr-sys-admin-test") @@ -102,21 +102,22 @@ def test_drop_role_positive(self): try: self.client.admin_query_role("usr-sys-admin-test") # role exists, clear it out. - self.client.admin_drop_role("usr-sys-admin-test") - time.sleep(1) + admin_drop_role_and_poll(self.client, "usr-sys-admin-test") except e.InvalidRole: pass # we are good, no such role exists - self.client.admin_create_role( - "usr-sys-admin-test", [{"code": aerospike.PRIV_USER_ADMIN}, {"code": aerospike.PRIV_SYS_ADMIN}] + admin_create_role_and_poll(self.client, + "usr-sys-admin-test", + [{"code": aerospike.PRIV_USER_ADMIN}, {"code": aerospike.PRIV_SYS_ADMIN}], ) - time.sleep(1) privs = self.client.admin_query_role("usr-sys-admin-test") - assert privs == [{"code": 0, "ns": "", "set": ""}, {"code": 1, "ns": "", "set": ""}] + assert privs == [ + {"code": 0, "ns": "", "set": ""}, + {"code": 1, "ns": "", "set": ""}, + ] - self.client.admin_drop_role("usr-sys-admin-test") - time.sleep(1) + admin_drop_role_and_poll(self.client, "usr-sys-admin-test") with pytest.raises(e.InvalidRole): self.client.admin_query_role("usr-sys-admin-test") @@ -126,7 +127,7 @@ def test_drop_non_existent_role(self): Drop non-existent role """ try: - self.client.admin_drop_role("usr-sys-admin-test") + admin_drop_role_and_poll(self.client, "usr-sys-admin-test") except e.InvalidRole as exception: assert exception.code == 70 @@ -147,17 +148,18 @@ def test_drop_role_with_incorrect_policy(self): """ Drop role with incorrect policy """ - status = self.client.admin_create_role("usr-sys-admin-test", [{"code": aerospike.PRIV_USER_ADMIN}]) + status = admin_create_role_and_poll(self.client, + "usr-sys-admin-test", [{"code": aerospike.PRIV_USER_ADMIN}] + ) assert status == 0 - time.sleep(3) try: - self.client.admin_drop_role("usr-sys-admin-test", {"timeout": 0.2}) + admin_drop_role_and_poll(self.client, "usr-sys-admin-test", {"timeout": 0.2}) except e.ParamError as exception: assert exception.code == -2 assert exception.msg == "timeout is invalid" try: - self.client.admin_drop_role("usr-sys-admin-test") + admin_drop_role_and_poll(self.client, "usr-sys-admin-test") except Exception: pass diff --git a/test/new_tests/test_admin_drop_user.py b/test/new_tests/test_admin_drop_user.py index 1765a90a46..5c9e45db9c 100644 --- a/test/new_tests/test_admin_drop_user.py +++ b/test/new_tests/test_admin_drop_user.py @@ -6,13 +6,15 @@ from aerospike import exception as e import aerospike +from .conftest import admin_drop_user_and_poll, poll_until_user_doesnt_exist, admin_create_user_and_poll @pytest.mark.usefixtures("connection_config") class TestDropUser(object): pytestmark = pytest.mark.skipif( - not TestBaseClass.auth_in_use(), reason="No user specified, may be not secured cluster." + not TestBaseClass.auth_in_use(), + reason="No user specified, may be not secured cluster.", ) def setup_method(self, method): @@ -21,10 +23,11 @@ def setup_method(self, method): """ config = TestBaseClass.get_connection_config() TestDropUser.Me = self - self.client = aerospike.client(config).connect(config["user"], config["password"]) + self.client = aerospike.client(config).connect( + config["user"], config["password"] + ) try: - self.client.admin_drop_user("foo-test") - time.sleep(2) + admin_drop_user_and_poll(self.client, "foo-test") except Exception: pass @@ -51,23 +54,13 @@ def test_drop_user_with_policy_none(self): user = "foo-test" password = "foo1" roles = ["read", "read-write", "sys-admin"] + admin_create_user_and_poll(self.client, user, password, roles, policy) - status = self.client.admin_create_user(user, password, roles, policy) - - time.sleep(2) - - assert status == 0 - user_info = self.client.admin_query_user_info(user, policy) - - assert user_info["roles"] == ["read", "read-write", "sys-admin"] - - status = self.client.admin_drop_user(user, policy) - + status = admin_drop_user_and_poll(self.client, user, policy) assert status == 0 try: self.client.admin_query_user_info(user) - except e.InvalidUser as exception: assert exception.code == 60 assert exception.msg == "AEROSPIKE_INVALID_USER" @@ -77,7 +70,7 @@ def test_drop_user_with_user_none(self): Invoke drop_user() with policy none """ try: - self.client.admin_drop_user(None) + admin_drop_user_and_poll(self.client, None) except e.ParamError as exception: assert exception.code == -2 @@ -91,22 +84,14 @@ def test_drop_user_positive(self): password = "foo1" roles = ["read", "read-write", "sys-admin"] - status = self.client.admin_create_user(user, password, roles) - - time.sleep(1) - + status = admin_create_user_and_poll(self.client, user, password, roles) assert status == 0 - user_info = self.client.admin_query_user_info(user) - assert user_info["roles"] == ["read", "read-write", "sys-admin"] - status = self.client.admin_drop_user(user) + status = admin_drop_user_and_poll(self.client, user) assert status == 0 - time.sleep(2) - try: self.client.admin_query_user_info(user) - except e.InvalidUser as exception: assert exception.code == 60 assert exception.msg == "AEROSPIKE_INVALID_USER" @@ -119,22 +104,13 @@ def test_drop_user_positive_without_policy(self): password = "foo1" roles = ["read", "read-write", "sys-admin"] - status = self.client.admin_create_user(user, password, roles) - - time.sleep(1) - - assert status == 0 - user_info = self.client.admin_query_user_info(user) + status = admin_create_user_and_poll(self.client, user, password, roles) - assert user_info["roles"] == ["read", "read-write", "sys-admin"] - status = self.client.admin_drop_user(user) + status = admin_drop_user_and_poll(self.client, user) assert status == 0 - time.sleep(1) - try: self.client.admin_query_user_info(user) - except e.InvalidUser as exception: assert exception.code == 60 assert exception.msg == "AEROSPIKE_INVALID_USER" @@ -152,7 +128,7 @@ def test_drop_user_negative(self): assert exception.msg == "AEROSPIKE_INVALID_USER" try: - self.client.admin_drop_user(user) + admin_drop_user_and_poll(self.client, user) except e.InvalidUser as exception: assert exception.code == 60 @@ -166,9 +142,7 @@ def test_drop_user_policy_incorrect(self): password = "foo1" roles = ["read", "read-write", "sys-admin"] - status = self.client.admin_create_user(user, password, roles) - - time.sleep(1) + status = admin_create_user_and_poll(self.client, user, password, roles) assert status == 0 user_details = self.client.admin_query_user_info(user) @@ -176,24 +150,28 @@ def test_drop_user_policy_incorrect(self): assert user_details["roles"] == ["read", "read-write", "sys-admin"] policy = {"timeout": 0.2} try: - status = self.client.admin_drop_user(user, policy) + status = admin_drop_user_and_poll(self.client, user, policy) except e.ParamError as exception: assert exception.code == -2 assert exception.msg == "timeout is invalid" - status = self.client.admin_drop_user(user) + status = admin_drop_user_and_poll(self.client, user) def test_drop_user_with_extra_argument(self): """ Invoke drop_user() with extra argument. """ with pytest.raises(TypeError) as typeError: - self.client.admin_drop_user("foo-test", None, "") + admin_drop_user_and_poll(self.client, "foo-test", None, "") - assert "admin_drop_user() takes at most 2 arguments (3 given)" in str(typeError.value) + assert "admin_drop_user() takes at most 2 arguments (3 given)" in str( + typeError.value + ) - @pytest.mark.xfail(reason="It is no longer possible to create a user with" "a name too long") + @pytest.mark.xfail( + reason="It is no longer possible to create a user with" "a name too long" + ) def test_drop_user_with_too_long_username(self): user = "user$" * 1000 @@ -201,14 +179,14 @@ def test_drop_user_with_too_long_username(self): roles = ["sys-admin"] try: - self.client.admin_create_user(user, password, roles) + admin_create_user_and_poll(self.client, user, password, roles) except e.InvalidUser as exception: assert exception.code == 60 assert exception.msg == "AEROSPIKE_INVALID_USER" try: - self.client.admin_drop_user(user) + admin_drop_user_and_poll(self.client, user) except e.InvalidUser as exception: assert exception.code == 60 @@ -221,12 +199,11 @@ def test_drop_user_with_special_characters_in_username(self): roles = ["read-write"] try: - status = self.client.admin_create_user(user, password, roles) + status = admin_create_user_and_poll(self.client, user, password, roles) assert status == 0 - time.sleep(1) except Exception: pass - status = self.client.admin_drop_user(user) + status = admin_drop_user_and_poll(self.client, user) assert status == 0 diff --git a/test/new_tests/test_admin_get_role.py b/test/new_tests/test_admin_get_role.py index 4379ad5768..aa31f5b97b 100644 --- a/test/new_tests/test_admin_get_role.py +++ b/test/new_tests/test_admin_get_role.py @@ -4,6 +4,7 @@ import time from .test_base_class import TestBaseClass from aerospike import exception as e +from .conftest import admin_drop_role_and_poll, poll_until_role_doesnt_exist, admin_create_role_and_poll import aerospike @@ -11,7 +12,8 @@ class TestGetRole(TestBaseClass): pytestmark = pytest.mark.skipif( - not TestBaseClass.auth_in_use(), reason="No user specified, may be not secured cluster." + not TestBaseClass.auth_in_use(), + reason="No user specified, may be not secured cluster.", ) def setup_method(self, method): @@ -19,29 +21,31 @@ def setup_method(self, method): Setup method """ config = TestBaseClass.get_connection_config() - self.client = aerospike.client(config).connect(config["user"], config["password"]) + self.client = aerospike.client(config).connect( + config["user"], config["password"] + ) try: - self.client.admin_drop_role("usr-sys-admin") - time.sleep(2) + admin_drop_role_and_poll(self.client, "usr-sys-admin") except Exception: pass - usr_sys_admin_privs = [{"code": aerospike.PRIV_USER_ADMIN}, {"code": aerospike.PRIV_SYS_ADMIN}] + usr_sys_admin_privs = [ + {"code": aerospike.PRIV_USER_ADMIN}, + {"code": aerospike.PRIV_SYS_ADMIN}, + ] try: - self.client.admin_drop_role("usr-sys-admin-test") - time.sleep(2) + admin_drop_role_and_poll(self.client, "usr-sys-admin-test") except Exception: pass - self.client.admin_create_role("usr-sys-admin-test", usr_sys_admin_privs) + admin_create_role_and_poll(self.client, "usr-sys-admin-test", usr_sys_admin_privs) self.delete_users = [] - time.sleep(1) def teardown_method(self, method): """ Teardown method """ try: - self.client.admin_drop_role("usr-sys-admin-test") + admin_drop_role_and_poll(self.client, "usr-sys-admin-test") except Exception: pass self.client.close() @@ -59,7 +63,10 @@ def test_admin_get_role_positive(self): """ roles = self.client.admin_get_role("usr-sys-admin-test") assert roles == { - "privileges": [{"ns": "", "set": "", "code": 0}, {"ns": "", "set": "", "code": 1}], + "privileges": [ + {"ns": "", "set": "", "code": 0}, + {"ns": "", "set": "", "code": 1}, + ], "whitelist": [], "read_quota": 0, "write_quota": 0, @@ -71,7 +78,10 @@ def test_admin_get_role_positive_with_policy(self): """ roles = self.client.admin_get_role("usr-sys-admin-test", {"timeout": 180000}) assert roles == { - "privileges": [{"ns": "", "set": "", "code": 0}, {"ns": "", "set": "", "code": 1}], + "privileges": [ + {"ns": "", "set": "", "code": 0}, + {"ns": "", "set": "", "code": 1}, + ], "whitelist": [], "read_quota": 0, "write_quota": 0, diff --git a/test/new_tests/test_admin_get_roles.py b/test/new_tests/test_admin_get_roles.py index 06a455e31d..8a4a3a2921 100644 --- a/test/new_tests/test_admin_get_roles.py +++ b/test/new_tests/test_admin_get_roles.py @@ -6,7 +6,7 @@ from aerospike import exception as e import aerospike - +from .conftest import admin_drop_role_and_poll, poll_until_role_doesnt_exist, admin_create_role_and_poll class TestGetRoles(TestBaseClass): @@ -21,26 +21,23 @@ def setup_method(self, method): config = TestBaseClass.get_connection_config() self.client = aerospike.client(config).connect(config["user"], config["password"]) try: - self.client.admin_drop_role("usr-sys-admin") + admin_drop_role_and_poll(self.client, "usr-sys-admin") except Exception: pass - time.sleep(2) usr_sys_admin_privs = [{"code": aerospike.PRIV_USER_ADMIN}, {"code": aerospike.PRIV_SYS_ADMIN}] try: - self.client.admin_drop_role("usr-sys-admin-test") + admin_drop_role_and_poll(self.client, "usr-sys-admin-test") except Exception: pass - time.sleep(2) - self.client.admin_create_role("usr-sys-admin-test", usr_sys_admin_privs) + admin_create_role_and_poll(self.client, "usr-sys-admin-test", usr_sys_admin_privs) self.delete_users = [] - time.sleep(2) def teardown_method(self, method): """ Teardown method """ try: - self.client.admin_drop_role("usr-sys-admin-test") + admin_drop_role_and_poll(self.client, "usr-sys-admin-test") except Exception: pass self.client.close() diff --git a/test/new_tests/test_admin_grant_privileges.py b/test/new_tests/test_admin_grant_privileges.py index b4d5990430..243de81423 100644 --- a/test/new_tests/test_admin_grant_privileges.py +++ b/test/new_tests/test_admin_grant_privileges.py @@ -6,6 +6,7 @@ from aerospike import exception as e import aerospike +from .conftest import admin_drop_role_and_poll, poll_until_role_doesnt_exist, admin_create_role_and_poll class TestGrantPrivileges(object): @@ -13,7 +14,8 @@ class TestGrantPrivileges(object): config = TestBaseClass.get_connection_config() pytestmark = pytest.mark.skipif( - not TestBaseClass.auth_in_use(), reason="No user specified, may be not secured cluster." + not TestBaseClass.auth_in_use(), + reason="No user specified, may be not secured cluster.", ) def setup_method(self, method): @@ -21,18 +23,19 @@ def setup_method(self, method): Setup method """ config = self.config - self.client = aerospike.client(config).connect(config["user"], config["password"]) + self.client = aerospike.client(config).connect( + config["user"], config["password"] + ) try: - self.client.admin_drop_role("usr-sys-admin-test") - time.sleep(1) + admin_drop_role_and_poll(self.client, "usr-sys-admin-test") except e.InvalidRole: pass - self.client.admin_create_role( - "usr-sys-admin-test", [{"code": aerospike.PRIV_USER_ADMIN}, {"code": aerospike.PRIV_SYS_ADMIN}] + admin_create_role_and_poll(self.client, + "usr-sys-admin-test", + [{"code": aerospike.PRIV_USER_ADMIN}, {"code": aerospike.PRIV_SYS_ADMIN}], ) self.delete_users = [] - time.sleep(1) def teardown_method(self, method): """ @@ -40,8 +43,8 @@ def teardown_method(self, method): """ try: - self.client.admin_drop_role("usr-sys-admin-test") - time.sleep(1) + # TODO: is this necessary if we already drop the role at the beginning of each test? + admin_drop_role_and_poll(self.client, "usr-sys-admin-test") except e.InvalidRole: pass self.client.close() @@ -57,7 +60,9 @@ def test_admin_grant_privileges_positive(self): """ Grant privileges positive """ - status = self.client.admin_grant_privileges("usr-sys-admin-test", [{"code": aerospike.PRIV_READ}]) + status = self.client.admin_grant_privileges( + "usr-sys-admin-test", [{"code": aerospike.PRIV_READ}] + ) assert status == 0 time.sleep(1) @@ -68,7 +73,9 @@ def test_admin_grant_privileges_positive(self): {"code": 10, "ns": "", "set": ""}, ] - status = self.client.admin_revoke_privileges("usr-sys-admin-test", [{"code": aerospike.PRIV_READ}]) + status = self.client.admin_revoke_privileges( + "usr-sys-admin-test", [{"code": aerospike.PRIV_READ}] + ) assert status == 0 @@ -94,7 +101,11 @@ def test_admin_grant_privileges_all_positive(self, privs): assert status == 0 time.sleep(1) roles = self.client.admin_query_role("usr-sys-admin-test") - assert roles == [{"code": 0, "ns": "", "set": ""}, {"code": 1, "ns": "", "set": ""}, *privs] + assert roles == [ + {"code": 0, "ns": "", "set": ""}, + {"code": 1, "ns": "", "set": ""}, + *privs, + ] status = self.client.admin_revoke_privileges("usr-sys-admin-test", privs) @@ -104,7 +115,9 @@ def test_admin_grant_privileges_positive_write(self): """ Grant write privileges positive """ - status = self.client.admin_grant_privileges("usr-sys-admin-test", [{"code": aerospike.PRIV_WRITE}]) + status = self.client.admin_grant_privileges( + "usr-sys-admin-test", [{"code": aerospike.PRIV_WRITE}] + ) assert status == 0 time.sleep(1) @@ -115,7 +128,9 @@ def test_admin_grant_privileges_positive_write(self): {"code": 13, "ns": "", "set": ""}, ] - status = self.client.admin_revoke_privileges("usr-sys-admin-test", [{"code": aerospike.PRIV_WRITE}]) + status = self.client.admin_revoke_privileges( + "usr-sys-admin-test", [{"code": aerospike.PRIV_WRITE}] + ) assert status == 0 @@ -136,7 +151,9 @@ def test_admin_grant_privileges_positive_with_policy(self): {"code": 10, "ns": "", "set": ""}, ] - status = self.client.admin_revoke_privileges("usr-sys-admin-test", [{"code": aerospike.PRIV_READ}]) + status = self.client.admin_revoke_privileges( + "usr-sys-admin-test", [{"code": aerospike.PRIV_READ}] + ) assert status == 0 @@ -145,7 +162,8 @@ def test_admin_grant_privileges_positive_with_ns_set(self): Grant privileges positive with ns and set """ status = self.client.admin_grant_privileges( - "usr-sys-admin-test", [{"code": aerospike.PRIV_READ, "ns": "test", "set": "demo"}] + "usr-sys-admin-test", + [{"code": aerospike.PRIV_READ, "ns": "test", "set": "demo"}], ) assert status == 0 @@ -158,7 +176,8 @@ def test_admin_grant_privileges_positive_with_ns_set(self): ] status = self.client.admin_revoke_privileges( - "usr-sys-admin-test", [{"code": aerospike.PRIV_READ, "ns": "test", "set": "demo"}] + "usr-sys-admin-test", + [{"code": aerospike.PRIV_READ, "ns": "test", "set": "demo"}], ) assert status == 0 diff --git a/test/new_tests/test_admin_grant_roles.py b/test/new_tests/test_admin_grant_roles.py index c009904f9e..02c82d9d5a 100644 --- a/test/new_tests/test_admin_grant_roles.py +++ b/test/new_tests/test_admin_grant_roles.py @@ -6,6 +6,7 @@ from aerospike import exception as e import aerospike +from .conftest import admin_drop_user_and_poll, poll_until_user_doesnt_exist, admin_create_user_and_poll class TestGrantRoles(TestBaseClass): @@ -23,8 +24,7 @@ def setup_method(self, method): self.client = aerospike.client(config).connect(config["user"], config["password"]) try: - self.client.admin_drop_user("example-test") - time.sleep(1) + admin_drop_user_and_poll(self.client, "example-test") except e.InvalidUser: pass user = "example-test" @@ -32,8 +32,7 @@ def setup_method(self, method): roles = ["read-write"] try: - self.client.admin_create_user(user, password, roles) - time.sleep(1) + admin_create_user_and_poll(self.client, user, password, roles) except e.UserExistsError: pass self.delete_users = [] @@ -44,8 +43,7 @@ def teardown_method(self, method): """ try: - self.client.admin_drop_user("example-test") - time.sleep(1) + admin_drop_user_and_poll(self.client, "example-test") except e.InvalidUser: pass self.client.close() @@ -141,8 +139,7 @@ def test_grant_roles_with_special_characters_in_username(self): roles = ["read-write"] try: - self.client.admin_create_user(user, password, roles) - time.sleep(1) + admin_create_user_and_poll(self.client, user, password, roles) except e.UserExistsError: pass @@ -157,7 +154,7 @@ def test_grant_roles_with_special_characters_in_username(self): assert set(user_details["roles"]) == set(["read", "read-write"]) - self.client.admin_drop_user(user) + admin_drop_user_and_poll(self.client, user) def test_grant_roles_with_empty_roles_list(self): diff --git a/test/new_tests/test_admin_query_role.py b/test/new_tests/test_admin_query_role.py index 0510ae3677..e5f5e0bb1e 100644 --- a/test/new_tests/test_admin_query_role.py +++ b/test/new_tests/test_admin_query_role.py @@ -6,42 +6,44 @@ from aerospike import exception as e import aerospike +from .conftest import admin_drop_role_and_poll, poll_until_role_doesnt_exist, admin_create_role_and_poll -class TestQueryRole(TestBaseClass): - - pytestmark = pytest.mark.skipif( - not TestBaseClass.auth_in_use(), reason="No user specified, may be not secured cluster." - ) +@pytest.mark.usefixtures("connection_config") +class TestQueryRole: def setup_method(self, method): """ Setup method """ + if not TestBaseClass.auth_in_use(): + pytest.skip(reason="No user specified, may be not secured cluster.") + config = TestBaseClass.get_connection_config() - self.client = aerospike.client(config).connect(config["user"], config["password"]) + self.client = aerospike.client(config).connect( + config["user"], config["password"] + ) try: - self.client.admin_drop_role("usr-sys-admin") - time.sleep(2) + admin_drop_role_and_poll(self.client, "usr-sys-admin") except Exception: pass - usr_sys_admin_privs = [{"code": aerospike.PRIV_USER_ADMIN}, {"code": aerospike.PRIV_SYS_ADMIN}] + usr_sys_admin_privs = [ + {"code": aerospike.PRIV_USER_ADMIN}, + {"code": aerospike.PRIV_SYS_ADMIN}, + ] try: - self.client.admin_drop_role("usr-sys-admin-test") - time.sleep(2) + admin_drop_role_and_poll(self.client, "usr-sys-admin-test") except Exception: pass - self.client.admin_create_role("usr-sys-admin-test", usr_sys_admin_privs) - + admin_create_role_and_poll(self.client, "usr-sys-admin-test", usr_sys_admin_privs) self.delete_users = [] - time.sleep(1) def teardown_method(self, method): """ Teardown method """ try: - self.client.admin_drop_role("usr-sys-admin-test") + admin_drop_role_and_poll(self.client, "usr-sys-admin-test") except Exception: pass self.client.close() @@ -58,14 +60,20 @@ def test_admin_query_role_positive(self): Query role positive """ roles = self.client.admin_query_role("usr-sys-admin-test") - assert roles == [{"code": 0, "ns": "", "set": ""}, {"code": 1, "ns": "", "set": ""}] + assert roles == [ + {"code": 0, "ns": "", "set": ""}, + {"code": 1, "ns": "", "set": ""}, + ] def test_admin_query_role_positive_with_policy(self): """ Query role positive policy """ roles = self.client.admin_query_role("usr-sys-admin-test", {"timeout": 180000}) - assert roles == [{"code": 0, "ns": "", "set": ""}, {"code": 1, "ns": "", "set": ""}] + assert roles == [ + {"code": 0, "ns": "", "set": ""}, + {"code": 1, "ns": "", "set": ""}, + ] def test_admin_query_role_incorrect_role_name(self): """ diff --git a/test/new_tests/test_admin_query_roles.py b/test/new_tests/test_admin_query_roles.py index 803d34e9e9..a68c14eafd 100644 --- a/test/new_tests/test_admin_query_roles.py +++ b/test/new_tests/test_admin_query_roles.py @@ -6,6 +6,7 @@ from aerospike import exception as e import aerospike +from .conftest import admin_drop_role_and_poll, poll_until_role_doesnt_exist, admin_create_role_and_poll class TestQueryRoles(TestBaseClass): @@ -21,26 +22,23 @@ def setup_method(self, method): config = TestBaseClass.get_connection_config() self.client = aerospike.client(config).connect(config["user"], config["password"]) try: - self.client.admin_drop_role("usr-sys-admin") + admin_drop_role_and_poll(self.client, "usr-sys-admin") except Exception: pass - time.sleep(2) usr_sys_admin_privs = [{"code": aerospike.PRIV_USER_ADMIN}, {"code": aerospike.PRIV_SYS_ADMIN}] try: - self.client.admin_drop_role("usr-sys-admin-test") + admin_drop_role_and_poll(self.client, "usr-sys-admin-test") except Exception: pass - time.sleep(2) - self.client.admin_create_role("usr-sys-admin-test", usr_sys_admin_privs) + admin_create_role_and_poll(self.client, "usr-sys-admin-test", usr_sys_admin_privs) self.delete_users = [] - time.sleep(2) def teardown_method(self, method): """ Teardown method """ try: - self.client.admin_drop_role("usr-sys-admin-test") + admin_drop_role_and_poll(self.client, "usr-sys-admin-test") except Exception: pass self.client.close() diff --git a/test/new_tests/test_admin_query_user_info.py b/test/new_tests/test_admin_query_user_info.py index b56a3e70f6..5c0b5f5ad3 100644 --- a/test/new_tests/test_admin_query_user_info.py +++ b/test/new_tests/test_admin_query_user_info.py @@ -6,6 +6,7 @@ from aerospike import exception as e import aerospike +from .conftest import admin_drop_user_and_poll, poll_until_user_doesnt_exist, admin_create_user_and_poll class TestQueryUserInfo(TestBaseClass): @@ -23,16 +24,14 @@ def setup_method(self, method): self.user = "example-test" self.client = aerospike.client(config).connect(config["user"], config["password"]) try: - self.client.admin_drop_user(self.user) - time.sleep(1) + admin_drop_user_and_poll(self.client, self.user) except e.InvalidUser: pass password = "foo2" roles = ["read-write", "sys-admin", "read"] try: - self.client.admin_create_user(self.user, password, roles) - time.sleep(1) + admin_create_user_and_poll(self.client, self.user, password, roles) except e.UserExistsError: pass self.delete_users = [] @@ -43,8 +42,7 @@ def teardown_method(self, method): """ try: - self.client.admin_drop_user(self.user) - time.sleep(1) + admin_drop_user_and_poll(self.client, self.user) except e.InvalidUser: pass @@ -57,7 +55,6 @@ def test_query_user_info_without_any_parameters(self): def test_query_user_info_with_proper_parameters(self): - time.sleep(2) user_details = self.client.admin_query_user_info(self.user) assert user_details.get("roles") == [ "read", diff --git a/test/new_tests/test_admin_query_users_info.py b/test/new_tests/test_admin_query_users_info.py index 11db38ef38..9bbc067790 100644 --- a/test/new_tests/test_admin_query_users_info.py +++ b/test/new_tests/test_admin_query_users_info.py @@ -6,12 +6,14 @@ from aerospike import exception as e import aerospike +from .conftest import admin_drop_user_and_poll, poll_until_user_doesnt_exist, admin_create_user_and_poll class TestQueryUsersInfo(TestBaseClass): pytestmark = pytest.mark.skipif( - not TestBaseClass.auth_in_use(), reason="No user specified, may not be secured cluster." + not TestBaseClass.auth_in_use(), + reason="No user specified, may not be secured cluster.", ) def setup_method(self, method): @@ -20,11 +22,12 @@ def setup_method(self, method): """ config = TestBaseClass.get_connection_config() TestQueryUsersInfo.Me = self - self.client = aerospike.client(config).connect(config["user"], config["password"]) + self.client = aerospike.client(config).connect( + config["user"], config["password"] + ) try: - self.client.admin_drop_user("example-test") - time.sleep(2) + admin_drop_user_and_poll(self.client, "example-test") except e.InvalidUser: pass user = "example-test" @@ -32,8 +35,7 @@ def setup_method(self, method): roles = ["read-write", "sys-admin", "read"] try: - self.client.admin_create_user(user, password, roles) - time.sleep(2) + admin_create_user_and_poll(self.client, user, password, roles) except e.UserExistsError: pass self.delete_users = [] @@ -44,14 +46,13 @@ def teardown_method(self, method): """ try: - self.client.admin_drop_user("example-test") + admin_drop_user_and_poll(self.client, "example-test") except Exception: pass self.client.close() def test_query_users_info_with_proper_parameters(self): - time.sleep(2) user_details = self.client.admin_query_users_info() # Usage test; doesn't actually test if the server records user data @@ -78,7 +79,11 @@ def test_query_users_info_with_proper_timeout_policy_value(self): user_details = self.client.admin_query_users_info(policy) - assert user_details.get("example-test").get("roles") == ["read", "read-write", "sys-admin"] + assert user_details.get("example-test").get("roles") == [ + "read", + "read-write", + "sys-admin", + ] def test_query_users_info_with_no_roles(self): @@ -100,7 +105,9 @@ def test_query_users_info_with_extra_argument(self): with pytest.raises(TypeError) as typeError: self.client.admin_query_users_info(None, "") - assert "admin_query_users_info() takes at most 1 argument (2 given)" in str(typeError.value) + assert "admin_query_users_info() takes at most 1 argument (2 given)" in str( + typeError.value + ) def test_query_users_info_with_policy_as_string(self): """ diff --git a/test/new_tests/test_admin_revoke_privileges.py b/test/new_tests/test_admin_revoke_privileges.py index e5bfef9c24..ceb52da490 100644 --- a/test/new_tests/test_admin_revoke_privileges.py +++ b/test/new_tests/test_admin_revoke_privileges.py @@ -6,6 +6,7 @@ from aerospike import exception as e import aerospike +from .conftest import admin_drop_role_and_poll, poll_until_role_doesnt_exist, admin_create_role_and_poll class TestRevokePrivilege(TestBaseClass): @@ -23,14 +24,12 @@ def setup_method(self, method): config = self.config self.client = aerospike.client(config).connect(config["user"], config["password"]) try: - self.client.admin_drop_role("usr-sys-admin-test") - time.sleep(2) + admin_drop_role_and_poll(self.client, "usr-sys-admin-test") except e.InvalidRole: pass - self.client.admin_create_role( + admin_create_role_and_poll(self.client, "usr-sys-admin-test", [{"code": aerospike.PRIV_USER_ADMIN}, {"code": aerospike.PRIV_SYS_ADMIN}] ) - time.sleep(2) self.delete_users = [] def teardown_method(self, method): @@ -38,7 +37,7 @@ def teardown_method(self, method): Teardown method """ try: - self.client.admin_drop_role("usr-sys-admin-test") + admin_drop_role_and_poll(self.client, "usr-sys-admin-test") except e.InvalidRole: pass self.client.close() diff --git a/test/new_tests/test_admin_revoke_roles.py b/test/new_tests/test_admin_revoke_roles.py index 10616159bf..5f171a2631 100644 --- a/test/new_tests/test_admin_revoke_roles.py +++ b/test/new_tests/test_admin_revoke_roles.py @@ -6,6 +6,7 @@ from aerospike import exception as e import aerospike +from .conftest import admin_drop_user_and_poll, poll_until_user_doesnt_exist, admin_create_user_and_poll class TestRevokeRoles(TestBaseClass): @@ -22,8 +23,7 @@ def setup_method(self, method): TestRevokeRoles.Me = self self.client = aerospike.client(config).connect(config["user"], config["password"]) try: - self.client.admin_drop_user("example-test") - time.sleep(1) + admin_drop_user_and_poll(self.client, "example-test") except e.InvalidUser: pass user = "example-test" @@ -31,8 +31,7 @@ def setup_method(self, method): roles = ["read-write", "sys-admin", "read"] try: - self.client.admin_create_user(user, password, roles) - time.sleep(1) + admin_create_user_and_poll(self.client, user, password, roles) except e.UserExistsError: pass @@ -44,8 +43,7 @@ def teardown_method(self, method): """ try: - self.client.admin_drop_user("example-test") - time.sleep(1) + admin_drop_user_and_poll(self.client, "example-test") except e.InvalidUser: pass self.client.close() @@ -73,7 +71,6 @@ def test_revoke_all_roles_with_proper_parameters(self): user = "example-test" roles = ["read", "sys-admin", "read-write"] - time.sleep(2) status = self.client.admin_revoke_roles(user, roles) assert status == 0 time.sleep(2) @@ -165,8 +162,7 @@ def test_revoke_roles_with_special_characters_in_username(self): password = "abcd" roles = ["read-write"] - status = self.client.admin_create_user(user, password, roles) - time.sleep(2) + status = admin_create_user_and_poll(self.client, user, password, roles) assert status == 0 status = self.client.admin_revoke_roles(user, roles) @@ -179,7 +175,7 @@ def test_revoke_roles_with_special_characters_in_username(self): assert user_details["roles"] == [] - status = self.client.admin_drop_user("!#Q#AEQ@#$%&^*((^&*~~~````[[") + status = admin_drop_user_and_poll(self.client, "!#Q#AEQ@#$%&^*((^&*~~~````[[") assert status == 0 def test_revoke_roles_nonpossessed(self): @@ -188,8 +184,7 @@ def test_revoke_roles_nonpossessed(self): password = "abcd" roles = ["read-write"] - status = self.client.admin_create_user(user, password, roles) - time.sleep(2) + status = admin_create_user_and_poll(self.client, user, password, roles) assert status == 0 roles = ["read"] @@ -202,7 +197,7 @@ def test_revoke_roles_nonpossessed(self): assert user_details["roles"] == ["read-write"] assert status == 0 - status = self.client.admin_drop_user(user) + status = admin_drop_user_and_poll(self.client, user) assert status == 0 def test_revoke_roles_with_roles_exceeding_max_length(self): diff --git a/test/new_tests/test_admin_set_password.py b/test/new_tests/test_admin_set_password.py index 0e0d5d400e..76f9c9c39f 100644 --- a/test/new_tests/test_admin_set_password.py +++ b/test/new_tests/test_admin_set_password.py @@ -6,6 +6,7 @@ from aerospike import exception as e import aerospike +from .conftest import admin_drop_user_and_poll, poll_until_user_doesnt_exist, admin_create_user_and_poll class TestSetPassword(TestBaseClass): @@ -22,17 +23,15 @@ def setup_method(self, method): TestSetPassword.Me = self self.client = aerospike.client(config).connect(config["user"], config["password"]) try: - self.client.admin_drop_user("testsetpassworduser") - time.sleep(2) + admin_drop_user_and_poll(self.client, "testsetpassworduser") except e.InvalidUser: pass try: - self.client.admin_create_user("testsetpassworduser", "aerospike", ["read"]) + admin_create_user_and_poll(self.client, "testsetpassworduser", "aerospike", ["read"]) except e.UserExistsError: pass - time.sleep(2) self.delete_users = [] def teardown_method(self, method): @@ -41,8 +40,7 @@ def teardown_method(self, method): """ try: - self.client.admin_drop_user("testsetpassworduser") - time.sleep(2) + admin_drop_user_and_poll(self.client, "testsetpassworduser") except e.InvalidUser: pass self.client.close() diff --git a/test/new_tests/test_admin_set_quotas.py b/test/new_tests/test_admin_set_quotas.py index 4f7e21316d..40b8c3a69a 100644 --- a/test/new_tests/test_admin_set_quotas.py +++ b/test/new_tests/test_admin_set_quotas.py @@ -6,6 +6,7 @@ from aerospike import exception as e import aerospike +from .conftest import admin_drop_role_and_poll, poll_until_role_doesnt_exist, admin_create_role_and_poll class TestSetQuotas(TestBaseClass): @@ -19,24 +20,22 @@ def setup_method(self, method): usr_sys_admin_privs = [{"code": aerospike.PRIV_USER_ADMIN}, {"code": aerospike.PRIV_SYS_ADMIN}] try: - self.client.admin_drop_role("usr-sys-admin-test") - time.sleep(2) + admin_drop_role_and_poll(self.client, "usr-sys-admin-test") except Exception: pass try: - self.client.admin_create_role("usr-sys-admin-test", usr_sys_admin_privs, write_quota=4500) + admin_create_role_and_poll(self.client, "usr-sys-admin-test", usr_sys_admin_privs, write_quota=4500) except e.QuotasNotEnabled: pytest.skip(reason="Got QuotasNotEnabled, skipping quota test.") - time.sleep(1) def teardown_method(self, method): """ Teardown method """ try: - self.client.admin_drop_role("usr-sys-admin-test") + admin_drop_role_and_poll(self.client, "usr-sys-admin-test") except Exception: pass diff --git a/test/new_tests/test_admin_set_whitelist.py b/test/new_tests/test_admin_set_whitelist.py index 1577129a34..e82f051689 100644 --- a/test/new_tests/test_admin_set_whitelist.py +++ b/test/new_tests/test_admin_set_whitelist.py @@ -6,6 +6,7 @@ from aerospike import exception as e import aerospike +from .conftest import admin_drop_role_and_poll, admin_drop_user_and_poll, poll_until_role_doesnt_exist, admin_create_role_and_poll class TestSetWhitelist(TestBaseClass): @@ -13,7 +14,8 @@ class TestSetWhitelist(TestBaseClass): config = TestBaseClass.get_connection_config() pytestmark = pytest.mark.skipif( - not TestBaseClass.auth_in_use(), reason="No user specified, may be not secured cluster." + not TestBaseClass.auth_in_use(), + reason="No user specified, may be not secured cluster.", ) def setup_method(self, method): @@ -21,25 +23,30 @@ def setup_method(self, method): Setup method """ config = self.config - self.client = aerospike.client(config).connect(config["user"], config["password"]) - usr_sys_admin_privs = [{"code": aerospike.PRIV_USER_ADMIN}, {"code": aerospike.PRIV_SYS_ADMIN}] + self.client = aerospike.client(config).connect( + config["user"], config["password"] + ) + usr_sys_admin_privs = [ + {"code": aerospike.PRIV_USER_ADMIN}, + {"code": aerospike.PRIV_SYS_ADMIN}, + ] whitelist = ["127.0.0.1"] try: - self.client.admin_drop_role("usr-sys-admin-test") - time.sleep(2) + admin_drop_role_and_poll(self.client, "usr-sys-admin-test") except Exception: pass - self.client.admin_create_role("usr-sys-admin-test", usr_sys_admin_privs, whitelist=whitelist) + admin_create_role_and_poll(self.client, + "usr-sys-admin-test", usr_sys_admin_privs, whitelist=whitelist + ) self.delete_users = [] - time.sleep(1) def teardown_method(self, method): """ Teardown method """ try: - self.client.admin_drop_role("usr-sys-admin-test") + admin_drop_role_and_poll(self.client, "usr-sys-admin-test") except Exception: pass self.client.close() @@ -59,7 +66,10 @@ def test_admin_set_whitelist_empty_whitelist_positive(self): time.sleep(1) roles = self.client.admin_get_role("usr-sys-admin-test") assert roles == { - "privileges": [{"ns": "", "set": "", "code": 0}, {"ns": "", "set": "", "code": 1}], + "privileges": [ + {"ns": "", "set": "", "code": 0}, + {"ns": "", "set": "", "code": 1}, + ], "whitelist": [], "read_quota": 0, "write_quota": 0, @@ -73,7 +83,10 @@ def test_admin_set_whitelist_none_whitelist_positive(self): time.sleep(1) roles = self.client.admin_get_role("usr-sys-admin-test") assert roles == { - "privileges": [{"ns": "", "set": "", "code": 0}, {"ns": "", "set": "", "code": 1}], + "privileges": [ + {"ns": "", "set": "", "code": 0}, + {"ns": "", "set": "", "code": 1}, + ], "whitelist": [], "read_quota": 0, "write_quota": 0, @@ -83,11 +96,17 @@ def test_admin_set_whitelist_one_whitelist_positive(self): """ Set whitelist with whitelist. """ - self.client.admin_set_whitelist(role="usr-sys-admin-test", whitelist=["10.0.2.0/24", "127.0.0.1", "127.0.0.2"]) + self.client.admin_set_whitelist( + role="usr-sys-admin-test", + whitelist=["10.0.2.0/24", "127.0.0.1", "127.0.0.2"], + ) time.sleep(1) roles = self.client.admin_get_role("usr-sys-admin-test") assert roles == { - "privileges": [{"ns": "", "set": "", "code": 0}, {"ns": "", "set": "", "code": 1}], + "privileges": [ + {"ns": "", "set": "", "code": 0}, + {"ns": "", "set": "", "code": 1}, + ], "whitelist": ["10.0.2.0/24", "127.0.0.1", "127.0.0.2"], "read_quota": 0, "write_quota": 0, @@ -101,7 +120,10 @@ def test_admin_set_quota_empty_positive(self): time.sleep(1) roles = self.client.admin_get_role("usr-sys-admin-test") assert roles == { - "privileges": [{"ns": "", "set": "", "code": 0}, {"ns": "", "set": "", "code": 1}], + "privileges": [ + {"ns": "", "set": "", "code": 0}, + {"ns": "", "set": "", "code": 1}, + ], "whitelist": [], "read_quota": 0, "write_quota": 0, @@ -112,12 +134,17 @@ def test_admin_set_whitelist_positive_with_policy(self): Set whitelist positive policy """ self.client.admin_set_whitelist( - role="usr-sys-admin-test", whitelist=["10.0.2.0/24", "127.0.0.1"], policy={"timeout": 180000} + role="usr-sys-admin-test", + whitelist=["10.0.2.0/24", "127.0.0.1"], + policy={"timeout": 180000}, ) time.sleep(1) roles = self.client.admin_get_role("usr-sys-admin-test") assert roles == { - "privileges": [{"ns": "", "set": "", "code": 0}, {"ns": "", "set": "", "code": 1}], + "privileges": [ + {"ns": "", "set": "", "code": 0}, + {"ns": "", "set": "", "code": 1}, + ], "whitelist": ["10.0.2.0/24", "127.0.0.1"], "read_quota": 0, "write_quota": 0, @@ -128,7 +155,9 @@ def test_admin_set_whitelist_incorrect_role_name(self): Incorrect role name """ try: - self.client.admin_set_whitelist(role="bad-role-name", whitelist=["10.0.2.0/24"]) + self.client.admin_set_whitelist( + role="bad-role-name", whitelist=["10.0.2.0/24"] + ) except e.InvalidRole as exception: assert exception.code == 70 @@ -150,7 +179,9 @@ def test_admin_set_whitelist_incorrect_whitelist(self): Incorrect role name """ try: - self.client.admin_set_whitelist(role="usr-sys-admin-test", whitelist=["bad_IP"]) + self.client.admin_set_whitelist( + role="usr-sys-admin-test", whitelist=["bad_IP"] + ) except e.InvalidWhitelist as exception: assert exception.code == 73 assert exception.msg == "AEROSPIKE_INVALID_WHITELIST" @@ -170,16 +201,22 @@ def test_admin_set_whitelist_forbiden_host(self): """ Forbiden host """ - self.client.admin_set_whitelist(role="usr-sys-admin-test", whitelist=["123.4.5.6"]) + self.client.admin_set_whitelist( + role="usr-sys-admin-test", whitelist=["123.4.5.6"] + ) - self.client.admin_create_user("test_whitelist_user", "123", ["usr-sys-admin-test"]) + self.client.admin_create_user( + "test_whitelist_user", "123", ["usr-sys-admin-test"] + ) config = TestBaseClass.get_connection_config() - new_client = aerospike.client(config).connect(config["user"], config["password"]) + new_client = aerospike.client(config).connect( + config["user"], config["password"] + ) try: new_client.connect("test_whitelist_user", "123") except e.NotWhitelisted as exception: assert exception.code == 82 assert exception.msg == "Failed to connect" finally: - self.client.admin_drop_user("test_whitelist_user") + admin_drop_user_and_poll(self.client, "test_whitelist_user")