command.py 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. '''
  2. /*#############################################################################
  3. HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. ############################################################################ */
  14. '''
  15. import logging
  16. from ...common.shell import Shell
  17. from ...util.ecl.file import ECLFile
  18. from ...common.error import Error
  19. from ...util.util import queryWuid
  20. class ECLcmd(Shell):
  21. def __init__(self):
  22. self.defaults = []
  23. self.cmd = self.which('ecl')
  24. def __ECLcmd(self):
  25. return self.command(self.cmd, *self.defaults)
  26. def runCmd(self, cmd, cluster, eclfile, report, **kwargs):
  27. args = []
  28. args.append(cmd)
  29. args.append('-v')
  30. args.append('-fpickBestEngine=false')
  31. args.append('--target=' + cluster)
  32. args.append('--cluster=' + cluster)
  33. args.append('--wait='+str(eclfile.getTimeout()*1000))
  34. server = kwargs.pop('server', False)
  35. if server:
  36. args.append('--server=' + server)
  37. username = kwargs.pop('username', False)
  38. if username:
  39. args.append("--username=" + username)
  40. password = kwargs.pop('password', False)
  41. if password:
  42. args.append("--password=" + password)
  43. args = args + eclfile.getFParameters()
  44. if cmd == 'publish':
  45. args.append(eclfile.getArchive())
  46. name = kwargs.pop('name', False)
  47. if not name:
  48. name = eclfile.getBaseEclName()
  49. args.append("--name=" + name)
  50. else:
  51. args.append('--exception-level=warning')
  52. args.append('--noroot')
  53. name = kwargs.pop('name', False)
  54. if not name:
  55. name = eclfile.getJobname()
  56. args.append("--name=" + name)
  57. args = args + eclfile.getDParameters()
  58. args = args + eclfile.getStoredInputParameters()
  59. args.append(eclfile.getArchive())
  60. data = ""
  61. wuid = "N/A"
  62. state = ""
  63. results=''
  64. try:
  65. #print "runCmd:", args
  66. results = self.__ECLcmd()(*args)
  67. logging.debug("%3d. results:'%s'", eclfile.getTaskId(), results)
  68. data = '\n'.join(line for line in
  69. results.split('\n') if line) + "\n"
  70. ret = data.split('\n')
  71. result = ""
  72. cnt = 0
  73. for i in ret:
  74. logging.debug("%3d. i:'%s'", eclfile.getTaskId(), i )
  75. if "wuid:" in i:
  76. logging.debug("------ runCmd:" + repr(i) + "------")
  77. wuid = i.split()[1]
  78. if "state:" in i:
  79. state = i.split()[1]
  80. if "aborted" in i:
  81. state = "aborted"
  82. if cnt > 4:
  83. result += i + "\n"
  84. cnt += 1
  85. data = '\n'.join(line for line in
  86. result.split('\n') if line) + "\n"
  87. except Error as err:
  88. data = str(err)
  89. logging.error("------" + err + "------")
  90. raise err
  91. finally:
  92. res = queryWuid(eclfile.getJobname(), eclfile.getTaskId())
  93. logging.debug("%3d. in finally -> 'wuid':'%s', 'state':'%s', data':'%s', ", eclfile.getTaskId(), wuid, state, data)
  94. if wuid == 'N/A':
  95. logging.debug("%3d. in finally queryWuid() -> 'result':'%s', 'wuid':'%s', 'state':'%s'", eclfile.getTaskId(), res['result'], res['wuid'], res['state'])
  96. wuid = res['wuid']
  97. if res['result'] != "OK":
  98. eclfile.diff=eclfile.getBaseEcl()+'\n\t'+res['state']+'\n'
  99. logging.error("%3d. %s in queryWuid(%s)", eclfile.getTaskId(), res['state'], eclfile.getJobname())
  100. eclfile.addResults(data, wuid)
  101. if cmd == 'publish':
  102. if state == 'compiled':
  103. test = True
  104. else:
  105. test = False
  106. eclfile.diff = 'Error'
  107. else:
  108. if (res['state'] == 'aborted') or eclfile.isAborted():
  109. eclfile.diff = ("%3d. Test: %s\n") % (eclfile.taskId, eclfile.getBaseEclRealName())
  110. eclfile.diff += '\t'+'Aborted ( reason: '+eclfile.getAbortReason()+' )'
  111. test = False
  112. elif eclfile.getIgnoreResult():
  113. logging.debug("%3d. Ignore result (ecl:'%s')", eclfile.getTaskId(), eclfile.getBaseEclRealName())
  114. test = True
  115. elif eclfile.testFail():
  116. logging.debug("%3d. Fail is the expected result (ecl:'%s')", eclfile.getTaskId(), eclfile.getBaseEclRealName())
  117. test = True
  118. elif eclfile.testNoKey():
  119. # keyfile comparaison disabled with //nokey tag
  120. if eclfile.testNoOutput():
  121. #output generation disabled with //nooutput tag
  122. eclfile.diff = '-'
  123. else:
  124. eclfile.diff = ("%3d. Test: %s\n") % (eclfile.taskId, eclfile.getBaseEclRealName())
  125. eclfile.diff += data
  126. test = True
  127. elif (res['state'] == 'failed') and ('error' in data):
  128. eclfile.diff = ("%3d. Test: %s\n") % (eclfile.taskId, eclfile.getBaseEclRealName())
  129. eclfile.diff += data
  130. test = False
  131. else:
  132. test = eclfile.testResults()
  133. report.addResult(eclfile)
  134. if not test:
  135. return False
  136. else:
  137. return True