Skip to content

[BUG] GPG state module always reports success without changes #63153

Closed
@lkubb

Description

Description
gpg.present and gpg.absent check for return status like this:

salt/salt/states/gpg.py

Lines 114 to 118 in 6874185

if "result" in result and not result["result"]:
ret["result"] = result["result"]
ret["comment"].append(result["comment"])
else:
ret["comment"].append("Adding {} to GPG keychain".format(name))

but the gpg execution module reports like this:

ret = {"res": True, "message": ""}

[On a side note, no changes are reported, always.]

Setup
irrelevant

Steps to Reproduce the behavior

# /srv/salt/gpgtest.sls
This should obviously fail, right?:
  gpg.present:
    - name: invalidkey
    - keyserver: non.exist.ant

Expected behavior
Failure + explanation why

Screenshots

$ salt-call state.apply gpgtest
[WARNING ] gpg returned a non-zero error code: 2
local:
----------
          ID: This should obviously fail, right?
    Function: gpg.present
        Name: invalidkey
      Result: True
     Comment: Adding invalidkey to GPG keychain
     Started: 18:00:18.801542
    Duration: 22.402 ms
     Changes:

Summary for local
------------
Succeeded: 1
Failed:    0
------------
Total states run:     1
Total run time:  22.402 ms

Versions Report

salt --versions-report (Provided by running salt --versions-report. Please also mention any differences in master/minion versions.)
Salt Version:
          Salt: 3005.1

Dependency Versions:
          cffi: 1.14.6
      cherrypy: 18.6.1
      dateutil: 2.8.1
     docker-py: Not Installed
         gitdb: 4.0.9
     gitpython: 3.1.29
        Jinja2: 3.1.0
       libgit2: Not Installed
      M2Crypto: Not Installed
          Mako: Not Installed
       msgpack: 1.0.2
  msgpack-pure: Not Installed
  mysql-python: Not Installed
     pycparser: 2.21
      pycrypto: Not Installed
  pycryptodome: 3.9.8
        pygit2: Not Installed
        Python: 3.9.14 (main, Sep 27 2022, 00:00:00)
  python-gnupg: 0.4.8
        PyYAML: 5.4.1
         PyZMQ: 23.2.0
         smmap: 5.0.0
       timelib: 0.2.4
       Tornado: 4.5.3
           ZMQ: 4.3.4

System Versions:
          dist: rocky 9.0 Blue Onyx
        locale: utf-8
       machine: x86_64
       release: 5.14.0-70.26.1.el9_0.x86_64
        system: Linux
       version: Rocky Linux 9.0 Blue Onyx

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions