synapse 2.195.1__py311-none-any.whl → 2.197.0__py311-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of synapse might be problematic. Click here for more details.
- synapse/axon.py +72 -5
- synapse/common.py +23 -0
- synapse/cortex.py +13 -8
- synapse/cryotank.py +2 -2
- synapse/daemon.py +1 -0
- synapse/lib/aha.py +159 -4
- synapse/lib/cell.py +133 -8
- synapse/lib/config.py +3 -3
- synapse/lib/jsonstor.py +2 -1
- synapse/lib/modelrev.py +5 -1
- synapse/lib/multislabseqn.py +2 -2
- synapse/lib/nexus.py +4 -1
- synapse/lib/reflect.py +4 -5
- synapse/lib/schemas.py +478 -1
- synapse/lib/snap.py +14 -7
- synapse/lib/storm.py +12 -394
- synapse/lib/stormlib/aha.py +351 -1
- synapse/lib/stormlib/graph.py +0 -61
- synapse/lib/stormlib/index.py +52 -0
- synapse/lib/stormlib/utils.py +37 -0
- synapse/lib/stormtypes.py +121 -1
- synapse/lib/task.py +13 -2
- synapse/lib/urlhelp.py +1 -1
- synapse/lib/version.py +2 -2
- synapse/models/base.py +3 -0
- synapse/models/doc.py +62 -0
- synapse/models/infotech.py +55 -16
- synapse/models/orgs.py +20 -14
- synapse/models/risk.py +23 -10
- synapse/models/transport.py +8 -3
- synapse/telepath.py +12 -0
- synapse/tests/test_axon.py +23 -0
- synapse/tests/test_common.py +28 -0
- synapse/tests/test_datamodel.py +15 -0
- synapse/tests/test_lib_aha.py +201 -0
- synapse/tests/test_lib_boss.py +15 -6
- synapse/tests/test_lib_cell.py +104 -0
- synapse/tests/test_lib_jsonstor.py +1 -0
- synapse/tests/test_lib_modelrev.py +6 -0
- synapse/tests/test_lib_stormlib_aha.py +188 -0
- synapse/tests/test_lib_stormlib_index.py +39 -0
- synapse/tests/test_lib_stormlib_utils.py +14 -0
- synapse/tests/test_lib_stormtypes.py +90 -3
- synapse/tests/test_lib_task.py +31 -13
- synapse/tests/test_model_base.py +2 -0
- synapse/tests/test_model_doc.py +38 -0
- synapse/tests/test_model_infotech.py +28 -1
- synapse/tests/test_model_orgs.py +9 -0
- synapse/tests/test_model_risk.py +2 -0
- synapse/tests/test_model_transport.py +1 -0
- synapse/tests/test_telepath.py +26 -0
- synapse/tests/test_tools_aha.py +192 -0
- synapse/tools/aha/mirror.py +193 -0
- synapse/tools/changelog.py +32 -27
- synapse/tools/genpkg.py +2 -2
- {synapse-2.195.1.dist-info → synapse-2.197.0.dist-info}/METADATA +1 -1
- {synapse-2.195.1.dist-info → synapse-2.197.0.dist-info}/RECORD +60 -55
- {synapse-2.195.1.dist-info → synapse-2.197.0.dist-info}/LICENSE +0 -0
- {synapse-2.195.1.dist-info → synapse-2.197.0.dist-info}/WHEEL +0 -0
- {synapse-2.195.1.dist-info → synapse-2.197.0.dist-info}/top_level.txt +0 -0
synapse/tests/test_axon.py
CHANGED
|
@@ -4,6 +4,7 @@ import csv
|
|
|
4
4
|
import sys
|
|
5
5
|
import base64
|
|
6
6
|
import shutil
|
|
7
|
+
import struct
|
|
7
8
|
import asyncio
|
|
8
9
|
import hashlib
|
|
9
10
|
import logging
|
|
@@ -489,6 +490,28 @@ bar baz",vv
|
|
|
489
490
|
with self.raises(s_exc.BadArg):
|
|
490
491
|
bytslist = [b async for b in axon.get(sha256, 0, size=0)]
|
|
491
492
|
|
|
493
|
+
# test unpack
|
|
494
|
+
intdata = struct.pack('>QQQ', 1, 2, 3)
|
|
495
|
+
size, sha256 = await axon.put(intdata)
|
|
496
|
+
self.eq((1,), await axon.unpack(sha256, '>Q'))
|
|
497
|
+
self.eq((2,), await axon.unpack(sha256, '>Q', offs=8))
|
|
498
|
+
self.eq((3,), await axon.unpack(sha256, '>Q', offs=16))
|
|
499
|
+
self.eq((2, 3), await axon.unpack(sha256, '>QQ', offs=8))
|
|
500
|
+
|
|
501
|
+
fmt = 'Q' * 150_000
|
|
502
|
+
with self.raises(s_exc.BadArg) as cm:
|
|
503
|
+
await axon.unpack(sha256, '>' + fmt)
|
|
504
|
+
self.isin('Struct format would read too much data', cm.exception.get('mesg'))
|
|
505
|
+
|
|
506
|
+
with self.raises(s_exc.BadArg):
|
|
507
|
+
await axon.unpack(sha256, 'not a valid format')
|
|
508
|
+
|
|
509
|
+
with self.raises(s_exc.BadArg):
|
|
510
|
+
await axon.unpack(sha256, 123)
|
|
511
|
+
|
|
512
|
+
with self.raises(s_exc.BadDataValu):
|
|
513
|
+
await axon.unpack(sha256, '>Q', offs=24)
|
|
514
|
+
|
|
492
515
|
async def test_axon_base(self):
|
|
493
516
|
async with self.getTestAxon() as axon:
|
|
494
517
|
self.isin('axon', axon.dmon.shared)
|
synapse/tests/test_common.py
CHANGED
|
@@ -12,6 +12,34 @@ import synapse.tests.utils as s_t_utils
|
|
|
12
12
|
logger = logging.getLogger(__name__)
|
|
13
13
|
|
|
14
14
|
class CommonTest(s_t_utils.SynTest):
|
|
15
|
+
|
|
16
|
+
async def test_waitgenr(self):
|
|
17
|
+
|
|
18
|
+
async def genr():
|
|
19
|
+
yield 10
|
|
20
|
+
raise Exception('omg')
|
|
21
|
+
|
|
22
|
+
rets = [retn async for retn in s_common.waitgenr(genr(), 10)]
|
|
23
|
+
|
|
24
|
+
self.true(rets[0][0])
|
|
25
|
+
self.false(rets[1][0])
|
|
26
|
+
|
|
27
|
+
async def one():
|
|
28
|
+
yield 'item'
|
|
29
|
+
|
|
30
|
+
rets = [retn async for retn in s_common.waitgenr(one(), timeout=1.0)]
|
|
31
|
+
self.eq(rets, [(True, 'item')])
|
|
32
|
+
|
|
33
|
+
async def genr():
|
|
34
|
+
yield 1
|
|
35
|
+
await asyncio.sleep(60)
|
|
36
|
+
yield 2
|
|
37
|
+
|
|
38
|
+
rets = [retn async for retn in s_common.waitgenr(genr(), timeout=0.1)]
|
|
39
|
+
self.eq(rets[0], (True, 1))
|
|
40
|
+
self.false(rets[1][0])
|
|
41
|
+
self.eq(rets[1][1]['err'], 'TimeoutError')
|
|
42
|
+
|
|
15
43
|
def test_tuplify(self):
|
|
16
44
|
tv = ['node', [['test:str', 'test'],
|
|
17
45
|
{'tags': {
|
synapse/tests/test_datamodel.py
CHANGED
|
@@ -2,6 +2,7 @@ import synapse.exc as s_exc
|
|
|
2
2
|
import synapse.datamodel as s_datamodel
|
|
3
3
|
|
|
4
4
|
import synapse.lib.module as s_module
|
|
5
|
+
import synapse.lib.schemas as s_schemas
|
|
5
6
|
|
|
6
7
|
import synapse.cortex as s_cortex
|
|
7
8
|
|
|
@@ -334,3 +335,17 @@ class DataModelTest(s_t_utils.SynTest):
|
|
|
334
335
|
self.none(core.model.edge(('meta:rule', 'matches', None)))
|
|
335
336
|
|
|
336
337
|
core.model.delEdge(('meta:rule', 'matches', None))
|
|
338
|
+
|
|
339
|
+
async def test_datamodel_locked_subs(self):
|
|
340
|
+
|
|
341
|
+
async with self.getTestCore() as core:
|
|
342
|
+
await core.setDeprLock('it:prod:softver:semver:major', True)
|
|
343
|
+
nodes = await core.nodes('[ it:prod:softver=* :semver=3.1.0 ]')
|
|
344
|
+
self.none(nodes[0].get('semver:major'))
|
|
345
|
+
self.eq(1, nodes[0].get('semver:minor'))
|
|
346
|
+
|
|
347
|
+
def test_datamodel_schema_basetypes(self):
|
|
348
|
+
# N.B. This test is to keep synapse.lib.schemas.datamodel_basetypes const
|
|
349
|
+
# in sync with the default s_datamodel.Datamodel().types
|
|
350
|
+
basetypes = list(s_datamodel.Model().types)
|
|
351
|
+
self.eq(s_schemas.datamodel_basetypes, basetypes)
|
synapse/tests/test_lib_aha.py
CHANGED
|
@@ -828,6 +828,33 @@ class AhaTest(s_test.SynTest):
|
|
|
828
828
|
async with await s_telepath.openurl(url) as prox:
|
|
829
829
|
self.fail(f'Connected to an expired clone URL {url}') # pragma: no cover
|
|
830
830
|
|
|
831
|
+
async def test_lib_aha_mirrors(self):
|
|
832
|
+
|
|
833
|
+
async with self.getTestAha() as aha:
|
|
834
|
+
async with await s_base.Base.anit() as base:
|
|
835
|
+
with self.getTestDir() as dirn:
|
|
836
|
+
user = 'synuser'
|
|
837
|
+
dirn00 = s_common.genpath(dirn, 'cell00')
|
|
838
|
+
dirn01 = s_common.genpath(dirn, 'cell01')
|
|
839
|
+
|
|
840
|
+
core00 = await base.enter_context(self.addSvcToAha(aha, '00.cortex', s_cortex.Cortex, dirn=dirn00,
|
|
841
|
+
provinfo={'conf': {'aha:user': user}}))
|
|
842
|
+
self.eq(core00.conf.get('aha:user'), user)
|
|
843
|
+
|
|
844
|
+
core01 = await base.enter_context(self.addSvcToAha(aha, '01.cortex', s_cortex.Cortex, dirn=dirn01,
|
|
845
|
+
conf={'axon': 'aha://cortex...'},
|
|
846
|
+
provinfo={'conf': {'aha:user': user}}))
|
|
847
|
+
self.eq(core01.conf.get('aha:user'), user)
|
|
848
|
+
|
|
849
|
+
async with aha.getLocalProxy() as ahaproxy:
|
|
850
|
+
self.eq(None, await ahaproxy.getAhaSvcMirrors('99.bogus'))
|
|
851
|
+
self.len(1, await ahaproxy.getAhaSvcMirrors('00.cortex.synapse'))
|
|
852
|
+
self.nn(await ahaproxy.getAhaServer(host=aha._getDnsName(), port=aha.sockaddr[1]))
|
|
853
|
+
|
|
854
|
+
todo = s_common.todo('getCellInfo')
|
|
855
|
+
res = await asyncio.wait_for(await aha.callAhaSvcApi('00.cortex.synapse', todo, timeout=3), 3)
|
|
856
|
+
self.nn(res)
|
|
857
|
+
|
|
831
858
|
async def test_aha_httpapi(self):
|
|
832
859
|
|
|
833
860
|
async with self.getTestAha() as aha:
|
|
@@ -905,6 +932,10 @@ class AhaTest(s_test.SynTest):
|
|
|
905
932
|
info = await resp.json()
|
|
906
933
|
self.eq(info.get('status'), 'err')
|
|
907
934
|
self.eq(info.get('code'), 'SchemaViolation')
|
|
935
|
+
async with sess.post(url, json={'name': 'doom' * 16}) as resp:
|
|
936
|
+
info = await resp.json()
|
|
937
|
+
self.eq(info.get('status'), 'err')
|
|
938
|
+
self.eq(info.get('code'), 'BadArg')
|
|
908
939
|
|
|
909
940
|
# Not an admin
|
|
910
941
|
await aha.addUser('lowuser', passwd='lowuser')
|
|
@@ -1093,6 +1124,35 @@ class AhaTest(s_test.SynTest):
|
|
|
1093
1124
|
self.stormHasNoWarnErr(msgs)
|
|
1094
1125
|
self.stormIsInPrint('Removed AHA service pool: pool00.synapse', msgs)
|
|
1095
1126
|
|
|
1127
|
+
async def test_aha_svc_api_exception(self):
|
|
1128
|
+
|
|
1129
|
+
async with self.getTestAha() as aha:
|
|
1130
|
+
|
|
1131
|
+
async def mockGetAhaSvcProxy(*args, **kwargs):
|
|
1132
|
+
raise s_exc.SynErr(mesg='proxy error')
|
|
1133
|
+
|
|
1134
|
+
aha.getAhaSvcProxy = mockGetAhaSvcProxy
|
|
1135
|
+
name = '00.cortex.synapse'
|
|
1136
|
+
todo = ('bogus', (), {})
|
|
1137
|
+
retn = await asyncio.wait_for(await aha.callAhaSvcApi(name, todo), 3)
|
|
1138
|
+
|
|
1139
|
+
self.false(retn[0])
|
|
1140
|
+
self.eq('SynErr', retn[1].get('err'))
|
|
1141
|
+
self.eq('proxy error', retn[1].get('errinfo').get('mesg'))
|
|
1142
|
+
|
|
1143
|
+
bad_info = {
|
|
1144
|
+
'urlinfo': {
|
|
1145
|
+
'host': 'nonexistent.host',
|
|
1146
|
+
'port': 12345,
|
|
1147
|
+
'scheme': 'ssl'
|
|
1148
|
+
}
|
|
1149
|
+
}
|
|
1150
|
+
|
|
1151
|
+
await aha.addAhaSvc(name, bad_info)
|
|
1152
|
+
async for ok, info in aha.callAhaPeerGenr(name, ('nonexistent.method', (), {})):
|
|
1153
|
+
self.false(ok)
|
|
1154
|
+
self.isin('err', info)
|
|
1155
|
+
|
|
1096
1156
|
async def test_aha_reprovision(self):
|
|
1097
1157
|
|
|
1098
1158
|
with self.withNexusReplay() as stack:
|
|
@@ -1317,3 +1377,144 @@ class AhaTest(s_test.SynTest):
|
|
|
1317
1377
|
async with await s_telepath.openurl(provurl) as prox:
|
|
1318
1378
|
info = await prox.getUserInfo()
|
|
1319
1379
|
self.eq(info.get('aha:user'), 'bob.grey')
|
|
1380
|
+
|
|
1381
|
+
async def test_aha_gather(self):
|
|
1382
|
+
|
|
1383
|
+
async with self.getTestAha() as aha:
|
|
1384
|
+
|
|
1385
|
+
async with aha.waiter(3, 'aha:svcadd', timeout=10):
|
|
1386
|
+
|
|
1387
|
+
conf = {'aha:provision': await aha.addAhaSvcProv('00.cell')}
|
|
1388
|
+
cell00 = await aha.enter_context(self.getTestCell(conf=conf))
|
|
1389
|
+
|
|
1390
|
+
conf = {'aha:provision': await aha.addAhaSvcProv('01.cell', {'mirror': 'cell'})}
|
|
1391
|
+
cell01 = await aha.enter_context(self.getTestCell(conf=conf))
|
|
1392
|
+
|
|
1393
|
+
await cell01.sync()
|
|
1394
|
+
|
|
1395
|
+
async with cell01.getLocalProxy() as proxy:
|
|
1396
|
+
self.true(proxy._hasTeleFeat('dynmirror'))
|
|
1397
|
+
self.true(proxy._hasTeleMeth('getNexsIndx'))
|
|
1398
|
+
|
|
1399
|
+
nexsindx = await cell00.getNexsIndx()
|
|
1400
|
+
|
|
1401
|
+
# test the call endpoint
|
|
1402
|
+
todo = s_common.todo('getCellInfo')
|
|
1403
|
+
items = dict([item async for item in aha.callAhaPeerApi(cell00.iden, todo, timeout=3)])
|
|
1404
|
+
self.sorteq(items.keys(), ('00.cell.synapse', '01.cell.synapse'))
|
|
1405
|
+
self.true(all(item[0] for item in items.values()))
|
|
1406
|
+
self.eq(cell00.runid, items['00.cell.synapse'][1]['cell']['run'])
|
|
1407
|
+
self.eq(cell01.runid, items['01.cell.synapse'][1]['cell']['run'])
|
|
1408
|
+
|
|
1409
|
+
todo = s_common.todo('newp')
|
|
1410
|
+
items = dict([item async for item in aha.callAhaPeerApi(cell00.iden, todo, timeout=3)])
|
|
1411
|
+
self.false(any(item[0] for item in items.values()))
|
|
1412
|
+
self.sorteq(items.keys(), ('00.cell.synapse', '01.cell.synapse'))
|
|
1413
|
+
|
|
1414
|
+
# test the genr endpoint
|
|
1415
|
+
reals = [item async for item in cell00.getNexusChanges(0, wait=False)]
|
|
1416
|
+
todo = s_common.todo('getNexusChanges', 0, wait=False)
|
|
1417
|
+
items = [item async for item in aha.callAhaPeerGenr(cell00.iden, todo, timeout=3) if item[1]]
|
|
1418
|
+
self.len(nexsindx * 2, items)
|
|
1419
|
+
|
|
1420
|
+
# ensure we handle down services correctly
|
|
1421
|
+
async with aha.waiter(1, 'aha:svcdown', timeout=10):
|
|
1422
|
+
await cell01.fini()
|
|
1423
|
+
|
|
1424
|
+
# test the call endpoint
|
|
1425
|
+
todo = s_common.todo('getCellInfo')
|
|
1426
|
+
items = dict([item async for item in aha.callAhaPeerApi(cell00.iden, todo, timeout=3)])
|
|
1427
|
+
self.sorteq(items.keys(), ('00.cell.synapse',))
|
|
1428
|
+
self.true(all(item[0] for item in items.values()))
|
|
1429
|
+
self.eq(cell00.runid, items['00.cell.synapse'][1]['cell']['run'])
|
|
1430
|
+
|
|
1431
|
+
# test the genr endpoint
|
|
1432
|
+
todo = s_common.todo('getNexusChanges', 0, wait=False)
|
|
1433
|
+
items = [item async for item in aha.callAhaPeerGenr(cell00.iden, todo, timeout=3) if item[1]]
|
|
1434
|
+
self.len(nexsindx, items)
|
|
1435
|
+
self.true(all(item[1][0] for item in items))
|
|
1436
|
+
|
|
1437
|
+
async def test_lib_aha_peer_api(self):
|
|
1438
|
+
|
|
1439
|
+
async with self.getTestAha() as aha:
|
|
1440
|
+
|
|
1441
|
+
purl00 = await aha.addAhaSvcProv('0.cell')
|
|
1442
|
+
purl01 = await aha.addAhaSvcProv('1.cell', provinfo={'mirror': '0.cell'})
|
|
1443
|
+
purl02 = await aha.addAhaSvcProv('2.cell', provinfo={'mirror': '0.cell'})
|
|
1444
|
+
|
|
1445
|
+
cell00 = await aha.enter_context(self.getTestCell(conf={'aha:provision': purl00}))
|
|
1446
|
+
cell01 = await aha.enter_context(self.getTestCell(conf={'aha:provision': purl01}))
|
|
1447
|
+
cell02 = await aha.enter_context(self.getTestCell(conf={'aha:provision': purl02}))
|
|
1448
|
+
|
|
1449
|
+
await cell01.sync()
|
|
1450
|
+
await cell02.sync()
|
|
1451
|
+
|
|
1452
|
+
todo = s_common.todo('getCellInfo')
|
|
1453
|
+
items = [item async for item in cell00.callPeerApi(todo)]
|
|
1454
|
+
self.len(2, items)
|
|
1455
|
+
|
|
1456
|
+
async def test_lib_aha_peer_genr(self):
|
|
1457
|
+
|
|
1458
|
+
async with self.getTestAha() as aha:
|
|
1459
|
+
|
|
1460
|
+
purl00 = await aha.addAhaSvcProv('0.cell')
|
|
1461
|
+
purl01 = await aha.addAhaSvcProv('1.cell', provinfo={'mirror': '0.cell'})
|
|
1462
|
+
|
|
1463
|
+
cell00 = await aha.enter_context(self.getTestCell(conf={'aha:provision': purl00}))
|
|
1464
|
+
cell01 = await aha.enter_context(self.getTestCell(conf={'aha:provision': purl01}))
|
|
1465
|
+
|
|
1466
|
+
await cell01.sync()
|
|
1467
|
+
|
|
1468
|
+
todo = s_common.todo('getNexusChanges', 0, wait=False)
|
|
1469
|
+
items = dict([item async for item in cell00.callPeerGenr(todo)])
|
|
1470
|
+
self.len(1, items)
|
|
1471
|
+
|
|
1472
|
+
todo = s_common.todo('getNexusChanges', 0, wait=False)
|
|
1473
|
+
items = dict([item async for item in cell00.callPeerGenr(todo, timeout=2)])
|
|
1474
|
+
self.len(1, items)
|
|
1475
|
+
|
|
1476
|
+
async def test_lib_aha_call_aha_peer_api_isactive(self):
|
|
1477
|
+
|
|
1478
|
+
async with self.getTestAha() as aha0:
|
|
1479
|
+
|
|
1480
|
+
async with aha0.waiter(3, 'aha:svcadd', timeout=10):
|
|
1481
|
+
|
|
1482
|
+
conf = {'aha:provision': await aha0.addAhaSvcProv('00.cell')}
|
|
1483
|
+
cell00 = await aha0.enter_context(self.getTestCell(conf=conf))
|
|
1484
|
+
|
|
1485
|
+
conf = {'aha:provision': await aha0.addAhaSvcProv('01.cell', {'mirror': 'cell'})}
|
|
1486
|
+
cell01 = await aha0.enter_context(self.getTestCell(conf=conf))
|
|
1487
|
+
|
|
1488
|
+
await cell01.sync()
|
|
1489
|
+
|
|
1490
|
+
# test active AHA peer
|
|
1491
|
+
todo = s_common.todo('getCellInfo')
|
|
1492
|
+
items = dict([item async for item in aha0.callAhaPeerApi(cell00.iden, todo, timeout=3)])
|
|
1493
|
+
self.sorteq(items.keys(), ('00.cell.synapse', '01.cell.synapse'))
|
|
1494
|
+
|
|
1495
|
+
todo = s_common.todo('getNexusChanges', 0, wait=False)
|
|
1496
|
+
items = dict([item async for item in aha0.callAhaPeerGenr(cell00.iden, todo, timeout=3)])
|
|
1497
|
+
self.sorteq(items.keys(), ('00.cell.synapse', '01.cell.synapse'))
|
|
1498
|
+
|
|
1499
|
+
async with aha0.getLocalProxy() as proxy0:
|
|
1500
|
+
purl = await proxy0.addAhaClone('01.aha.loop.vertex.link')
|
|
1501
|
+
|
|
1502
|
+
conf1 = {'clone': purl}
|
|
1503
|
+
async with self.getTestAha(conf=conf1) as aha1:
|
|
1504
|
+
|
|
1505
|
+
await aha1.sync()
|
|
1506
|
+
|
|
1507
|
+
self.eq(aha0.iden, aha1.iden)
|
|
1508
|
+
self.nn(aha1.conf.get('mirror'))
|
|
1509
|
+
|
|
1510
|
+
self.true(aha0.isactive)
|
|
1511
|
+
self.false(aha1.isactive)
|
|
1512
|
+
|
|
1513
|
+
# test non-active AHA peer
|
|
1514
|
+
todo = s_common.todo('getCellInfo')
|
|
1515
|
+
items = dict([item async for item in aha1.callAhaPeerApi(cell00.iden, todo, timeout=3)])
|
|
1516
|
+
self.sorteq(items.keys(), ('00.cell.synapse', '01.cell.synapse'))
|
|
1517
|
+
|
|
1518
|
+
todo = s_common.todo('getNexusChanges', 0, wait=False)
|
|
1519
|
+
items = dict([item async for item in aha1.callAhaPeerGenr(cell00.iden, todo, timeout=3)])
|
|
1520
|
+
self.sorteq(items.keys(), ('00.cell.synapse', '01.cell.synapse'))
|
synapse/tests/test_lib_boss.py
CHANGED
|
@@ -3,13 +3,21 @@ import asyncio
|
|
|
3
3
|
import synapse.exc as s_exc
|
|
4
4
|
import synapse.common as s_common
|
|
5
5
|
import synapse.lib.boss as s_boss
|
|
6
|
+
import synapse.lib.cell as s_cell
|
|
6
7
|
import synapse.tests.utils as s_test
|
|
7
8
|
|
|
9
|
+
class BossCell(s_cell.Cell):
|
|
10
|
+
async def initServiceRuntime(self):
|
|
11
|
+
self.cboss = await s_boss.Boss.anit()
|
|
12
|
+
self.onfini(self.cboss)
|
|
13
|
+
|
|
8
14
|
class BossTest(s_test.SynTest):
|
|
9
15
|
|
|
10
16
|
async def test_boss_base(self):
|
|
11
17
|
|
|
12
|
-
async with
|
|
18
|
+
async with self.getTestCell(BossCell) as bcell:
|
|
19
|
+
boss = bcell.cboss
|
|
20
|
+
root = await bcell.auth.getUserByName('root')
|
|
13
21
|
|
|
14
22
|
evnt = asyncio.Event()
|
|
15
23
|
|
|
@@ -20,18 +28,19 @@ class BossTest(s_test.SynTest):
|
|
|
20
28
|
|
|
21
29
|
self.len(0, boss.ps())
|
|
22
30
|
|
|
23
|
-
synt = await boss.promote('test',
|
|
31
|
+
synt = await boss.promote('test', root, info={'hehe': 'haha'})
|
|
24
32
|
|
|
25
33
|
self.len(1, boss.ps())
|
|
26
34
|
|
|
27
35
|
self.eq('test', synt.name)
|
|
28
36
|
self.eq('haha', synt.info.get('hehe'))
|
|
37
|
+
self.eq(root.iden, synt.user.iden)
|
|
29
38
|
|
|
30
|
-
synt0 = await boss.execute(testloop(), 'testloop',
|
|
39
|
+
synt0 = await boss.execute(testloop(), 'testloop', root, info={'foo': 'bar'})
|
|
31
40
|
iden = synt0.iden
|
|
32
41
|
|
|
33
42
|
with self.raises(s_exc.BadArg):
|
|
34
|
-
_ = await boss.execute(asyncio.sleep(1), 'testsleep',
|
|
43
|
+
_ = await boss.execute(asyncio.sleep(1), 'testsleep', root, iden=iden)
|
|
35
44
|
|
|
36
45
|
await evnt.wait()
|
|
37
46
|
|
|
@@ -47,8 +56,8 @@ class BossTest(s_test.SynTest):
|
|
|
47
56
|
iden = s_common.guid()
|
|
48
57
|
|
|
49
58
|
async def double_promote():
|
|
50
|
-
await boss.promote(f'double',
|
|
51
|
-
await boss.promote(f'double',
|
|
59
|
+
await boss.promote(f'double', root, taskiden=iden)
|
|
60
|
+
await boss.promote(f'double', root, taskiden=iden + iden)
|
|
52
61
|
|
|
53
62
|
coro = boss.schedCoro(double_promote())
|
|
54
63
|
self.true(await stream.wait(timeout=6))
|
synapse/tests/test_lib_cell.py
CHANGED
|
@@ -784,6 +784,10 @@ class CellTest(s_t_utils.SynTest):
|
|
|
784
784
|
cell.VERSION = (1, 2, 3)
|
|
785
785
|
cell.VERSTRING = '1.2.3'
|
|
786
786
|
|
|
787
|
+
cell.features.update({
|
|
788
|
+
'testvalu': 2
|
|
789
|
+
})
|
|
790
|
+
|
|
787
791
|
http_info = []
|
|
788
792
|
host, port = await cell.addHttpsPort(0)
|
|
789
793
|
http_info.append({'host': host, 'port': port})
|
|
@@ -807,6 +811,9 @@ class CellTest(s_t_utils.SynTest):
|
|
|
807
811
|
# A Cortex populated cellvers
|
|
808
812
|
self.isin('cortex:defaults', cnfo.get('cellvers', {}))
|
|
809
813
|
|
|
814
|
+
self.eq(info.get('features'), cell.features)
|
|
815
|
+
self.eq(info.get('features', {}).get('testvalu'), 2)
|
|
816
|
+
|
|
810
817
|
# Defaults aha data is
|
|
811
818
|
self.eq(cnfo.get('aha'), {'name': None, 'leader': None, 'network': None})
|
|
812
819
|
|
|
@@ -3294,6 +3301,51 @@ class CellTest(s_t_utils.SynTest):
|
|
|
3294
3301
|
await cell00.promote(graceful=True)
|
|
3295
3302
|
self.isin('02.cell is not the current leader', cm.exception.get('mesg'))
|
|
3296
3303
|
|
|
3304
|
+
async def test_cell_get_aha_proxy(self):
|
|
3305
|
+
|
|
3306
|
+
async with self.getTestCell() as cell:
|
|
3307
|
+
|
|
3308
|
+
self.none(await cell.getAhaProxy())
|
|
3309
|
+
|
|
3310
|
+
class MockAhaClient:
|
|
3311
|
+
def __init__(self, proxy=None):
|
|
3312
|
+
self._proxy = proxy
|
|
3313
|
+
|
|
3314
|
+
async def proxy(self, timeout=None):
|
|
3315
|
+
return self._proxy
|
|
3316
|
+
|
|
3317
|
+
with self.getAsyncLoggerStream('synapse.lib.cell', 'AHA client connection failed.') as stream:
|
|
3318
|
+
cell.ahaclient = MockAhaClient()
|
|
3319
|
+
self.none(await cell.getAhaProxy())
|
|
3320
|
+
self.true(await stream.wait(timeout=1))
|
|
3321
|
+
|
|
3322
|
+
class MockProxyHasNot:
|
|
3323
|
+
def _hasTeleFeat(self, name, vers):
|
|
3324
|
+
return False
|
|
3325
|
+
|
|
3326
|
+
cell.ahaclient = MockAhaClient(proxy=MockProxyHasNot())
|
|
3327
|
+
self.none(await cell.getAhaProxy(feats=(('test', 1),)))
|
|
3328
|
+
|
|
3329
|
+
class MockProxyHas:
|
|
3330
|
+
def _hasTeleFeat(self, name, vers):
|
|
3331
|
+
return True
|
|
3332
|
+
|
|
3333
|
+
mock_proxy = MockProxyHas()
|
|
3334
|
+
cell.ahaclient = MockAhaClient(proxy=mock_proxy)
|
|
3335
|
+
self.eq(await cell.getAhaProxy(), mock_proxy)
|
|
3336
|
+
self.eq(await cell.getAhaProxy(feats=(('test', 1),)), mock_proxy)
|
|
3337
|
+
|
|
3338
|
+
async def test_lib_cell_sadaha(self):
|
|
3339
|
+
|
|
3340
|
+
async with self.getTestCell() as cell:
|
|
3341
|
+
|
|
3342
|
+
self.none(await cell.getAhaProxy())
|
|
3343
|
+
cell.ahaclient = await s_telepath.Client.anit('cell:///tmp/newp')
|
|
3344
|
+
|
|
3345
|
+
# coverage for failure of aha client to connect
|
|
3346
|
+
with self.raises(TimeoutError):
|
|
3347
|
+
self.none(await cell.getAhaProxy(timeout=0.1))
|
|
3348
|
+
|
|
3297
3349
|
async def test_stream_backup_exception(self):
|
|
3298
3350
|
|
|
3299
3351
|
with self.getTestDir() as dirn:
|
|
@@ -3356,3 +3408,55 @@ class CellTest(s_t_utils.SynTest):
|
|
|
3356
3408
|
with self.raises(s_exc.BackupAlreadyRunning):
|
|
3357
3409
|
async for _ in proxy.iterNewBackupArchive('newbackup', remove=True):
|
|
3358
3410
|
pass
|
|
3411
|
+
|
|
3412
|
+
async def test_cell_peer_noaha(self):
|
|
3413
|
+
|
|
3414
|
+
todo = s_common.todo('newp')
|
|
3415
|
+
async with self.getTestCell() as cell:
|
|
3416
|
+
async for item in cell.callPeerApi(todo):
|
|
3417
|
+
pass
|
|
3418
|
+
async for item in cell.callPeerGenr(todo):
|
|
3419
|
+
pass
|
|
3420
|
+
|
|
3421
|
+
async def test_cell_task_apis(self):
|
|
3422
|
+
async with self.getTestAha() as aha:
|
|
3423
|
+
|
|
3424
|
+
# test some of the gather API implementations...
|
|
3425
|
+
purl00 = await aha.addAhaSvcProv('00.cell')
|
|
3426
|
+
purl01 = await aha.addAhaSvcProv('01.cell', provinfo={'mirror': 'cell'})
|
|
3427
|
+
|
|
3428
|
+
cell00 = await aha.enter_context(self.getTestCell(conf={'aha:provision': purl00}))
|
|
3429
|
+
cell01 = await aha.enter_context(self.getTestCell(conf={'aha:provision': purl01}))
|
|
3430
|
+
|
|
3431
|
+
await cell01.sync()
|
|
3432
|
+
|
|
3433
|
+
async def sleep99(cell):
|
|
3434
|
+
await cell.boss.promote('sleep99', cell.auth.rootuser)
|
|
3435
|
+
await cell00.fire('sleep99')
|
|
3436
|
+
await asyncio.sleep(99)
|
|
3437
|
+
|
|
3438
|
+
async with cell00.waiter(2, 'sleep99', timeout=6):
|
|
3439
|
+
task00 = cell00.schedCoro(sleep99(cell00))
|
|
3440
|
+
task01 = cell01.schedCoro(sleep99(cell01))
|
|
3441
|
+
|
|
3442
|
+
tasks = [task async for task in cell00.getTasks(timeout=6)]
|
|
3443
|
+
|
|
3444
|
+
self.len(2, tasks)
|
|
3445
|
+
self.eq(tasks[0]['service'], '00.cell.synapse')
|
|
3446
|
+
self.eq(tasks[1]['service'], '01.cell.synapse')
|
|
3447
|
+
self.eq(('sleep99', 'sleep99'), [task.get('name') for task in tasks])
|
|
3448
|
+
self.eq(('root', 'root'), [task.get('username') for task in tasks])
|
|
3449
|
+
|
|
3450
|
+
self.eq(tasks[0], await cell00.getTask(tasks[0].get('iden')))
|
|
3451
|
+
self.eq(tasks[1], await cell00.getTask(tasks[1].get('iden')))
|
|
3452
|
+
self.none(await cell00.getTask(tasks[1].get('iden'), peers=False))
|
|
3453
|
+
|
|
3454
|
+
self.true(await cell00.killTask(tasks[0].get('iden')))
|
|
3455
|
+
|
|
3456
|
+
task01 = tasks[1].get('iden')
|
|
3457
|
+
self.false(await cell00.killTask(task01, peers=False))
|
|
3458
|
+
|
|
3459
|
+
self.true(await cell00.killTask(task01))
|
|
3460
|
+
|
|
3461
|
+
self.none(await cell00.getTask(task01))
|
|
3462
|
+
self.false(await cell00.killTask(task01))
|
|
@@ -116,6 +116,7 @@ class JsonStorTest(s_test.SynTest):
|
|
|
116
116
|
self.eq({'hehe': 'haha', 'zip': {}}, await prox.getPathObj('foo/bar'))
|
|
117
117
|
|
|
118
118
|
self.false(await prox.delPathObjProp('newp/newp', 'newp'))
|
|
119
|
+
self.false(await prox.delPathObjProp('foo/bar', 'nested/newp'))
|
|
119
120
|
|
|
120
121
|
await prox.delPathObj('foo/bar')
|
|
121
122
|
self.none(await prox.getPathObj('foo/bar'))
|
|
@@ -1766,3 +1766,9 @@ class ModelRevTest(s_tests.SynTest):
|
|
|
1766
1766
|
self.eq('foo bar', nodes[0].get('model'))
|
|
1767
1767
|
nodes = await core.nodes('transport:sea:vessel')
|
|
1768
1768
|
self.eq('foo bar', nodes[0].get('model'))
|
|
1769
|
+
|
|
1770
|
+
async def test_modelrev_0_2_33(self):
|
|
1771
|
+
async with self.getRegrCore('model-0.2.33') as core:
|
|
1772
|
+
nodes = await core.nodes('entity:name')
|
|
1773
|
+
self.len(1, nodes)
|
|
1774
|
+
self.eq('foo bar', nodes[0].repr())
|