build/release/sanity.py

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/build/release/sanity.py	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,124 @@
     1.4 +import difflib
     1.5 +import logging
     1.6 +import re
     1.7 +import urllib2
     1.8 +from util.commands import run_cmd, get_output
     1.9 +from util.hg import get_repo_name, make_hg_url
    1.10 +from subprocess import CalledProcessError
    1.11 +
    1.12 +log = logging.getLogger(__name__)
    1.13 +
    1.14 +
    1.15 +def check_buildbot():
    1.16 +    """check if buildbot command works"""
    1.17 +    try:
    1.18 +        run_cmd(['buildbot', '--version'])
    1.19 +    except CalledProcessError:
    1.20 +        log.error("FAIL: buildbot command doesn't work", exc_info=True)
    1.21 +        raise
    1.22 +
    1.23 +
    1.24 +def find_version(contents, versionNumber):
    1.25 +    """Given an open readable file-handle look for the occurrence
    1.26 +       of the version # in the file"""
    1.27 +    ret = re.search(re.compile(re.escape(versionNumber), re.DOTALL), contents)
    1.28 +    return ret
    1.29 +
    1.30 +
    1.31 +def locale_diff(locales1, locales2):
    1.32 +    """ accepts two lists and diffs them both ways, returns any differences
    1.33 +    found """
    1.34 +    diff_list = [locale for locale in locales1 if not locale in locales2]
    1.35 +    diff_list.extend(locale for locale in locales2 if not locale in locales1)
    1.36 +    return diff_list
    1.37 +
    1.38 +
    1.39 +def get_buildbot_username_param():
    1.40 +    cmd = ['buildbot', 'sendchange', '--help']
    1.41 +    output = get_output(cmd)
    1.42 +    if "-W, --who=" in output:
    1.43 +        return "--who"
    1.44 +    else:
    1.45 +        return "--username"
    1.46 +
    1.47 +
    1.48 +def sendchange(branch, revision, username, master, products):
    1.49 +    """Send the change to buildbot to kick off the release automation"""
    1.50 +    if isinstance(products, basestring):
    1.51 +        products = [products]
    1.52 +    cmd = [
    1.53 +        'buildbot',
    1.54 +        'sendchange',
    1.55 +        get_buildbot_username_param(),
    1.56 +        username,
    1.57 +        '--master',
    1.58 +        master,
    1.59 +        '--branch',
    1.60 +        branch,
    1.61 +        '-p',
    1.62 +        'products:%s' % ','.join(products),
    1.63 +        '-p',
    1.64 +        'script_repo_revision:%s' % revision,
    1.65 +        'release_build'
    1.66 +    ]
    1.67 +    logging.info("Executing: %s" % cmd)
    1.68 +    run_cmd(cmd)
    1.69 +
    1.70 +
    1.71 +def verify_mozconfigs(mozconfig_pair, nightly_mozconfig_pair, platform,
    1.72 +                      mozconfigWhitelist={}):
    1.73 +    """Compares mozconfig to nightly_mozconfig and compare to an optional
    1.74 +    whitelist of known differences. mozconfig_pair and nightly_mozconfig_pair
    1.75 +    are pairs containing the mozconfig's identifier and the list of lines in
    1.76 +    the mozconfig."""
    1.77 +
    1.78 +    # unpack the pairs to get the names, the names are just for
    1.79 +    # identifying the mozconfigs when logging the error messages
    1.80 +    mozconfig_name, mozconfig_lines = mozconfig_pair
    1.81 +    nightly_mozconfig_name, nightly_mozconfig_lines = nightly_mozconfig_pair
    1.82 +
    1.83 +    missing_args = mozconfig_lines == [] or nightly_mozconfig_lines == []
    1.84 +    if missing_args:
    1.85 +        log.info("Missing mozconfigs to compare for %s" % platform)
    1.86 +        return False
    1.87 +
    1.88 +    success = True
    1.89 +
    1.90 +    diffInstance = difflib.Differ()
    1.91 +    diff_result = diffInstance.compare(mozconfig_lines, nightly_mozconfig_lines)
    1.92 +    diffList = list(diff_result)
    1.93 +
    1.94 +    for line in diffList:
    1.95 +        clean_line = line[1:].strip()
    1.96 +        if (line[0] == '-' or line[0] == '+') and len(clean_line) > 1:
    1.97 +            # skip comment lines
    1.98 +            if clean_line.startswith('#'):
    1.99 +                continue
   1.100 +            # compare to whitelist
   1.101 +            message = ""
   1.102 +            if line[0] == '-':
   1.103 +                if platform in mozconfigWhitelist.get('release', {}):
   1.104 +                    if clean_line in \
   1.105 +                            mozconfigWhitelist['release'][platform]:
   1.106 +                        continue
   1.107 +            elif line[0] == '+':
   1.108 +                if platform in mozconfigWhitelist.get('nightly', {}):
   1.109 +                    if clean_line in \
   1.110 +                            mozconfigWhitelist['nightly'][platform]:
   1.111 +                        continue
   1.112 +                    else:
   1.113 +                        log.warning("%s not in %s %s!" % (
   1.114 +                            clean_line, platform,
   1.115 +                            mozconfigWhitelist['nightly'][platform]))
   1.116 +            else:
   1.117 +                log.error("Skipping line %s!" % line)
   1.118 +                continue
   1.119 +            message = "found in %s but not in %s: %s"
   1.120 +            if line[0] == '-':
   1.121 +                log.error(message % (mozconfig_name,
   1.122 +                                     nightly_mozconfig_name, clean_line))
   1.123 +            else:
   1.124 +                log.error(message % (nightly_mozconfig_name,
   1.125 +                                     mozconfig_name, clean_line))
   1.126 +            success = False
   1.127 +    return success

mercurial