summaryrefslogtreecommitdiffstats
path: root/src/software/test/rpmcache.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/software/test/rpmcache.py')
-rw-r--r--src/software/test/rpmcache.py52
1 files changed, 37 insertions, 15 deletions
diff --git a/src/software/test/rpmcache.py b/src/software/test/rpmcache.py
index f68f128..9a0e98a 100644
--- a/src/software/test/rpmcache.py
+++ b/src/software/test/rpmcache.py
@@ -61,7 +61,7 @@ RE_REPO = re.compile(
r'(?:^\*?)(?P<name>[^\s/]+\b)(?!\s+id)', re.MULTILINE | re.IGNORECASE)
# maximum number of packages, that will be selected for testing
-MAX_PKG_DB_SIZE = 5
+MAX_PKG_DB_SIZE = 10
# step used to iterate over package names used to check for thery dependencies
# it's a number of packages, that will be passed to yum command at once
PKG_DEPS_ITER_STEP = 50
@@ -95,6 +95,22 @@ def make_nevra(name, epoch, ver, rel, arch, with_epoch='NOT_ZERO'):
estr += ":"
return "%s-%s%s-%s.%s" % (name, estr, ver, rel, arch)
+def run_yum(*params, **kwargs):
+ """
+ Runs yum with params and returns its output
+ It's here especially to allow pass a repolist argument, that
+ specifies list of repositories, to run the command on.
+ """
+ cmd = ['yum'] + list(params)
+ repolist = kwargs.get('repolist', [])
+ if repolist:
+ cmd += ['--disablerepo=*']
+ cmd += ['--enablerepo='+r for r in repolist]
+ try:
+ return check_output(cmd)
+ except Exception:
+ import pdb;pdb.set_trace()
+
class Package(object): #pylint: disable=R0902
"""
Element of test package database. It's a container for package
@@ -244,20 +260,21 @@ def _check_single_pkg_deps(
def _check_pkg_dependencies(
installed,
dup_list,
- number_of_packages=MAX_PKG_DB_SIZE):
+ number_of_packages=MAX_PKG_DB_SIZE,
+ repolist=[]):
"""
Finds packages from dup_list with satisfied (installed) dependencies.
@param installed is a set of installed package names
@return filtered dup_list with at least number_of_packages elements.
"""
- cmd = ['yum', 'deplist']
+ yum_params = ['deplist']
dups_no_deps = []
for i in range(0, len(dup_list), PKG_DEPS_ITER_STEP):
dups_part = dup_list[i:i+PKG_DEPS_ITER_STEP]
- cmd = cmd[:2]
+ yum_params = yum_params[:1]
for dups in dups_part:
- cmd.extend([d.get_nevra(newer=False) for d in dups])
- deplist_str = check_output(cmd)
+ yum_params.extend([d.get_nevra(newer=False) for d in dups])
+ deplist_str = run_yum(*yum_params, repolist=repolist)
matches = RE_PKG_DEPS.finditer(deplist_str)
prev_match = None
for pkgs in dups_part:
@@ -283,14 +300,14 @@ def _check_pkg_dependencies(
break
return dups_no_deps
-def _sorted_db_by_size(pkgdb):
+def _sorted_db_by_size(pkgdb, repolist=[]):
"""
@param pkgdb is a list of lists of packages with common name
@return sorted instances of Package according to their size
"""
- cmd = ['yum', 'info', '--showduplicates']
- cmd.extend([ps[0].name for ps in pkgdb])
- info_str = check_output(cmd)
+ yum_params = ['info', '--showduplicates']
+ yum_params.extend([ps[0].name for ps in pkgdb])
+ info_str = run_yum(*yum_params, repolist=repolist)
pkg_sizes = {}
# to get correct ordering from "yum info" command
# { pkg_name : [(epoch, version, release), ... ] }
@@ -376,7 +393,8 @@ def is_installed(pkg, newer=True):
return call(["rpm", "--quiet", "-q", pkg]) == 0
else:
try:
- cmd = [ "rpm", "-q", "--qf", "%{EPOCH}:%{NVRA}", pkg.name ]
+ cmd = [ "rpm", "-q", "--qf", "%{EPOCH}:%{NVRA}", pkg.get_nevra(
+ newer, with_epoch='NEVER') ]
out = check_output(cmd)
epoch, nvra = out.split(':') #pylint: disable=E1103
if not epoch or epoch == "(none)":
@@ -430,7 +448,9 @@ def load_pkgdb(cache_dir=''):
#print "Loaded package database from: %s" % date_time
return pkgdb
-def get_pkg_database(force_update=False, use_cache=True, cache_dir=''):
+def get_pkg_database(force_update=False, use_cache=True,
+ cache_dir='',
+ repolist=[]):
"""
Checks yum database for available packages, that have at least two
different versions in repositories. Only not installed ones with
@@ -454,16 +474,18 @@ def get_pkg_database(force_update=False, use_cache=True, cache_dir=''):
installed = set(check_output( #pylint: disable=E1103
['rpm', '-qa', '--qf=%{NAME}\n']).splitlines())
#print "Getting all available packages"
- avail_str = check_output(['yum', 'list', 'available', '--showduplicates'])
+ avail_str = run_yum('list', 'available', '--showduplicates',
+ repolist=repolist)
# list of lists of packages with the same name, longer than 2
#print "Finding duplicates"
dups_list = _filter_duplicates(installed, avail_str)
#print "Selecting only those (from %d) with installed dependencies" % \
#len(dups_list)
selected = _check_pkg_dependencies(installed, dups_list,
- number_of_packages=MAX_PKG_DB_SIZE*5)
+ number_of_packages=MAX_PKG_DB_SIZE*5,
+ repolist=repolist)
#print "Selecting the smallest ones"
- pkgdb = _sorted_db_by_size(selected)
+ pkgdb = _sorted_db_by_size(selected, repolist=repolist)
if use_cache:
repolist = _get_repo_list()
_download_pkgdb(repolist, pkgdb, cache_dir)