Blame tests/z_centos_pkg/centos_rpm_checker.py

Athmane Madjoudj ad86dc
#!/usr/bin/python
Athmane Madjoudj ad86dc
# Author: Athmane Madjoudj <athmanem@gmail.com>
Athmane Madjoudj ad86dc
# A script that search for CentOS branding issues in installed rpm
Athmane Madjoudj ad86dc
    
Athmane Madjoudj ad86dc
import rpm
Athmane Madjoudj ad86dc
import sys
Athmane Madjoudj ad86dc
import re
Athmane Madjoudj ad86dc
    
Athmane Madjoudj 07bf75
def is_valid_changelog_entry(entry):
Athmane Madjoudj 8f3bbe
    regex = re.compile(r"\w+\ ?\w*\ ?<\b[\w\.-]+@[\w\.-]+\.\w{2,4}\b>\ ?-?\ ?[\w_\.]+-[\w_\.]+")
Athmane Madjoudj ad86dc
    if regex.match(entry) is None:
Athmane Madjoudj ad86dc
        return False
Athmane Madjoudj ad86dc
    else:
Athmane Madjoudj ad86dc
        return True
Athmane Madjoudj ad86dc
Athmane Madjoudj ad86dc
def main():
Athmane Madjoudj ad86dc
    ts=rpm.ts()
Athmane Madjoudj ad86dc
    mi=ts.dbMatch()
Athmane Madjoudj ad86dc
    # Comment the following line to check all rpms
Athmane Madjoudj ad86dc
    mi.pattern("release", rpm.RPMMIRE_GLOB, "*centos*")
Athmane Madjoudj ad86dc
    ret=True
Athmane Madjoudj ad86dc
    print "Searching for CentOS branding issues in installed rpm..."
Athmane Madjoudj ad86dc
    for hdr in mi:
Athmane Madjoudj ad86dc
        if hdr['buildhost'][-11:] != '.centos.org':
Athmane Madjoudj ad86dc
            print "  Build host is not centos.org machine in: %s" % hdr['name']
Athmane Madjoudj ad86dc
            ret=False
Athmane Madjoudj ad86dc
        if hdr['vendor'] != 'CentOS':
Athmane Madjoudj ad86dc
            print "  Vendor is not CentOS in: %s" % hdr['name']
Athmane Madjoudj ad86dc
            ret=False
Athmane Madjoudj ad86dc
        if hdr['packager'] != 'CentOS BuildSystem <http://bugs.centos.org>':
Athmane Madjoudj ad86dc
            print "  Packager is not CentOS BuildSystem in: %s" % hdr['name']
Athmane Madjoudj ad86dc
            ret=False
Athmane Madjoudj ad86dc
        try:
Athmane Madjoudj ad86dc
            changelog = hdr['changelogname'][0]
Athmane Madjoudj 07bf75
            if not is_valid_changelog_entry(changelog):
Athmane Madjoudj ad86dc
                 print "  Bad changelog entry in: %s" % hdr['name']
Athmane Madjoudj ad86dc
                 ret=False
Athmane Madjoudj ad86dc
        except Exception, e:
Athmane Madjoudj ad86dc
            print "  Errors found when reading changelog entry of: %s" % hdr['name']
Athmane Madjoudj ad86dc
            ret=False
Athmane Madjoudj ad86dc
    return ret
Athmane Madjoudj ad86dc
    
Athmane Madjoudj ad86dc
if __name__ == "__main__":
Athmane Madjoudj ad86dc
    if main():  
Athmane Madjoudj ad86dc
        print "All tests PASSED"
Athmane Madjoudj ad86dc
        sys.exit(0)
Athmane Madjoudj ad86dc
    else:
Athmane Madjoudj ad86dc
        print "Some tests FAILED"
Athmane Madjoudj ad86dc
        sys.exit(1)