Enforcing NXAPI default HTTP behavior (#41817)

* nxos_nxapi http default behavior

* Use nxos_nxapi module in prepare_nxos_tests

* Refactor nxos_nxapi configure test to use yaml block

* Extend nxos_nxapi https & http test cases

* Removed NXOS internal release naming

* Resolved ansibot sanity errors

* Fix typo in prepare_nxos_tests

* Address PR comments

* Shippable indicates this is no longer needed

* Add port change logic and testing
This commit is contained in:
tstoner 2018-07-02 14:58:37 -04:00 committed by Nathaniel Case
parent b87e1a023d
commit db7300904d
17 changed files with 279 additions and 64 deletions

View file

@ -162,7 +162,8 @@ def check_args(module, warnings):
def map_obj_to_commands(want, have, module):
commands = list()
send_commands = list()
commands = dict()
def needs_update(x):
return want.get(x) is not None and (want.get(x) != have.get(x))
@ -170,29 +171,30 @@ def map_obj_to_commands(want, have, module):
if needs_update('state'):
if want['state'] == 'absent':
return ['no feature nxapi']
commands.append('feature nxapi')
send_commands.append('feature nxapi')
elif want['state'] == 'absent':
return send_commands
if needs_update('http') or (have.get('http') and needs_update('http_port')):
if want['http'] is True or (want['http'] is None and have['http'] is True):
port = want['http_port'] or 80
commands.append('nxapi http port %s' % port)
elif want['http'] is False:
commands.append('no nxapi http')
for parameter in ['http', 'https']:
port_param = parameter + '_port'
if needs_update(parameter):
if want.get(parameter) is False:
commands[parameter] = 'no nxapi %s' % parameter
else:
commands[parameter] = 'nxapi %s port %s' % (parameter, want.get(port_param))
if needs_update('https') or (have.get('https') and needs_update('https_port')):
if want['https'] is True or (want['https'] is None and have['https'] is True):
port = want['https_port'] or 443
commands.append('nxapi https port %s' % port)
elif want['https'] is False:
commands.append('no nxapi https')
if needs_update(port_param) and want.get(parameter) is True:
commands[parameter] = 'nxapi %s port %s' % (parameter, want.get(port_param))
if needs_update('sandbox'):
cmd = 'nxapi sandbox'
commands['sandbox'] = 'nxapi sandbox'
if not want['sandbox']:
cmd = 'no %s' % cmd
commands.append(cmd)
commands['sandbox'] = 'no %s' % commands['sandbox']
return commands
for parameter in commands.keys():
send_commands.append(commands[parameter])
return send_commands
def parse_http(data):
@ -265,10 +267,10 @@ def main():
""" main entry point for module execution
"""
argument_spec = dict(
http=dict(aliases=['enable_http'], type='bool'),
http_port=dict(type='int'),
https=dict(aliases=['enable_https'], type='bool'),
https_port=dict(type='int'),
http=dict(aliases=['enable_http'], type='bool', default=True),
http_port=dict(type='int', default=80),
https=dict(aliases=['enable_https'], type='bool', default=False),
https_port=dict(type='int', default=443),
sandbox=dict(aliases=['enable_sandbox'], type='bool'),
state=dict(default='present', choices=['started', 'stopped', 'present', 'absent'])
)
@ -279,6 +281,11 @@ def main():
supports_check_mode=True)
warnings = list()
warning_msg = "Module nxos_nxapi currently defaults to configure 'http port 80'. "
warning_msg += "Default behavior is changing to configure 'https port 443'"
warning_msg += " when params 'http, http_port, https, https_port' are not set in the playbook"
module.deprecate(msg=warning_msg, version="2.11")
check_args(module, warnings)
result = {'changed': False, 'warnings': warnings}