salt icon indicating copy to clipboard operation
salt copied to clipboard

[2018.3.0] pkg.installed breaks with virtual packages

Open syphernl opened this issue 8 years ago • 11 comments

Description of Issue/Question

There are a few psuedo packages in the repo: php7.0-redis, php7.1-redis etc are all actually php-redis.

With versions prior to 2018.3.0 this worked fine. However, a highstate with a 2018.3.0 minion results in:

          ID: php7.0-redis
    Function: pkg.installed
      Result: False
     Comment: The following packages failed to install/update: php7.0-redis
     Started: 11:55:47.567707
    Duration: 422.623 ms
     Changes:   

The package is however (already) installed. Installing it by hand shows no errors:

root@testing01:~# apt install php7.0-redis
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Note, selecting 'php-redis' instead of 'php7.0-redis'
php-redis is already the newest version (4.0.0-1+ubuntu16.04.1+deb.sury.org+1).
0 upgraded, 0 newly installed, 0 to remove and 4 not upgraded.

Why is Salt giving an error? I couldn't find anything in the changelogs regarding to this. Digging some more, it appears that this may have been caused by changes done in #44455 in regards to virtual packages.

Setup

php7.0-redis:
  pkg.installed

Steps to Reproduce Issue

root@testing01:~# salt-call --local pkg.install php7.0-redis -l debug
[DEBUG   ] Reading configuration from /etc/salt/minion
[DEBUG   ] Including configuration from '/etc/salt/minion.d/99-master-address.conf'
[DEBUG   ] Reading configuration from /etc/salt/minion.d/99-master-address.conf
[DEBUG   ] Including configuration from '/etc/salt/minion.d/_schedule.conf'
[DEBUG   ] Reading configuration from /etc/salt/minion.d/_schedule.conf
[DEBUG   ] Including configuration from '/etc/salt/minion.d/mysql.conf'
[DEBUG   ] Reading configuration from /etc/salt/minion.d/mysql.conf
[DEBUG   ] Using cached minion ID from /etc/salt/minion_id: testing01.example.com
[DEBUG   ] Configuration file path: /etc/salt/minion
[WARNING ] Insecure logging configuration detected! Sensitive data may be logged.
[DEBUG   ] Grains refresh requested. Refreshing grains.
[DEBUG   ] Reading configuration from /etc/salt/minion
[DEBUG   ] Including configuration from '/etc/salt/minion.d/99-master-address.conf'
[DEBUG   ] Reading configuration from /etc/salt/minion.d/99-master-address.conf
[DEBUG   ] Including configuration from '/etc/salt/minion.d/_schedule.conf'
[DEBUG   ] Reading configuration from /etc/salt/minion.d/_schedule.conf
[DEBUG   ] Including configuration from '/etc/salt/minion.d/mysql.conf'
[DEBUG   ] Reading configuration from /etc/salt/minion.d/mysql.conf
[DEBUG   ] Loading static grains from /etc/salt/grains
[DEBUG   ] Determining pillar cache
[DEBUG   ] LazyLoaded jinja.render
[DEBUG   ] LazyLoaded yaml.render
[DEBUG   ] LazyLoaded jinja.render
[DEBUG   ] LazyLoaded yaml.render
[DEBUG   ] LazyLoaded pkg.install
[DEBUG   ] LazyLoaded pkg_resource.parse_targets
[DEBUG   ] Module DSC: Only available on Windows systems
[DEBUG   ] Module PSGet: Only available on Windows systems
[DEBUG   ] Marking 'strftime' as a jinja filter
[DEBUG   ] Could not LazyLoad pkg.normalize_name: 'pkg.normalize_name' is not available.
[INFO    ] Executing command [u'dpkg-query', u'--showformat', u'${Status} ${Package} ${Version} ${Architecture}', u'-W'] in directory '/home/ubuntu'
[INFO    ] Executing command [u'dpkg', u'--get-selections', u'*'] in directory '/home/ubuntu'
[INFO    ] Executing command [u'systemd-run', u'--scope', u'apt-get', u'-q', u'-y', u'-o', u'DPkg::Options::=--force-confold', u'-o', u'DPkg::Options::=--force-confdef', u'install', u'php7.0-redis'] in directory '/home/ubuntu'
[INFO    ] Executing command [u'dpkg-query', u'--showformat', u'${Status} ${Package} ${Version} ${Architecture}', u'-W'] in directory '/home/ubuntu'
[DEBUG   ] LazyLoaded nested.output
local:
    ----------

Versions Report

Salt Version:
           Salt: 2018.3.0
 
Dependency Versions:
           cffi: Not Installed
       cherrypy: Not Installed
       dateutil: 2.4.2
      docker-py: Not Installed
          gitdb: Not Installed
      gitpython: Not Installed
          ioflo: Not Installed
         Jinja2: 2.8
        libgit2: Not Installed
        libnacl: Not Installed
       M2Crypto: Not Installed
           Mako: 1.0.3
   msgpack-pure: Not Installed
 msgpack-python: 0.4.6
   mysql-python: 1.3.7
      pycparser: Not Installed
       pycrypto: 2.6.1
   pycryptodome: Not Installed
         pygit2: Not Installed
         Python: 2.7.12 (default, Dec  4 2017, 14:50:18)
   python-gnupg: Not Installed
         PyYAML: 3.11
          PyZMQ: 15.2.0
           RAET: Not Installed
          smmap: Not Installed
        timelib: Not Installed
        Tornado: 4.2.1
            ZMQ: 4.1.4
 
System Versions:
           dist: Ubuntu 16.04 xenial
         locale: UTF-8
        machine: x86_64
        release: 4.4.0-1054-aws
         system: Linux
        version: Ubuntu 16.04 xenial

syphernl avatar Apr 16 '18 10:04 syphernl

This is the way it has been for a while now.

This is 2017.7

ltroot@b6438e85ae6a:/srv/salt# salt \* state.apply test
b6438e85ae6a:
----------
          ID: php7.0-redis
    Function: pkg.installed
      Result: False
     Comment: Problem encountered installing package(s). Additional info follows:

              errors:
                  - Running scope as unit run-r395af39b4ef549438741985a0c0426a2.scope.
                    E: Unable to locate package php7.0-redis
                    E: Couldn't find any package by glob 'php7.0-redis'
                    E: Couldn't find any package by regex 'php7.0-redis'
     Started: 14:29:10.267277
    Duration: 5682.888 ms
     Changes:

Summary for b6438e85ae6a
------------
Succeeded: 0
Failed:    1
------------
Total states run:     1
Total run time:   5.683 s
ERROR: Minions returned with non-zero exit code

@terminalmage do you remember why resolving meta packages was removed from the pkg modules?

Thanks, Daniel

gtmanfred avatar Apr 16 '18 14:04 gtmanfred

I had seen a similar issue today, albeit with another package, and with similar results with an install attempt directly on the minion:

          ID: install_base_pkgs
    Function: pkg.latest
      Result: False
     Comment: Package libxslt-dev failed to update.50 packages were already up-to-date
     Started: 16:42:54.850657
    Duration: 7153.115 ms
     Changes:   

I experience no issues when reverting to salt 2017.7.5-ds+1 . Minion and master were running the same version.

wschmrdrNS avatar Apr 17 '18 21:04 wschmrdrNS

@gtmanfred I was not involved at all with it, so I cannot say. It seems to be related to https://github.com/saltstack/salt/issues/38838 and PR https://github.com/saltstack/salt/pull/44455 as the OP noted.

terminalmage avatar Apr 17 '18 21:04 terminalmage

@samodid it looks like you worked on this, can you take a look here?

Thanks, Daniel

gtmanfred avatar Apr 17 '18 22:04 gtmanfred

@gtmanfred I did quick test on fresh ubuntu xenial instance and run into same issue as you did

root@lab-smaster:/# salt-call --local pkg.install php7.0-redis -l debug
[DEBUG   ] Reading configuration from /etc/salt/minion
[DEBUG   ] Using cached minion ID from /etc/salt/minion_id: lab-smaster
[DEBUG   ] Configuration file path: /etc/salt/minion
[WARNING ] Insecure logging configuration detected! Sensitive data may be logged.
[DEBUG   ] Grains refresh requested. Refreshing grains.
[DEBUG   ] Reading configuration from /etc/salt/minion
[DEBUG   ] The `lspci` binary is not available on the system. GPU grains will not be available.
[DEBUG   ] Please install 'virt-what' to improve results of the 'virtual' grain.
[DEBUG   ] Determining pillar cache
[DEBUG   ] LazyLoaded jinja.render
[DEBUG   ] LazyLoaded yaml.render
[DEBUG   ] LazyLoaded jinja.render
[DEBUG   ] LazyLoaded yaml.render
[DEBUG   ] LazyLoaded pkg.install
[DEBUG   ] LazyLoaded pkg_resource.parse_targets
[DEBUG   ] Module DSC: Only available on Windows systems
[DEBUG   ] Module PSGet: Only available on Windows systems
[DEBUG   ] Marking 'strftime' as a jinja filter
[DEBUG   ] Could not LazyLoad pkg.normalize_name: 'pkg.normalize_name' is not available.
[INFO    ] Executing command [u'dpkg-query', u'--showformat', u'${Status} ${Package} ${Version} ${Architecture}', u'-W'] in directory '/root'
[INFO    ] Executing command [u'dpkg', u'--get-selections', u'*'] in directory '/root'
[INFO    ] Executing command [u'systemd-run', u'--scope', u'apt-get', u'-q', u'-y', u'-o', u'DPkg::Options::=--force-confold', u'-o', u'DPkg::Options::=--force-confdef', u'install', u'php7.0-redis'] in directory '/root'
[ERROR   ] Command '[u'systemd-run', u'--scope', u'apt-get', u'-q', u'-y', u'-o', u'DPkg::Options::=--force-confold', u'-o', u'DPkg::Options::=--force-confdef', u'install', u'php7.0-redis']' failed with return code: 100
[ERROR   ] stdout: Reading package lists...
Building dependency tree...
Reading state information...
[ERROR   ] stderr: Running scope as unit run-r796a7da7bb11467daceacecd4a6194e1.scope.
E: Unable to locate package php7.0-redis
E: Couldn't find any package by glob 'php7.0-redis'
E: Couldn't find any package by regex 'php7.0-redis'
[ERROR   ] retcode: 100
[INFO    ] Executing command [u'dpkg-query', u'--showformat', u'${Status} ${Package} ${Version} ${Architecture}', u'-W'] in directory '/root'
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/salt/cli/caller.py", line 212, in call
    ret['return'] = func(*args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/salt/modules/aptpkg.py", line 837, in install
    info={'errors': errors, 'changes': ret}
CommandExecutionError: Problem encountered installing package(s). Additional info follows:

changes:
    ----------
errors:
    - Running scope as unit run-r796a7da7bb11467daceacecd4a6194e1.scope.
      E: Unable to locate package php7.0-redis
      E: Couldn't find any package by glob 'php7.0-redis'
      E: Couldn't find any package by regex 'php7.0-redis'
Error running 'pkg.install': Problem encountered installing package(s). Additional info follows:

changes:
    ----------
errors:
    - Running scope as unit run-r796a7da7bb11467daceacecd4a6194e1.scope.
      E: Unable to locate package php7.0-redis
      E: Couldn't find any package by glob 'php7.0-redis'
      E: Couldn't find any package by regex 'php7.0-redis'


root@lab-smaster:/# salt -V
Salt Version:
           Salt: 2018.3.0
 
Dependency Versions:
           cffi: Not Installed
       cherrypy: Not Installed
       dateutil: 2.4.2
      docker-py: Not Installed
          gitdb: 0.6.4
      gitpython: 1.0.1
          ioflo: Not Installed
         Jinja2: 2.8
        libgit2: Not Installed
        libnacl: Not Installed
       M2Crypto: Not Installed
           Mako: 1.0.3
   msgpack-pure: Not Installed
 msgpack-python: 0.4.6
   mysql-python: Not Installed
      pycparser: Not Installed
       pycrypto: 2.6.1
   pycryptodome: Not Installed
         pygit2: Not Installed
         Python: 2.7.12 (default, Dec  4 2017, 14:50:18)
   python-gnupg: Not Installed
         PyYAML: 3.11
          PyZMQ: 15.2.0
           RAET: Not Installed
          smmap: 0.9.0
        timelib: Not Installed
        Tornado: 4.2.1
            ZMQ: 4.1.4
 
System Versions:
           dist: Ubuntu 16.04 xenial
         locale: UTF-8
        machine: x86_64
        release: 4.9.0-6-amd64
         system: Linux
        version: Ubuntu 16.04 xenial

As you can see from log output apt-get exit with return core 100 and that trigger error login in aptpkg module

[ERROR   ] Command '[u'systemd-run', u'--scope', u'apt-get', u'-q', u'-y', u'-o', u'DPkg::Options::=--force-confold', u'-o', u'DPkg::Options::=--force-confdef', u'install', u'php7.0-redis']' failed with return code: 100

There is not php7.0-redis package ( virtual ) on fresh xenial instance with default repo

@syphernl could you provide more info about your setup? show me output of "apt policy php7.0-redis ; apt policy php-redis"

samodid avatar Apr 18 '18 06:04 samodid

@wschmrdrNS I can reproduce your issue.

root@lab-smaster:/# salt-call --local state.single pkg.latest libxslt-dev 
[ERROR   ] Package libxslt-dev failed to update.
local:
----------
          ID: libxslt-dev
    Function: pkg.latest
      Result: False
     Comment: Package libxslt-dev failed to update.
     Started: 06:18:02.970888
    Duration: 2174.291 ms
     Changes:   

Summary for local
------------
Succeeded: 0
Failed:    1
------------
Total states run:     1
Total run time:   2.174 s
root@lab-smaster:/# dpkg -l  libxslt-dev
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                        Version            Architecture       Description
+++-===========================-==================-==================-============================================================
un  libxslt-dev                 <none>             <none>             (no description available)

@gtmanfred @terminalmage

Where were changes in states/pkg.py between 2017 and 2018 versions. I think we should look at that direction.

samodid avatar Apr 18 '18 06:04 samodid

@samodid

ubuntu@testing01:~$ apt policy php7.0-redis
php7.0-redis:
  Installed: (none)
  Candidate: (none)
  Version table:

ubuntu@testing01:~$ apt-cache showpkg php7.0-redis
Package: php7.0-redis
Versions: 

Reverse Depends: 
Dependencies: 
Provides: 
Reverse Provides: 
php-redis 4.0.0-1+ubuntu16.04.1+deb.sury.org+1 (= )

root@testing01:~# apt install php7.0-redis
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Note, selecting 'php-redis' instead of 'php7.0-redis'
php-redis is already the newest version (4.0.0-1+ubuntu16.04.1+deb.sury.org+1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

We're using this PPA for our PHP* packages

syphernl avatar Apr 18 '18 12:04 syphernl

https://github.com/saltstack/salt/pull/44455 was not the correct fix. The actual problem is that the logic in _get_virtual() which uses python-apt to get the virtual packages was not written correctly. I'm looking into how to coax the correct info out of python-apt right now.

terminalmage avatar Apr 23 '18 15:04 terminalmage

Actually, upon further investigation, it wasn't python-apt that was used incorrectly, it was the fact that the alternate code for discovering virtual packages was using grep-available when it should have been using grep-status. When switching to grep-status, and commenting out the python-apt stuff to ensure that we don't use it, the virtual packages that are identified match what python-apt comes up with.

However, the larger issue is that there really is no such thing as a "virtual package", in a true sense. Some packages have an associated list of packages which they provide. This allows you to do things like run apt-get install foo when the real package name is foo1.0, and get the right package installed.

Salt has traditionally designated as "virtual packages" ones which are provided by an installed package, but for which we have no explicitly-installed package by that name.

I'll use the nginx example from https://github.com/saltstack/salt/issues/38838 as an example here. The nginx-core package provides httpd, httpd-cgi, and nginx, so we would assume that all three of those are installed (as virtual packages, if not installed explicitly) so long as nginx-core is present.

And here's something that makes this problematic: In Ubuntu 16.04, nginx actually is a package, but it has no actual files, aside from the typical ones all (or most) packages get in /usr/share/doc. It is what is called a "dependency package". If you try installing it, then apt will go to its dependency list:

Depends: nginx-core (>= 1.10.3-0ubuntu0.16.04.2) | nginx-full (>= 1.10.3-0ubuntu0.16.04.2) | nginx-light (>= 1.10.3-0ubuntu0.16.04.2) | nginx-extras (>= 1.10.3-0ubuntu0.16.04.2), nginx-core (<< 1.10.3-0ubuntu0.16.04.2.1~) | nginx-full (<< 1.10.3-0ubuntu0.16.04.2.1~) | nginx-light (<< 1.10.3-0ubuntu0.16.04.2.1~) | nginx-extras (<< 1.10.3-0ubuntu0.16.04.2.1~)

Along with installing the nginx dependency package, it will check if any of those dependencies are met. If not, it will install the first thing in the dependency list, which is nginx-core. So, if you do an apt-get install nginx, you're installing both nginx (which has nothing of substance within it), as well as nginx-core, which pulls in nginx-common as a dependency. If you do an apt-get remove nginx, you're not really removing nginx, you're removing the dependency package called nginx; nginx-core will still be installed, and thus nginx would shift to being seen as a "virtual package". You can even just do an apt-get install nginx-core and you'll never have an nginx package installed!

I haven't looked at the php package being referenced here, but I assume there is something similar going on.

In my opinion, Salt shouldn't be dealing at all with "virtual packages". Users should be using the actual package names provided by the repositories. It's not Salt's fault when a distro does something weird like with nginx above, and we can't be expected to just automagically know what the package maintainer intended to do with various metapackages and Provides clauses, etc.

Salt already provides a function which allows users to search for packages matching a glob expression:

root@77713e1c44c2:~# salt-call --local pkg.list_repo_pkgs 'nginx*'
local:
    ----------
    nginx:
        - 1.10.3-0ubuntu0.16.04.2
        - 1.9.15-0ubuntu1
    nginx-common:
        - 1.10.3-0ubuntu0.16.04.2
        - 1.9.15-0ubuntu1
    nginx-core:
        - 1.10.3-0ubuntu0.16.04.2
        - 1.9.15-0ubuntu1
    nginx-core-dbg:
        - 1.10.3-0ubuntu0.16.04.2
        - 1.9.15-0ubuntu1
    nginx-doc:
        - 1.10.3-0ubuntu0.16.04.2
        - 1.9.15-0ubuntu1
    nginx-extras:
        - 1.10.3-0ubuntu0.16.04.2
        - 1.9.15-0ubuntu1
    nginx-extras-dbg:
        - 1.10.3-0ubuntu0.16.04.2
        - 1.9.15-0ubuntu1
    nginx-full:
        - 1.10.3-0ubuntu0.16.04.2
        - 1.9.15-0ubuntu1
    nginx-full-dbg:
        - 1.10.3-0ubuntu0.16.04.2
        - 1.9.15-0ubuntu1
    nginx-light:
        - 1.10.3-0ubuntu0.16.04.2
        - 1.9.15-0ubuntu1
    nginx-light-dbg:
        - 1.10.3-0ubuntu0.16.04.2
        - 1.9.15-0ubuntu1

This function should be more than enough in most cases for users to know what package name to use in their states.

I just don't think it is reasonable to expect Salt to deal with all of the Provides metadata. We don't do it for any other package manager, so apt is an outlier here.

I'm willing to reverse the modification made in https://github.com/saltstack/salt/pull/44455 to allow Salt to return to the prior behavior for the remainder of the 2018.3.x release cycle, but IMO we should do away completely with "virtual packages" for Fluorine.

terminalmage avatar Apr 23 '18 18:04 terminalmage

Virtual package detection has been fixed in https://github.com/saltstack/salt/pull/47250.

terminalmage avatar Apr 23 '18 19:04 terminalmage

After discussing the matter internally, we have decided to drop "virtual package" support in the upcoming Fluorine feature release, due to be released this fall. This has been done in pull request https://github.com/saltstack/salt/pull/47263.

Pull request #47250, (which undoes the change @samodid made in #44455 that completely killed virtual packages in 2018.3.0), will be part of the 2018.3.1 release. This will restore the old behavior, which will remain for the duration of the 2018.3.x release cycle.

terminalmage avatar Apr 24 '18 04:04 terminalmage