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

Let dpkg.info expose package status #55256

Merged
merged 7 commits into from
Dec 20, 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
1 change: 1 addition & 0 deletions salt/modules/dpkg_lowpkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ def _get_pkg_info(*packages, **kwargs):
"SHA256:${SHA256}\\n" \
"origin:${Origin}\\n" \
"homepage:${Homepage}\\n" \
"status:${db:Status-Abbrev}\\n" \
"======\\n" \
"description:${Description}\\n" \
"------\\n'"
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/modules/test_pkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,9 @@ def test_pkg_info(self, grains):
func = 'pkg.info_installed'

if grains['os_family'] == 'Debian':
ret = self.run_function(func, ['bash-completion', 'dpkg'])
ret = self.run_function(func, ['bash', 'dpkg'])
keys = ret.keys()
self.assertIn('bash-completion', keys)
self.assertIn('bash', keys)
self.assertIn('dpkg', keys)
elif grains['os_family'] == 'RedHat':
ret = self.run_function(func, ['rpm', 'bash'])
Expand Down
67 changes: 67 additions & 0 deletions tests/unit/modules/test_dpkg_lowpkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

# Import Python libs
from __future__ import absolute_import, print_function, unicode_literals
import os

# Import Salt Testing Libs
from tests.support.mixins import LoaderModuleMockMixin
Expand Down Expand Up @@ -102,3 +103,69 @@ def test_file_dict(self):
'stdout': 'Salt'})
with patch.dict(dpkg.__salt__, {'cmd.run_all': mock}):
self.assertEqual(dpkg.file_dict('httpd'), 'Error: error')

def test_info(self):
'''
Test package info
'''
mock = MagicMock(return_value={'retcode': 0,
'stderr': '',
'stdout':
os.linesep.join([
'package:bash',
'revision:',
'architecture:amd64',
'maintainer:Ubuntu Developers <[email protected]>',
'summary:',
'source:bash',
'version:4.4.18-2ubuntu1',
'section:shells',
'installed_size:1588',
'size:',
'MD5:',
'SHA1:',
'SHA256:',
'origin:',
'homepage:http://tiswww.case.edu/php/chet/bash/bashtop.html',
'status:ii ',
'======',
'description:GNU Bourne Again SHell',
' Bash is an sh-compatible command language interpreter that executes',
' commands read from the standard input or from a file. Bash also',
' incorporates useful features from the Korn and C shells (ksh and csh).',
' .',
' Bash is ultimately intended to be a conformant implementation of the',
' IEEE POSIX Shell and Tools specification (IEEE Working Group 1003.2).',
' .',
' The Programmable Completion Code, by Ian Macdonald, is now found in',
' the bash-completion package.',
'------'
])})

with patch.dict(dpkg.__salt__, {'cmd.run_all': mock}), \
patch.dict(dpkg.__grains__, {'os': 'Ubuntu', 'osrelease_info': (18, 4)}), \
patch('salt.utils.path.which', MagicMock(return_value=False)), \
patch('os.path.exists', MagicMock(return_value=False)),\
patch('os.path.getmtime', MagicMock(return_value=1560199259.0)):
self.assertDictEqual(dpkg.info('bash'),
{'bash': {'architecture': 'amd64',
'description': os.linesep.join([
'GNU Bourne Again SHell',
' Bash is an sh-compatible command language interpreter that executes',
' commands read from the standard input or from a file. Bash also',
' incorporates useful features from the Korn and C shells (ksh and csh).',
' .',
' Bash is ultimately intended to be a conformant implementation of the',
' IEEE POSIX Shell and Tools specification (IEEE Working Group 1003.2).',
' .',
' The Programmable Completion Code, by Ian Macdonald, is now found in',
' the bash-completion package.' + os.linesep
]),
'homepage': 'http://tiswww.case.edu/php/chet/bash/bashtop.html',
'maintainer': 'Ubuntu Developers '
'<[email protected]>',
'package': 'bash',
'section': 'shells',
'source': 'bash',
'status': 'ii',
'version': '4.4.18-2ubuntu1'}})