saltstack / salt

Software to automate the management and configuration of any infrastructure or application at scale. Install Salt from the Salt package repositories here:
https://docs.saltproject.io/salt/install-guide/en/latest/
Apache License 2.0
14.23k stars 5.49k forks source link

pkg.latest improperly reports failure when latest package is already installed. #35747

Closed joejulian closed 8 years ago

joejulian commented 8 years ago

Description of Issue/Question

With multiple packages, pkg.latest fails if the latest packages are already installed:

# salt-call state.single pkg.latest name=lots_wife 'pkgs=[git,vim]'         
[ERROR   ] The following targeted packages failed to update. See debug log for details: (git, vim).
local:
----------
          ID: lots_wife
    Function: pkg.latest
      Result: False
     Comment: The following targeted packages failed to update. See debug log for details: (git, vim).
     Started: 12:20:03.014792
    Duration: 544.661 ms
     Changes:   

Summary for local
------------
Succeeded: 0
Failed:    1
------------
Total states run:     1
# pacman -Q git vim
git 2.9.3-1
vim 7.4.2143-1

# pacman -S --needed git vim
warning: git-2.9.3-1 is up to date -- skipping
warning: vim-7.4.2143-1 is up to date -- skipping
 there is nothing to do

Fails in Centos 7 also.

Versions Report

Salt Version:
           Salt: 2016.3.2

Dependency Versions:
           cffi: Not Installed
       cherrypy: Not Installed
       dateutil: Not Installed
          gitdb: Not Installed
      gitpython: Not Installed
          ioflo: 1.5.5
         Jinja2: 2.8
        libgit2: Not Installed
        libnacl: 1.4.5
       M2Crypto: 0.24.0
           Mako: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.4.7
   mysql-python: Not Installed
      pycparser: Not Installed
       pycrypto: 2.6.1
         pygit2: Not Installed
         Python: 2.7.12 (default, Jun 28 2016, 08:31:05)
   python-gnupg: Not Installed
         PyYAML: 3.11
          PyZMQ: 15.2.0
           RAET: 0.6.5
          smmap: Not Installed
        timelib: Not Installed
        Tornado: 4.4.1
            ZMQ: 4.1.5

System Versions:
           dist:   
        machine: x86_64
        release: 4.7.0-1-ARCH
         system: Linux
        version: Not Installed
Salt Version:
           Salt: 2016.3.2

Dependency Versions:
           cffi: Not Installed
       cherrypy: Not Installed
       dateutil: Not Installed
          gitdb: Not Installed
      gitpython: Not Installed
          ioflo: Not Installed
         Jinja2: 2.7.2
        libgit2: Not Installed
        libnacl: Not Installed
       M2Crypto: Not Installed
           Mako: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.4.7
   mysql-python: Not Installed
      pycparser: Not Installed
       pycrypto: 2.6.1
         pygit2: Not Installed
         Python: 2.7.5 (default, Nov 20 2015, 02:00:19)
   python-gnupg: Not Installed
         PyYAML: 3.10
          PyZMQ: 15.3.0
           RAET: Not Installed
          smmap: Not Installed
        timelib: Not Installed
        Tornado: 4.2.1
            ZMQ: 4.1.4

System Versions:
           dist: centos 7.2.1511 Core
        machine: x86_64
        release: 4.7.0-1-ARCH
         system: Linux
        version: CentOS Linux 7.2.1511 Core
Ch3LL commented 8 years ago

@joejulian i'm having a hard time replicating this:

sls file:

mypkgs:
  pkg.latest:
    - pkgs:
      - docker-engine
      - vivaldi-snapshot
local:
----------
          ID: mypkgs
    Function: pkg.latest
      Result: True
     Comment: The following packages were successfully installed/upgraded: vivaldi-snapshot The following packages were already up-to-date: docker-engine
     Started: 12:07:33.031168
    Duration: 86660.927 ms
     Changes:   
              ----------
              vivaldi-snapshot:
                  ----------
                  new:
                      1.3.551.37-1
                  old:
                      1.3.551.28-1

Summary for local
------------
Succeeded: 1 (changed=1)
Failed:    0
------------
Total states run:     1

It does seem like in your PR that you note you are working on a fix so if you see where the issue is thats great. I'll label as a bug and it might be a system side issue, because it seems to be workign for me on 2016.3.2.

joejulian commented 8 years ago

@Ch3LL Now run it again. You successfully upgraded a package. Upgrading no packages seems to be where the bug is.

terminalmage commented 8 years ago

This is caused by incorrect behavior of the pkg.latest_version function. It is supposed to return an empty string for packages which do not have an upgrade available (or for which there is no match in the package database).

This is fixed in https://github.com/saltstack/salt/pull/35880.

joejulian commented 8 years ago

I'll just use a for loop.

terminalmage commented 8 years ago

Uh, for what?

joejulian commented 8 years ago

{% for pkg in pkgs %}...

terminalmage commented 8 years ago

Yeah, we cleared it up via email. Unfortunately requisites check for either the name declaration or the ID declaration. It may be possible to alter the requisite system to pay attention to the sources or pkgs param when the requisite type is pkg, though.

rthille commented 1 year ago

This is caused by incorrect behavior of the pkg.latest_version function. It is supposed to return an empty string for packages which do not have an upgrade available (or for which there is no match in the package database).

This is fixed in #35880.

This seems to be an issue with mac_brew_pkg's implementation as well: https://docs.saltproject.io/en/latest/ref/modules/all/salt.modules.mac_brew_pkg.html#salt.modules.mac_brew_pkg.latest_version

bash-3.2$ salt-ssh -l info 'ci-example' state.sls_id latest_packages ci/packages
[INFO    ] Loading Saltfile from '/Users/example/mac-example/Saltfile'
[INFO    ] Caching directory '_modules/' for environment 'base'
[INFO    ] Caching directory '_states/' for environment 'base'
[INFO    ] Caching directory '_grains/' for environment 'base'
[INFO    ] Caching directory '_renderers/' for environment 'base'
[INFO    ] Caching directory '_returners/' for environment 'base'
[INFO    ] Caching directory '_output/' for environment 'base'
[INFO    ] Caching directory '_utils/' for environment 'base'
ci-example:
----------
          ID: latest_packages
    Function: pkg.latest
      Result: False
     Comment: Package ruby-build failed to update.
     Started: 14:59:14.391136
    Duration: 6462.049 ms
     Changes:   

Summary for ci-example
------------
Succeeded: 0
Failed:    1
------------
Total states run:     1
Total run time:   6.462 s
bash-3.2$ salt-ssh -l info 'ci*-example' pkg.latest_version ruby-build
[INFO    ] Loading Saltfile from '/Users/example/mac-example/Saltfile'
ci-example
    20230512
bash-3.2$