Skip to content

Commit

Permalink
Prepare metadata cache before package installation
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomas Bajer committed Nov 14, 2024
1 parent b9cf8fa commit 793ac8a
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tmt/package_managers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,6 @@ def install_debuginfo(
*installables: Installable,
options: Optional[Options] = None) -> CommandOutput:
raise NotImplementedError

def refresh_metadata(self) -> CommandOutput:
raise NotImplementedError
6 changes: 6 additions & 0 deletions tmt/package_managers/apk.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ def check_presence(self, *installables: Installable) -> dict[Installable, bool]:

return results

def refresh_metadata(self) -> CommandOutput:
script = ShellScript(
f'{self.command.to_script()} update ')

return self.guest.execute(script)

def install(
self,
*installables: Installable,
Expand Down
8 changes: 8 additions & 0 deletions tmt/package_managers/apt.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,14 @@ def _extra_options(self, options: Options) -> Command:

return extra_options

def refresh_metadata(self) -> CommandOutput:
script = ShellScript(
f'{self.command.to_script()} update ')

return self.guest.execute(script, env=Environment({
'DEBIAN_FRONTEND': EnvVarValue('noninteractive')
}))

def install(
self,
*installables: Installable,
Expand Down
7 changes: 7 additions & 0 deletions tmt/package_managers/dnf.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,13 @@ def _construct_install_debuginfo_script(
f'{self.options.to_script()} {extra_options} '
f'{" ".join(escape_installables(*installables))}')

def refresh_metadata(self) -> CommandOutput:
script = ShellScript(
f'{self.command.to_script()} makecache '
f'{self.options.to_script()} --refresh ')

return self.guest.execute(script)

def install(
self,
*installables: Installable,
Expand Down
6 changes: 6 additions & 0 deletions tmt/package_managers/rpm_ostree.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ def _extra_options(

return extra_options

def refresh_metadata(self) -> CommandOutput:
script = ShellScript(
f'{self.command.to_script()} update ')

return self.guest.execute(script)

def install(
self,
*installables: Installable,
Expand Down
9 changes: 9 additions & 0 deletions tmt/steps/prepare/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,15 @@ def install_debuginfo(self) -> None:

def install(self) -> None:
""" Perform the actual installation """
try:
self._install()
except Exception:
# Refresh cache in case of recent but not updated change do repodata
self.guest.package_manager.refresh_metadata()
self._install()

def _install(self) -> None:
""" Helper method to perform the actual installation steps """
if self.local_packages:
self.prepare_install_local()
self.install_local()
Expand Down

0 comments on commit 793ac8a

Please sign in to comment.