pkg.installed with custom repo added via file.managed broken in v2014.1, worked in 0.17
After upgrading from 0.17 to v2014.1 my salt states are all broken. I'm using CentOS 6.5 and EPEL release.
If I have a sls that installs a package, and then drops in a /etc/yum.repos.d file to add a repository, and then tries to install a package from that repository, it fails with:
[ERROR ] Package 'php-mcrypt' not found (possible matches: php-mcrypt). Package 'php-pecl-xdebug' not found (possible matches: php-pecl-xdebug). Package 'php-mysqlnd' not found (possible matches: php-mysqlnd). Package 'php-drush-drush' not found (possible matches: php-drush-drush).
If I remove the first package install, so it's just the repo file and then a package install. It works fine. It seems that on the first package install it CACHE the list of available packages - but since the repo file not created yet - it doesn't contain that repo's packages. Then on second package command it uses the CACHEd package list and ignored the fact I just dropped one in. Refresh: True does nothing to help.
Blame seems to be at in salt/states/pkg.py in check_db - it keeps the list in pkg._avail in context, but it doesn't appear to ever clear.
How can I resolve this without rewriting many many SLS files and without downgrading to 0.17 which worked perfectly?
If the Refresh: True can be made to work that would be best.
This is a snippet from the log before the error appears:
[INFO ] Executing state pkg.installed for php
[INFO ] Executing command 'repoquery --queryformat="%{NAME}_|-%{VERSION}_|-%{RELEASE}_|-%{ARCH}_|-%{REPOID}" --all --quiet --whatprovides \'php-mysqlnd\'' in directory '/root'
[DEBUG ] stdout: php-mysqlnd_|-5.5.10_|-1.el6.remi.1_|-x86_64_|-remi-php55
php-mysqlnd_|-5.5.10_|-1.el6.remi.1_|-x86_64_|-remi-php55
php-mysqlnd_|-5.4.25_|-2.el6.remi_|-x86_64_|-remi
php-mysqlnd_|-5.4.26_|-1.el6.remi_|-x86_64_|-remi
php-mysqlnd_|-5.5.10_|-1.el6.remi_|-x86_64_|-remi-php55
This is some time after it cache the available packages, and after a repo file was added by salt:
[INFO ] Executing command 'repoquery --queryformat="%{NAME}_|-%{ARCH}" --pkgnarrow=all --all' in directory '/root'
I can't quite understand why it lists ALL packages though... this just seems a bit silly. Surely it should simply just query for the packages I want to add - surely that will be way way quicker. "repoquery" has its own cache does it not so we just end up caching twice.
Pretty sure this is related to the changes to pkg refreshes for the new release to try to optimize.
@terminalmage any idea why refresh: True isn't working? I know you were closely involved with the refresh changes, and I know a file.managed state isn't going to trigger a refresh like a pkgrepo state would.
FYI: have the same issue, and on DEVELOP it works again.
Too bad that right now Centos does not have any working salt package.
I think this is the commit which caused this issue:
https://github.com/saltstack/salt/commit/7c3d0cc80db5d455fde8cd5044a3dc91bfa272f0
This is fixed in 2014.1.1 which is in epel-testing right now. Proof below:
Example SLS
mongodb-repo:
pkgrepo:
- managed
- name: mongodb
- humanname: MongoDB Repository
- baseurl: http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/
- gpgcheck: 0
- enabled: 1
mongo-10gen:
pkg:
- installed
- require:
- pkgrepo: mongodb
No mongo repo already configured, no mongo packages already installed
[root@virtucentos saltdev]# ls -l /etc/yum.repos.d/
total 28
-rw-r--r--. 1 root root 1926 Nov 30 18:07 CentOS-Base.repo
-rw-r--r--. 1 root root 638 Nov 30 18:07 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root 630 Nov 30 18:07 CentOS-Media.repo
-rw-r--r--. 1 root root 4528 Nov 30 18:07 CentOS-Vault.repo
-rw-r--r--. 1 root root 957 Nov 4 2012 epel.repo
-rw-r--r--. 1 root root 1056 Nov 4 2012 epel-testing.repo
[root@virtucentos saltdev]# rpm -qa | grep mongo
Master and Minion both running 2014.1.1
[root@virtucentos saltdev]# salt --versions-report
Salt: 2014.1.1
Python: 2.6.6 (r266:84292, Jan 22 2014, 09:42:36)
Jinja2: 2.2.1
M2Crypto: 0.20.2
msgpack-python: 0.1.13
msgpack-pure: Not Installed
pycrypto: 2.0.1
PyYAML: 3.10
PyZMQ: 14.0.1
ZMQ: 4.0.3
[root@virtucentos saltdev]# salt-call --versions-report
Salt: 2014.1.1
Python: 2.6.6 (r266:84292, Jan 22 2014, 09:42:36)
Jinja2: 2.2.1
M2Crypto: 0.20.2
msgpack-python: 0.1.13
msgpack-pure: Not Installed
pycrypto: 2.0.1
PyYAML: 3.10
PyZMQ: 14.0.1
ZMQ: 4.0.3
Result of running SLS file
[root@virtucentos saltdev]# salt virtucentos state.sls test
virtucentos:
----------
ID: mongodb-repo
Function: pkgrepo.managed
Name: mongodb
Result: True
Comment: Configured package repo 'mongodb'
Changes:
----------
repo:
mongodb
----------
ID: mongo-10gen
Function: pkg.installed
Result: True
Comment: The following packages were installed/updated: mongo-10gen.
Changes:
----------
mongo-10gen:
----------
new:
2.4.9-mongodb_1
old:
Summary
------------
Succeeded: 2
Failed: 0
------------
Total: 2
Your proof uses pkgrepo.managed. The issue is when using file.managed.
Could you test for file.managed too?
Thanks!
I believe the issue is specifically with "refresh: True" not working on the pkg.installed. So as long as that fixes I don't mind sed'in it into my SLS. To use pkgrepo means a big refactoring :(
After removing the repo conf file and deploying it using a file.managed state, with a refresh: True on the pkg.installed state, it still works. Below are the logs, with a bunch of additional log entries snipped, here are the relevant entries:
[INFO ] [salt.state 1298] Running state [/etc/yum.repos.d/mongodb.repo] at time 12:57:44.594752
[INFO ] [salt.state 1318] Executing state file.managed for /etc/yum.repos.d/mongodb.repo
[INFO ] [salt.state 173 ] File changed:
New file
[INFO ] [salt.state 1415] Completed state [/etc/yum.repos.d/mongodb.repo] at time 12:57:44.976721
[INFO ] [salt.state 1298] Running state [mongo-10gen] at time 12:57:44.977662
[INFO ] [salt.state 1318] Executing state pkg.installed for mongo-10gen
[INFO ] [salt.loaded.int.module.cmdmod 348 ] Executing command 'yum -q clean expire-cache && yum -q check-update' in directory '/root'
[INFO ] [salt.loaded.int.module.cmdmod 348 ] Executing command 'yum -y install mongo-10gen' in directory '/root'
You can see that the yum -q clean expire-cache && yum -q check-update is indeed being run, which is what forces yum to re-download the repo metadata, effectively refreshing the repo information and allowing for the package to be installed.
This does indeed seem to be resolved in 2014.1.1.
Hi @terminalmage
Really sorry to be a pain. Could you make it install a package from another repo first, then do the repo file and new package install from that repo.
The first pkg install should not have any require in the following file and pkg.
The problem was cache so if you did file then pkg like you did... Because the pkg is the first use of pkg it loaded list and it loads the new repo. So we need to pkg install first so it loads a list not including the repo... Then install the repo file and try a package from that repo.
That would test it fully. Again, sorry for being a pain, I should've mentioned this in my last entry.
Thanks for the testing though it's appreciated!
Jason
Although it does look like it should be good since I don't get the yum clean with refresh true. But best to test the reproduction exactly I think just to be sure!
Thanks again
Still works with an additional pkg.installed state coming before it:
[root@virtucentos saltdev]# salt virtucentos state.sls test
virtucentos:
----------
ID: /etc/yum.repos.d/mongodb.repo
Function: file.managed
Result: True
Comment: File /etc/yum.repos.d/mongodb.repo updated
Changes:
----------
diff:
New file
mode:
0644
----------
ID: sl
Function: pkg.installed
Result: True
Comment: The following packages were installed/updated: sl.
Changes:
----------
sl:
----------
new:
3.03-6.el6
old:
----------
ID: mongo-10gen
Function: pkg.installed
Result: True
Comment: The following packages were installed/updated: mongo-10gen.
Changes:
----------
mongo-10gen:
----------
new:
2.4.9-mongodb_1
old:
Summary
------------
Succeeded: 3
Failed: 0
------------
Total: 3
@terminalmage is right: I checked again and it now works in epel testing. (it was broken in both EPEL stable and testing until last week)
Awresone thanks! Soon as I can I'll test it too. Great that it's in epel testing already too :)
Since @unicolet was able to confirm that this works as well, I'll close this report. @driskell Please re-open if you experience further issues with this.
And if you can't re-open, just comment and one of us will re-open. :smile: