Fix nxos provider transport warning issue (#30610)

* Fix nxos provider transport warning issue

*  Add default value of transport arg in provider spec
*  Remove default value if transport arg in top level spec
   This ensure deprecation warning is seen only in case transport
   is given as a top level arg in task
*  Refactor nxos modules to reference transport value from provider
   spec

* Fix unit test

* Remove transport arg assignment in nxos action plugin

* As assigning transport value is handled in provider spec
  top level task arg assignment is no longer required
This commit is contained in:
Ganesh Nalawade 2017-09-22 10:32:25 +05:30 committed by GitHub
commit d72eb08902
13 changed files with 33 additions and 29 deletions

View file

@ -161,12 +161,13 @@ from ansible.module_utils.basic import AnsibleModule
def execute_show_command(command, module, command_type='cli_show'):
if module.params['transport'] == 'cli':
provider = module.params['provider']
if provider['transport'] == 'cli':
if 'show run' not in command:
command += ' | json'
cmds = [command]
body = run_commands(module, cmds)
elif module.params['transport'] == 'nxapi':
elif provider['transport'] == 'nxapi':
cmds = {'command': command, 'output': 'text'}
body = run_commands(module, cmds)

View file

@ -170,9 +170,10 @@ from ansible.module_utils.basic import AnsibleModule
def execute_show_command(command, module, command_type='cli_show_ascii'):
cmds = [command]
if module.params['transport'] == 'cli':
provider = module.params['provider']
if provider['transport'] == 'cli':
body = run_commands(module, cmds)
elif module.params['transport'] == 'nxapi':
elif provider['transport'] == 'nxapi':
body = run_commands(module, cmds)
return body

View file

@ -129,11 +129,12 @@ from ansible.module_utils.basic import AnsibleModule
def execute_show_command(command, module):
if module.params['transport'] == 'cli':
provider = module.params['provider']
if provider['transport'] == 'cli':
command += ' | json'
cmds = [command]
body = run_commands(module, cmds)
elif module.params['transport'] == 'nxapi':
elif provider['transport'] == 'nxapi':
cmds = [command]
body = run_commands(module, cmds)
@ -394,7 +395,7 @@ def main():
auth_type = module.params['auth_type']
auth_string = module.params['auth_string']
transport = module.params['transport']
transport = module.params['provider']['transport']
if state == 'present' and not vip:
module.fail_json(msg='the "vip" param is required when state=present')

View file

@ -425,7 +425,7 @@ def validate_params(addr, interface, mask, tag, allow_secondary, version, state,
module.fail_json(msg="IPv6 address and mask must be provided when "
"state=absent.")
if intf_type != "ethernet" and module.params["transport"] == "cli":
if intf_type != "ethernet" and module.params["provider"]["transport"] == "cli":
if is_default(interface, module) == "DNE":
module.fail_json(msg="That interface does not exist yet. Create "
"it first.", interface=interface)

View file

@ -131,10 +131,9 @@ from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.six import iteritems
def check_args(module, warnings):
transport = module.params['transport']
provider_transport = (module.params['provider'] or {}).get('transport')
if 'nxapi' in (transport, provider_transport):
module.fail_json(msg='transport=nxapi is not supporting when configuring nxapi')
provider = module.params['provider']
if provider['transport'] == 'nxapi':
module.fail_json(msg='module not supported over nxapi transport')
nxos_check_args(module, warnings)
@ -149,9 +148,6 @@ def check_args(module, warnings):
warnings.append('state=stopped is deprecated and will be removed in a '
'a future release. Please use state=absent instead')
if module.params['transport'] == 'nxapi':
module.fail_json(msg='module not supported over nxapi transport')
for key in ['config']:
if module.params[key]:
warnings.append('argument %s is deprecated and will be ignored' % key)

View file

@ -142,12 +142,13 @@ def get_custom_value(arg, config, module):
def execute_show_command(command, module):
if module.params['transport'] == 'cli':
provider = module.params['provider']
if provider['transport'] == 'cli':
if 'show port-channel summary' in command:
command += ' | json'
cmds = [command]
body = run_commands(module, cmds)
elif module.params['transport'] == 'nxapi':
elif provider['transport'] == 'nxapi':
cmds = [command]
body = run_commands(module, cmds)

View file

@ -434,11 +434,12 @@ def apply_value_map(value_map, resource):
def execute_show_command(command, module, command_type='cli_show'):
if module.params['transport'] == 'cli':
provider = module.params['provider']
if provider['transport'] == 'cli':
command += ' | json'
cmds = [command]
body = run_commands(module, cmds)
elif module.params['transport'] == 'nxapi':
elif provider['transport'] == 'nxapi':
cmds = [command]
body = run_commands(module, cmds)

View file

@ -121,12 +121,13 @@ import re
def execute_show_command(command, module, command_type='cli_show'):
if module.params['transport'] == 'cli':
provider = module.params['provider']
if provider['transport'] == 'cli':
if 'show run' not in command:
command += ' | json'
cmds = [command]
body = run_commands(module, cmds)
elif module.params['transport'] == 'nxapi':
elif provider['transport'] == 'nxapi':
cmds = [command]
body = run_commands(module, cmds)

View file

@ -116,12 +116,13 @@ from ansible.module_utils.basic import AnsibleModule
def execute_show_command(command, module, command_type='cli_show'):
if module.params['transport'] == 'cli':
provider = module.params['provider']
if provider['transport'] == 'cli':
if 'show run' not in command:
command += ' | json'
cmds = [command]
body = run_commands(module, cmds)
elif module.params['transport'] == 'nxapi':
elif provider['transport'] == 'nxapi':
cmds = [command]
body = run_commands(module, cmds)

View file

@ -204,7 +204,7 @@ def main():
"Use nxos_vrf to fix this.")
intf_type = get_interface_type(interface)
if (intf_type != 'ethernet' and module.params['transport'] == 'cli'):
if (intf_type != 'ethernet' and module.params['provider']['transport'] == 'cli'):
if is_default(interface, module) == 'DNE':
module.fail_json(msg="interface does not exist on switch. Verify "
"switch platform or create it first with "