Skip to content

Commit

Permalink
In updater.py, repo list is built using YUM enabled repositories
Browse files Browse the repository at this point in the history
Signed-off-by: Ronan Abhamon <[email protected]>
  • Loading branch information
Wescoeur committed Apr 17, 2023
1 parent f75d6e6 commit b80636d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
12 changes: 8 additions & 4 deletions SOURCES/etc/xapi.d/plugins/updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ def display_package(p):
return {'name': p.name, 'version': p.version, 'release': p.release, 'description': p.summary,
'changelog': changelog, 'url': p.url, 'size': p.size, 'license': p.license}

def build_repo_list(additional_repos):
def build_repo_list(enabled_repos, additional_repos):
repos = list(DEFAULT_REPOS)
if additional_repos:
repos += [x.strip() for x in additional_repos.split(',')]
return repos
return [x.id for x in enabled_repos if x.id in repos]

def install_helper(session, args, action):
assert action in ('install', 'update')
Expand All @@ -119,7 +119,11 @@ def install_helper(session, args, action):
if action == 'install' and not packages:
raise Exception('Missing or empty argument `packages`')

repos = build_repo_list(args.get('repos'))
yum_instance = yum.YumBase()
yum_instance.preconf.debuglevel = 0
yum_instance.preconf.plugins = False
repos = build_repo_list(yum_instance.repos.listEnabled(), args.get('repos'))

task = None
res = None
error = None
Expand Down Expand Up @@ -157,10 +161,10 @@ def install(session, args):
@error_wrapped
@operationlock()
def check_update(session, args):
repos = build_repo_list(args.get('repos'))
yum_instance = yum.YumBase()
yum_instance.preconf.debuglevel = 0
yum_instance.preconf.plugins = True
repos = build_repo_list(yum_instance.repos.listEnabled(), args.get('repos'))
yum_instance.repos.disableRepo('*')
yum_instance.repos.enableRepo(','.join(repos))
packages = yum_instance.doPackageLists(pkgnarrow='updates')
Expand Down
8 changes: 8 additions & 0 deletions tests/mocked_yum.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ def enableRepo(self, repos):
def disableRepo(self, repos):
return 0

def listEnabled(self):
repos = ['xcp-ng-base', 'xcp-ng-updates', 'totoro', 'lalala', 'riri', 'fifi', 'loulou']

class RepoObject:
def __init__(self, repo):
self.id = repo
return [RepoObject(repo) for repo in repos]

class Ts:
def __init__(self):
return
Expand Down
10 changes: 10 additions & 0 deletions tests/test_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,16 @@ def test_update_with_additional_repos(self, run_command, fs):
['yum', 'update', '--disablerepo=*', '--enablerepo=' + ','.join(repos), '-y']
)

def test_update_with_disabled_repo(self, run_command, fs):
run_command.return_value = {}

repos = list(DEFAULT_REPOS)
repos.append('ignored_repo')
update(mock.MagicMock(), {'repos': 'ignored_repo'})
run_command.assert_called_once_with(
['yum', 'update', '--disablerepo=*', '--enablerepo=' + ','.join(DEFAULT_REPOS), '-y']
)

def test_update_with_additional_repos_and_packages(self, run_command, fs):
run_command.return_value = {}

Expand Down

0 comments on commit b80636d

Please sign in to comment.