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.19k stars 5.48k forks source link

Interaction between prereq and archive.extracted #53379

Open OrangeDog opened 5 years ago

OrangeDog commented 5 years ago
/opt/foo/bar:
  file.absent:
    - prereq:
      - archive: /opt/foo

/opt/foo:
  archive.extracted:
    - source: ...
    - source_hash: ...
    - source_hash_update: true
    - enforce_toplevel: false

Instead of only running file.absent before the archive is due to be extracted, it instead runs both states on every application.

... extracted to /opt/foo/, due to absence of one or more files/dirs

Removing the file state causes the archive state to (correctly) only run when the source changes or there are files missing.

Output with test=true:

----------
          ID: /opt/foo/bar
    Function: file.absent
      Result: None
     Comment: Directory /opt/foo/bar is set for removal
     Started: 12:25:58.075050
    Duration: 0.404 ms
     Changes:
              ----------
              removed:
                  /opt/foo/bar
----------
          ID: /opt/foo
    Function: archive.extracted
      Result: None
     Comment: Archive ... would be cached (if necessary) and checked to discover if extraction is needed
     Started: 12:25:58.170252
    Duration: 1.165 ms
     Changes:

Versions Report

Salt Version:
           Salt: 2018.3.4

Dependency Versions:
           cffi: Not Installed
       cherrypy: Not Installed
       dateutil: 2.6.1
      docker-py: Not Installed
          gitdb: 2.0.3
      gitpython: 2.1.8
          ioflo: Not Installed
         Jinja2: 2.10
        libgit2: 0.26.0
        libnacl: Not Installed
       M2Crypto: 0.32.0
           Mako: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.5.6
   mysql-python: Not Installed
      pycparser: Not Installed
       pycrypto: 2.6.1
   pycryptodome: Not Installed
         pygit2: 0.26.2
         Python: 3.6.7 (default, Oct 22 2018, 11:32:17)
   python-gnupg: 0.4.1
         PyYAML: 3.12
          PyZMQ: 16.0.2
           RAET: Not Installed
          smmap: 2.0.3
        timelib: Not Installed
        Tornado: 4.5.3
            ZMQ: 4.2.5

System Versions:
           dist: Ubuntu 18.04 bionic
         locale: ISO-8859-1
        machine: x86_64
        release: 4.15.0-50-generic
         system: Linux
        version: Ubuntu 18.04 bionic
OrangeDog commented 5 years ago

52748 covers the case when test=true. Perhaps the same bug extends to non-test runs as well.

angeloudy commented 5 years ago

One of the problems is that prereq never worked the way the documentation claimed since the very begining; See #52200

The other problem is that archive.extracted can't return correct changes when test=true

I am looking at the code from latest develop branch

if source_is_local:
        cached = source_match
    else:
        if __opts__['test']:
            ret['result'] = None
            ret['comment'] = (
                'Archive {0} would be cached (if necessary) and checked to '
                'discover if extraction is needed'.format(
                    salt.utils.url.redact_http_basic_auth(source_match)
                )
            )
            return ret

if an archive is not local, the state stops here and wouldn't return any changes.

There are a few other places that need to be fixed in order to return expected changes.

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.

OrangeDog commented 4 years ago

This issue still exists.

stale[bot] commented 4 years ago

Thank you for updating this issue. It is no longer marked as stale.

Dainii commented 5 months ago

This issue is still present if someone wonder.