Skip to content

Commit

Permalink
Merge pull request #55203 from brejoc/master-mod-repo-enabled
Browse files Browse the repository at this point in the history
Adds enabled kwarg
  • Loading branch information
dwoz authored Jan 13, 2020
2 parents 07addbb + d95146f commit 7f9fd64
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions salt/modules/aptpkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -2294,6 +2294,8 @@ def mod_repo(repo, saltenv='base', **kwargs):

if 'disabled' in kwargs:
kwargs['disabled'] = salt.utils.data.is_true(kwargs['disabled'])
elif 'enabled' in kwargs:
kwargs['disabled'] = not salt.utils.data.is_true(kwargs['enabled'])

kw_type = kwargs.get('type')
kw_dist = kwargs.get('dist')
Expand Down
24 changes: 24 additions & 0 deletions tests/unit/modules/test_aptpkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,30 @@ def test_show(self):
self.assert_called_once(refresh_mock)
refresh_mock.reset_mock()

def test_mod_repo_enabled(self):
'''
Checks if a repo is enabled or disabled depending on the passed kwargs.
'''
with patch.dict(aptpkg.__salt__, {'config.option': MagicMock(), 'no_proxy': MagicMock(return_value=False)}):
with patch('salt.modules.aptpkg._check_apt', MagicMock(return_value=True)):
with patch('salt.modules.aptpkg.refresh_db', MagicMock(return_value={})):
with patch('salt.utils.data.is_true', MagicMock(return_value=True)) as data_is_true:
with patch('salt.modules.aptpkg.sourceslist', MagicMock(), create=True):
repo = aptpkg.mod_repo('foo', enabled=False)
data_is_true.assert_called_with(False)
# with disabled=True; should call salt.utils.data.is_true True
data_is_true.reset_mock()
repo = aptpkg.mod_repo('foo', disabled=True)
data_is_true.assert_called_with(True)
# with enabled=True; should call salt.utils.data.is_true with False
data_is_true.reset_mock()
repo = aptpkg.mod_repo('foo', enabled=True)
data_is_true.assert_called_with(True)
# with disabled=True; should call salt.utils.data.is_true False
data_is_true.reset_mock()
repo = aptpkg.mod_repo('foo', disabled=False)
data_is_true.assert_called_with(False)

@patch('salt.utils.path.os_walk', MagicMock(return_value=[('test', 'test', 'test')]))
@patch('os.path.getsize', MagicMock(return_value=123456))
@patch('os.path.getctime', MagicMock(return_value=1234567890.123456))
Expand Down

0 comments on commit 7f9fd64

Please sign in to comment.