Skip to content

Commit b2fba1a

Browse files
authored
25-1: sysview make database admin tests stable (#15466)
Make tests on database admin access to auth_* sysviews stable.
1 parent 2b365ce commit b2fba1a

File tree

2 files changed

+36
-11
lines changed

2 files changed

+36
-11
lines changed

ydb/tests/functional/tenants/test_auth_system_views.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,20 +88,27 @@ def stream_query_result(driver, query):
8888
return result, error
8989

9090

91-
@pytest.fixture(scope='function')
92-
def prepared_test_env(ydb_cluster, ydb_root, ydb_database, ydb_client):
91+
@pytest.fixture(scope='module')
92+
def prepared_root_db(ydb_cluster, ydb_root, ydb_endpoint):
9393
cluster_admin = ydb.AuthTokenCredentials(ydb_cluster.config.default_clusteradmin)
9494

9595
# prepare root database
96-
with ydb_client(ydb_root, credentials=cluster_admin) as driver:
96+
driver_config = ydb.DriverConfig(ydb_endpoint, ydb_root, credentials=cluster_admin)
97+
with ydb.Driver(driver_config) as driver:
9798
pool = ydb.SessionPool(driver)
9899
with pool.checkout() as session:
99100
session.execute_scheme("create user clusteradmin password '1234'")
100101
session.execute_scheme("create user clusteruser password '1234'")
101102

103+
104+
@pytest.fixture(scope='module')
105+
def prepared_tenant_db(ydb_cluster, ydb_endpoint, ydb_database_module_scope):
106+
cluster_admin = ydb.AuthTokenCredentials(ydb_cluster.config.default_clusteradmin)
107+
102108
# prepare tenant database
103-
database_path = ydb_database
104-
with ydb_client(database_path, credentials=cluster_admin) as driver:
109+
database_path = ydb_database_module_scope
110+
driver_config = ydb.DriverConfig(ydb_endpoint, database_path, credentials=cluster_admin)
111+
with ydb.Driver(driver_config) as driver:
105112
pool = ydb.SessionPool(driver)
106113
with pool.checkout() as session:
107114
# add users
@@ -139,8 +146,8 @@ def login_user(endpoint, database, user, password):
139146
('dbadmin', True),
140147
('ordinaryuser', False)
141148
])
142-
def test_tenant_auth_groups_access(ydb_endpoint, ydb_root, prepared_test_env, ydb_client, user, expected_access):
143-
tenant_database = prepared_test_env
149+
def test_tenant_auth_groups_access(ydb_endpoint, ydb_root, prepared_root_db, prepared_tenant_db, ydb_client, user, expected_access):
150+
tenant_database = prepared_tenant_db
144151

145152
# user could be either from the root or tenant database,
146153
# but they must obtain auth token by logging in the database they live in

ydb/tests/library/harness/ydb_fixtures.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,33 @@ def ydb_database_ctx(ydb_cluster, database_path, node_count=1, timeout_seconds=2
105105
logger.debug("destroy database %s: database down", database_path)
106106

107107

108-
@pytest.fixture(scope='function')
109-
def ydb_database(ydb_cluster, ydb_root, ydb_safe_test_name):
110-
database = os.path.join(ydb_root, ydb_safe_test_name)
108+
def _ydb_database(cluster, database_path_base, unique_name):
109+
database = os.path.join(database_path_base, unique_name)
111110

112-
with ydb_database_ctx(ydb_cluster, database):
111+
with ydb_database_ctx(cluster, database):
113112
yield database
114113

115114

116115
@pytest.fixture(scope='function')
116+
def ydb_database(ydb_cluster, ydb_root, ydb_safe_test_name):
117+
# FIXME: PY2 syntax compatibility quirk: "yield from" emulation
118+
# Can't use py3 syntax here cause there are nasty dependencies on
119+
# tests/library/harness from some py2-only code in some other repositories
120+
for i in _ydb_database(ydb_cluster, ydb_root, ydb_safe_test_name):
121+
yield i
122+
123+
124+
@pytest.fixture(scope='module')
125+
def ydb_database_module_scope(ydb_cluster, ydb_root, request):
126+
# make unique database name from the test module name, ensuring that
127+
# it does not contains the dots
128+
unique_name = request.module.__name__.split('.')[-1]
129+
# FIXME: PY2 syntax compatibility quirk: "yield from" emulation
130+
for i in _ydb_database(ydb_cluster, ydb_root, unique_name):
131+
yield i
132+
133+
134+
@pytest.fixture(scope='module')
117135
def ydb_endpoint(ydb_cluster):
118136
return "%s:%s" % (ydb_cluster.nodes[1].host, ydb_cluster.nodes[1].port)
119137

0 commit comments

Comments
 (0)