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
f49232
from __future__ import print_function
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
f49232
    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':
f49232
            print("  Build host is not centos.org machine in: %s" % hdr['name'])
Athmane Madjoudj ad86dc
            ret=False
Athmane Madjoudj ad86dc
        if hdr['vendor'] != 'CentOS':
f49232
            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>':
f49232
            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):
f49232
                 print("  Bad changelog entry in: %s" % hdr['name'])
Athmane Madjoudj ad86dc
                 ret=False
Athmane Madjoudj ad86dc
        except Exception, e:
f49232
            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)