diff --git a/salt/modules/aptpkg.py b/salt/modules/aptpkg.py index a88dd6aa30c0..029d02f34e1e 100644 --- a/salt/modules/aptpkg.py +++ b/salt/modules/aptpkg.py @@ -2792,6 +2792,8 @@ def info_installed(*names, **kwargs): ret = dict() for pkg_name, pkg_nfo in __salt__['lowpkg.info'](*names, failhard=failhard).items(): t_nfo = dict() + if pkg_nfo.get('status', 'ii')[1] != 'i': + continue # return only packages that are really installed # Translate dpkg-specific keys to a common structure for key, value in pkg_nfo.items(): if key == 'package': @@ -2804,6 +2806,8 @@ def info_installed(*names, **kwargs): t_nfo['packager'] = value elif key == 'homepage': t_nfo['url'] = value + elif key == 'status': + continue # only installed pkgs are returned, no need for status else: t_nfo[key] = value diff --git a/tests/unit/modules/test_aptpkg.py b/tests/unit/modules/test_aptpkg.py index 09d496284919..3fcd974aead9 100644 --- a/tests/unit/modules/test_aptpkg.py +++ b/tests/unit/modules/test_aptpkg.py @@ -90,7 +90,26 @@ 'name': 'wget', 'section': 'web', 'source': 'wget', - 'version': '1.15-1ubuntu1.14.04.2' + 'version': '1.15-1ubuntu1.14.04.2', + 'status': 'ii', + }, + 'apache2': { + 'architecture': 'amd64', + 'description': """Apache HTTP Server + The Apache HTTP Server Project's goal is to build a secure, efficient and + extensible HTTP server as standards-compliant open source software. The + result has long been the number one web server on the Internet. + . + Installing this package results in a full installation, including the + configuration files, init scripts and support scripts.""", + 'homepage': 'http://httpd.apache.org/', + 'install_date': '2016-08-30T22:20:15Z', + 'maintainer': 'Ubuntu Developers ', + 'name': 'apache2', + 'section': 'httpd', + 'source': 'apache2', + 'version': '2.4.18-2ubuntu3.9', + 'status': 'rc', } } @@ -244,14 +263,16 @@ def test_info_installed(self): 'url': 'homepage' } - installed = copy.deepcopy(LOWPKG_INFO) + installed = copy.deepcopy({'wget': LOWPKG_INFO['wget']}) for name in names: if installed['wget'].get(names[name], False): installed['wget'][name] = installed['wget'].pop(names[name]) mock = MagicMock(return_value=LOWPKG_INFO) with patch.dict(aptpkg.__salt__, {'lowpkg.info': mock}): + del installed['wget']['status'] self.assertEqual(aptpkg.info_installed('wget'), installed) + self.assertEqual(len(aptpkg.info_installed()), 1) def test_owner(self): '''