Skip to content

Commit

Permalink
Merge pull request #55256 from mateiw/master-dpkg-info-status
Browse files Browse the repository at this point in the history
Let dpkg.info expose package status
  • Loading branch information
dwoz authored Dec 20, 2019
2 parents 5eb70ce + d1de4dc commit 576bd85
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 2 deletions.
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 @@ -241,9 +241,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 @@ -99,3 +100,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 <ubuntu-devel-discuss@lists.ubuntu.com>',
'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 '
'<ubuntu-devel-discuss@lists.ubuntu.com>',
'package': 'bash',
'section': 'shells',
'source': 'bash',
'status': 'ii',
'version': '4.4.18-2ubuntu1'}})

0 comments on commit 576bd85

Please sign in to comment.