Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make aptpkg.info return only installed packages #55258

Merged
merged 1 commit into from
Dec 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions salt/modules/aptpkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -2791,6 +2791,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 @@ -2803,6 +2805,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