initializer.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. import subprocess, os
  2. from toolset.utils.output_helper import FNULL
  3. def initialize(args):
  4. fwroot = os.getenv('FWROOT')
  5. dbuser = args.database_user
  6. dbhost = args.database_host
  7. dbiden = args.database_identity_file
  8. cluser = args.client_user
  9. clhost = args.client_host
  10. cliden = args.client_identity_file
  11. aphost = args.server_host
  12. # test ssh connections to all the machines
  13. client_conn = __check_connection(cluser, clhost, cliden, aphost)
  14. database_conn = __check_connection(dbuser, dbhost, dbiden, aphost)
  15. conn_success = client_conn and database_conn
  16. if not conn_success and not args.quiet:
  17. return __print_failure()
  18. # set up client machine
  19. if not __init_client(fwroot, cluser, clhost, cliden,
  20. args.quiet) and not args.quiet:
  21. return __print_failure()
  22. # set up database software
  23. if not __init_database(fwroot, dbuser, dbhost, dbiden,
  24. args.quiet) and not args.quiet:
  25. return __print_failure()
  26. def __print_failure():
  27. print("""
  28. -------------------------------------------------------------------------------
  29. This wizard is intended to help configure the required software on all the
  30. machines in the ecosystem specified in benchmark.cfg.
  31. Note: It is expected that you have already set up passwordless-sudo on all
  32. of the machines (app, database, client) as well as identity file based
  33. authentication and hostname setup in your hosts file.
  34. More information on this required setup can be found at:
  35. frameworkbenchmarks.readthedocs.io/en/latest/Development/Installation-Guide/
  36. Please ensure that your benchmark.cfg is correctly configured as well as all
  37. of the machines (app, database, client).
  38. -------------------------------------------------------------------------------"""
  39. )
  40. def __ssh_string(user, host, identity_file):
  41. return [
  42. "ssh", "-T", "-o", "StrictHostKeyChecking=no",
  43. "%s@%s" % (user, host), "-i", identity_file
  44. ]
  45. def __check_connection(user, host, identity_file, app_host):
  46. '''
  47. Checks that the given user and host are accessible via ssh with the given
  48. identity file and have the the following permissions:
  49. 1. passwordless sudo
  50. 2. ability to ssh back to app machine
  51. '''
  52. client_conn = True
  53. try:
  54. p = subprocess.Popen(
  55. __ssh_string(user, host, identity_file),
  56. stdin=subprocess.PIPE,
  57. stdout=FNULL,
  58. stderr=subprocess.STDOUT)
  59. p.communicate("ssh -T -o StrictHostKeyChecking=no %s" % app_host)
  60. if p.returncode:
  61. client_conn = False
  62. except Exception:
  63. client_conn = False
  64. return client_conn
  65. def __init_client(fwroot, user, host, identity_file, quiet):
  66. '''
  67. Initializes and configures the software required to run the suite on the
  68. client machine.
  69. '''
  70. if not quiet:
  71. print("INSTALL: Installing client software")
  72. with open(
  73. os.path.join(fwroot, "toolset", "setup", "linux", "client.sh"),
  74. "r") as myfile:
  75. remote_script = myfile.read()
  76. if quiet:
  77. p = subprocess.Popen(
  78. __ssh_string(user, host, identity_file),
  79. stdin=subprocess.PIPE,
  80. stdout=FNULL,
  81. stderr=subprocess.STDOUT)
  82. else:
  83. p = subprocess.Popen(
  84. __ssh_string(user, host, identity_file), stdin=subprocess.PIPE)
  85. p.communicate(remote_script)
  86. return p.returncode == 0
  87. def __init_database(fwroot, user, host, identity_file, quiet):
  88. '''
  89. Initializes and configures the software required to run the suite on the
  90. database machine.
  91. '''
  92. if not quiet:
  93. print("INSTALL: Installing database software")
  94. with open(
  95. os.path.join(fwroot, "toolset", "setup", "linux", "database.sh"),
  96. "r") as myfile:
  97. remote_script = myfile.read()
  98. if quiet:
  99. p = subprocess.Popen(
  100. __ssh_string(user, host, identity_file),
  101. stdin=subprocess.PIPE,
  102. stdout=FNULL,
  103. stderr=subprocess.STDOUT)
  104. else:
  105. p = subprocess.Popen(
  106. __ssh_string(user, host, identity_file), stdin=subprocess.PIPE)
  107. p.communicate(remote_script)
  108. return p.returncode == 0