mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 08:58:59 +00:00
Merge branch 'byname' into sam_raet_50
This commit is contained in:
commit
e38491d710
@ -110,7 +110,7 @@ class SaltRaetRoadStackSetup(ioflo.base.deeding.Deed):
|
|||||||
'local': {'ipath': 'local',
|
'local': {'ipath': 'local',
|
||||||
'ival': {'name': 'master',
|
'ival': {'name': 'master',
|
||||||
'main': False,
|
'main': False,
|
||||||
'auto': True,
|
'auto': None,
|
||||||
'eid': 0,
|
'eid': 0,
|
||||||
'sigkey': None,
|
'sigkey': None,
|
||||||
'prikey': None}},
|
'prikey': None}},
|
||||||
@ -151,16 +151,18 @@ class SaltRaetRoadStackSetup(ioflo.base.deeding.Deed):
|
|||||||
prikey=prikey)
|
prikey=prikey)
|
||||||
txMsgs = self.txmsgs.value
|
txMsgs = self.txmsgs.value
|
||||||
rxMsgs = self.rxmsgs.value
|
rxMsgs = self.rxmsgs.value
|
||||||
safe = salting.SaltSafe(opts=self.opts.value)
|
|
||||||
|
keep = salting.SaltKeep(opts=self.opts.value,
|
||||||
|
basedirpath=basedirpath,
|
||||||
|
stackname=name,
|
||||||
|
auto=auto)
|
||||||
|
|
||||||
self.stack.value = RoadStack(
|
self.stack.value = RoadStack(
|
||||||
local=local,
|
local=local,
|
||||||
store=self.store,
|
store=self.store,
|
||||||
name=name,
|
name=name,
|
||||||
auto=auto,
|
|
||||||
main=main,
|
main=main,
|
||||||
basedirpath=basedirpath,
|
keep=keep,
|
||||||
safe=safe,
|
|
||||||
txMsgs=txMsgs,
|
txMsgs=txMsgs,
|
||||||
rxMsgs=rxMsgs,
|
rxMsgs=rxMsgs,
|
||||||
period=3.0,
|
period=3.0,
|
||||||
|
@ -7,6 +7,7 @@ salting.py module of salt specific interfaces to raet
|
|||||||
# pylint: disable=W0611
|
# pylint: disable=W0611
|
||||||
|
|
||||||
# Import Python libs
|
# Import Python libs
|
||||||
|
import os
|
||||||
|
|
||||||
# Import ioflo libs
|
# Import ioflo libs
|
||||||
from ioflo.base.odicting import odict
|
from ioflo.base.odicting import odict
|
||||||
@ -19,123 +20,95 @@ from raet.road.keeping import RoadKeep
|
|||||||
|
|
||||||
from salt.key import RaetKey
|
from salt.key import RaetKey
|
||||||
|
|
||||||
class SaltSafe(object):
|
|
||||||
'''
|
|
||||||
Interface between Salt Key management and RAET keep key management
|
|
||||||
'''
|
|
||||||
LocalFields = ['sighex', 'prihex', 'auto']
|
|
||||||
RemoteFields = ['uid', 'name', 'acceptance', 'verhex', 'pubhex']
|
|
||||||
|
|
||||||
def __init__(self, opts, **kwa):
|
class SaltKeep(RoadKeep):
|
||||||
|
'''
|
||||||
|
RAET protocol estate on road data persistence for a given estate
|
||||||
|
road specific data
|
||||||
|
|
||||||
|
road/
|
||||||
|
keep/
|
||||||
|
stackname/
|
||||||
|
local/
|
||||||
|
estate.ext
|
||||||
|
remote/
|
||||||
|
estate.uid.ext
|
||||||
|
estate.uid.ext
|
||||||
|
'''
|
||||||
|
LocalFields = ['uid', 'name', 'ha', 'main', 'sid', 'neid', 'sighex', 'prihex', 'auto']
|
||||||
|
LocalDumpFields = ['uid', 'name', 'ha', 'main', 'sid', 'neid']
|
||||||
|
RemoteFields = ['uid', 'name', 'ha', 'sid', 'joined', 'acceptance', 'verhex', 'pubhex']
|
||||||
|
RemoteDumpFields = ['uid', 'name', 'ha', 'sid', 'joined']
|
||||||
|
|
||||||
|
Auto = False #auto accept
|
||||||
|
|
||||||
|
def __init__(self, opts, basedirpath='', auto=None, **kwa):
|
||||||
'''
|
'''
|
||||||
Setup SaltSafe instance
|
Setup RoadKeep instance
|
||||||
'''
|
'''
|
||||||
self.auto = opts['auto_accept']
|
basedirpath = basedirpath or os.path.join(opts['cache_dir'], 'raet')
|
||||||
self.dirpath = opts['pki_dir']
|
auto = auto if auto is not None else opts['auto_accept']
|
||||||
|
super(SaltKeep, self).__init__(basedirpath=basedirpath, auto=auto, **kwa)
|
||||||
self.saltRaetKey = RaetKey(opts)
|
self.saltRaetKey = RaetKey(opts)
|
||||||
|
|
||||||
def verifyLocalData(self, data):
|
|
||||||
'''
|
|
||||||
Returns True if the fields in .LocalFields match the fields in data
|
|
||||||
'''
|
|
||||||
return (set(self.LocalFields) == set(data.keys()))
|
|
||||||
|
|
||||||
def dumpLocalData(self, data):
|
|
||||||
'''
|
|
||||||
Dump the key data from the local estate
|
|
||||||
'''
|
|
||||||
self.saltRaetKey.write_local(data['prihex'], data['sighex'])
|
|
||||||
|
|
||||||
def loadLocalData(self):
|
def loadLocalData(self):
|
||||||
'''
|
'''
|
||||||
Load and Return the data from the local estate
|
Load and Return the data from the local estate
|
||||||
'''
|
'''
|
||||||
data = self.saltRaetKey.read_local()
|
|
||||||
|
data = super(SaltKeep, self).loadLocalData()
|
||||||
if not data:
|
if not data:
|
||||||
return None
|
return None
|
||||||
return (odict(sighex=data['sign'], prihex=data['priv'], auto=self.auto))
|
srkdata = self.saltRaetKey.read_local()
|
||||||
|
if not srkdata:
|
||||||
def clearLocalData(self):
|
srkdata = dict(sign=None, priv=None)
|
||||||
'''
|
data.update(sighex=srkdata['sign'], prihex=srkdata['priv'], auto=self.auto)
|
||||||
Load and Return the data from the local estate
|
|
||||||
'''
|
|
||||||
pass
|
|
||||||
|
|
||||||
def verifyRemoteData(self, data):
|
|
||||||
'''
|
|
||||||
Returns True if the fields in .RemoteFields match the fields in data
|
|
||||||
'''
|
|
||||||
return (set(self.RemoteFields) == set(data.keys()))
|
|
||||||
|
|
||||||
def dumpRemoteData(self, data, uid):
|
|
||||||
'''
|
|
||||||
Dump the data from the remote estate given by uid
|
|
||||||
'''
|
|
||||||
self.saltRaetKey.status(data['name'],
|
|
||||||
data['uid'],
|
|
||||||
data['pubhex'],
|
|
||||||
data['verhex'])
|
|
||||||
|
|
||||||
def loadAllRemoteData(self):
|
|
||||||
'''
|
|
||||||
Load and Return the data from the all the remote estate files
|
|
||||||
'''
|
|
||||||
data = odict()
|
|
||||||
|
|
||||||
for status, mids in self.saltRaetKey.list_keys().items():
|
|
||||||
for mid in mids:
|
|
||||||
keydata = self.saltRaetKey.read_remote(mid, status)
|
|
||||||
if keydata:
|
|
||||||
rdata = odict()
|
|
||||||
rdata['uid'] = keydata['device_id']
|
|
||||||
rdata['name'] = keydata['minion_id']
|
|
||||||
rdata['acceptance'] = raeting.ACCEPTANCES[status]
|
|
||||||
rdata['verhex'] = keydata['verify']
|
|
||||||
rdata['pubhex'] = keydata['pub']
|
|
||||||
data[str(rdata['uid'])] = rdata
|
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def clearAllRemoteData(self):
|
|
||||||
'''
|
|
||||||
Remove all the remote estate files
|
|
||||||
'''
|
|
||||||
self.saltRaetKey.delete_all()
|
|
||||||
|
|
||||||
def dumpLocal(self, local):
|
def dumpLocal(self, local):
|
||||||
'''
|
'''
|
||||||
Dump the key data from the local estate
|
Dump local estate
|
||||||
'''
|
'''
|
||||||
data = odict([
|
data = odict([
|
||||||
('sighex', local.signer.keyhex),
|
('uid', local.uid),
|
||||||
('prihex', local.priver.keyhex),
|
('name', local.name),
|
||||||
('auto', self.auto),
|
('ha', local.ha),
|
||||||
|
('main', local.main),
|
||||||
|
('sid', local.sid),
|
||||||
|
('neid', local.neid),
|
||||||
])
|
])
|
||||||
if self.verifyLocalData(data):
|
if self.verifyLocalData(data, localFields = self.LocalDumpFields):
|
||||||
self.dumpLocalData(data)
|
self.dumpLocalData(data)
|
||||||
|
|
||||||
|
self.saltRaetKey.write_local(local.priver.keyhex, local.signer.keyhex)
|
||||||
|
|
||||||
def dumpRemote(self, remote):
|
def dumpRemote(self, remote):
|
||||||
'''
|
'''
|
||||||
Dump the data from the remote estate by calling status on it which
|
Dump remote estate
|
||||||
will persist the data
|
|
||||||
'''
|
'''
|
||||||
data = odict([
|
data = odict([
|
||||||
('uid', remote.uid),
|
('uid', remote.uid),
|
||||||
('name', remote.name),
|
('name', remote.name),
|
||||||
('acceptance', remote.acceptance),
|
('ha', remote.ha),
|
||||||
('verhex', remote.verfer.keyhex),
|
('sid', remote.sid),
|
||||||
('pubhex', remote.pubber.keyhex),
|
('joined', remote.joined),
|
||||||
])
|
])
|
||||||
if self.verifyRemoteData(data):
|
if self.verifyRemoteData(data, remoteFields =self.RemoteDumpFields):
|
||||||
self.dumpRemoteData(data, remote.uid)
|
self.dumpRemoteData(data, remote.uid)
|
||||||
|
|
||||||
|
self.saltRaetKey.status(remote.name,
|
||||||
|
remote.uid,
|
||||||
|
remote.pubber.keyhex,
|
||||||
|
remote.verfer.keyhex)
|
||||||
|
|
||||||
def loadRemote(self, remote):
|
def loadRemote(self, remote):
|
||||||
'''
|
'''
|
||||||
Load and Return the data from the remote estate file
|
Load and Return the data from the remote estate file
|
||||||
Override this in sub class to change uid
|
Override this in sub class to change uid
|
||||||
'''
|
'''
|
||||||
#status = raeting.ACCEPTANCE_NAMES.get(remote.acceptance, 'accepted')
|
data = super(SaltKeep, self).loadRemote(remote)
|
||||||
#status='accepted'
|
if not data:
|
||||||
|
return None
|
||||||
|
|
||||||
mid = remote.name
|
mid = remote.name
|
||||||
statae = raeting.ACCEPTANCES.keys()
|
statae = raeting.ACCEPTANCES.keys()
|
||||||
@ -147,20 +120,35 @@ class SaltSafe(object):
|
|||||||
if not keydata:
|
if not keydata:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
data = odict()
|
data.update(acceptance=raeting.ACCEPTANCES[status],
|
||||||
data['uid'] = keydata['device_id']
|
verhex=keydata['verify'],
|
||||||
data['name'] = keydata['minion_id']
|
pubhex=keydata['pub'])
|
||||||
data['acceptance'] = raeting.ACCEPTANCES[status]
|
|
||||||
data['verhex'] = keydata['verify']
|
|
||||||
data['pubhex'] = keydata['pub']
|
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def clearRemote(self, remote):
|
def loadAllRemoteData(self):
|
||||||
'''
|
'''
|
||||||
Salt level keys should not be auto removed with cache changes
|
Load and Return the data from the all the remote estate files
|
||||||
'''
|
'''
|
||||||
pass
|
data = super(SaltKeep, self).loadAllRemoteData()
|
||||||
|
|
||||||
|
for status, mids in self.saltRaetKey.list_keys().items():
|
||||||
|
for mid in mids:
|
||||||
|
keydata = self.saltRaetKey.read_remote(mid, status)
|
||||||
|
if keydata:
|
||||||
|
uid = str(keydata['device_id'])
|
||||||
|
if uid in data:
|
||||||
|
data[uid].update(acceptance=raeting.ACCEPTANCES[status],
|
||||||
|
verhex=keydata['verify'],
|
||||||
|
pubhex=keydata['pub'])
|
||||||
|
return data
|
||||||
|
|
||||||
|
def clearAllRemoteData(self):
|
||||||
|
'''
|
||||||
|
Remove all the remote estate files
|
||||||
|
'''
|
||||||
|
super(SaltKeep, self).clearAllRemoteData()
|
||||||
|
self.saltRaetKey.delete_all()
|
||||||
|
|
||||||
def replaceRemote(self, remote, old):
|
def replaceRemote(self, remote, old):
|
||||||
'''
|
'''
|
||||||
@ -219,14 +207,11 @@ class SaltSafe(object):
|
|||||||
mid = remote.name
|
mid = remote.name
|
||||||
self.saltRaetKey.accept(match=mid, include_rejected=True)
|
self.saltRaetKey.accept(match=mid, include_rejected=True)
|
||||||
|
|
||||||
|
def clearAllKeep(dirpath):
|
||||||
def clearAllKeepSafe(dirpath, opts):
|
|
||||||
'''
|
'''
|
||||||
Convenience function to clear all road and safe keep data in dirpath
|
Convenience function to clear all road keep data in dirpath
|
||||||
'''
|
'''
|
||||||
road = RoadKeep(dirpath=dirpath)
|
road = RoadKeep(dirpath=dirpath)
|
||||||
road.clearLocalData()
|
road.clearLocalData()
|
||||||
road.clearAllRemoteData()
|
road.clearAllRemoteData()
|
||||||
safe = SaltSafe(opts=opts)
|
|
||||||
safe.clearLocalData()
|
|
||||||
safe.clearAllRemoteData()
|
|
||||||
|
@ -42,32 +42,18 @@ class BasicTestCase(unittest.TestCase):
|
|||||||
self.store = storing.Store(stamp=0.0)
|
self.store = storing.Store(stamp=0.0)
|
||||||
self.timer = StoreTimer(store=self.store, duration=1.0)
|
self.timer = StoreTimer(store=self.store, duration=1.0)
|
||||||
|
|
||||||
self.mainDirpath = tempfile.mkdtemp(prefix="salt", suffix='main', dir='/tmp')
|
self.tempDirpath = tempfile.mkdtemp(prefix="salt", suffix='keep', dir='/tmp')
|
||||||
opts = self.createOpts(self.mainDirpath, openMode=True, autoAccept=True)
|
|
||||||
self.mainSafe = salting.SaltSafe(opts=opts)
|
|
||||||
|
|
||||||
self.otherDirpath = tempfile.mkdtemp(prefix="salt", suffix='other', dir='/tmp')
|
|
||||||
opts = self.createOpts(self.otherDirpath, openMode=True, autoAccept=True)
|
|
||||||
self.otherSafe = salting.SaltSafe(opts=opts)
|
|
||||||
|
|
||||||
self.baseDirpath = tempfile.mkdtemp(prefix="raet", suffix="base", dir='/tmp')
|
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
if os.path.exists(self.mainDirpath):
|
if os.path.exists(self.tempDirpath):
|
||||||
shutil.rmtree(self.mainDirpath)
|
shutil.rmtree(self.tempDirpath)
|
||||||
|
|
||||||
if os.path.exists(self.otherDirpath):
|
def createOpts(self, name, dirpath, openMode=False, autoAccept=True):
|
||||||
shutil.rmtree(self.otherDirpath)
|
|
||||||
|
|
||||||
if os.path.exists(self.baseDirpath):
|
|
||||||
shutil.rmtree(self.baseDirpath)
|
|
||||||
|
|
||||||
def createOpts(self, dirpath, openMode=False, autoAccept=True):
|
|
||||||
'''
|
'''
|
||||||
Create associated pki directories for stack and return opts
|
Create associated pki directories for stack and return opts
|
||||||
'''
|
'''
|
||||||
|
|
||||||
pkiDirpath = os.path.join(dirpath, 'pki')
|
pkiDirpath = os.path.join(dirpath, 'pki', name, 'raet')
|
||||||
if not os.path.exists(pkiDirpath):
|
if not os.path.exists(pkiDirpath):
|
||||||
os.makedirs(pkiDirpath)
|
os.makedirs(pkiDirpath)
|
||||||
|
|
||||||
@ -89,8 +75,8 @@ class BasicTestCase(unittest.TestCase):
|
|||||||
print mode
|
print mode
|
||||||
os.chmod(localFilepath, mode | stat.S_IWUSR | stat.S_IWUSR)
|
os.chmod(localFilepath, mode | stat.S_IWUSR | stat.S_IWUSR)
|
||||||
|
|
||||||
cacheDirpath = os.path.join(dirpath, 'cache')
|
cacheDirpath = os.path.join(dirpath, 'cache', name)
|
||||||
sockDirpath = os.path.join(dirpath, 'sock')
|
sockDirpath = os.path.join(dirpath, 'sock', name)
|
||||||
|
|
||||||
opts = dict(
|
opts = dict(
|
||||||
pki_dir=pkiDirpath,
|
pki_dir=pkiDirpath,
|
||||||
@ -102,7 +88,7 @@ class BasicTestCase(unittest.TestCase):
|
|||||||
)
|
)
|
||||||
return opts
|
return opts
|
||||||
|
|
||||||
def createRoadData(self, name, base):
|
def createRoadData(self, name, cachedirpath):
|
||||||
'''
|
'''
|
||||||
Creates odict and populates with data to setup road stack
|
Creates odict and populates with data to setup road stack
|
||||||
{
|
{
|
||||||
@ -116,7 +102,7 @@ class BasicTestCase(unittest.TestCase):
|
|||||||
'''
|
'''
|
||||||
data = odict()
|
data = odict()
|
||||||
data['name'] = name
|
data['name'] = name
|
||||||
data['dirpath'] = os.path.join(base, 'road', 'keep', name)
|
data['basedirpath'] = os.path.join(cachedirpath, 'raet')
|
||||||
signer = nacling.Signer()
|
signer = nacling.Signer()
|
||||||
data['sighex'] = signer.keyhex
|
data['sighex'] = signer.keyhex
|
||||||
data['verhex'] = signer.verhex
|
data['verhex'] = signer.verhex
|
||||||
@ -126,7 +112,7 @@ class BasicTestCase(unittest.TestCase):
|
|||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def createRoadStack(self, data, eid=0, main=None, auto=None, ha=None, safe=None):
|
def createRoadStack(self, data, keep, eid=0, main=None, ha=None):
|
||||||
'''
|
'''
|
||||||
Creates stack and local estate from data with
|
Creates stack and local estate from data with
|
||||||
local estate.eid = eid
|
local estate.eid = eid
|
||||||
@ -148,10 +134,8 @@ class BasicTestCase(unittest.TestCase):
|
|||||||
stack = stacking.RoadStack(name=data['name'],
|
stack = stacking.RoadStack(name=data['name'],
|
||||||
local=local,
|
local=local,
|
||||||
main=main,
|
main=main,
|
||||||
dirpath=data['dirpath'],
|
|
||||||
store=self.store,
|
store=self.store,
|
||||||
safe=safe,
|
keep=keep)
|
||||||
auto=auto,)
|
|
||||||
|
|
||||||
return stack
|
return stack
|
||||||
|
|
||||||
@ -201,35 +185,41 @@ class BasicTestCase(unittest.TestCase):
|
|||||||
'''
|
'''
|
||||||
console.terse("{0}\n".format(self.testBasic.__doc__))
|
console.terse("{0}\n".format(self.testBasic.__doc__))
|
||||||
|
|
||||||
self.assertEqual(self.mainSafe.loadLocalData(), None)
|
opts = self.createOpts(name='main',
|
||||||
self.assertEqual(self.mainSafe.loadAllRemoteData(), {})
|
dirpath=self.tempDirpath,
|
||||||
|
openMode=True,
|
||||||
|
autoAccept=True)
|
||||||
|
mainData = self.createRoadData(name='main', cachedirpath=opts['cachedir'] )
|
||||||
|
mainKeep = salting.SaltKeep(opts=opts,
|
||||||
|
basedirpath=mainData['basedirpath'],
|
||||||
|
stackname=mainData['name'])
|
||||||
|
|
||||||
dataMain = self.createRoadData(name='main', base=self.baseDirpath)
|
self.assertEqual(mainKeep.loadLocalData(), None)
|
||||||
main = self.createRoadStack(data=dataMain,
|
self.assertEqual(mainKeep.loadAllRemoteData(), {})
|
||||||
|
|
||||||
|
main = self.createRoadStack(data=mainData,
|
||||||
eid=1,
|
eid=1,
|
||||||
main=True,
|
main=True,
|
||||||
ha=None, #default ha is ("", raeting.RAET_PORT)
|
ha=None, #default ha is ("", raeting.RAET_PORT)
|
||||||
safe=self.mainSafe)
|
keep=mainKeep)
|
||||||
|
|
||||||
console.terse("{0}\nkeep dirpath = {1}\nsafe dirpath = {2}\n".format(
|
console.terse("{0}\nkeep dirpath = {1}\n".format(
|
||||||
main.name, main.keep.dirpath, main.safe.dirpath))
|
main.name, main.keep.dirpath))
|
||||||
self.assertTrue(main.keep.dirpath.endswith('road/keep/main'))
|
self.assertTrue(main.keep.dirpath.endswith('main/raet/main'))
|
||||||
self.assertTrue(main.safe.dirpath.endswith('pki'))
|
|
||||||
self.assertTrue(main.local.ha, ("0.0.0.0", raeting.RAET_PORT))
|
self.assertTrue(main.local.ha, ("0.0.0.0", raeting.RAET_PORT))
|
||||||
self.assertTrue(main.safe.auto)
|
self.assertTrue(main.keep.auto)
|
||||||
self.assertDictEqual(main.keep.loadLocalData(), {'uid': 1,
|
self.assertDictEqual(main.keep.loadLocalData(), {'uid': 1,
|
||||||
'name': 'main',
|
'name': 'main',
|
||||||
'ha': ['0.0.0.0', 7530],
|
'ha': ['0.0.0.0', 7530],
|
||||||
'main': True,
|
'main': True,
|
||||||
'sid': 0,
|
'sid': 0,
|
||||||
'stack': 'main',
|
'neid': 1,
|
||||||
'neid': 1,})
|
'sighex': mainData['sighex'],
|
||||||
self.assertDictEqual(main.safe.loadLocalData(), {'prihex': dataMain['prihex'],
|
'prihex': mainData['prihex'],
|
||||||
'sighex': dataMain['sighex'],
|
'auto': True,
|
||||||
'auto': True})
|
})
|
||||||
|
|
||||||
|
data1 = self.createRoadData(name='remote1', cachedirpath=opts['cachedir'])
|
||||||
data1 = self.createRoadData(name='remote1', base=self.baseDirpath)
|
|
||||||
main.addRemote(estating.RemoteEstate(stack=main,
|
main.addRemote(estating.RemoteEstate(stack=main,
|
||||||
eid=3,
|
eid=3,
|
||||||
name=data1['name'],
|
name=data1['name'],
|
||||||
@ -239,7 +229,7 @@ class BasicTestCase(unittest.TestCase):
|
|||||||
period=main.period,
|
period=main.period,
|
||||||
offset=main.offset, ))
|
offset=main.offset, ))
|
||||||
|
|
||||||
data2 = self.createRoadData(name='remote2', base=self.baseDirpath)
|
data2 = self.createRoadData(name='remote2', cachedirpath=opts['cachedir'])
|
||||||
main.addRemote(estating.RemoteEstate(stack=main,
|
main.addRemote(estating.RemoteEstate(stack=main,
|
||||||
eid=4,
|
eid=4,
|
||||||
name=data2['name'],
|
name=data2['name'],
|
||||||
@ -251,69 +241,78 @@ class BasicTestCase(unittest.TestCase):
|
|||||||
|
|
||||||
main.dumpRemotes()
|
main.dumpRemotes()
|
||||||
|
|
||||||
self.assertDictEqual(main.safe.loadAllRemoteData(),
|
self.assertDictEqual(main.keep.loadAllRemoteData(),
|
||||||
{'3':
|
{'3':
|
||||||
{'uid': 3,
|
{'uid': 3,
|
||||||
'name': data1['name'],
|
'name': data1['name'],
|
||||||
|
'ha': ['127.0.0.1', 7532],
|
||||||
|
'sid': 0,
|
||||||
|
'joined': None,
|
||||||
'acceptance': 1,
|
'acceptance': 1,
|
||||||
'verhex': data1['verhex'],
|
'verhex': data1['verhex'],
|
||||||
'pubhex': data1['pubhex']},
|
'pubhex': data1['pubhex']},
|
||||||
'4':
|
'4':
|
||||||
{'uid': 4,
|
{'uid': 4,
|
||||||
'name': data2['name'],
|
'name': data2['name'],
|
||||||
|
'ha': ['127.0.0.1', 7533],
|
||||||
|
'sid': 0,
|
||||||
|
'joined': None,
|
||||||
'acceptance': 1,
|
'acceptance': 1,
|
||||||
'verhex': data2['verhex'],
|
'verhex': data2['verhex'],
|
||||||
'pubhex': data2['pubhex']}})
|
'pubhex': data2['pubhex']}})
|
||||||
|
|
||||||
self.assertDictEqual(main.keep.loadAllRemoteData(),
|
|
||||||
{'3':
|
|
||||||
{'uid': 3,
|
|
||||||
'name': 'remote1',
|
|
||||||
'ha': ['127.0.0.1', 7532],
|
|
||||||
'sid': 0,
|
|
||||||
'joined': None,},
|
|
||||||
'4':
|
|
||||||
{'uid': 4,
|
|
||||||
'name': 'remote2',
|
|
||||||
'ha': ['127.0.0.1', 7533],
|
|
||||||
'sid': 0,
|
|
||||||
'joined': None,}})
|
|
||||||
|
|
||||||
# now recreate with saved data
|
# now recreate with saved data
|
||||||
main.server.close()
|
main.server.close()
|
||||||
main = stacking.RoadStack(name='main',
|
mainKeep = salting.SaltKeep(opts=opts,
|
||||||
dirpath=dataMain['dirpath'],
|
basedirpath=mainData['basedirpath'],
|
||||||
|
stackname=mainData['name'])
|
||||||
|
main = stacking.RoadStack(name=mainData['name'],
|
||||||
store=self.store,
|
store=self.store,
|
||||||
safe=self.mainSafe)
|
keep=mainKeep)
|
||||||
|
|
||||||
self.assertEqual(main.local.priver.keyhex, dataMain['prihex'])
|
self.assertEqual(main.local.priver.keyhex, mainData['prihex'])
|
||||||
self.assertEqual(main.local.signer.keyhex, dataMain['sighex'])
|
self.assertEqual(main.local.signer.keyhex, mainData['sighex'])
|
||||||
|
|
||||||
self.assertEqual(len(main.remotes.values()), 2)
|
self.assertEqual(len(main.remotes.values()), 2)
|
||||||
|
|
||||||
self.assertEqual(self.otherSafe.loadLocalData(), None)
|
|
||||||
self.assertEqual(self.otherSafe.loadAllRemoteData(), {})
|
|
||||||
|
|
||||||
# other stack
|
# other stack
|
||||||
|
opts = self.createOpts(name='other',
|
||||||
|
dirpath=self.tempDirpath,
|
||||||
|
openMode=True,
|
||||||
|
autoAccept=True)
|
||||||
|
otherData = self.createRoadData(name='other', cachedirpath=opts['cachedir'] )
|
||||||
|
otherKeep = salting.SaltKeep(opts=opts,
|
||||||
|
basedirpath=otherData['basedirpath'],
|
||||||
|
stackname=otherData['name'])
|
||||||
|
|
||||||
dataOther = self.createRoadData(name='other', base=self.baseDirpath)
|
self.assertEqual(otherKeep.loadLocalData(), None)
|
||||||
other = self.createRoadStack(data=dataOther,
|
self.assertEqual(otherKeep.loadAllRemoteData(), {})
|
||||||
|
|
||||||
|
other = self.createRoadStack(data=otherData,
|
||||||
eid=0,
|
eid=0,
|
||||||
main=None,
|
main=None,
|
||||||
ha=("", raeting.RAET_TEST_PORT),
|
ha=("", raeting.RAET_TEST_PORT),
|
||||||
safe=self.otherSafe)
|
keep=otherKeep)
|
||||||
|
|
||||||
console.terse("{0} keep dirpath = {1} safe dirpath = {2}\n".format(
|
console.terse("{0} keep dirpath = {1}\n".format(
|
||||||
other.name, other.keep.dirpath, other.safe.dirpath))
|
other.name, other.keep.dirpath))
|
||||||
self.assertTrue(other.keep.dirpath.endswith('road/keep/other'))
|
self.assertTrue(other.keep.dirpath.endswith('other/raet/other'))
|
||||||
self.assertTrue(other.safe.dirpath.endswith('pki'))
|
|
||||||
self.assertEqual(other.local.ha, ("0.0.0.0", raeting.RAET_TEST_PORT))
|
self.assertEqual(other.local.ha, ("0.0.0.0", raeting.RAET_TEST_PORT))
|
||||||
|
|
||||||
self.assertDictEqual(other.safe.loadLocalData(), {'prihex': dataOther['prihex'],
|
self.assertDictEqual(other.keep.loadLocalData(),
|
||||||
'sighex': dataOther['sighex'],
|
{
|
||||||
'auto': True,})
|
'uid': 0,
|
||||||
|
'name': 'other',
|
||||||
|
'ha': ['0.0.0.0', 7531],
|
||||||
|
'main': None,
|
||||||
|
'sid': 0,
|
||||||
|
'neid': 1,
|
||||||
|
'sighex': otherData['sighex'],
|
||||||
|
'prihex': otherData['prihex'],
|
||||||
|
'auto': True,
|
||||||
|
})
|
||||||
|
|
||||||
data3 = self.createRoadData(name='remote3', base=self.baseDirpath)
|
data3 = self.createRoadData(name='remote3', cachedirpath=opts['cachedir'])
|
||||||
other.addRemote(estating.RemoteEstate(stack=other,
|
other.addRemote(estating.RemoteEstate(stack=other,
|
||||||
eid=3,
|
eid=3,
|
||||||
name=data3['name'],
|
name=data3['name'],
|
||||||
@ -323,7 +322,7 @@ class BasicTestCase(unittest.TestCase):
|
|||||||
period=main.period,
|
period=main.period,
|
||||||
offset=main.offset,))
|
offset=main.offset,))
|
||||||
|
|
||||||
data4 = self.createRoadData(name='remote4', base=self.baseDirpath)
|
data4 = self.createRoadData(name='remote4', cachedirpath=opts['cachedir'])
|
||||||
other.addRemote(estating.RemoteEstate(stack=other,
|
other.addRemote(estating.RemoteEstate(stack=other,
|
||||||
eid=4,
|
eid=4,
|
||||||
name=data4['name'],
|
name=data4['name'],
|
||||||
@ -334,34 +333,31 @@ class BasicTestCase(unittest.TestCase):
|
|||||||
offset=main.offset,))
|
offset=main.offset,))
|
||||||
|
|
||||||
other.dumpRemotes()
|
other.dumpRemotes()
|
||||||
self.assertDictEqual(other.safe.loadAllRemoteData(),
|
|
||||||
{'3':
|
|
||||||
{'uid': 3,
|
|
||||||
'name': data3['name'],
|
|
||||||
'acceptance': 1,
|
|
||||||
'verhex': data3['verhex'],
|
|
||||||
'pubhex': data3['pubhex']},
|
|
||||||
'4':
|
|
||||||
{'uid': 4,
|
|
||||||
'name': data4['name'],
|
|
||||||
'acceptance': 1,
|
|
||||||
'verhex': data4['verhex'],
|
|
||||||
'pubhex': data4['pubhex']}})
|
|
||||||
other.server.close()
|
|
||||||
|
|
||||||
self.assertDictEqual(other.keep.loadAllRemoteData(),
|
self.assertDictEqual(other.keep.loadAllRemoteData(),
|
||||||
{'3':
|
{
|
||||||
{'uid': 3,
|
'3':
|
||||||
'name': 'remote3',
|
{
|
||||||
'ha': ['127.0.0.1', 7534],
|
'uid': 3,
|
||||||
'sid': 0,
|
'name': data3['name'],
|
||||||
'joined': None,},
|
'ha': ['127.0.0.1', 7534],
|
||||||
'4':
|
'sid': 0,
|
||||||
{'uid': 4,
|
'joined': None,
|
||||||
'name': 'remote4',
|
'acceptance': 1,
|
||||||
'ha': ['127.0.0.1', 7535],
|
'verhex': data3['verhex'],
|
||||||
'sid': 0,
|
'pubhex': data3['pubhex']
|
||||||
'joined': None,}})
|
},
|
||||||
|
'4':
|
||||||
|
{
|
||||||
|
'uid': 4,
|
||||||
|
'name': data4['name'],
|
||||||
|
'ha': ['127.0.0.1', 7535],
|
||||||
|
'sid': 0,
|
||||||
|
'joined': None,
|
||||||
|
'acceptance': 1,
|
||||||
|
'verhex': data4['verhex'],
|
||||||
|
'pubhex': data4['pubhex']
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
main.server.close()
|
main.server.close()
|
||||||
other.server.close()
|
other.server.close()
|
||||||
@ -370,53 +366,76 @@ class BasicTestCase(unittest.TestCase):
|
|||||||
'''
|
'''
|
||||||
Basic keep setup for stack keep and safe persistence load and dump
|
Basic keep setup for stack keep and safe persistence load and dump
|
||||||
'''
|
'''
|
||||||
console.terse("{0}\n".format(self.testBasic.__doc__))
|
console.terse("{0}\n".format(self.testBootstrapClean.__doc__))
|
||||||
|
|
||||||
self.assertEqual(self.mainSafe.loadLocalData(), None)
|
opts = self.createOpts(name='main',
|
||||||
self.assertEqual(self.mainSafe.loadAllRemoteData(), {})
|
dirpath=self.tempDirpath,
|
||||||
|
openMode=True,
|
||||||
|
autoAccept=True)
|
||||||
|
mainData = self.createRoadData(name='main', cachedirpath=opts['cachedir'] )
|
||||||
|
mainKeep = salting.SaltKeep(opts=opts,
|
||||||
|
basedirpath=mainData['basedirpath'],
|
||||||
|
stackname=mainData['name'])
|
||||||
|
|
||||||
dataMain = self.createRoadData(name='main', base=self.baseDirpath)
|
self.assertEqual(mainKeep.loadLocalData(), None)
|
||||||
main = self.createRoadStack(data=dataMain,
|
self.assertEqual(mainKeep.loadAllRemoteData(), {})
|
||||||
|
|
||||||
|
main = self.createRoadStack(data=mainData,
|
||||||
eid=1,
|
eid=1,
|
||||||
main=True,
|
main=True,
|
||||||
ha=None, #default ha is ("", raeting.RAET_PORT)
|
ha=None, #default ha is ("", raeting.RAET_PORT)
|
||||||
safe=self.mainSafe)
|
keep=mainKeep)
|
||||||
|
|
||||||
self.assertTrue(main.keep.dirpath.endswith('road/keep/main'))
|
console.terse("{0}\nkeep dirpath = {1}\n".format(
|
||||||
self.assertTrue(main.safe.dirpath.endswith('pki'))
|
main.name, main.keep.dirpath))
|
||||||
|
self.assertTrue(main.keep.dirpath.endswith('main/raet/main'))
|
||||||
self.assertTrue(main.local.ha, ("0.0.0.0", raeting.RAET_PORT))
|
self.assertTrue(main.local.ha, ("0.0.0.0", raeting.RAET_PORT))
|
||||||
self.assertTrue(main.safe.auto)
|
self.assertTrue(main.keep.auto)
|
||||||
self.assertDictEqual(main.keep.loadLocalData(), {'uid': 1,
|
self.assertDictEqual(main.keep.loadLocalData(), {'uid': 1,
|
||||||
'name': 'main',
|
'name': 'main',
|
||||||
'ha': ['0.0.0.0', 7530],
|
'ha': ['0.0.0.0', 7530],
|
||||||
'main': True,
|
'main': True,
|
||||||
'sid': 0,
|
'sid': 0,
|
||||||
'stack': 'main',
|
'neid': 1,
|
||||||
'neid': 1,})
|
'sighex': mainData['sighex'],
|
||||||
self.assertDictEqual(main.safe.loadLocalData(), {'prihex': dataMain['prihex'],
|
'prihex': mainData['prihex'],
|
||||||
'sighex': dataMain['sighex'],
|
'auto': True,
|
||||||
'auto': True,})
|
})
|
||||||
|
|
||||||
self.assertEqual(self.otherSafe.loadLocalData(), None)
|
opts = self.createOpts(name='other',
|
||||||
self.assertEqual(self.otherSafe.loadAllRemoteData(), {})
|
dirpath=self.tempDirpath,
|
||||||
|
openMode=True,
|
||||||
|
autoAccept=True)
|
||||||
|
otherData = self.createRoadData(name='other', cachedirpath=opts['cachedir'] )
|
||||||
|
otherKeep = salting.SaltKeep(opts=opts,
|
||||||
|
basedirpath=otherData['basedirpath'],
|
||||||
|
stackname=otherData['name'])
|
||||||
|
|
||||||
dataOther = self.createRoadData(name='other', base=self.baseDirpath)
|
self.assertEqual(otherKeep.loadLocalData(), None)
|
||||||
other = self.createRoadStack(data=dataOther,
|
self.assertEqual(otherKeep.loadAllRemoteData(), {})
|
||||||
|
|
||||||
|
other = self.createRoadStack(data=otherData,
|
||||||
eid=0,
|
eid=0,
|
||||||
main=None,
|
main=None,
|
||||||
ha=("", raeting.RAET_TEST_PORT),
|
ha=("", raeting.RAET_TEST_PORT),
|
||||||
safe=self.otherSafe)
|
keep=otherKeep)
|
||||||
|
|
||||||
console.terse("{0} keep dirpath = {1} safe dirpath = {2}\n".format(
|
console.terse("{0} keep dirpath = {1}\n".format(
|
||||||
other.name, other.keep.dirpath, other.safe.dirpath))
|
other.name, other.keep.dirpath))
|
||||||
self.assertTrue(other.keep.dirpath.endswith('road/keep/other'))
|
self.assertTrue(other.keep.dirpath.endswith('other/raet/other'))
|
||||||
self.assertTrue(other.safe.dirpath.endswith('pki'))
|
|
||||||
self.assertEqual(other.local.ha, ("0.0.0.0", raeting.RAET_TEST_PORT))
|
self.assertEqual(other.local.ha, ("0.0.0.0", raeting.RAET_TEST_PORT))
|
||||||
self.assertTrue(other.safe.auto)
|
self.assertDictEqual(other.keep.loadLocalData(),
|
||||||
|
{
|
||||||
self.assertDictEqual(other.safe.loadLocalData(), {'prihex': dataOther['prihex'],
|
'uid': 0,
|
||||||
'sighex': dataOther['sighex'],
|
'name': 'other',
|
||||||
'auto': True,})
|
'ha': ['0.0.0.0', 7531],
|
||||||
|
'main': None,
|
||||||
|
'sid': 0,
|
||||||
|
'neid': 1,
|
||||||
|
'sighex': otherData['sighex'],
|
||||||
|
'prihex': otherData['prihex'],
|
||||||
|
'auto': True,
|
||||||
|
})
|
||||||
|
|
||||||
self.join(other, main)
|
self.join(other, main)
|
||||||
self.assertEqual(len(main.transactions), 0)
|
self.assertEqual(len(main.transactions), 0)
|
||||||
@ -452,7 +471,8 @@ def runSome():
|
|||||||
Unittest runner
|
Unittest runner
|
||||||
'''
|
'''
|
||||||
tests = []
|
tests = []
|
||||||
names = ['testBasic',]
|
names = ['testBasic',
|
||||||
|
'testBootstrapClean', ]
|
||||||
|
|
||||||
tests.extend(map(BasicTestCase, names))
|
tests.extend(map(BasicTestCase, names))
|
||||||
|
|
||||||
@ -472,8 +492,8 @@ if __name__ == '__main__' and __package__ is None:
|
|||||||
|
|
||||||
#console.reinit(verbosity=console.Wordage.concise)
|
#console.reinit(verbosity=console.Wordage.concise)
|
||||||
|
|
||||||
runAll() #run all unittests
|
#runAll() #run all unittests
|
||||||
|
|
||||||
#runSome()#only run some
|
runSome()#only run some
|
||||||
|
|
||||||
#runOne('testBootstrap')
|
#runOne('testBootstrapClean')
|
@ -94,22 +94,23 @@ class Depends(object):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
# if not, unload dependent_set
|
# if not, unload dependent_set
|
||||||
mod_key = '{0}.{1}'.format(module.__name__.split('.')[-1],
|
if module:
|
||||||
func.__name__)
|
mod_key = '{0}.{1}'.format(module.__name__.split('.')[-1],
|
||||||
|
func.__name__)
|
||||||
|
|
||||||
# if we don't have this module loaded, skip it!
|
# if we don't have this module loaded, skip it!
|
||||||
if mod_key not in functions:
|
if mod_key not in functions:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if fallback_function is not None:
|
if fallback_function is not None:
|
||||||
functions[mod_key] = fallback_function
|
functions[mod_key] = fallback_function
|
||||||
else:
|
else:
|
||||||
del functions[mod_key]
|
del functions[mod_key]
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
# we already did???
|
# we already did???
|
||||||
log.trace('{0} already removed, skipping'.format(mod_key))
|
log.trace('{0} already removed, skipping'.format(mod_key))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
||||||
class depends(Depends): # pylint: disable=C0103
|
class depends(Depends): # pylint: disable=C0103
|
||||||
|
Loading…
Reference in New Issue
Block a user