mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #50316 from rallytime/bp-50301
Back-port #50301 to 2018.3
This commit is contained in:
commit
51e333ada2
2 changed files with 70 additions and 2 deletions
|
@ -77,7 +77,6 @@ def __virtual__():
|
|||
|
||||
def managed(name,
|
||||
data,
|
||||
*models,
|
||||
**kwargs):
|
||||
'''
|
||||
Manage the device configuration given the input data structured
|
||||
|
@ -143,6 +142,7 @@ def managed(name,
|
|||
config:
|
||||
description: "description example"
|
||||
'''
|
||||
models = kwargs.get('models', None)
|
||||
if isinstance(models, tuple) and isinstance(models[0], list):
|
||||
models = models[0]
|
||||
ret = salt.utils.napalm.default_ret(name)
|
||||
|
@ -206,7 +206,6 @@ def managed(name,
|
|||
|
||||
def configured(name,
|
||||
data,
|
||||
*models,
|
||||
**kwargs):
|
||||
'''
|
||||
Configure the network device, given the input data strucuted
|
||||
|
@ -276,6 +275,7 @@ def configured(name,
|
|||
config:
|
||||
description: "description example"
|
||||
'''
|
||||
models = kwargs.get('models', None)
|
||||
if isinstance(models, tuple) and isinstance(models[0], list):
|
||||
models = models[0]
|
||||
ret = salt.utils.napalm.default_ret(name)
|
||||
|
|
68
tests/unit/states/test_netyang.py
Normal file
68
tests/unit/states/test_netyang.py
Normal file
|
@ -0,0 +1,68 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
'''
|
||||
:codeauthor: Anthony Shaw <anthonyshaw@apache.org>
|
||||
'''
|
||||
# Import Python libs
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Import Salt Libs
|
||||
import salt.states.netyang as netyang
|
||||
|
||||
# Import Salt Testing Libs
|
||||
from tests.support.mixins import LoaderModuleMockMixin
|
||||
from tests.support.unit import skipIf, TestCase
|
||||
from tests.support.mock import (
|
||||
NO_MOCK,
|
||||
NO_MOCK_REASON,
|
||||
MagicMock,
|
||||
patch
|
||||
)
|
||||
|
||||
TEST_DATA = {
|
||||
'foo': 'bar'
|
||||
}
|
||||
|
||||
|
||||
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
||||
class NetyangTestCase(TestCase, LoaderModuleMockMixin):
|
||||
def setup_loader_modules(self):
|
||||
return {netyang: {}}
|
||||
|
||||
def test_managed(self):
|
||||
ret = {'changes': {}, 'comment': 'Loaded.',
|
||||
'name': 'test', 'result': False,
|
||||
'pchanges': {'compliance_report': {'complies': False}}}
|
||||
parse = MagicMock(return_value='abcdef')
|
||||
temp_file = MagicMock(return_value='')
|
||||
compliance_report = MagicMock(return_value={'complies': False})
|
||||
load_config = MagicMock(return_value={'comment': 'Loaded.'})
|
||||
file_remove = MagicMock()
|
||||
|
||||
with patch('salt.utils.files.fopen'):
|
||||
with patch.dict(netyang.__salt__,
|
||||
{'temp.file': temp_file,
|
||||
'napalm_yang.parse': parse,
|
||||
'napalm_yang.load_config': load_config,
|
||||
'napalm_yang.compliance_report': compliance_report,
|
||||
'file.remove': file_remove}):
|
||||
with patch.dict(netyang.__opts__, {'test': False}):
|
||||
self.assertDictEqual(netyang.managed('test', 'test', models=('model1',)), ret)
|
||||
assert parse.called
|
||||
assert temp_file.called
|
||||
assert compliance_report.called
|
||||
assert load_config.called
|
||||
assert file_remove.called
|
||||
|
||||
def test_configured(self):
|
||||
ret = {'changes': {}, 'comment': 'Loaded.',
|
||||
'name': 'test', 'result': False,
|
||||
'pchanges': {}}
|
||||
load_config = MagicMock(return_value={'comment': 'Loaded.'})
|
||||
|
||||
with patch('salt.utils.files.fopen'):
|
||||
with patch.dict(netyang.__salt__,
|
||||
{'napalm_yang.load_config': load_config}):
|
||||
with patch.dict(netyang.__opts__, {'test': False}):
|
||||
self.assertDictEqual(netyang.configured('test', 'test', models=('model1',)), ret)
|
||||
|
||||
assert load_config.called
|
Loading…
Add table
Reference in a new issue