openSUSE / salt

openSUSE and SUSE patches and backports for SaltStack
Apache License 2.0
22 stars 52 forks source link

[BUG] Zypperpkg does not use the version parameter #658

Open m-czernek opened 4 months ago

m-czernek commented 4 months ago

Description When using the pkg.removed function with the version parameter to remove a specific package version, the zypperpkg module does not use the version parameter to remove only that specified package. The assumption is that the pkg module verifies that the version is installed in [0], and the zypperpkg module then removes the package without using a version in [1].

This assumption does not hold for RPM packages that enable multiple versions installed at the same time, such as the kernel package. In such cases, zypperpkg removes the package by using its name, which results in both kernel versions being removed.

For example, this SLS:

remove_previous_kernel_default:
  pkg.removed:
    - name: kernel-default
    - version: 6.4.0-150600.21.1

results in no Kernels installed:

localhost:~ # rpm -qa | grep kernel-default
kernel-default-6.9.1-1.1.x86_64
kernel-default-6.4.0-150600.21.1.x86_64
localhost:~ # salt-call --local state.sls test
local:
----------
          ID: remove_previous_kernel-default
    Function: pkg.removed
        Name: kernel-default
      Result: True
     Comment: All targeted packages were removed.
     Started: 17:03:13.430864
    Duration: 3788.295 ms
     Changes:   
              ----------
              kernel-default:
                  ----------
                  new:
                  old:
                      6.4.0-150600.21.1,6.9.1-1.1
localhost:~ # rpm -qa | grep kernel-default

[0] https://github.com/openSUSE/salt/blob/openSUSE/release/3006.0/salt/states/pkg.py#L2903-L2905 [1] https://github.com/openSUSE/salt/blob/openSUSE/release/3006.0/salt/modules/zypperpkg.py#L2150

Expected behavior Only the specified RPM package version gets removed.