VirtualName for states.apt

This fixes #24397

Signed-off-by: Mathieu Le Marec - Pasquet <kiorky@cryptelium.net>
This commit is contained in:
Mathieu Le Marec - Pasquet 2015-06-04 13:22:06 +02:00
parent 3ca35d1ec3
commit 785d27707f
2 changed files with 13 additions and 7 deletions

View File

@ -14,11 +14,17 @@ import salt.utils
log = logging.getLogger(__name__)
# Define the module's virtual name
__virtualname__ = 'apt'
def __virtual__():
'''
Only work on apt-based platforms with pkg.get_selections
'''
return 'pkg.get_selections' in __salt__
return (__virtualname__
if __salt__.get('pkg.get_selections', False)
else False)
def held(name):

View File

@ -18,16 +18,16 @@ from salttesting.helpers import ensure_in_syspath
ensure_in_syspath('../../')
# Import Salt Libs
from salt.states import apt
from salt.states import aptpkg
apt.__opts__ = {}
apt.__salt__ = {}
aptpkg.__opts__ = {}
aptpkg.__salt__ = {}
@skipIf(NO_MOCK, NO_MOCK_REASON)
class AptTestCase(TestCase):
'''
Test cases for salt.states.apt
Test cases for salt.states.aptpkg
'''
# 'held' function tests: 1
@ -43,8 +43,8 @@ class AptTestCase(TestCase):
'comment': 'Package {0} does not have a state'.format(name)}
mock = MagicMock(return_value=False)
with patch.dict(apt.__salt__, {'pkg.get_selections': mock}):
self.assertDictEqual(apt.held(name), ret)
with patch.dict(aptpkg.__salt__, {'pkg.get_selections': mock}):
self.assertDictEqual(aptpkg.held(name), ret)
if __name__ == '__main__':