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

vmupdater: fix #9072 #164

Merged
merged 3 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
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
10 changes: 6 additions & 4 deletions vmupdate/agent/entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ def get_package_manager(os_data, log, log_handler, log_level, no_progress):
If appropriate python package is not installed or `no_progress` is `True`
cli based version is returned.
"""
requirements = {}
# plugins MUST be applied before import anything from package managers.
# in case of apt configuration is loaded on `import apt`.
for plugin in plugins.entrypoints:
plugin(os_data, log, requirements=requirements)

if os_data["os_family"] == "Debian":
try:
from source.apt.apt_api import APT as PackageManager
Expand All @@ -82,10 +88,6 @@ def get_package_manager(os_data, log, log_handler, log_level, no_progress):
raise NotImplementedError(
"Only Debian, RedHat and ArchLinux based OS is supported.")

requirements = {}
for plugin in plugins.entrypoints:
plugin(os_data, log, requirements=requirements)

pkg_mng = PackageManager(log_handler, log_level)
pkg_mng.requirements = requirements
return pkg_mng
Expand Down
2 changes: 2 additions & 0 deletions vmupdate/agent/source/apt/apt_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ def upgrade_internal(self, remove_obsolete: bool) -> ProcessResult:
Path(os.path.join(
apt_pkg.config.find_dir("Dir::Cache::Archives"), "partial")
).mkdir(parents=True, exist_ok=True)
apt_pkg.config.set('Dpkg::Options::', "--force-confdef")
apt_pkg.config.set('Dpkg::Options::', "--force-confold")
self.log.debug("Committing upgrade...")
self.apt_cache.commit(
self.progress.fetch_progress,
Expand Down
7 changes: 6 additions & 1 deletion vmupdate/agent/source/apt/apt_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,12 @@ def get_action(self, remove_obsolete: bool) -> List[str]:
"""
Return command `upgrade` or `dist-upgrade` if `remove_obsolete`.
"""
return ["dist-upgrade"] if remove_obsolete else ["upgrade"]
result = ["-y",
"-o", 'Dpkg::Options::=--force-confdef',
"-o", 'Dpkg::Options::=--force-confold'
]
result += ["dist-upgrade"] if remove_obsolete else ["upgrade"]
return result

def clean(self) -> int:
"""
Expand Down
6 changes: 2 additions & 4 deletions vmupdate/agent/source/common/package_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,17 +267,15 @@ def get_packages(self) -> Dict[str, List[str]]:

def get_action(self, remove_obsolete: bool) -> List[str]:
"""
Return command for upgrade or upgrade with removing obsolete packages.
Return command and options for upgrade with optional removing obsoletes.
"""
raise NotImplementedError()

def upgrade_internal(self, remove_obsolete: bool) -> ProcessResult:
"""
Just run upgrade via CLI.
"""
cmd = [self.package_manager,
"--noconfirm" if self.package_manager == "pacman" else "-y",
*self.get_action(remove_obsolete)]
cmd = [self.package_manager, *self.get_action(remove_obsolete)]

return self.run_cmd(cmd)

Expand Down
4 changes: 2 additions & 2 deletions vmupdate/agent/source/dnf/dnf_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ def get_action(self, remove_obsolete) -> List[str]:
Disable or enforce obsolete flag in dnf/yum.
"""
if remove_obsolete:
return ["--obsoletes", "upgrade"]
return ["--setopt=obsoletes=0",
return ["-y", "--obsoletes", "upgrade"]
return ["-y", "--setopt=obsoletes=0",
"upgrade" if self.package_manager == "dnf" else "update"]

def clean(self) -> int:
Expand Down
2 changes: 1 addition & 1 deletion vmupdate/agent/source/pacman/pacman_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def get_action(self, remove_obsolete) -> List[str]:
"""
Pacman will handle obsoletions itself
"""
return ["-Syu"]
return ["--noconfirm", "-Syu"]

def clean(self) -> int:
"""
Expand Down