Skip to content

Commit

Permalink
Fix uninstall test for protected packages
Browse files Browse the repository at this point in the history
  • Loading branch information
Korulag committed Jul 3, 2024
1 parent e2a17d5 commit ad5ff21
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 6 deletions.
19 changes: 17 additions & 2 deletions alts/worker/runners/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,21 @@ 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
)
dnf_protected = [i.strip() for i in stdout.split('\n') if i.strip()]
if dnf_protected:
protected.extend(dnf_protected)
return list(set(protected))

def _uninstall_package(
self,
Expand Down Expand Up @@ -1055,7 +1069,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

0 comments on commit ad5ff21

Please sign in to comment.