salt icon indicating copy to clipboard operation
salt copied to clipboard

gitfs not writing actual files

Open dizzythinks opened this issue 10 years ago • 12 comments

I have a problem with specific formulas not pulling from git correctly with GitPython. I'm using gitfs just fine and its works for everything but no matter where I put two particular formulas i.e. if I use forks, use the official saltstack repo, move the files from a formula into another repo, they are not being written to disk in the cache, even thought the commit hashes say they are and Salt believes they exist.

The two formulas are: https://github.com/saltstack-formulas/mysql-formula and https://github.com/saltstack-formulas/sensu-formula

Here the snipped remote_map.txt in /var/cache/salt/master/gitfs

    # gitfs_remote map as of 18 Mar 2016 06:42:18.318116
    7eb92ad81455937d0e24f0d40458461d = https://github.com/saltstack-formulas/sensu-formula.git
    525a56016ff11a8a4530e50a13ebabc2 = https://github.com/saltstack-formulas/mysql-formula.git

Git log from the checked out part

    /var/cache/salt/master/gitfs/7eb92ad81455937d0e24f0d40458461d# git log --all
    commit ed3288495fffcd2ff58525cf13a4d8259d92a8cd
    Merge: 9ee0962 017dd79
    Author: Forrest <[email protected]>
    Date:   Wed Jan 27 21:22:45 2016 -0800

        Merge pull request #24 from envintus/master

        added check name to pillar example

    commit 017dd7933b23e1cd584a4e4a848f8d52222061ce
    Author: Hunter Satterwhite <[email protected]>
    Date:   Thu Jan 28 00:06:05 2016 -0500

        added check name to pillar example



    /var/cache/salt/master/gitfs/525a56016ff11a8a4530e50a13ebabc2# git log --all
    commit 9152d88cbf898bb459ae0a9a506d4407d89c4e0e
    Merge: 83b865a 3bc3026
    Author: Forrest <[email protected]>
    Date:   Thu Feb 25 10:49:55 2016 -0800

        Merge pull request #109 from HealthForge/master

        Allow loading into remote databases

    commit 3bc30263c3599b410c3a6123e980880392f2fe11
    Author: jam13 <[email protected]>
    Date:   Thu Feb 25 17:08:16 2016 +0000

        Allow loading into remote databases

When I run salt-run to check the file salt says they're there.

    salt-run fileserver.file_list | grep mysql
    - mysql/client.sls
    - mysql/config.sls
    - mysql/database.sls
    - mysql/defaults.yaml
    - mysql/dev.sls
    - mysql/disabled.sls
    - mysql/files/client.cnf
    - mysql/files/my-include.cnf
    - mysql/files/my.cnf
    - mysql/files/mysql-clients.cnf
    - mysql/files/server.cnf
    - mysql/files/usr-my.cnf
    - mysql/init.sls
    - mysql/python.sls
    - mysql/remove_test_database.sls
    - mysql/salt-user.sls
    - mysql/server.sls
    - mysql/supported_sections.yaml
    - mysql/user.sls


    salt-run fileserver.file_list | grep sensu
    - sensu/api.sls
    - sensu/api_conf.sls
    - sensu/client.sls
    - sensu/configfile_map.jinja
    - sensu/files/conf.d/check_cron.json
    - sensu/files/extensions/.gitignore
    - sensu/files/handlers/.gitignore
    - sensu/files/mutators/.gitignore
    - sensu/files/plugins/check-procs.rb
    - sensu/files/windows/sensu-client.xml
    - sensu/init.sls
    - sensu/pillar_map.jinja
    - sensu/rabbitmq_conf.sls
    - sensu/redis_conf.sls
    - sensu/server.sls
    - sensu/service_map.jinja
    - sensu/uchiwa.sls

Yet:

    root@host:~# ls -trla /var/cache/salt/master/gitfs/refs/base/mysql
    ls: cannot access /var/cache/salt/master/gitfs/refs/base/mysql: No such file or directory
    root@host:~# ls -trla /var/cache/salt/master/gitfs/refs/base/sensu
    ls: cannot access /var/cache/salt/master/gitfs/refs/base/sensu: No such file or directory

All my other forumlas work just fine e.g.

    root@host:~# ls -trla /var/cache/salt/master/gitfs/refs/base/tomcat
    total 28
    -rw-r--r--  1 root root   28 Mar 18 06:44 init.sls
    -rw-r--r--  1 root root 2780 Mar 18 06:44 package.sls
    -rw-r--r--  1 root root 1196 Mar 18 06:44 map.jinja
    -rw-r--r--  1 root root 2212 Mar 18 06:44 ssl.sls
    drwxr-xr-x  3 root root 4096 Mar 18 06:44 .
    drwxr-xr-x  2 root root 4096 Mar 18 06:44 files
    drwxr-xr-x 16 root root 4096 Mar 18 06:44 ..

Here's my version

    root@host:~# salt --versions
    Salt Version:
               Salt: 2015.8.5

    Dependency Versions:
             Jinja2: 2.7.2
           M2Crypto: Not Installed
               Mako: 0.9.1
             PyYAML: 3.10
              PyZMQ: 14.0.1
             Python: 2.7.6 (default, Jun 22 2015, 17:58:13)
               RAET: Not Installed
            Tornado: 4.2.1
                ZMQ: 4.0.4
               cffi: 1.5.2
           cherrypy: 3.2.2
           dateutil: 2.4.2
              gitdb: 0.5.4
          gitpython: 0.3.2 RC1
              ioflo: Not Installed
            libgit2: Not Installed
            libnacl: Not Installed
       msgpack-pure: Not Installed
     msgpack-python: 0.3.0
       mysql-python: 1.2.3
          pycparser: 2.14
           pycrypto: 2.6.1
             pygit2: Not Installed
       python-gnupg: Not Installed
              smmap: 0.8.2
            timelib: Not Installed

    System Versions:
               dist: Ubuntu 14.04 trusty
            machine: x86_64
            release: 3.13.0-48-generic
             system: Ubuntu 14.04 trusty

I even tried adding another repo of my own with a test file in it but that behaved the same way too. I've been looking at the PythonGit util in salt and it's almost as if the writing of these repos is just failing silently. Anyhelp greatly appreciated.

dizzythinks avatar Mar 18 '16 06:03 dizzythinks

@dizzythinks, thanks for the report.

jfindlay avatar Mar 18 '16 19:03 jfindlay

@jfindlay given all the tags does this mean I'm not going insane?

dizzythinks avatar Mar 18 '16 20:03 dizzythinks

@dizzythinks, if you say that the files are not being cached on the master where they should be, I'm willing to consider this a bug so long as it can be reproduced and fixed.

jfindlay avatar Mar 18 '16 21:03 jfindlay

Not sure if it is related to this one from last year perhaps? https://github.com/saltstack/salt/issues/26149

dizzythinks avatar Mar 19 '16 17:03 dizzythinks

@terminalmage This is probably one that you'll want to be aware of.

rallytime avatar Apr 08 '16 20:04 rallytime

Files aren't written to the cache until they are requested by the minion, at which time they're assembled from the blobs in the subdirectories referenced in the remote_map.txt. There should not be any expectation that the entire contents of the repo are reproduced in /var/cache/salt/master/gitfs/refs, that's just not how gitfs works.

Are the minions failing to cache files from these gitfs repos? What happens when you run salt myminion cp.cache_file salt://sensu/api.sls? What is the output from that command, and what are the contents of /var/cache/salt/master/gitfs/refs/base/sensu on the master after running it? Have you tried running the master with debug logging?

terminalmage avatar Apr 08 '16 20:04 terminalmage

@dizzythinks It has been about 5 weeks since I asked my questions, can you provide an update?

terminalmage avatar May 13 '16 16:05 terminalmage

Apologies. I seem to have missed the alerts. This mysteriously started working again. I will close. Apologies again.

dizzythinks avatar May 16 '16 07:05 dizzythinks

For the record I experienced the same issue and found where it comes from.

the directory /var/cache/salt/master/gitfs/refs/base/ is modified when you run salt states.

Following the example of @dizzythinks we can do this :

rm -rf /var/cache/salt/master/gitfs/refs/base/*
salt-run fileserver.update  # may not be necessary
salt '*' state.sls sensu test=True  # You can reduce the scope to make it shorter

You will see that /var/cache/salt/master/gitfs/refs/base/sensu is populated with some file. If you hve still files missing it means you have sub states in this formula like sensu.client or sensu.YY.

This actually illustrates what @terminalmage said before.

Hope it can helps someone, someday 😃

Seb-Solon avatar Dec 13 '16 18:12 Seb-Solon

@Seb-Solon Not specifically when you run states, but when any file is requested from gitfs. That could be a top file or SLS file if you are keeping your Salt configuration in gitfs, or it would also happen if you do something like salt someminion cp.cache_file salt://path/to/file, assuming salt://path/to/file is in gitfs.

/var/cache/salt/master/gitfs/refs/<environment> is simply used as a destination for files pulled from gitfs. Because gitfs maps branches and tags to environments, and a single gitfs repo could provide any number of environments, gitfs never actually checks out the repo. If you cd to the cachedir for a given repo (as specified in the remote_map.txt), you shouldn't see any files. We don't care about them, all we care about in the cachedir is its .git directory. Gitfs will use git Python bindings (GitPyhon, pygit2, or dulwich) to check if a file is available at a specific path in a specific branch/tag of a repo and, if present, will assemble that file out of the git objects. But we need a place to store that assembled file so that the master can serve it up to satisfy a fileclient's request for the file. That's where /var/cache/salt/master/gitfs/refs/<environment> comes in. It should never be seen as an authoritative snapshot of a repo, the files stored in there merely represent the state of the file the most recent time it was requested. /var/cache/salt/master/gitfs/refs/base/foo/bar/baz.txt would represent salt://foo/bar/baz.txt pulled from the base environment (i.e. the master branch).

terminalmage avatar Dec 13 '16 18:12 terminalmage

I am having the same issue, one gitfs_remote seems to flicker between being there and not being there. (saltmaster is also a minion)

gitfs_remotes:
   - git://github.com/saltstack-formulas/letsencrypt-formula.git
   - git://github.com/saltstack-formulas/shorewall-formula.git
user@saltmaster:/var/cache/salt/master$ sudo salt-run fileserver.file_list
- CHANGELOG.rst
- LICENSE
- README.rst
- docker/default/docker
- docker/init.sls
- letsencrypt/config.sls
- letsencrypt/defaults.yaml
- letsencrypt/domains.sls
- letsencrypt/files/renew_letsencrypt_cert.sh.jinja
- letsencrypt/init.sls
- letsencrypt/install.sls
- letsencrypt/map.jinja
- nginx/conf/mime.types
- nginx/fastcgi.conf
- nginx/init.sls
- nginx/nginx.conf
- nginx/proxy.conf
- pillar.example
- top.sls
user@saltmaster:/var/cache/salt/master$ sudo salt-run fileserver.update backend=git
True
user@saltmaster:/var/cache/salt/master$ sudo salt-run fileserver.file_list
- .gitignore
- CHANGELOG.rst
- LICENSE
- README.rst
- VERSION
- docker/default/docker
- docker/init.sls
- letsencrypt/config.sls
- letsencrypt/defaults.yaml
- letsencrypt/domains.sls
- letsencrypt/files/renew_letsencrypt_cert.sh.jinja
- letsencrypt/init.sls
- letsencrypt/install.sls
- letsencrypt/map.jinja
- nginx/conf/mime.types
- nginx/fastcgi.conf
- nginx/init.sls
- nginx/nginx.conf
- nginx/proxy.conf
- pillar.example
- shorewall/etcdefault.sls
- shorewall/files/etcdefault.jinja
- shorewall/files/interfaces.jinja
- shorewall/files/macro.SaltMaster
- shorewall/files/masq.jinja
- shorewall/files/params.jinja
- shorewall/files/policy.jinja
- shorewall/files/routestopped.jinja
- shorewall/files/rules.jinja
- shorewall/files/tcclasses.jinja
- shorewall/files/tcdevices.jinja
- shorewall/files/tcinterfaces.jinja
- shorewall/files/tcpri.jinja
- shorewall/files/tcrules.jinja
- shorewall/files/tunnels.jinja
- shorewall/files/zones.jinja
- shorewall/init.sls
- shorewall/map.jinja
- shorewall/upnp.sls
- top.sls

However, when I try to apply the state the shorewall formulas disappear again:

user@saltmaster:/var/cache/salt/master$ sudo salt 'saltmaster' state.apply
saltmaster:
    Data failed to compile:
----------
    No matching sls found for 'shorewall' in env 'base'
ERROR: Minions returned with non-zero exit code
user@saltmaster:/var/cache/salt/master$ sudo salt-run fileserver.file_list
- CHANGELOG.rst
- LICENSE
- README.rst
- docker/default/docker
- docker/init.sls
- letsencrypt/config.sls
- letsencrypt/defaults.yaml
- letsencrypt/domains.sls
- letsencrypt/files/renew_letsencrypt_cert.sh.jinja
- letsencrypt/init.sls
- letsencrypt/install.sls
- letsencrypt/map.jinja
- nginx/conf/mime.types
- nginx/fastcgi.conf
- nginx/init.sls
- nginx/nginx.conf
- nginx/proxy.conf
- pillar.example
- top.sls

EDIT: Turns out that I forgot to restart the salt-master. I guess it is a bug that the files from the gitfs_remote show up when running salt-run fileserver.update backend=git since they are not really available.

oak1980 avatar Feb 28 '18 07:02 oak1980

@oak1980 When you execute a runner, it's separate from the master daemon. In fact, you can stop the master, and execute the runner, and it'll work just fine. I've added some documentation to make this more clear in https://github.com/saltstack/salt/pull/46250.

terminalmage avatar Feb 28 '18 16:02 terminalmage