Skip to content

dpkg "purge ok installed" status confuses pkg.installed #10719

Closed

Description

@boltronics

From my debug logs:

[INFO    ] Running state [curl] at time 15:52:40.171239
[INFO    ] Executing state pkg.installed for curl
[INFO    ] Executing command 'apt-get -q update' in directory '/root'
[INFO    ] Executing command ['apt-get', '-q', '-y', '-o', 'DPkg::Options::=--force-confold', '-o', 'DPkg::Options::=--force-confdef', 'install', 'curl'] in directory '/root'
[INFO    ] Executing command "dpkg-query --showformat='${Status} ${Package} ${Version} ${Architecture}\n' -W" in directory '/root'
[ERROR   ] The following packages failed to install/update: curl.

The normal output:

----------
          ID: curl
    Function: pkg.installed
      Result: False
     Comment: The following packages failed to install/update: curl.
     Changes:   
----------

Some manual execution to troubleshoot this:

# apt-get -q -y -o DPkg::Options::=--force-confold -o DPkg::Options::=--force-confdef install curl
Reading package lists...
Building dependency tree...
Reading state information...
curl is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
root@ip-10-151-76-86:~#

Also:

# dpkg-query --showformat='${Status} ${Package} ${Version} ${Architecture}\n' -W
...
purge ok installed curl 7.26.0-1+wheezy8 amd64

This situation came about because I wanted to test a state was successfully installing curl (although it must have been baked into the image anyway due to an apt-file dependency). From my xterm history:

# dpkg -P curl capcertificates
dpkg: dependency problems prevent removal of curl:
 apt-file depends on curl.
 debian-goodies depends on curl.

dpkg: error processing curl (--purge):
 dependency problems - not removing
dpkg: warning: ignoring request to remove capcertificates which isn't installed
Errors were encountered while processing:
 curl

The workaround was to manually reinstall the curl package:

# apt-get install --reinstall curl

I feel that this is a bug, and that I shouldn't have to do this to prevent a pkg.installed state failure.

# salt-call --versions-report
           Salt: 2014.1.0-1-gf5d103f
         Python: 2.7.3 (default, Jan  2 2013, 13:56:14)
         Jinja2: 2.6
       M2Crypto: 0.21.1
 msgpack-python: 0.1.10
   msgpack-pure: Not Installed
       pycrypto: 2.6
         PyYAML: 3.10
          PyZMQ: 13.1.0
            ZMQ: 3.2.3

Activity

  1. basepi commented on Feb 26, 2014

    @basepi
    Contributor

    Can you clarify exactly what was wrong with the curl install? Seems like handling edge cases in non-standard installs is heading down a rabbit hole. Just trying to clarify exactly what went wrong and what we could have done differently.

  2. added this to the milestone on Feb 26, 2014
  3. boltronics commented on Feb 27, 2014

    @boltronics
    ContributorAuthor

    The problem is that, even though I have a pkg.installed Salt state that says to install curl, it fails when the current dpkg selection state is set to purge. Note that by "fails", I mean the Salt state (and hence all dependencies) error out - this is not just a case of Salt not doing the right thing.

    This situation should be trivial to reproduce with dpkg -P curl on a Debian-based system, but of course the problem isn't package-specific. dpkg -P x11-common or the attempt at uninstalling any other package which has installed dependencies would result in the same Salt breakage, where the package is specified using pkg.installed.

    Essentially, this means that we have indicated to dpkg that we wish to purge the package, but it is unable to do so at this time due to other installed packages depending on it. It is a perfectly valid state as far as the package manager is concerned - nothing non-standard about it - but Salt should be overriding this. If we tell Salt that we want a specified package to be installed, Salt should install it (if it is not already) and set the dpkg status to installed. That is the expected behavior.

    Note that the presence of the dpkg purge selection status indicates that the package is already installed, so for illustration purposes, here's how you might solve this in bash:

    #!/bin/bash
    
    declare -r package="${1}"
    declare p_status
    declare s_state
    
    
    install_pkg()
    {
        # Presumably we ignore holds. Regardless, it's not the focus of this script.
        DEBIAN_FRONTEND=noninteractive apt-get -o Dpkg::Options::="--force-confold" \
            --ignore-hold --force-yes -y install "${package}"
    }
    
    
    p_status="$(dpkg-query --showformat='${Status} ${Package}\n' \
        -W ${package} 2>/dev/null)"
    
    # Package already has a dpkg selection status.
    if [ "${?}" -eq 0 ]
    then
        s_state="$(echo "${p_status}" | cut -d ' ' -f 1)"
    
        if [ "${s_state}" = "purge" ]
        then
            # just need to update the status
            dpkg --get-selections "${package}" | sed 's/purge/install/' | \
                dpkg --set-selections
        elif [ "${s_state}" != "install" ]
        then
            # Set to either 'deinstall' or 'hold'.
            install_pkg
        fi
    else
        install_pkg
    fi
    

    I hope that makes a bit more sense.

  4. basepi commented on Feb 27, 2014

    @basepi
    Contributor

    Ah, yes, that was exactly what I needed. I wasn't familiar with the "purge" state of a package under dpkg.

    We definitely should handle this case, thanks!

  5. modified the milestones: Outstanding Bugs, on Feb 27, 2014
  6. terminalmage commented on Mar 6, 2014

    @terminalmage
    Contributor

    @boltronics Can you test from develop? I submitted a change yesterday which should handle this, and it was merged a few hours ago.

  7. boltronics commented on Mar 6, 2014

    @boltronics
    ContributorAuthor

    Thanks @terminalmage! I can't test develop immediately, but will try to find time over the weekend.

  8. terminalmage commented on Mar 6, 2014

    @terminalmage
    Contributor

    Thanks. Regression tests on pkg installation passed, but we're not testing the edge case you brought up yet. In my testing though, on 12.04 LTS, I was able to confirm that a package marked purge is successfully set back to install.

  9. basepi commented on Mar 12, 2014

    @basepi
    Contributor

    I'm going to close this one. But if it's still an issue, @boltronics, don't hesitate to comment and we'll re-open.

  10. boltronics commented on Mar 12, 2014

    @boltronics
    ContributorAuthor

    No worries @basepi, that's fine. Perhaps needless to say, I didn't get around to testing this yet as I had anticipated - sorry.

  11. terminalmage commented on Mar 12, 2014

    @terminalmage
    Contributor

    @boltronics We're preparing for a 2014.1.1 release, so it'll be easier for you to test soon.

    I did test quite a bit in my dev environment, so I'm confident this is resolved. If you notice that this doesn't appear to be fixed in 2014.1.1, please do not hesitate to let us know.

  12. boltronics commented on Mar 12, 2014

    @boltronics
    ContributorAuthor

    Nice one - thanks! Will do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugfixed-pls-verifyseverity-low

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions