mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-07 13:52:54 +00:00
@@ -0,0 +1,4 @@
|
||||
vrf context coke
|
||||
vrf context management
|
||||
ip route 172.26.0.0/16 172.26.4.1
|
||||
vrf context test-vrf
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"TABLE_vrf": {
|
||||
"ROW_vrf": {
|
||||
"vrf_name": "management",
|
||||
"vrf_id": 2,
|
||||
"vrf_state": "Up",
|
||||
"vrf_reason": "--"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,7 @@
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import json
|
||||
import os
|
||||
|
||||
from ansible.compat.tests.mock import patch
|
||||
from ansible.modules.network.nxos import nxos_vrf
|
||||
@@ -31,32 +31,45 @@ class TestNxosVrfModule(TestNxosModule):
|
||||
module = nxos_vrf
|
||||
|
||||
def setUp(self):
|
||||
self.mock_run_commands = patch('ansible.modules.network.nxos.nxos_vrf.run_commands')
|
||||
self.run_commands = self.mock_run_commands.start()
|
||||
|
||||
self.mock_load_config = patch('ansible.modules.network.nxos.nxos_vrf.load_config')
|
||||
self.load_config = self.mock_load_config.start()
|
||||
|
||||
self.mock_get_config = patch('ansible.modules.network.nxos.nxos_vrf.get_config')
|
||||
self.get_config = self.mock_get_config.start()
|
||||
self.mock_run_commands = patch('ansible.modules.network.nxos.nxos_vrf.run_commands')
|
||||
self.run_commands = self.mock_run_commands.start()
|
||||
|
||||
def tearDown(self):
|
||||
self.mock_run_commands.stop()
|
||||
self.mock_load_config.stop()
|
||||
self.mock_get_config.stop()
|
||||
self.mock_run_commands.stop()
|
||||
|
||||
def load_fixtures(self, commands=None):
|
||||
def load_from_file(*args, **kwargs):
|
||||
module, commands = args
|
||||
output = list()
|
||||
|
||||
for command in commands:
|
||||
filename = str(command).split(' | ')[0].replace(' ', '_')
|
||||
filename = os.path.join('nxos_vrf', filename)
|
||||
output.append(load_fixture(filename))
|
||||
return output
|
||||
|
||||
self.load_config.return_value = None
|
||||
self.run_commands.side_effect = load_from_file
|
||||
|
||||
def test_nxos_vrf_present(self):
|
||||
set_module_args(dict(vrf='ntc', state='present', admin_state='up'))
|
||||
result = self.execute_module(changed=True)
|
||||
self.assertEqual(result['commands'], ['vrf context ntc', 'no shutdown'])
|
||||
self.execute_module(changed=True, commands=['vrf context ntc', 'no shutdown'])
|
||||
|
||||
def test_nxos_vrf_present_no_change(self):
|
||||
set_module_args(dict(vrf='management', state='present', admin_state='up'))
|
||||
self.execute_module(changed=False, commands=[])
|
||||
|
||||
def test_nxos_vrf_absent(self):
|
||||
set_module_args(dict(vrf='management', state='absent'))
|
||||
self.execute_module(changed=True, commands=['no vrf context management'])
|
||||
|
||||
def test_nxos_vrf_absent_no_change(self):
|
||||
set_module_args(dict(vrf='ntc', state='absent'))
|
||||
result = self.execute_module(changed=True)
|
||||
self.assertEqual(result['commands'], ['no vrf context ntc'])
|
||||
self.execute_module(changed=False, commands=[])
|
||||
|
||||
def test_nxos_vrf_default(self):
|
||||
set_module_args(dict(vrf='default'))
|
||||
|
||||
Reference in New Issue
Block a user