mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
nxos_vxlan_vtep (#25971)
* nxos_vxlan_vtep tests * Fix issues with nxos_vxlan_vtep
This commit is contained in:
parent
3482a6326b
commit
21c7fcf9c0
4 changed files with 134 additions and 126 deletions
|
@ -16,9 +16,11 @@
|
|||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
ANSIBLE_METADATA = {'metadata_version': '1.0',
|
||||
ANSIBLE_METADATA = {
|
||||
'metadata_version': '1.0',
|
||||
'status': ['preview'],
|
||||
'supported_by': 'community'}
|
||||
'supported_by': 'community',
|
||||
}
|
||||
|
||||
|
||||
DOCUMENTATION = '''
|
||||
|
@ -86,47 +88,20 @@ EXAMPLES = '''
|
|||
source_interface: Loopback0
|
||||
source_interface_hold_down_time: 30
|
||||
shutdown: default
|
||||
username: "{{ un }}"
|
||||
password: "{{ pwd }}"
|
||||
host: "{{ inventory_hostname }}"
|
||||
'''
|
||||
|
||||
RETURN = '''
|
||||
proposed:
|
||||
description: k/v pairs of parameters passed into module
|
||||
returned: verbose mode
|
||||
type: dict
|
||||
sample: {"description": "simple description", "host_reachability": true,
|
||||
"interface": "nve1", "shutdown": true, "source_interface": "loopback0",
|
||||
"source_interface_hold_down_time": "30"}
|
||||
existing:
|
||||
description: k/v pairs of existing VXLAN VTEP configuration
|
||||
returned: verbose mode
|
||||
type: dict
|
||||
sample: {}
|
||||
end_state:
|
||||
description: k/v pairs of VXLAN VTEP configuration after module execution
|
||||
returned: verbose mode
|
||||
type: dict
|
||||
sample: {"description": "simple description", "host_reachability": true,
|
||||
"interface": "nve1", "shutdown": true, "source_interface": "loopback0",
|
||||
"source_interface_hold_down_time": "30"}
|
||||
updates:
|
||||
commands:
|
||||
description: commands sent to the device
|
||||
returned: always
|
||||
type: list
|
||||
sample: ["interface nve1", "source-interface loopback0",
|
||||
"source-interface hold-down-time 30", "description simple description",
|
||||
"shutdown", "host-reachability protocol bgp"]
|
||||
changed:
|
||||
description: check to see if a change was made on the device
|
||||
returned: always
|
||||
type: boolean
|
||||
sample: true
|
||||
'''
|
||||
|
||||
import re
|
||||
from ansible.module_utils.nxos import get_config, load_config, run_commands
|
||||
from ansible.module_utils.nxos import get_config, load_config
|
||||
from ansible.module_utils.nxos import nxos_argument_spec, check_args
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.netcfg import CustomNetworkConfig
|
||||
|
@ -148,14 +123,6 @@ PARAM_TO_DEFAULT_KEYMAP = {
|
|||
'shutdown': True,
|
||||
}
|
||||
|
||||
WARNINGS = []
|
||||
|
||||
|
||||
def invoke(name, *args, **kwargs):
|
||||
func = globals().get(name)
|
||||
if func:
|
||||
return func(*args, **kwargs)
|
||||
|
||||
|
||||
def get_value(arg, config, module):
|
||||
if arg in BOOL_PARAMS:
|
||||
|
@ -305,36 +272,22 @@ def main():
|
|||
source_interface=dict(required=False, type='str'),
|
||||
source_interface_hold_down_time=dict(required=False, type='str'),
|
||||
m_facts=dict(required=False, default=False, type='bool'),
|
||||
state=dict(choices=['present', 'absent'], default='present',
|
||||
required=False),
|
||||
include_defaults=dict(default=True),
|
||||
config=dict(),
|
||||
save=dict(type='bool', default=False)
|
||||
state=dict(choices=['present', 'absent'], default='present', required=False),
|
||||
)
|
||||
|
||||
argument_spec.update(nxos_argument_spec)
|
||||
|
||||
module = AnsibleModule(argument_spec=argument_spec,
|
||||
supports_check_mode=True)
|
||||
module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)
|
||||
|
||||
warnings = list()
|
||||
result = {'changed': False, 'commands': [], 'warnings': warnings}
|
||||
check_args(module, warnings)
|
||||
|
||||
|
||||
state = module.params['state']
|
||||
interface = module.params['interface'].lower()
|
||||
|
||||
args = [
|
||||
'interface',
|
||||
'description',
|
||||
'host_reachability',
|
||||
'shutdown',
|
||||
'source_interface',
|
||||
'source_interface_hold_down_time'
|
||||
]
|
||||
args = PARAM_TO_DEFAULT_KEYMAP.keys()
|
||||
|
||||
existing = invoke('get_existing', module, args)
|
||||
end_state = existing
|
||||
existing = get_existing(module, args)
|
||||
proposed_args = dict((k, v) for k, v in module.params.items()
|
||||
if v is not None and k in args)
|
||||
|
||||
|
@ -352,35 +305,27 @@ def main():
|
|||
value = False
|
||||
else:
|
||||
value = 'default'
|
||||
if existing.get(key) or (not existing.get(key) and value):
|
||||
if existing.get(key) != value:
|
||||
proposed[key] = value
|
||||
|
||||
result = {}
|
||||
if state == 'present' or (state == 'absent' and existing):
|
||||
candidate = CustomNetworkConfig(indent=3)
|
||||
if state == 'present':
|
||||
if not existing:
|
||||
WARNINGS.append("The proposed NVE interface did not exist. "
|
||||
warnings.append("The proposed NVE interface did not exist. "
|
||||
"It's recommended to use nxos_interface to create "
|
||||
"all logical interfaces.")
|
||||
candidate = CustomNetworkConfig(indent=3)
|
||||
invoke('state_%s' % state, module, existing, proposed, candidate)
|
||||
response = load_config(module, candidate)
|
||||
result.update(response)
|
||||
state_present(module, existing, proposed, candidate)
|
||||
elif state == 'absent' and existing:
|
||||
state_absent(module, existing, proposed, candidate)
|
||||
|
||||
else:
|
||||
result['updates'] = []
|
||||
|
||||
if module._verbosity > 0:
|
||||
end_state = invoke('get_existing', module, args)
|
||||
result['end_state'] = end_state
|
||||
result['existing'] = existing
|
||||
result['proposed'] = proposed_args
|
||||
|
||||
if WARNINGS:
|
||||
result['warnings'] = WARNINGS
|
||||
if candidate:
|
||||
candidate = candidate.items_text()
|
||||
result['commands'] = candidate
|
||||
result['changed'] = True
|
||||
load_config(module, candidate)
|
||||
|
||||
module.exit_json(**result)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
|
|
|
@ -395,7 +395,6 @@ lib/ansible/modules/network/nxos/nxos_vrrp.py
|
|||
lib/ansible/modules/network/nxos/nxos_vtp_domain.py
|
||||
lib/ansible/modules/network/nxos/nxos_vtp_password.py
|
||||
lib/ansible/modules/network/nxos/nxos_vtp_version.py
|
||||
lib/ansible/modules/network/nxos/nxos_vxlan_vtep.py
|
||||
lib/ansible/modules/network/nxos/nxos_vxlan_vtep_vni.py
|
||||
lib/ansible/modules/net_tools/omapi_host.py
|
||||
lib/ansible/modules/network/openswitch/_ops_template.py
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
interface nve1
|
||||
member vni 6000
|
62
test/units/modules/network/nxos/test_nxos_vxlan_vtep.py
Normal file
62
test/units/modules/network/nxos/test_nxos_vxlan_vtep.py
Normal file
|
@ -0,0 +1,62 @@
|
|||
# (c) 2016 Red Hat Inc.
|
||||
#
|
||||
# This file is part of Ansible
|
||||
#
|
||||
# Ansible is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Ansible is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
# Make coding more python3-ish
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import json
|
||||
|
||||
from ansible.compat.tests.mock import patch
|
||||
from ansible.modules.network.nxos import nxos_vxlan_vtep
|
||||
from .nxos_module import TestNxosModule, load_fixture, set_module_args
|
||||
|
||||
|
||||
class TestNxosVxlanVtepVniModule(TestNxosModule):
|
||||
|
||||
module = nxos_vxlan_vtep
|
||||
|
||||
def setUp(self):
|
||||
self.mock_load_config = patch('ansible.modules.network.nxos.nxos_vxlan_vtep.load_config')
|
||||
self.load_config = self.mock_load_config.start()
|
||||
|
||||
self.mock_get_config = patch('ansible.modules.network.nxos.nxos_vxlan_vtep.get_config')
|
||||
self.get_config = self.mock_get_config.start()
|
||||
|
||||
def tearDown(self):
|
||||
self.mock_get_config.stop()
|
||||
self.mock_load_config.stop()
|
||||
|
||||
def load_fixtures(self, commands=None, device=''):
|
||||
self.get_config.return_value = load_fixture('nxos_vxlan_vtep/config.cfg')
|
||||
self.load_config.return_value = None
|
||||
|
||||
def test_nxos_vxlan_vtep(self):
|
||||
set_module_args(dict(interface='nve1', description='simple description'))
|
||||
self.execute_module(changed=True, commands=['interface nve1', 'description simple description'])
|
||||
|
||||
def test_nxos_vxlan_vtep_present_no_change(self):
|
||||
set_module_args(dict(interface='nve1'))
|
||||
self.execute_module(changed=False, commands=[])
|
||||
|
||||
def test_nxos_vxlan_vtep_absent(self):
|
||||
set_module_args(dict(interface='nve1', state='absent'))
|
||||
self.execute_module(changed=True, commands=['no interface nve1'])
|
||||
|
||||
def test_nxos_vxlan_vtep_absent_no_change(self):
|
||||
set_module_args(dict(interface='nve2', state='absent'))
|
||||
self.execute_module(changed=False, commands=[])
|
Loading…
Reference in a new issue