Skip to content

Commit

Permalink
Ensure we always have an integer when yum history tid is fetched
Browse files Browse the repository at this point in the history
  • Loading branch information
Wescoeur committed Jul 21, 2023
1 parent b3305ec commit b428fee
Showing 1 changed file with 12 additions and 4 deletions.
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

0 comments on commit b428fee

Please sign in to comment.