launch 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/usr/bin/env python3
  2. import argparse
  3. import os
  4. import shlex
  5. import subprocess
  6. import sys
  7. import threading
  8. import yaml
  9. sys.path.insert(0, os.getcwd())
  10. import mkconfig
  11. # The default manifest file
  12. MANIFEST = "manifest.yaml"
  13. # The default pubkeys file
  14. PUBKEYS = "pubkeys.yaml"
  15. # The TEEMS binary
  16. TEEMS = "./teems"
  17. def launch(node, manifest, config):
  18. manifestdata = manifest[node]
  19. cmdline = ''
  20. if 'launchprefix' in manifestdata:
  21. cmdline = manifestdata['launchprefix'] + ' '
  22. cmdline += TEEMS + " %s %s" % (manifestdata['sprvfile'], node)
  23. if 'args' in manifestdata:
  24. cmdline += ' ' + manifestdata['args']
  25. proc = subprocess.Popen(shlex.split(cmdline), stdin=subprocess.PIPE,
  26. stdout=subprocess.PIPE, stderr=subprocess.STDOUT, bufsize=0)
  27. proc.stdin.write(config.encode('utf-8'))
  28. while True:
  29. line = proc.stdout.readline()
  30. if not line:
  31. break
  32. print(node + ": " + line.decode('utf-8'), end='')
  33. if __name__ == "__main__":
  34. aparse = argparse.ArgumentParser(
  35. description='Launch TEEMS nodes'
  36. )
  37. aparse.add_argument('-m', default=MANIFEST,
  38. help='manifest.yaml file')
  39. aparse.add_argument('-p', default=PUBKEYS,
  40. help='pubkeys.yaml file')
  41. aparse.add_argument('-n', nargs='*', help='nodes to include')
  42. aparse.add_argument('cmd', nargs='*', help='experiment to run')
  43. args = aparse.parse_args()
  44. with open(args.m) as mf:
  45. manifest = yaml.safe_load(mf)
  46. config = mkconfig.create_json(args.m, args.p, args.n)
  47. # There must not be any newlines in the config json string
  48. if "\n" in config:
  49. print("Error: config.json must not contain embedded newlines")
  50. sys.exit(1)
  51. # Now add a trailing newline
  52. config += "\n"
  53. nodelist = args.n
  54. if nodelist is None or len(nodelist) == 0:
  55. nodelist = manifest.keys()
  56. threadlist = []
  57. for node in nodelist:
  58. if node == "params":
  59. continue
  60. thread = threading.Thread(target=launch,
  61. args=(node, manifest, config))
  62. thread.start()
  63. threadlist.append(thread)
  64. for thread in threadlist:
  65. thread.join()