[PUP-6324] DNF provider cannot update packages (install command will not update) Created: 2016/05/19  Updated: 2016/10/05  Resolved: 2016/06/29

Status: Resolved
Project: Puppet
Component/s: None
Affects Version/s: PUP 4.5.0
Fix Version/s: None

Type: Bug Priority: Normal
Reporter: Peter Souter Assignee: Unassigned
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Relates
relates to PUP-6798 Ensuring latest does not use upgrade ... Closed
Template:

 Description   

tl;dr dnf install will not install a newer version of a package if it's already installed:

[root@fedora-22-x64 vagrant]# /bin/dnf -y install cockpit
Last metadata expiration check performed 0:18:07 ago on Thu May 19 13:40:06 2016.
Package cockpit-0.67-2.fc22.x86_64 is already installed, skipping.
Dependencies resolved.
Nothing to do.
Complete!

Full log of proof:

[root@fedora-22-x64 vagrant]# rpm -qa cockpit
cockpit-0.67-2.fc22.x86_64
[root@fedora-22-x64 vagrant]# dnf list cockpit
Last metadata expiration check performed 0:17:14 ago on Thu May 19 13:40:06 2016.
Installed Packages
cockpit.x86_64                                     0.67-2.fc22                                       @System
Available Packages
cockpit.src                                        0.106-1.fc22                                      group_cockpit-cockpit-preview
cockpit.x86_64                                     0.106-1.fc22                                      group_cockpit-cockpit-preview
[root@fedora-22-x64 vagrant]# puppet resource package cockpit
package { 'cockpit':
  ensure => '0.67-2.fc22',
}
[root@fedora-22-x64 vagrant]# puppet resource package cockpit ensure=latest --debug
Debug: Prefetching dnf resources for package
Debug: Executing: '/bin/rpm --version'
Debug: Executing '/bin/rpm -qa --nosignature --nodigest --qf '%{NAME} %|EPOCH?{%{EPOCH}}:{0}| %{VERSION} %{RELEASE} %{ARCH}\n''
Debug: Executing: '/bin/dnf check-update'
Debug: /Package[cockpit]/ensure: cockpit "0.67-2.fc22" is installed, latest is "0:0.94-1.fc22"
Debug: Package[cockpit](provider=dnf): Ensuring => latest
Debug: Executing: '/bin/dnf -d 0 -e 1 -y install cockpit'
Notice: /Package[cockpit]/ensure: ensure changed '0.67-2.fc22' to '0:0.94-1.fc22'
Debug: Finishing transaction 36208880
Debug: Storing state
Debug: Stored state in 0.01 seconds
Debug: Executing: '/bin/rpm -q cockpit --nosignature --nodigest --qf %{NAME} %|EPOCH?{%{EPOCH}}:{0}| %{VERSION} %{RELEASE} %{ARCH}\n'
package { 'cockpit':
  ensure => '0.67-2.fc22',
}
[root@fedora-22-x64 vagrant]# /bin/dnf -y install cockpit
Last metadata expiration check performed 0:18:07 ago on Thu May 19 13:40:06 2016.
Package cockpit-0.67-2.fc22.x86_64 is already installed, skipping.
Dependencies resolved.
Nothing to do.
Complete!
[root@fedora-22-x64 vagrant]# /bin/dnf -y upgrade cockpit
Last metadata expiration check performed 0:18:26 ago on Thu May 19 13:40:06 2016.
Dependencies resolved.
==================================================================================================================================
 Package                              Arch         Version                              Repository                           Size
==================================================================================================================================
Installing:
 cockpit-networkmanager               noarch       0.106-1.fc22                         group_cockpit-cockpit-preview        42 k
 cockpit-storaged                     noarch       0.106-1.fc22                         group_cockpit-cockpit-preview        52 k
 device-mapper-multipath              x86_64       0.4.9-73.fc22                        fedora                              116 k
 device-mapper-multipath-libs         x86_64       0.4.9-73.fc22                        fedora                              215 k
 iscsi-initiator-utils                x86_64       6.2.0.873-25.gitc9d830b.fc22         fedora                              423 k
 iscsi-initiator-utils-iscsiuio       x86_64       6.2.0.873-25.gitc9d830b.fc22         fedora                               83 k
 libstoraged                          x86_64       2.1.2-1.fc22                         group_cockpit-cockpit-preview       119 k
 python3                              x86_64       3.4.2-6.fc22                         updates                              53 k
 python3-libs                         x86_64       3.4.2-6.fc22                         updates                             6.6 M
 python3-pip                          noarch       6.0.8-1.fc22                         fedora                              1.7 M
 python3-setuptools                   noarch       17.1.1-3.fc22                        updates                             406 k
 storaged                             x86_64       2.1.2-1.fc22                         group_cockpit-cockpit-preview       360 k
 storaged-lvm2                        x86_64       2.1.2-1.fc22                         group_cockpit-cockpit-preview        64 k
Upgrading:
 cockpit                              x86_64       0.106-1.fc22                         group_cockpit-cockpit-preview        43 k
 cockpit-bridge                       x86_64       0.106-1.fc22                         group_cockpit-cockpit-preview       184 k
 cockpit-docker                       x86_64       0.106-1.fc22                         group_cockpit-cockpit-preview        51 k
 cockpit-shell                        noarch       0.106-1.fc22                         group_cockpit-cockpit-preview       727 k
 cockpit-ws                           x86_64       0.106-1.fc22                         group_cockpit-cockpit-preview       487 k
 
Transaction Summary
==========================================================================e



 Comments   
Comment by William Hopper [ 2016/05/19 ]

A few useful links:

Yum manuals for RedHat 5, 6, and 7: https://access.redhat.com/solutions/9934
DNF reference: http://www.liquidweb.com/kb/dnf-dandified-yum-command-examples-install-remove-upgrade-and-downgrade/

It looks like every version of Yum since RedHat 5 uses yum update package_name, while DNF uses dnf upgrade package_name. In DNF, update has been deprecated in favor of upgrade.

Comment by Peter Souter [ 2016/05/19 ]

Some background reading as to why I picked update for yum and upgrade for dnf:

In yum both `upgrade` and `update` can be used to update packages
`yum upgrade` == `yum --obsoletes update`
Quote the DNF docs:
Yum does this if its obsoletes config option is enabled but
the behavior is not properly documented and can be harmful.
So we'll stick with the safter option
If a user wants to remove obsoletes, they can use { :install_options => '--obsoletes' }
More detail here: https://bugzilla.redhat.com/show_bug.cgi?id=1096506

If any RHEL peeps are reading this and thing my assumptions are wrong, feel free to PR, I just went for the least destructive option

Comment by Juan Campo [ 2016/10/04 ]

I still see the bug.
Yum and dnf are still trying to run install when a package is marked as "latest" and there is a new version.
In this case, yum will update the package anyway, while dnf will refuse to do so (and not fail).

Comment by Peter Souter [ 2016/10/04 ]

Juan Campo What Puppet release are you using? This was tested on 4.5 at release and latest worked, using Fedora 23 and cockpit package.

Comment by Juan Campo [ 2016/10/04 ]

I have seen this issue in most (all?) fedora installations that use dnf, with various puppet versions.
For reference, it's definitely failing now with Puppet 4.7 on fedora 24.

I've dug a bit more:
The yum.rb code I have sets the operation variable to install, and then never changes it if ensure is a Symbol (which it is, if it's set to latest).
Therefore puppet will run dnf install -y .... which fails to update an already installed package when there is a new version available.

Is this already fixed? The patch for this bug seems to change the operation for a dnf update, but that code is never reached in this scenario, AFAICS

Comment by Peter Souter [ 2016/10/05 ]

Juan Campo can you post the code to recreate the issue?

Comment by Juan Campo [ 2016/10/05 ]

I meant the code of the default yum provider in puppet 4.7, from line 154 in the install function:

    should = @resource.should(:ensure)
    self.debug "Ensuring => #{should}"
    operation = :install
 
    case should
    when true, false, Symbol
      # pass
      should = nil
    else
          (...)
          operation = update_command
    end

As you can see, when ensure is latest, operation stays install.
This is broken for dnf, as it will not upgrade an existing package.

Note that dnf does not fail in this case. It just successfully does nothing.
So puppet reports the update, but the installed package version remains unchanged.

Comment by Peter Souter [ 2016/10/05 ]

Hmm, ok in the test I did just now where I install cockpit ensure => '0.79-1.fc23', then do a second run where I install latest, 0.96-1.fc23 is successfully installed. Puppet 4.7.0

Let me run it again because it's a docker container so it might have a clean-test box issue.

Comment by Peter Souter [ 2016/10/05 ]

The code you listed above uses the `update_command` class variable, which is changed to upgrade on DNF:

  def self.update_command
    # In DNF, update is deprecated for upgrade
    'upgrade'
  end

Just tested and confirmed, the upgrade change works for dnf from Puppet 4.5.0

package{ 'cockpit':
  ensure   => '0.55-1.fc22',
  provider => dnf,
}

fedora-22-x64 20:41:35$ puppet apply --verbose --detailed-exitcodes /tmp/apply_manifest.pp.macb08
  Notice: Compiled catalog for fedora-22-x64.home in environment production in 0.67 seconds
  Info: Applying configuration version '1475696496'
  Notice: /Stage[main]/Main/Package[cockpit]/ensure: created
  Notice: Applied catalog in 15.37 seconds

package{ 'cockpit':
  ensure   => 'latest',
  provider => dnf,
}

fedora-22-x64 20:41:53$ puppet apply --verbose --detailed-exitcodes /tmp/apply_manifest.pp.dkLnpq
  Notice: Compiled catalog for fedora-22-x64.home in environment production in 0.63 seconds
  Info: Applying configuration version '1475696513'
  Notice: /Stage[main]/Main/Package[cockpit]/ensure: ensure changed '0.55-1.fc22' to '0:0.67-2.fc22'
  Notice: Applied catalog in 1.53 seconds

Juan Campo can you post the Puppet manifest that's causing the issue and what version of Puppet you're using?

Comment by Juan Campo [ 2016/10/05 ]

The code you listed above uses the `update_command` class variable, which is changed to upgrade on DNF:

It does not, because should is a Symbol. The only thing that happens in the code above is that should is set to nil.

I see the same output from puppet as you. However, the old cockpit package is still installed in the system.

Comment by Peter Souter [ 2016/10/05 ]

Huh, you're right...

fedora-22-x64 21:16:53$ puppet apply --verbose --detailed-exitcodes /tmp/apply_manifest.pp.qf80AA
  Notice: Compiled catalog for fedora-22-x64.home in environment production in 0.59 seconds
  Warning: Found multiple default providers for package: dnf_update, dnf; using dnf_update
  Info: Applying configuration version '1475698614'
  Notice: /Stage[main]/Main/Package[cockpit]/ensure: ensure changed '0.55-1.fc22' to '0:0.67-2.fc22'
  Notice: Applied catalog in 1.52 seconds

fedora-22-x64 21:16:57$ /bin/sh -c rpm\ -qa\ \|\ grep\ cockpit
  cockpit-docker-0.55-1.fc22.x86_64
  cockpit-ws-0.55-1.fc22.x86_64
  cockpit-bridge-0.55-1.fc22.x86_64
  cockpit-0.55-1.fc22.x86_64
  cockpit-shell-0.55-1.fc22.noarch

Comment by Peter Souter [ 2016/10/05 ]

Juan Campo moving into new ticket (https://tickets.puppetlabs.com/browse/PUP-6798)

Generated at Mon Oct 21 08:14:54 PDT 2019 using JIRA 7.7.1#77002-sha1:e75ca93d5574d9409c0630b81c894d9065296414.