Skip to content

Commit 576bd85

Browse files
authored
Merge pull request saltstack#55256 from mateiw/master-dpkg-info-status
Let dpkg.info expose package status
2 parents 5eb70ce + d1de4dc commit 576bd85

File tree

3 files changed

+70
-2
lines changed

3 files changed

+70
-2
lines changed

salt/modules/dpkg_lowpkg.py

+1
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ def _get_pkg_info(*packages, **kwargs):
287287
"SHA256:${SHA256}\\n" \
288288
"origin:${Origin}\\n" \
289289
"homepage:${Homepage}\\n" \
290+
"status:${db:Status-Abbrev}\\n" \
290291
"======\\n" \
291292
"description:${Description}\\n" \
292293
"------\\n'"

tests/integration/modules/test_pkg.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -241,9 +241,9 @@ def test_pkg_info(self, grains):
241241
func = 'pkg.info_installed'
242242

243243
if grains['os_family'] == 'Debian':
244-
ret = self.run_function(func, ['bash-completion', 'dpkg'])
244+
ret = self.run_function(func, ['bash', 'dpkg'])
245245
keys = ret.keys()
246-
self.assertIn('bash-completion', keys)
246+
self.assertIn('bash', keys)
247247
self.assertIn('dpkg', keys)
248248
elif grains['os_family'] == 'RedHat':
249249
ret = self.run_function(func, ['rpm', 'bash'])

tests/unit/modules/test_dpkg_lowpkg.py

+67
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
# Import Python libs
77
from __future__ import absolute_import, print_function, unicode_literals
8+
import os
89

910
# Import Salt Testing Libs
1011
from tests.support.mixins import LoaderModuleMockMixin
@@ -99,3 +100,69 @@ def test_file_dict(self):
99100
'stdout': 'Salt'})
100101
with patch.dict(dpkg.__salt__, {'cmd.run_all': mock}):
101102
self.assertEqual(dpkg.file_dict('httpd'), 'Error: error')
103+
104+
def test_info(self):
105+
'''
106+
Test package info
107+
'''
108+
mock = MagicMock(return_value={'retcode': 0,
109+
'stderr': '',
110+
'stdout':
111+
os.linesep.join([
112+
'package:bash',
113+
'revision:',
114+
'architecture:amd64',
115+
'maintainer:Ubuntu Developers <[email protected]>',
116+
'summary:',
117+
'source:bash',
118+
'version:4.4.18-2ubuntu1',
119+
'section:shells',
120+
'installed_size:1588',
121+
'size:',
122+
'MD5:',
123+
'SHA1:',
124+
'SHA256:',
125+
'origin:',
126+
'homepage:http://tiswww.case.edu/php/chet/bash/bashtop.html',
127+
'status:ii ',
128+
'======',
129+
'description:GNU Bourne Again SHell',
130+
' Bash is an sh-compatible command language interpreter that executes',
131+
' commands read from the standard input or from a file. Bash also',
132+
' incorporates useful features from the Korn and C shells (ksh and csh).',
133+
' .',
134+
' Bash is ultimately intended to be a conformant implementation of the',
135+
' IEEE POSIX Shell and Tools specification (IEEE Working Group 1003.2).',
136+
' .',
137+
' The Programmable Completion Code, by Ian Macdonald, is now found in',
138+
' the bash-completion package.',
139+
'------'
140+
])})
141+
142+
with patch.dict(dpkg.__salt__, {'cmd.run_all': mock}), \
143+
patch.dict(dpkg.__grains__, {'os': 'Ubuntu', 'osrelease_info': (18, 4)}), \
144+
patch('salt.utils.path.which', MagicMock(return_value=False)), \
145+
patch('os.path.exists', MagicMock(return_value=False)),\
146+
patch('os.path.getmtime', MagicMock(return_value=1560199259.0)):
147+
self.assertDictEqual(dpkg.info('bash'),
148+
{'bash': {'architecture': 'amd64',
149+
'description': os.linesep.join([
150+
'GNU Bourne Again SHell',
151+
' Bash is an sh-compatible command language interpreter that executes',
152+
' commands read from the standard input or from a file. Bash also',
153+
' incorporates useful features from the Korn and C shells (ksh and csh).',
154+
' .',
155+
' Bash is ultimately intended to be a conformant implementation of the',
156+
' IEEE POSIX Shell and Tools specification (IEEE Working Group 1003.2).',
157+
' .',
158+
' The Programmable Completion Code, by Ian Macdonald, is now found in',
159+
' the bash-completion package.' + os.linesep
160+
]),
161+
'homepage': 'http://tiswww.case.edu/php/chet/bash/bashtop.html',
162+
'maintainer': 'Ubuntu Developers '
163+
164+
'package': 'bash',
165+
'section': 'shells',
166+
'source': 'bash',
167+
'status': 'ii',
168+
'version': '4.4.18-2ubuntu1'}})

0 commit comments

Comments
 (0)