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
pull/30731/head
Ganesh Nalawade 7 years ago committed by GitHub
parent 118d2cda24
commit d72eb08902

@ -49,6 +49,7 @@ nxos_provider_spec = {
'use_ssl': dict(type='bool'), 'use_ssl': dict(type='bool'),
'validate_certs': dict(type='bool'), 'validate_certs': dict(type='bool'),
'timeout': dict(type='int'), 'timeout': dict(type='int'),
'transport': dict(default='cli', choices=['cli', 'nxapi']) 'transport': dict(default='cli', choices=['cli', 'nxapi'])
@ -68,7 +69,7 @@ nxos_top_spec = {
'validate_certs': dict(removed_in_version=2.9, type='bool'), 'validate_certs': dict(removed_in_version=2.9, type='bool'),
'timeout': dict(removed_in_version=2.9, type='int'), 'timeout': dict(removed_in_version=2.9, type='int'),
'transport': dict(removed_in_version=2.9, default='cli', choices=['cli', 'nxapi']) 'transport': dict(removed_in_version=2.9, choices=['cli', 'nxapi'])
} }
nxos_argument_spec.update(nxos_top_spec) nxos_argument_spec.update(nxos_top_spec)
@ -84,7 +85,7 @@ def check_args(module, warnings):
def load_params(module): def load_params(module):
provider = module.params.get('provider') or dict() provider = module.params.get('provider') or dict()
for key, value in iteritems(provider): for key, value in iteritems(provider):
if key in nxos_argument_spec: if key in nxos_provider_spec:
if module.params.get(key) is None and value is not None: if module.params.get(key) is None and value is not None:
module.params[key] = value module.params[key] = value

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

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

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

@ -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 " module.fail_json(msg="IPv6 address and mask must be provided when "
"state=absent.") "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": if is_default(interface, module) == "DNE":
module.fail_json(msg="That interface does not exist yet. Create " module.fail_json(msg="That interface does not exist yet. Create "
"it first.", interface=interface) "it first.", interface=interface)

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

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

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

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

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

@ -204,7 +204,7 @@ def main():
"Use nxos_vrf to fix this.") "Use nxos_vrf to fix this.")
intf_type = get_interface_type(interface) 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': if is_default(interface, module) == 'DNE':
module.fail_json(msg="interface does not exist on switch. Verify " module.fail_json(msg="interface does not exist on switch. Verify "
"switch platform or create it first with " "switch platform or create it first with "

@ -107,8 +107,5 @@ class ActionModule(_ActionModule):
self._task.args['provider'] = provider self._task.args['provider'] = provider
# make sure a transport value is set in args
self._task.args['transport'] = transport
result = super(ActionModule, self).run(tmp, task_vars) result = super(ActionModule, self).run(tmp, task_vars)
return result return result

@ -29,6 +29,9 @@ from ansible.module_utils._text import to_bytes
def set_module_args(args): def set_module_args(args):
if 'provider' not in args:
args['provider'] = {'transport': args.get('transport') or 'cli'}
args = json.dumps({'ANSIBLE_MODULE_ARGS': args}) args = json.dumps({'ANSIBLE_MODULE_ARGS': args})
basic._ANSIBLE_ARGS = to_bytes(args) basic._ANSIBLE_ARGS = to_bytes(args)

Loading…
Cancel
Save