installer.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import subprocess
  2. import os
  3. import os.path
  4. import time
  5. import traceback
  6. import sys
  7. import glob
  8. import logging
  9. import setup_util
  10. from benchmark.utils import gather_tests
  11. class Installer:
  12. ############################################################
  13. # install_software
  14. ############################################################
  15. def install_software(self):
  16. linux_install_root = self.fwroot + "/toolset/setup/linux"
  17. imode = self.benchmarker.install
  18. script_vars = {
  19. 'TFB_DBHOST': self.benchmarker.database_host
  20. }
  21. l=[]
  22. for k,v in script_vars.iteritems():
  23. l.append("export %s=%s" % (k,v))
  24. script_vars_str = "\n".join(l) + "\n\n"
  25. if imode == 'all' or imode == 'database':
  26. print("\nINSTALL: Installing database software\n")
  27. self.__run_command("cd .. && " + self.benchmarker.database_sftp_string(batch_file="../config/database_sftp_batch"), True)
  28. with open (linux_install_root + "/database.sh", "r") as myfile:
  29. print("\nINSTALL: %s" % self.benchmarker.database_ssh_string)
  30. p = subprocess.Popen(self.benchmarker.database_ssh_string.split(" ") +
  31. ["bash"], stdin=subprocess.PIPE)
  32. remote_script = myfile.read()
  33. p.communicate(script_vars_str + remote_script)
  34. returncode = p.returncode
  35. if returncode != 0:
  36. self.__install_error("status code %s running subprocess '%s'." % (returncode, self.benchmarker.database_ssh_string))
  37. print("\nINSTALL: Finished installing database software\n")
  38. if imode == 'all' or imode == 'client':
  39. print("\nINSTALL: Installing client software\n")
  40. with open (linux_install_root + "/client.sh", "r") as myfile:
  41. remote_script=myfile.read()
  42. print("\nINSTALL: %s" % self.benchmarker.client_ssh_string)
  43. p = subprocess.Popen(self.benchmarker.client_ssh_string.split(" ") + ["bash"], stdin=subprocess.PIPE)
  44. p.communicate(remote_script)
  45. returncode = p.returncode
  46. if returncode != 0:
  47. self.__install_error("status code %s running subprocess '%s'." % (returncode, self.benchmarker.client_ssh_string))
  48. print("\nINSTALL: Finished installing client software\n")
  49. ############################################################
  50. # End install_software
  51. ############################################################
  52. ############################################################
  53. # __install_error
  54. ############################################################
  55. def __install_error(self, message):
  56. print("\nINSTALL ERROR: %s\n" % message)
  57. if self.benchmarker.install_error_action == 'abort':
  58. sys.exit("Installation aborted.")
  59. ############################################################
  60. # End __install_error
  61. ############################################################
  62. ############################################################
  63. # __run_command
  64. ############################################################
  65. def __run_command(self, command, send_yes=False, cwd=None):
  66. if cwd is None:
  67. cwd = self.install_dir
  68. if send_yes:
  69. command = "yes yes | " + command
  70. rel_cwd = setup_util.path_relative_to_root(cwd)
  71. print("INSTALL: %s (cwd=$FWROOT/%s)" % (command, rel_cwd))
  72. try:
  73. subprocess.check_call(command, shell=True, cwd=cwd, executable='/bin/bash')
  74. except:
  75. exceptionType, exceptionValue, exceptionTraceBack = sys.exc_info()
  76. error_message = "".join(traceback.format_exception_only(exceptionType, exceptionValue))
  77. self.__install_error(error_message)
  78. ############################################################
  79. # End __run_command
  80. ############################################################
  81. ############################################################
  82. # __init__(benchmarker)
  83. ############################################################
  84. def __init__(self, benchmarker, install_strategy):
  85. self.benchmarker = benchmarker
  86. self.install_dir = "installs"
  87. self.fwroot = benchmarker.fwroot
  88. self.strategy = install_strategy
  89. # setup logging
  90. logging.basicConfig(stream=sys.stderr, level=logging.INFO)
  91. try:
  92. os.mkdir(self.install_dir)
  93. except OSError:
  94. pass
  95. ############################################################
  96. # End __init__
  97. ############################################################
  98. # vim: sw=2