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
f49232
from __future__ import print_function
Athmane Madjoudj 509fd6
Athmane Madjoudj 509fd6
import sys 
Athmane Madjoudj 6bb5a8
import datetime
9a5ec9
import os
Athmane Madjoudj 509fd6
f49232
repos = []
f49232
f49232
try:
f49232
    import yum
f49232
    base = yum.YumBase()
f49232
    repos = base.repos.listEnabled()
f49232
except Exception:
f49232
    import dnf
f49232
    base = dnf.Base()
f49232
    base.read_all_repos()
f49232
    repos = list(base.repos.iter_enabled())
f49232
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
f49232
    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
f49232
with open('/etc/centos-release') as x:
f49232
    f = x.read()
f49232
    if 'Stream' in f:
f49232
        centos_default_repos = ['appstream', 'baseos', 'extras-common']
f49232
f49232
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
f49232
print("[+] %s -> Check if non default repo is enabled" % now()) 
f49232
print(repos)
f49232
for repo in repos:
Athmane Madjoudj 509fd6
    if not repo.id in centos_default_repos:
f49232
        print('%s is enabled, should be disabled at this stage' % repo.id)
f49232
        print('[+] %s -> FAIL' % now())
Athmane Madjoudj 509fd6
        sys.exit(1)
f49232
print('[+] %s -> PASS' % now())
Athmane Madjoudj 509fd6
sys.exit(0)
Athmane Madjoudj 509fd6