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
We have had this trace in our Jenkins instance:
```
Jul 20 14:44:50 WARNING An error occurred in `exec_on_hosts_on_error_continue` for host 172.16.210.26
Backtrace:
Traceback (most recent call last):
  File "/home/vates/workspace/8.3 storage-main/lib/pool.py", line 64, in exec_on_hosts_on_error_continue
    func(h)
  File "/home/vates/workspace/8.3 storage-main/pkgfixtures.py", line 38, in <lambda>
    host.pool.exec_on_hosts_on_error_continue(lambda h: h.yum_restore_saved_state())
  File "/home/vates/workspace/8.3 storage-main/lib/host.py", line 322, in yum_restore_saved_state
    self.saved_rollback_id, '-y'
  File "/home/vates/workspace/8.3 storage-main/lib/host.py", line 57, in ssh
    decode=decode)
  File "/home/vates/workspace/8.3 storage-main/lib/commands.py", line 149, in ssh
    raise result_or_exc
lib.commands.SSHCommandFailed: SSH command (yum history rollback --enablerepo=xcp-ng-base,xcp-ng-testing,xcp-ng-updates The -y) failed with return code 1: Loaded plugins: fastestmirror
Bad transaction ID given
Error: Failed history rollback, no transaction
```

We don't have an integer during yum rollback here. Only a string: "The".
Because we don't know how this problem happens, it is interesting to make sure to always have an integer
when the transaction is started and also to throw an exception with the full yum command output in case
of problem.

Signed-off-by: Ronan Abhamon <[email protected]>
  • Loading branch information
Wescoeur committed Jul 21, 2023
1 parent 6ab0e43 commit a25def8
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 a25def8

Please sign in to comment.