From 1cba8418f88f29ec121df303c4195bfbcbf9e690 Mon Sep 17 00:00:00 2001 From: Samuel M Smith Date: Mon, 3 Mar 2014 11:17:05 -0700 Subject: [PATCH 1/4] Changed name lookup logic --- salt/transport/road/raet/stacking.py | 4 ++-- salt/transport/road/raet/yarding.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/salt/transport/road/raet/stacking.py b/salt/transport/road/raet/stacking.py index 5c763a2265..da44ad2258 100644 --- a/salt/transport/road/raet/stacking.py +++ b/salt/transport/road/raet/stacking.py @@ -501,12 +501,12 @@ class StackUxd(object): if name is None: name = yard.name - if name in self.yards: + if name in self.yards or name == self.yard.name: emsg = "Device with name '{0}' alreadys exists".format(name) raise raeting.StackError(emsg) yard.stack = self self.yards[name] = yard - if yard.ha in self.names: + if yard.ha in self.names or yard.ha == self.yard.ha: emsg = "Yard with ha '{0}' alreadys exists".format(yard.ha) raise raeting.StackError(emsg) self.names[yard.ha] = yard.name diff --git a/salt/transport/road/raet/yarding.py b/salt/transport/road/raet/yarding.py index a0895cf03e..6f85637298 100644 --- a/salt/transport/road/raet/yarding.py +++ b/salt/transport/road/raet/yarding.py @@ -43,8 +43,8 @@ class Yard(object): yid = Yard.Yid Yard.Yid += 1 - self.yid = yid # yard ID - self.name = name or "yard{0}".format(self.yid) + #self.yid = yid # yard ID + self.name = name or "yard{0}".format(yid) if " " in self.name: emsg = "Invalid Yard name '{0}'".format(self.name) raise raeting.YardError(emsg) From fdf28e9e482412dc4bb5e25effe7f6980efa3fcf Mon Sep 17 00:00:00 2001 From: Samuel M Smith Date: Mon, 3 Mar 2014 11:18:24 -0700 Subject: [PATCH 2/4] added forking.py --- salt/transport/road/raet/test/forking.py | 77 ++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 salt/transport/road/raet/test/forking.py diff --git a/salt/transport/road/raet/test/forking.py b/salt/transport/road/raet/test/forking.py new file mode 100644 index 0000000000..50d6d3fc18 --- /dev/null +++ b/salt/transport/road/raet/test/forking.py @@ -0,0 +1,77 @@ +import multiprocessing +import time + +from salt.transport.road.raet import stacking +from salt.transport.road.raet import yarding + +ESTATE = 'minion1' +def fudal(): + ''' + Make a single process raet uxd stack + ''' + lord_stack = stacking.StackUxd(name='lord', lanename='execute', yid=0, dirpath='/tmp') + serf_stack = stacking.StackUxd(name='serf', lanename='execute', yid=1, dirpath='/tmp') + lord_yard = yarding.Yard(yid=0, prefix='execute', dirpath='/tmp') + #serf_yard = yarding.Yard(name=serf_stack.yard.name, prefix='execute') + serf_stack.addRemoteYard(lord_yard) + #print 'stack: {0}\nyid: {1}\nname: {2}\nha: {3}\ndirpath: {4}'.format(lord_stack.yard.stack, lord_stack.yard.yid, lord_stack.yard.name, lord_stack.yard.ha, lord_stack.yard.dirpath) + #lord_stack.addRemoteYard(serf_yard) + + src = (ESTATE, serf_stack.yard.name, None) + dst = (ESTATE, lord_stack.yard.name, None) + + route = {'src': src, 'dst': dst} + msg = {'route': route, 'stuff': 'Serf to Lord, I am not a couch'} + + serf_stack.transmit(msg=msg) + + serf_stack.serviceAll() + lord_stack.serviceAll() + #print lord_stack.rxMsgs + +def lord(serfs=5): + ''' + Make a lord that can spawn serfs + ''' + lord_yid = 0 + dirpath = '/tmp' + lord_stack = stacking.StackUxd(name='lord', lanename='execute', yid=lord_yid, dirpath=dirpath) + lord_stack.serviceAll() + for serf_id in range(1, serfs + 1): + serf_yard = yarding.Yard(yid=serf_id, prefix='execute', dirpath=dirpath) + lord_stack.addRemoteYard(serf_yard) + proc = multiprocessing.Process(target=serf, args=(lord_stack.yard.name, lord_yid, serf_id, dirpath)) + proc.start() + + while True: + lord_stack.serviceAll() + print 'serviced lord stack' + print lord_stack.rxMsgs + for msg in lord_stack.rxMsgs: + print msg + time.sleep(1) + +def serf(lord_name, lord_yid, id_, dirpath): + ''' + Call to spawn a serf and start sending messages + ''' + serf_stack = stacking.StackUxd( + name='serf{0}'.format(id_), + lanename='execute', + yid=id_, + dirpath=dirpath) + lord_yard = yarding.Yard(yid=lord_yid, prefix='execute', dirpath=dirpath) + serf_stack.addRemoteYard(lord_yard) + src = (ESTATE, serf_stack.yard.name, None) + dst = (ESTATE, lord_name, None) + route = {'src': src, 'dst': dst} + msg = {'route': route, 'stuff': 'Serf {0} to Lord, I am not a couch'.format(id_)} + while True: + serf_stack.transmit(msg=msg) + serf_stack.serviceAll() + print 'serf messages transmitted' + time.sleep(1) + +if __name__ == '__main__': + lord() + #fudal() From 79ecd9caa67cc71dfc60d16cc7d190c16bcd2336 Mon Sep 17 00:00:00 2001 From: Samuel M Smith Date: Mon, 3 Mar 2014 11:22:02 -0700 Subject: [PATCH 3/4] minor refactor keep together --- salt/transport/road/raet/yarding.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/salt/transport/road/raet/yarding.py b/salt/transport/road/raet/yarding.py index e13b138a4d..0017053fab 100644 --- a/salt/transport/road/raet/yarding.py +++ b/salt/transport/road/raet/yarding.py @@ -38,8 +38,6 @@ class Yard(object): ''' Initialize instance ''' - if dirpath is None: - dirpath = YARD_UXD_DIR self.stack = stack if yid is None: yid = Yard.Yid @@ -51,7 +49,10 @@ class Yard(object): emsg = "Invalid Yard name '{0}'".format(self.name) raise raeting.YardError(emsg) + if dirpath is None: + dirpath = YARD_UXD_DIR self.dirpath = dirpath + if " " in prefix: emsg = "Invalid prefix '{0}'".format(prefix) raise raeting.YardError(emsg) From b9249734b0d96f4d2b4854d625f7e096088e531c Mon Sep 17 00:00:00 2001 From: Samuel M Smith Date: Mon, 3 Mar 2014 12:47:10 -0700 Subject: [PATCH 4/4] Fixed default dirpath --- salt/transport/road/raet/yarding.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/salt/transport/road/raet/yarding.py b/salt/transport/road/raet/yarding.py index 0017053fab..be406f3b88 100644 --- a/salt/transport/road/raet/yarding.py +++ b/salt/transport/road/raet/yarding.py @@ -18,7 +18,7 @@ from . import nacling from ioflo.base.consoling import getConsole console = getConsole() -YARD_UXD_DIR = os.path.join('/tmp', '.raet') +YARD_UXD_DIR = os.path.join('/tmp', 'raet')