From fdf28e9e482412dc4bb5e25effe7f6980efa3fcf Mon Sep 17 00:00:00 2001 From: Samuel M Smith Date: Mon, 3 Mar 2014 11:18:24 -0700 Subject: [PATCH] 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()