Skip to content

Commit 42bbe14

Browse files
test: assert admin commands success
Admin command are sent through text protocol. Responses are rarely processed, especially those which sets up schema and users. But such requests can contain errors, like "already exists" or syntax ones. Having asserts on schema set up makes it easier to debug some cases. For example, it was helpful in discovering the reason behind "user not exists" fails fixed in "wait until server is ready" patchset commit [1]. 1. https://github.com/tarantool/tarantool-python/actions/runs/5784619729/job/15675655683?pr=306
1 parent ed8d3d2 commit 42bbe14

15 files changed

+419
-267
lines changed

test/suites/test_connection.py

Lines changed: 43 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,17 @@
55

66
import sys
77
import unittest
8-
98
import decimal
9+
10+
import pkg_resources
1011
import msgpack
1112

1213
import tarantool
1314
import tarantool.msgpack_ext.decimal as ext_decimal
1415

1516
from .lib.skip import skip_or_run_decimal_test, skip_or_run_varbinary_test
1617
from .lib.tarantool_server import TarantoolServer
18+
from .utils import assert_admin_success
1719

1820

1921
class TestSuiteConnection(unittest.TestCase):
@@ -26,35 +28,48 @@ def setUpClass(cls):
2628
cls.srv.start()
2729

2830
cls.adm = cls.srv.admin
29-
cls.adm(r"""
31+
resp = cls.adm("""
3032
box.schema.user.create('test', {password = 'test', if_not_exists = true})
31-
box.schema.user.grant('test', 'read,write,execute', 'universe')
32-
33-
box.schema.create_space('space_varbin')
34-
35-
box.space['space_varbin']:format({
36-
{
37-
'id',
38-
type = 'number',
39-
is_nullable = false
40-
},
41-
{
42-
'varbin',
43-
type = 'varbinary',
44-
is_nullable = false,
45-
}
46-
})
47-
48-
box.space['space_varbin']:create_index('id', {
49-
type = 'tree',
50-
parts = {1, 'number'},
51-
unique = true})
52-
53-
box.space['space_varbin']:create_index('varbin', {
54-
type = 'tree',
55-
parts = {2, 'varbinary'},
56-
unique = true})
33+
box.schema.user.grant('test', 'read,write,execute', 'universe',
34+
nil, {if_not_exists = true})
35+
36+
return true
5737
""")
38+
assert_admin_success(resp)
39+
40+
if cls.srv.admin.tnt_version >= pkg_resources.parse_version('2.2.1'):
41+
resp = cls.adm("""
42+
box.schema.create_space('space_varbin', {if_not_exists = true})
43+
44+
box.space['space_varbin']:format({
45+
{
46+
'id',
47+
type = 'number',
48+
is_nullable = false
49+
},
50+
{
51+
'varbin',
52+
type = 'varbinary',
53+
is_nullable = false,
54+
}
55+
})
56+
57+
box.space['space_varbin']:create_index('id', {
58+
type = 'tree',
59+
parts = {1, 'number'},
60+
unique = true,
61+
if_not_exists = true})
62+
63+
box.space['space_varbin']:create_index('varbin', {
64+
type = 'tree',
65+
parts = {2, 'varbinary'},
66+
unique = true,
67+
if_not_exists = true})
68+
69+
return true
70+
""")
71+
assert_admin_success(resp)
72+
5873
cls.con = None
5974

6075
def setUp(self):

test/suites/test_datetime.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
from .lib.tarantool_server import TarantoolServer
1818
from .lib.skip import skip_or_run_datetime_test, skip_or_run_datetime_2_11_test
19+
from .utils import assert_admin_success
1920

2021

2122
class TestSuiteDatetime(unittest.TestCase):
@@ -28,25 +29,28 @@ def setUpClass(cls):
2829
cls.srv.start()
2930

3031
cls.adm = cls.srv.admin
31-
cls.adm(r"""
32+
resp = cls.adm("""
3233
_, datetime = pcall(require, 'datetime')
3334
34-
box.schema.space.create('test')
35+
box.schema.space.create('test', {if_not_exists = true})
3536
box.space['test']:create_index('primary', {
3637
type = 'tree',
3738
parts = {1, 'string'},
38-
unique = true})
39+
unique = true,
40+
if_not_exists = true})
3941
4042
pcall(function()
4143
box.schema.space.create('test_pk')
4244
box.space['test_pk']:create_index('primary', {
4345
type = 'tree',
4446
parts = {1, 'datetime'},
45-
unique = true})
47+
unique = true,
48+
if_not_exists = true})
4649
end)
4750
4851
box.schema.user.create('test', {password = 'test', if_not_exists = true})
49-
box.schema.user.grant('test', 'read,write,execute', 'universe')
52+
box.schema.user.grant('test', 'read,write,execute', 'universe',
53+
nil, {if_not_exists = true})
5054
5155
local function add(arg1, arg2)
5256
return arg1 + arg2
@@ -57,7 +61,10 @@ def setUpClass(cls):
5761
return arg1 - arg2
5862
end
5963
rawset(_G, 'sub', sub)
64+
65+
return true
6066
""")
67+
assert_admin_success(resp)
6168

6269
cls.con = tarantool.Connection(cls.srv.host, cls.srv.args['primary'],
6370
user='test', password='test')
@@ -67,7 +74,11 @@ def setUp(self):
6774
if self.srv.is_started():
6875
self.srv.touch_lock()
6976

70-
self.adm("box.space['test']:truncate()")
77+
resp = self.adm("""
78+
box.space['test']:truncate()
79+
return true
80+
""")
81+
assert_admin_success(resp)
7182

7283
def test_datetime_class_api(self):
7384
datetime = tarantool.Datetime(year=2022, month=8, day=31, hour=18, minute=7, sec=54,

test/suites/test_dbapi.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from tarantool import dbapi
1313
from .lib.tarantool_server import TarantoolServer
1414
from .lib.skip import skip_or_run_sql_test
15+
from .utils import assert_admin_success
1516

1617

1718
class TestSuiteDBAPI(dbapi20.DatabaseAPI20Test):
@@ -39,17 +40,21 @@ def setUpClass(cls):
3940
"port": cls.srv.args['primary']
4041
}
4142

43+
# grant full access to guest
44+
resp = cls.srv.admin("""
45+
box.schema.user.grant('guest', 'create,read,write,execute', 'universe',
46+
nil, {if_not_exists = true})
47+
return true
48+
""")
49+
assert_admin_success(resp)
50+
4251
@skip_or_run_sql_test
4352
def setUp(self):
4453
# prevent a remote tarantool from clean our session
4554
if self.srv.is_started():
4655
self.srv.touch_lock()
4756
self.con.flush_schema()
4857

49-
# grant full access to guest
50-
self.srv.admin("box.schema.user.grant('guest', 'create,read,write,"
51-
"execute', 'universe')")
52-
5358
@classmethod
5459
def tearDownClass(cls):
5560
cls.con.close()

test/suites/test_decimal.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
from .lib.tarantool_server import TarantoolServer
1818
from .lib.skip import skip_or_run_decimal_test
19+
from .utils import assert_admin_success
1920

2021

2122
class TestSuiteDecimal(unittest.TestCase):
@@ -28,26 +29,32 @@ def setUpClass(cls):
2829
cls.srv.start()
2930

3031
cls.adm = cls.srv.admin
31-
cls.adm(r"""
32-
_, decimal = pcall(require, 'decimal')
32+
resp = cls.adm("""
33+
decimal_supported, decimal = pcall(require, 'decimal')
3334
34-
box.schema.space.create('test')
35+
box.schema.space.create('test', {if_not_exists = true})
3536
box.space['test']:create_index('primary', {
3637
type = 'tree',
3738
parts = {1, 'string'},
38-
unique = true})
39+
unique = true,
40+
if_not_exists = true})
3941
40-
pcall(function()
42+
if decimal_supported then
4143
box.schema.space.create('test_pk')
4244
box.space['test_pk']:create_index('primary', {
4345
type = 'tree',
4446
parts = {1, 'decimal'},
45-
unique = true})
46-
end)
47+
unique = true,
48+
if_not_exists = true})
49+
end
4750
4851
box.schema.user.create('test', {password = 'test', if_not_exists = true})
49-
box.schema.user.grant('test', 'read,write,execute', 'universe')
52+
box.schema.user.grant('test', 'read,write,execute', 'universe',
53+
nil, {if_not_exists = true})
54+
55+
return true
5056
""")
57+
assert_admin_success(resp)
5158

5259
cls.con = tarantool.Connection(cls.srv.host, cls.srv.args['primary'],
5360
user='test', password='test')
@@ -57,7 +64,11 @@ def setUp(self):
5764
if self.srv.is_started():
5865
self.srv.touch_lock()
5966

60-
self.adm("box.space['test']:truncate()")
67+
resp = self.adm("""
68+
box.space['test']:truncate()
69+
return true
70+
""")
71+
assert_admin_success(resp)
6172

6273
valid_cases = {
6374
'simple_decimal_1': {

test/suites/test_dml.py

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
from .lib.tarantool_server import TarantoolServer
1212
from .lib.skip import skip_or_run_error_extra_info_test
13+
from .utils import assert_admin_success
1314

1415

1516
class TestSuiteRequest(unittest.TestCase):
@@ -22,29 +23,35 @@ def setUpClass(cls):
2223
cls.srv.start()
2324
cls.con = tarantool.Connection(cls.srv.host, cls.srv.args['primary'])
2425
cls.adm = cls.srv.admin
25-
cls.space_created = cls.adm("box.schema.create_space('space_1')")
26-
cls.adm("""
27-
box.space['space_1']:create_index('primary', {
28-
type = 'tree',
29-
parts = {1, 'num'},
30-
unique = true})
31-
""".replace('\n', ' '))
32-
cls.adm("""
33-
box.space['space_1']:create_index('secondary', {
34-
type = 'tree',
35-
parts = {2, 'num', 3, 'str'},
36-
unique = false})
37-
""".replace('\n', ' '))
38-
cls.space_created = cls.adm("box.schema.create_space('space_2')")
39-
cls.adm("""
40-
box.space['space_2']:create_index('primary', {
41-
type = 'hash',
42-
parts = {1, 'num'},
43-
unique = true})
44-
""".replace('\n', ' '))
45-
cls.adm("json = require('json')")
46-
cls.adm("fiber = require('fiber')")
47-
cls.adm("uuid = require('uuid')")
26+
cls.space_created = cls.adm("box.schema.create_space('space_1', {if_not_exists = true})")
27+
resp = cls.adm("""
28+
box.space['space_1']:create_index('primary', {
29+
type = 'tree',
30+
parts = {1, 'num'},
31+
unique = true,
32+
if_not_exists = true})
33+
34+
box.space['space_1']:create_index('secondary', {
35+
type = 'tree',
36+
parts = {2, 'num', 3, 'str'},
37+
unique = false,
38+
if_not_exists = true})
39+
40+
box.schema.create_space('space_2', {if_not_exists = true})
41+
42+
box.space['space_2']:create_index('primary', {
43+
type = 'hash',
44+
parts = {1, 'num'},
45+
unique = true,
46+
if_not_exists = true})
47+
48+
json = require('json')
49+
fiber = require('fiber')
50+
uuid = require('uuid')
51+
52+
return true
53+
""")
54+
assert_admin_success(resp)
4855

4956
if not sys.platform.startswith("win"):
5057
cls.sock_srv = TarantoolServer(create_unix_socket=True)
@@ -60,10 +67,11 @@ def setUp(self):
6067

6168
def test_00_00_authenticate(self):
6269
self.assertIsNone(self.srv.admin("""
63-
box.schema.user.create('test', { password = 'test' })
70+
box.schema.user.create('test', { password = 'test', if_not_exists = true })
6471
"""))
6572
self.assertIsNone(self.srv.admin("""
66-
box.schema.user.grant('test', 'execute,read,write', 'universe')
73+
box.schema.user.grant('test', 'execute,read,write', 'universe',
74+
nil, {if_not_exists = true})
6775
"""))
6876
self.assertEqual(self.con.authenticate('test', 'test')._data, None)
6977

@@ -311,7 +319,7 @@ def test_11_select_all_hash(self):
311319
space.select((), iterator=tarantool.const.ITERATOR_EQ)
312320

313321
def test_12_update_fields(self):
314-
self.srv.admin(
322+
resp = self.srv.admin(
315323
"""
316324
do
317325
local sp = box.schema.create_space('sp', {
@@ -325,7 +333,9 @@ def test_12_update_fields(self):
325333
parts = {1, 'unsigned'}
326334
})
327335
end
336+
return true
328337
""")
338+
assert_admin_success(resp)
329339
self.con.insert('sp', [2, 'help', 4])
330340
self.assertSequenceEqual(
331341
self.con.update('sp', (2,), [('+', 'thi', 3)]),

0 commit comments

Comments
 (0)