Blame tests/0_common/000_centos_default_repos.py

Athmane Madjoudj 509fd6
#!/usr/bin/python
Athmane Madjoudj 509fd6
# Author: Athmane Madjoudj <athmanem@gmail.com>
Karanbir Singh d76413
#         Karanbir Singh <kbsingh@karan.org>
Athmane Madjoudj 509fd6
# Test default CentOS repos
Karanbir Singh 32fd86
# Note: since the -qa and CI setup will modify the
Karanbir Singh 32fd86
#       local repos, we need to run this tests
Karanbir Singh 32fd86
#       before those changes are made
Athmane Madjoudj 509fd6
Athmane Madjoudj 509fd6
import yum
Athmane Madjoudj 509fd6
import sys 
Athmane Madjoudj 6bb5a8
import datetime
9a5ec9
import os
Athmane Madjoudj 509fd6
Athmane Madjoudj 509fd6
yb = yum.YumBase()
9a5ec9
454cf9
def getEnvironOpt(varname,defval):
586274
    global now
454cf9
    val=defval
454cf9
    try:
454cf9
        val = int(os.environ[varname])
454cf9
    except KeyError:
454cf9
        pass
586274
    print "[+] %s -> %s:%d" % (now(),varname,val)
454cf9
    return val
9a5ec9
586274
now = lambda: datetime.datetime.today().strftime("%c")
454cf9
centos_default_repos = ['base']
454cf9
454cf9
if getEnvironOpt('UPDATES',1):
454cf9
    centos_default_repos.append('updates')
454cf9
if getEnvironOpt('EXTRAS',1):
454cf9
    centos_default_repos.append('extras')
454cf9
if getEnvironOpt('CR',1):
454cf9
    centos_default_repos.append('cr')
454cf9
if getEnvironOpt('CENTOS_KERNEL',1):
454cf9
    centos_default_repos.append('centos-kernel')
454cf9
if getEnvironOpt('FASTTRACK',0):
454cf9
    centos_default_repos.append('fasttrack')
454cf9
if getEnvironOpt('CENTOSPLUS',0):
454cf9
    centos_default_repos.append('centosplus')
9a5ec9
Athmane Madjoudj 6bb5a8
print "[+] %s -> Check if non default repo is enabled" % now() 
Athmane Madjoudj 509fd6
for repo in yb.repos.listEnabled():
Athmane Madjoudj 509fd6
    if not repo.id in centos_default_repos:
Karanbir Singh d76413
        print '%s is enabled, should be disabled at this stage' % repo.id
Athmane Madjoudj 6bb5a8
        print '[+] %s -> FAIL' % now()
Athmane Madjoudj 509fd6
        sys.exit(1)
Athmane Madjoudj 6bb5a8
print '[+] %s -> PASS' % now()
Athmane Madjoudj 509fd6
sys.exit(0)
Athmane Madjoudj 509fd6