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