Skip to content

Commit

Permalink
Merge pull request #55258 from mateiw/master-aptpkg-info-only-installed
Browse files Browse the repository at this point in the history
Make aptpkg.info return only installed packages
  • Loading branch information
dwoz authored Dec 2, 2019
2 parents d1725c1 + e20362f commit c883fa4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
4 changes: 4 additions & 0 deletions salt/modules/aptpkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand All @@ -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

Expand Down
25 changes: 23 additions & 2 deletions tests/unit/modules/test_aptpkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>',
'name': 'apache2',
'section': 'httpd',
'source': 'apache2',
'version': '2.4.18-2ubuntu3.9',
'status': 'rc',
}
}

Expand Down Expand Up @@ -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):
'''
Expand Down

0 comments on commit c883fa4

Please sign in to comment.