Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure we always have an integer when yum history tid is fetched #157

Merged
merged 1 commit into from
Jul 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions lib/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,16 +261,21 @@ def get_last_yum_history_tid(self):
[...]
"""
try:
history = self.ssh(['yum', 'history', 'list', '--noplugins']).splitlines()
history_str = self.ssh(['yum', 'history', 'list', '--noplugins'])
except commands.SSHCommandFailed as e:
# yum history list fails if the list is empty, and it's also not possible to rollback
# to before the first transaction, so "0" would not be appropriate as last transaction.
# To workaround this, create transactions: install and remove a small package.
logging.info('Install and remove a small package to workaround empty yum history.')
self.yum_install(['gpm-libs'])
self.yum_remove(['gpm-libs'])
history = self.ssh(['yum', 'history', 'list', '--noplugins']).splitlines()
return history[2].split()[0]
history_str = self.ssh(['yum', 'history', 'list', '--noplugins'])

history = history_str.splitlines()
try:
return int(history[2].split()[0])
except ValueError:
raise Exception('Unable to parse correctly last yum history tid. Output\n:' + history_str)

def yum_install(self, packages, enablerepo=None):
logging.info('Install packages: %s on host %s' % (' '.join(packages), self))
Expand Down Expand Up @@ -318,9 +323,12 @@ def yum_restore_saved_state(self):
"Can't restore previous state without a package list: no saved packages list"
assert self.saved_rollback_id is not None, \
"Can't restore previous state without a package list: no rollback id"

assert isinstance(self.saved_rollback_id, int)

self.ssh([
'yum', 'history', 'rollback', '--enablerepo=xcp-ng-base,xcp-ng-testing,xcp-ng-updates',
self.saved_rollback_id, '-y'
str(self.saved_rollback_id), '-y'
])
pkgs = self.packages()
if self.saved_packages_list != pkgs:
Expand Down