Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to servers tools to allow custom share names for telepath. #1170

Merged
merged 1 commit into from
Mar 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions synapse/servers/axon.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ def parse(argv):

https = os.getenv('SYN_AXON_HTTPS', '4443')
telep = os.getenv('SYN_AXON_TELEPATH', 'tcp://0.0.0.0:27492/')
telen = os.getenv('SYN_AXON_NAME', None)

pars = argparse.ArgumentParser(prog='synapse.servers.axon')
pars.add_argument('--telepath', default=telep, help='The telepath URL to listen on.')
pars.add_argument('--https', default=https, dest='port', type=int, help='The port to bind for the HTTPS/REST API.')
pars.add_argument('--name', default=telen, help='The (optional) additional name to share the Axon as.')
pars.add_argument('axondir', help='The directory for the axon to use for storage.')

return pars.parse_args(argv)
Expand All @@ -43,6 +45,10 @@ async def main(argv, outp=s_output.stdout):
outp.printf('...axon API (https): %s' % (opts.port,))
await axon.addHttpsPort(opts.port)

if opts.name:
outp.printf(f'...axon additional share name: {opts.name}')
axon.dmon.share(opts.name, axon)

return axon

except Exception:
Expand Down
6 changes: 6 additions & 0 deletions synapse/servers/cortex.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ def parse(argv):

https = os.getenv('SYN_CORTEX_HTTPS', '4443')
telep = os.getenv('SYN_CORTEX_TELEPATH', 'tcp://0.0.0.0:27492/')
telen = os.getenv('SYN_CORTEX_NAME', None)

pars = argparse.ArgumentParser(prog='synapse.servers.cortex')
pars.add_argument('--telepath', default=telep, help='The telepath URL to listen on.')
pars.add_argument('--https', default=https, dest='port', type=int, help='The port to bind for the HTTPS/REST API.')
pars.add_argument('--name', default=telen, help='The (optional) additional name to share the Cortex as.')
pars.add_argument('coredir', help='The directory for the cortex to use for storage.')

return pars.parse_args(argv)
Expand All @@ -43,6 +45,10 @@ async def main(argv, outp=s_output.stdout):
outp.printf('...cortex API (https): %s' % (opts.port,))
await core.addHttpsPort(opts.port)

if opts.name:
outp.printf(f'...cortex additional share name: {opts.name}')
core.dmon.share(opts.name, core)

return core

except Exception:
Expand Down
6 changes: 6 additions & 0 deletions synapse/servers/cryotank.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ def parse(argv):

https = os.getenv('SYN_CRYOTANK_HTTPS', '4443')
telep = os.getenv('SYN_CRYOTANK_TELEPATH', 'tcp://0.0.0.0:27492/')
telen = os.getenv('SYN_CRYOTANK_NAME', None)

pars = argparse.ArgumentParser(prog='synapse.servers.cryotank')
pars.add_argument('--telepath', default=telep, help='The telepath URL to listen on.')
pars.add_argument('--https', default=https, dest='port', type=int, help='The port to bind for the HTTPS/REST API.')
pars.add_argument('--name', default=telen, help='The (optional) additional name to share the Cryotank as.')
pars.add_argument('cryodir', help='The directory for the cryotank server to use for storage.')

return pars.parse_args(argv)
Expand All @@ -43,6 +45,10 @@ async def main(argv, outp=s_output.stdout):
outp.printf('...cryotank API (https): %s' % (opts.port,))
await cryo.addHttpsPort(opts.port)

if opts.name:
outp.printf(f'...cryotank additional share name: {opts.name}')
cryo.dmon.share(opts.name, cryo)

return cryo

except Exception:
Expand Down
10 changes: 6 additions & 4 deletions synapse/tests/test_servers_axon.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import hashlib

import synapse.common as s_common
import synapse.telepath as s_telepath

import synapse.servers.axon as s_s_axon

import synapse.tests.utils as s_t_utils
Expand All @@ -17,13 +14,18 @@ async def test_server(self):

outp = self.getTestOutp()

argv = [dirn, '--telepath', 'tcp://127.0.0.1:0/', '--https', '0']
argv = [dirn,
'--telepath', 'tcp://127.0.0.1:0/',
'--https', '0',
'--name', 'teleaxon']
async with await s_s_axon.main(argv, outp=outp) as axon:
async with axon.getLocalProxy() as proxy:
async with await proxy.upload() as fd:
await fd.write(b'asdfasdf')
await fd.save()

self.true(axon.dmon.shared.get('teleaxon') is axon)

# And data persists...
async with await s_s_axon.main(argv, outp=outp) as axon:
async with axon.getLocalProxy() as proxy:
Expand Down
7 changes: 6 additions & 1 deletion synapse/tests/test_servers_cortex.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,19 @@ async def test_server(self):
outp = self.getTestOutp()
guid = s_common.guid()

argv = [dirn, '--telepath', 'tcp://127.0.0.1:0/', '--https', '0']
argv = [dirn,
'--telepath', 'tcp://127.0.0.1:0/',
'--https', '0',
'--name', 'telecore']
async with await s_s_cortex.main(argv, outp=outp) as core:

async with await s_telepath.openurl(f'cell://{dirn}') as proxy:
# Make a node with the cortex
podes = await s_t_utils.alist(proxy.eval(f'[ou:org={guid}]'))
self.len(1, podes)

self.true(core.dmon.shared.get('telecore') is core)

# And data persists...
async with await s_s_cortex.main(argv, outp=outp) as core:
async with await s_telepath.openurl(f'cell://{dirn}') as proxy:
Expand Down
33 changes: 33 additions & 0 deletions synapse/tests/test_servers_cryotank.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import synapse.servers.cryotank as s_s_cryo

import synapse.tests.utils as s_t_utils

class CryoServerTest(s_t_utils.SynTest):

async def test_server(self):

recs = (
('hehe', {'haha': 1}),
('woah', {'dude': 1}),
)

with self.getTestDir() as dirn:

outp = self.getTestOutp()

argv = [dirn,
'--telepath', 'tcp://127.0.0.1:0/',
'--https', '0',
'--name', 'telecryo']
async with await s_s_cryo.main(argv, outp=outp) as cryotank:
async with cryotank.getLocalProxy() as proxy:
await proxy.puts('foo', recs)

self.true(cryotank.dmon.shared.get('telecryo') is cryotank)

# And data persists...
async with await s_s_cryo.main(argv, outp=outp) as telecryo:
async with telecryo.getLocalProxy() as proxy:
precs = await s_t_utils.alist(proxy.slice('foo', 0, 100))
precs = [rec for offset, rec in precs]
self.eq(precs, recs)