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

Fix uninstall test for protected packages #98

Merged
merged 2 commits into from
Jul 4, 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
20 changes: 18 additions & 2 deletions alts/worker/runners/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,22 @@ def detect_protected_packages(self):
file_protected = [i.strip() for i in stdout.split('\n') if i.strip()]
if file_protected:
protected.extend(file_protected)
return protected
protected.append('kernel-core')
dnf_command = (
r'dnf', '-q', '--qf=%{NAME}', 'repoquery', '--requires', '--resolve', '--recursive' +
' '.join(protected)
)
exit_code, stdout, stderr = self.exec_command(*dnf_command)
if exit_code != 0:
self._logger.warning(
'Cannot resolve non-uninstallable packages via DNF: %s',
dnf_command
)
return protected
dnf_protected = [i.strip() for i in stdout.split('\n') if i.strip()]
javihernandez marked this conversation as resolved.
Show resolved Hide resolved
if dnf_protected:
protected.extend(dnf_protected)
return list(set(protected))

def _uninstall_package(
self,
Expand Down Expand Up @@ -1055,7 +1070,8 @@ def check_package_existence(
if self.dist_name in CONFIG.rhel_flavors:
cmd = ('rpm', '-q', package_name)
elif self.dist_name in CONFIG.debian_flavors:
cmd = ('dpkg', '-l', package_name)
cmd = ('dpkg-query', '-Wf', r'${db:Status-Status} ${Package}\n',
package_name)
else:
raise ValueError(f'Unknown distribution: {self.dist_name}')
exit_code, stdout, stderr = self.exec_command(*cmd)
Expand Down
2 changes: 1 addition & 1 deletion resources/ansible.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ ssh_args = -o ControlMaster=auto -o ControlPersist=600s -o UserKnownHostsFile=/d
pipelining = True

[persistent_connection]
command_timeout = 1200
command_timeout = 590
30 changes: 27 additions & 3 deletions resources/roles/install_uninstall/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
---

- set_fact:
short_deb_pkg_name: "{{ pkg_name.split('=')[0] }}"
when: ansible_distribution_file_variety == 'Debian'
tags:
- uninstall_package

- name: Enable module
shell: dnf module enable -y "{{ module_name }}:{{ module_stream }}:{{ module_version }}"
when: >
Expand Down Expand Up @@ -27,24 +33,42 @@
tags:
- install_package

- name: Check RPM package is installed
shell:
cmd: "rpm -q {{ pkg_name }}"
register: rpm_installed
failed_when: rpm_installed.rc not in [0, 1]
when: ansible_facts.os_family == 'RedHat'
tags:
- uninstall_package

- name: Uninstall RPM package
shell:
cmd: "rpm -e --nodeps {{ pkg_name }}"
register: result
retries: 30
delay: 10
until: result.rc == 0
when: ansible_facts.os_family == 'RedHat'
when: ansible_facts.os_family == 'RedHat' and rpm_installed.rc == 0
tags:
- uninstall_package

- name: Check DEB package is installed
shell:
cmd: "dpkg-query -Wf '${db:Status-Status} ${Package}\n' {{ short_deb_pkg_name }}"
register: deb_installed
failed_when: deb_installed.rc not in [0, 1]
when: ansible_distribution_file_variety == 'Debian'
tags:
- uninstall_package

- name: Uninstall DEB package
shell:
cmd: "dpkg -r --force-depends {{ pkg_name }}"
cmd: "dpkg -r --force-depends {{ short_deb_pkg_name }}"
register: result
retries: 30
delay: 10
until: result.rc == 0
when: ansible_distribution_file_variety == 'Debian'
when: ansible_distribution_file_variety == 'Debian' and deb_installed.rc == 0
tags:
- uninstall_package