Failing to remove nginx
Description of Issue/Question
Hi there,
I am playing with SaltStack, trying to get a feel for everything. I've ran into what I think could possibly be a bug - removing nginx does not work correctly. All involved machines are running fully updated Ubuntu 16.04 and all packages are current. For what it's worth, the salt minions are all running as VMware virtual machines with 4GB of RAM each. None of the minions have any extra apt repos besides SaltStack (no DotDeb or anything like that).
Setup
This is my top.sls file:
base:
'*':
- core
This is my core/init.sls file:
remove-things:
pkg.removed:
- name: nginx
Steps to Reproduce Issue
- Install nginx on minion
- On master, run sudo salt 'vm1' state.apply core
- First result:
vm1:
----------
ID: remove-things
Function: pkg.removed
Name: nginx
Result: False
Comment: The following packages failed to remove: nginx.
Started: 21:21:08.401320
Duration: 1315.336 ms
Changes:
----------
nginx:
----------
new:
1
old:
1.10.0-0ubuntu0.16.04.4
It does succeed at removing the nginx package, but claims to have failed.
Now, run it again:
- On master, run sudo salt 'vm1' state.apply core
vm1:
----------
ID: remove-things
Function: pkg.removed
Name: nginx
Result: False
Comment: The following packages failed to remove: nginx.
Started: 21:22:14.792268
Duration: 977.843 ms
Changes:
The exact same process does NOT fail with simple packages like "sl" and "cowsay".
Versions Report
root@nebula:/srv/salt# salt --versions-report
Salt Version:
Salt: 2016.11.1
Dependency Versions:
cffi: Not Installed
cherrypy: 3.5.0
dateutil: 2.4.2
gitdb: 0.6.4
gitpython: 1.0.1
ioflo: Not Installed
Jinja2: 2.8
libgit2: Not Installed
libnacl: Not Installed
M2Crypto: Not Installed
Mako: 1.0.3
msgpack-pure: Not Installed
msgpack-python: 0.4.6
mysql-python: Not Installed
pycparser: Not Installed
pycrypto: 2.6.1
pygit2: Not Installed
Python: 2.7.12 (default, Nov 19 2016, 06:48:10)
python-gnupg: Not Installed
PyYAML: 3.11
PyZMQ: 15.2.0
RAET: Not Installed
smmap: 0.9.0
timelib: Not Installed
Tornado: 4.2.1
ZMQ: 4.1.4
System Versions:
dist: Ubuntu 16.04 xenial
machine: x86_64
release: 4.4.0-59-generic
system: Linux
version: Ubuntu 16.04 xenial
@Zorlin looks like i'm able to replicate this. Looks like salt runs this command to check if its been removed:
dpkg-query --showformat '${Status} ${Package} ${Version} ${Architecture}' -W If you manually uninstall nginx as well the following packages still show up in the output of that command: nginx-common and nginx-core. So it seems removing nginx does not unisntall those packages.
I will labe this as a bug as we could probably improve our detection of the exact package. Thanks
Here is a docker container for someone that wants to quickly replicate this:
docker run -it -v /home/ch3ll/git/salt/:/testing/ ch3ll/issues:38838 salt-call --local state.sls test -ldebug(where /home/ch3ll/git/salt is a local cloned git salt repo)
Any update on this?
There is not currently an update. We are more then willing to accept a PR for this though since its not currently assigned out
The issue is in aptpkg.list_pkgs function. It returns wrong information - marks uninstalled package as virtual.
Steps to reproduce:
# dpkg -l | grep -c nginx
0
Install nginx package
# salt-call pkg.install nginx
local:
----------
httpd:
----------
new:
1
old:
httpd-cgi:
----------
new:
1
old:
nginx:
----------
new:
1.10.3-0ubuntu0.16.04.2
old:
nginx-common:
----------
new:
1.10.3-0ubuntu0.16.04.2
old:
nginx-core:
----------
new:
1.10.3-0ubuntu0.16.04.2
old:
As you can see we have wrong data here too - in return we got httpd and httpd-cgi packages marked as virtual ( version 1)
check for installed packages
# dpkg -l | grep nginx
ii nginx 1.10.3-0ubuntu0.16.04.2 all small, powerful, scalable web/proxy server
ii nginx-common 1.10.3-0ubuntu0.16.04.2 all small, powerful, scalable web/proxy server - common files
ii nginx-core 1.10.3-0ubuntu0.16.04.2 amd64 nginx web/proxy server (core version)
Remove package nginx
# salt-call pkg.remove nginx
local:
----------
nginx:
----------
new:
1
old:
1.10.3-0ubuntu0.16.04.2
check
# dpkg -l | grep nginx
ii nginx-common 1.10.3-0ubuntu0.16.04.2 all small, powerful, scalable web/proxy server - common files
ii nginx-core 1.10.3-0ubuntu0.16.04.2 amd64 nginx web/proxy server (core version)
get packages list with list_pkgs fuction
# salt-call pkg.list_pkgs --output=json | jq '."local" |=with_entries(select( .key | test("nginx") ))'
{
"local": {
"nginx-core": "1.10.3-0ubuntu0.16.04.2",
"nginx": "1",
"nginx-common": "1.10.3-0ubuntu0.16.04.2"
}
}
So nginx marked as virtual and added to result.
That code responsible for such behavior
https://github.com/saltstack/salt/blob/8e99aeed6ac69461cfb3fa1549800ff4b8260d98/salt/modules/aptpkg.py#L1401-L1408
nginx-core - provides nginx and code above add nginx package to installed dict with version 1
Thanks for looking into it @samodid :)
I have nothing further to add just yet, but hopefully this can be solved.
@Zorlin please try my fix. It should help