sanity.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. import difflib
  2. import logging
  3. import re
  4. import urllib2
  5. from util.commands import run_cmd, get_output
  6. from util.hg import get_repo_name, make_hg_url
  7. from subprocess import CalledProcessError
  8. log = logging.getLogger(__name__)
  9. def check_buildbot():
  10. """check if buildbot command works"""
  11. try:
  12. run_cmd(['buildbot', '--version'])
  13. except CalledProcessError:
  14. log.error("FAIL: buildbot command doesn't work", exc_info=True)
  15. raise
  16. def find_version(contents, versionNumber):
  17. """Given an open readable file-handle look for the occurrence
  18. of the version # in the file"""
  19. ret = re.search(re.compile(re.escape(versionNumber), re.DOTALL), contents)
  20. return ret
  21. def locale_diff(locales1, locales2):
  22. """ accepts two lists and diffs them both ways, returns any differences
  23. found """
  24. diff_list = [locale for locale in locales1 if not locale in locales2]
  25. diff_list.extend(locale for locale in locales2 if not locale in locales1)
  26. return diff_list
  27. def get_buildbot_username_param():
  28. cmd = ['buildbot', 'sendchange', '--help']
  29. output = get_output(cmd)
  30. if "-W, --who=" in output:
  31. return "--who"
  32. else:
  33. return "--username"
  34. def sendchange(branch, revision, username, master, products):
  35. """Send the change to buildbot to kick off the release automation"""
  36. if isinstance(products, basestring):
  37. products = [products]
  38. cmd = [
  39. 'buildbot',
  40. 'sendchange',
  41. get_buildbot_username_param(),
  42. username,
  43. '--master',
  44. master,
  45. '--branch',
  46. branch,
  47. '-p',
  48. 'products:%s' % ','.join(products),
  49. '-p',
  50. 'script_repo_revision:%s' % revision,
  51. 'release_or_beta'
  52. ]
  53. logging.info("Executing: %s" % cmd)
  54. run_cmd(cmd)
  55. def verify_mozconfigs(mozconfig_pair, nightly_mozconfig_pair, platform,
  56. mozconfigWhitelist={}):
  57. """Compares mozconfig to nightly_mozconfig and compare to an optional
  58. whitelist of known differences. mozconfig_pair and nightly_mozconfig_pair
  59. are pairs containing the mozconfig's identifier and the list of lines in
  60. the mozconfig."""
  61. # unpack the pairs to get the names, the names are just for
  62. # identifying the mozconfigs when logging the error messages
  63. mozconfig_name, mozconfig_lines = mozconfig_pair
  64. nightly_mozconfig_name, nightly_mozconfig_lines = nightly_mozconfig_pair
  65. missing_args = mozconfig_lines == [] or nightly_mozconfig_lines == []
  66. if missing_args:
  67. log.info("Missing mozconfigs to compare for %s" % platform)
  68. return False
  69. success = True
  70. diffInstance = difflib.Differ()
  71. diff_result = diffInstance.compare(mozconfig_lines, nightly_mozconfig_lines)
  72. diffList = list(diff_result)
  73. for line in diffList:
  74. clean_line = line[1:].strip()
  75. if (line[0] == '-' or line[0] == '+') and len(clean_line) > 1:
  76. # skip comment lines
  77. if clean_line.startswith('#'):
  78. continue
  79. # compare to whitelist
  80. message = ""
  81. if line[0] == '-':
  82. if platform in mozconfigWhitelist.get('release', {}):
  83. if clean_line in \
  84. mozconfigWhitelist['release'][platform]:
  85. continue
  86. elif line[0] == '+':
  87. if platform in mozconfigWhitelist.get('nightly', {}):
  88. if clean_line in \
  89. mozconfigWhitelist['nightly'][platform]:
  90. continue
  91. else:
  92. log.warning("%s not in %s %s!" % (
  93. clean_line, platform,
  94. mozconfigWhitelist['nightly'][platform]))
  95. else:
  96. log.error("Skipping line %s!" % line)
  97. continue
  98. message = "found in %s but not in %s: %s"
  99. if line[0] == '-':
  100. log.error(message % (mozconfig_name,
  101. nightly_mozconfig_name, clean_line))
  102. else:
  103. log.error(message % (nightly_mozconfig_name,
  104. mozconfig_name, clean_line))
  105. success = False
  106. return success