Add integration tests and fix nxos providers (#26913)

* fix issues with python3.x

* Add integration testa and fix for nxos_evpn_vni

* add nxos_evpn_vni to nxos.yaml

* fix get_vtp_config()

* add new integration tests

* fix rollback

* add integration test files
This commit is contained in:
saichint 2017-07-27 06:32:35 -07:00 committed by Nathaniel Case
commit 9b9a8749da
66 changed files with 1158 additions and 80 deletions

View file

@ -297,9 +297,10 @@ def main():
else:
candidate = CustomNetworkConfig(indent=3)
candidate.add(commands, parents=parents)
candidate = candidate.items_text()
load_config(module, candidate)
results['changed'] = True
results['commands'] = candidate.items_text()
results['commands'] = candidate
else:
results['commands'] = []
module.exit_json(**results)

View file

@ -83,12 +83,20 @@ from ansible.module_utils.basic import AnsibleModule
def checkpoint(filename, module):
commands = ['terminal dont-ask', 'checkpoint file %s' % filename]
commands = [{
'command': 'terminal dont-ask',
'output': 'text', }, {
'command': 'checkpoint file %s' % filename,
'output': 'text',
}]
run_commands(module, commands)
def rollback(filename, module):
commands = ['rollback running-config file %s' % filename]
commands = [{
'command': 'rollback running-config file %s' % filename,
'output': 'text',
}]
run_commands(module, commands)

View file

@ -104,12 +104,14 @@ from ansible.module_utils.basic import AnsibleModule
def execute_show_command(command, module):
transport = module.params['transport']
if transport == 'cli':
if 'show run' not in command:
command += ' | json'
cmds = [command]
if 'show run' not in command:
output = 'json'
else:
output = 'text'
cmds = [{
'command': command,
'output': output,
}]
body = run_commands(module, cmds)
return body
@ -222,7 +224,6 @@ def main():
check_args(module, warnings)
results = dict(changed=False, warnings=warnings)
vrf = module.params['vrf']
admin_state = module.params['admin_state'].lower()
description = module.params['description']

View file

@ -101,23 +101,24 @@ changed:
'''
import re
from ansible.module_utils.nxos import get_config, load_config, run_commands
from ansible.module_utils.nxos import load_config, run_commands
from ansible.module_utils.nxos import nxos_argument_spec, check_args
from ansible.module_utils.basic import AnsibleModule
WARNINGS = []
def execute_show_command(command, module, command_type='cli_show'):
if module.params['transport'] == 'cli':
if 'show run' not in command:
command += ' | json'
cmds = [command]
body = run_commands(module, cmds)
elif module.params['transport'] == 'nxapi':
cmds = [command]
body = run_commands(module, cmds)
def execute_show_command(command, module, command_type='cli_show'):
if 'show run' not in command:
output = 'json'
else:
output = 'text'
cmds = [{
'command': command,
'output': output,
}]
body = run_commands(module, cmds)
return body
@ -174,9 +175,6 @@ def get_interface_info(interface, module):
if not interface.startswith('loopback'):
interface = interface.capitalize()
interface_type = get_interface_type(interface)
intf_module = re.split('\d+', interface)[0]
intf_name = interface_type + interface.split(intf_module)[1]
command = 'show run | section interface.{0}'.format(interface)
vrf_regex = ".*vrf\s+member\s+(?P<vrf>\S+).*"
@ -227,7 +225,6 @@ def main():
warnings = list()
check_args(module, warnings)
vrf = module.params['vrf']
interface = module.params['interface'].lower()
state = module.params['state']
@ -305,4 +302,3 @@ def main():
if __name__ == '__main__':
main()

View file

@ -137,21 +137,22 @@ changed:
type: boolean
sample: true
'''
import re
from ansible.module_utils.nxos import get_config, load_config, run_commands
from ansible.module_utils.nxos import load_config, run_commands
from ansible.module_utils.nxos import nxos_argument_spec, check_args
from ansible.module_utils.basic import AnsibleModule
def execute_show_command(command, module, command_type='cli_show'):
if module.params['transport'] == 'cli':
command += ' | json'
cmds = [command]
body = run_commands(module, cmds)
elif module.params['transport'] == 'nxapi':
cmds = [command]
body = run_commands(module, cmds)
def execute_show_command(command, module):
if 'show run' not in command:
output = 'json'
else:
output = 'text'
cmds = [{
'command': command,
'output': output,
}]
body = run_commands(module, cmds)
return body
@ -167,7 +168,6 @@ def apply_key_map(key_map, table):
new_dict[new_key] = value
return new_dict
def get_interface_type(interface):
if interface.upper().startswith('ET'):
return 'ethernet'
@ -223,7 +223,7 @@ def get_interface_mode(interface, intf_type, module):
def get_vrr_status(group, module, interface):
command = 'show run all | section interface.{0}$'.format(interface)
body = execute_show_command(command, module, command_type='cli_show_ascii')[0]
body = execute_show_command(command, module)[0]
vrf_index = None
admin_state = 'shutdown'
@ -373,7 +373,6 @@ def main():
warnings = list()
check_args(module, warnings)
state = module.params['state']
interface = module.params['interface'].lower()
group = module.params['group']
@ -451,4 +450,3 @@ def main():
if __name__ == '__main__':
main()

View file

@ -86,22 +86,22 @@ changed:
'''
from ansible.module_utils.nxos import get_config, load_config, run_commands
from ansible.module_utils.nxos import load_config, run_commands
from ansible.module_utils.nxos import nxos_argument_spec, check_args
from ansible.module_utils.basic import AnsibleModule
import re
def execute_show_command(command, module, command_type='cli_show'):
if module.params['transport'] == 'cli':
if 'status' not in command:
command += ' | json'
cmds = [command]
body = run_commands(module, cmds)
elif module.params['transport'] == 'nxapi':
cmds = [command]
body = run_commands(module, cmds)
if 'status' not in command:
output = 'json'
else:
output = 'text'
cmds = [{
'command': command,
'output': output,
}]
body = run_commands(module, cmds)
return body
@ -117,9 +117,8 @@ def flatten_list(command_lists):
def get_vtp_config(module):
command = 'show vtp status'
body = execute_show_command(
command, module, command_type='cli_show_ascii')[0]
command, module)[0]
vtp_parsed = {}
if body:
@ -169,7 +168,6 @@ def main():
warnings = list()
check_args(module, warnings)
domain = module.params['domain']
existing = get_vtp_config(module)
@ -209,4 +207,3 @@ def main():
if __name__ == '__main__':
main()

View file

@ -103,22 +103,22 @@ changed:
sample: true
'''
from ansible.module_utils.nxos import get_config, load_config, run_commands
from ansible.module_utils.nxos import load_config, run_commands
from ansible.module_utils.nxos import nxos_argument_spec, check_args
from ansible.module_utils.basic import AnsibleModule
import re
def execute_show_command(command, module, command_type='cli_show'):
if module.params['transport'] == 'cli':
if 'show run' not in command:
command += ' | json'
cmds = [command]
body = run_commands(module, cmds)
elif module.params['transport'] == 'nxapi':
cmds = [command]
body = run_commands(module, cmds)
if 'status' not in command:
output = 'json'
else:
output = 'text'
cmds = [{
'command': command,
'output': output,
}]
body = run_commands(module, cmds)
return body
@ -149,7 +149,7 @@ def get_vtp_config(module):
command = 'show vtp status'
body = execute_show_command(
command, module, command_type='cli_show_ascii')[0]
command, module)[0]
vtp_parsed = {}
if body:
@ -201,7 +201,6 @@ def main():
warnings = list()
check_args(module, warnings)
vtp_password = module.params['vtp_password'] or None
state = module.params['state']
@ -266,4 +265,3 @@ def main():
if __name__ == '__main__':
main()

View file

@ -81,7 +81,7 @@ changed:
type: boolean
sample: true
'''
from ansible.module_utils.nxos import get_config, load_config, run_commands
from ansible.module_utils.nxos import load_config, run_commands
from ansible.module_utils.nxos import nxos_argument_spec, check_args
from ansible.module_utils.basic import AnsibleModule
@ -91,15 +91,15 @@ import re
def execute_show_command(command, module, command_type='cli_show'):
if module.params['transport'] == 'cli':
if 'status' not in command:
command += ' | json'
cmds = [command]
body = run_commands(module, cmds)
elif module.params['transport'] == 'nxapi':
cmds = [command]
body = run_commands(module, cmds)
if 'status' not in command:
output = 'json'
else:
output = 'text'
cmds = [{
'command': command,
'output': output,
}]
body = run_commands(module, cmds)
return body
@ -115,9 +115,8 @@ def flatten_list(command_lists):
def get_vtp_config(module):
command = 'show vtp status'
body = execute_show_command(
command, module, command_type='cli_show_ascii')[0]
command, module)[0]
vtp_parsed = {}
if body:
@ -167,7 +166,6 @@ def main():
warnings = list()
check_args(module, warnings)
version = module.params['version']
existing = get_vtp_config(module)
@ -207,4 +205,3 @@ def main():
if __name__ == '__main__':
main()