ACI: Fixes to recent change to parameter choices (#35968)

This PR includes:
- Fixes related to the recent merge of #31637 and #34537
- A generic fix for a reference for assignment issue
- Fixes to aci.boolean() in order to catch exception
(cherry picked from commit 01ba3a4efc)
pull/36302/head
Dag Wieers 7 years ago committed by Matt Davis
parent 36e5e4ad62
commit 76648f358e

@ -169,24 +169,34 @@ class ACIModule(object):
def boolean(self, value, true='yes', false='no'): def boolean(self, value, true='yes', false='no'):
''' Return an acceptable value back ''' ''' Return an acceptable value back '''
# When we expect value is of type=bool
if value is None: if value is None:
return None return None
elif value is True: elif value is True:
return true return true
elif value is False: elif value is False:
return false return false
elif boolean(value) is True: # When type=raw, this supports Ansible booleans
return true # When we expect value is of type=raw, deprecate in Ansible v2.8 (and all modules use type=bool)
elif boolean(value) is False: # When type=raw, this supports Ansible booleans try:
return false # This supports all Ansible boolean types
elif value == true: # When type=raw, this supports the original boolean values bool_value = boolean(value)
self.module.deprecate("Boolean value '%s' is no longer valid, please use 'yes' as a boolean value." % value, '2.9') if bool_value is True:
return true return true
elif value == false: # When type=raw, this supports the original boolean values elif bool_value is False:
self.module.deprecate("Boolean value '%s' is no longer valid, please use 'no' as a boolean value." % value, '2.9') return false
return false except:
else: # When type=raw, escalate back to user # This provides backward compatibility to Ansible v2.4, deprecate in Ansible v2.8
self.module.fail_json(msg="Boolean value '%s' is an invalid ACI boolean value.") if value == true:
self.module.deprecate("Boolean value '%s' is no longer valid, please use 'yes' as a boolean value." % value, '2.9')
return true
elif value == false:
self.module.deprecate("Boolean value '%s' is no longer valid, please use 'no' as a boolean value." % value, '2.9')
return false
# If all else fails, escalate back to user
self.module.fail_json(msg="Boolean value '%s' is an invalid ACI boolean value.")
def iso8601_format(self, dt): def iso8601_format(self, dt):
''' Return an ACI-compatible ISO8601 formatted time: 2123-12-12T00:00:00.000+00:00 ''' ''' Return an ACI-compatible ISO8601 formatted time: 2123-12-12T00:00:00.000+00:00 '''

@ -269,28 +269,25 @@ def main():
], ],
) )
aci = ACIModule(module)
if not HAS_DATEUTIL: if not HAS_DATEUTIL:
module.fail_json(msg='dateutil required for this module') module.fail_json(msg='dateutil required for this module')
aaa_password = module.params['aaa_password'] aaa_password = module.params['aaa_password']
aaa_password_lifetime = module.params['aaa_password_lifetime'] aaa_password_lifetime = module.params['aaa_password_lifetime']
aaa_password_update_required = module.params['aaa_password_update_required'] aaa_password_update_required = aci.boolean(module.params['aaa_password_update_required'])
aaa_user = module.params['aaa_user'] aaa_user = module.params['aaa_user']
clear_password_history = module.params['clear_password_history'] clear_password_history = module.params['clear_password_history']
description = module.params['description'] description = module.params['description']
email = module.params['email'] email = module.params['email']
enabled = module.params['enabled'] enabled = aci.boolean(module.params['enabled'], 'active', 'inactive')
expires = aci.boolean(module.params['expires'])
first_name = module.params['first_name'] first_name = module.params['first_name']
last_name = module.params['last_name'] last_name = module.params['last_name']
phone = module.params['phone'] phone = module.params['phone']
state = module.params['state'] state = module.params['state']
aci = ACIModule(module)
aaa_password_update_required = aci.boolean(module.params['aaa_password_update_required'])
enabled = aci.boolean(module.params['enabled'], 'active', 'inactive')
expires = aci.boolean(module.params['expires'])
expiration = module.params['expiration'] expiration = module.params['expiration']
if expiration is not None and expiration != 'never': if expiration is not None and expiration != 'never':
try: try:

@ -310,7 +310,7 @@ SUBNET_CONTROL_MAPPING = dict(nd_ra='nd', no_gw='no-default-gateway', querier_ip
from ansible.module_utils.network.aci.aci import ACIModule, aci_argument_spec from ansible.module_utils.network.aci.aci import ACIModule, aci_argument_spec
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule, SEQUENCETYPE
def main(): def main():
@ -326,10 +326,7 @@ def main():
preferred=dict(type='bool'), preferred=dict(type='bool'),
route_profile=dict(type='str'), route_profile=dict(type='str'),
route_profile_l3_out=dict(type='str'), route_profile_l3_out=dict(type='str'),
scope=dict( scope=dict(type='list', choices=['private', 'public', 'shared']),
type='list',
choices=[['private'], ['public'], ['shared'], ['private', 'shared'], ['shared', 'private'], ['public', 'shared'], ['shared', 'public']],
),
subnet_control=dict(type='str', choices=['nd_ra', 'no_gw', 'querier_ip', 'unspecified']), subnet_control=dict(type='str', choices=['nd_ra', 'no_gw', 'querier_ip', 'unspecified']),
state=dict(type='str', default='present', choices=['absent', 'present', 'query']), state=dict(type='str', default='present', choices=['absent', 'present', 'query']),
tenant=dict(type='str', aliases=['tenant_name']), tenant=dict(type='str', aliases=['tenant_name']),
@ -366,13 +363,11 @@ def main():
route_profile = module.params['route_profile'] route_profile = module.params['route_profile']
route_profile_l3_out = module.params['route_profile_l3_out'] route_profile_l3_out = module.params['route_profile_l3_out']
scope = module.params['scope'] scope = module.params['scope']
if scope: if isinstance(scope, SEQUENCETYPE):
if len(scope) == 1: if 'private' in scope and 'public' in scope:
scope = scope[0] module.fail_json(msg="Parameter 'scope' cannot be both 'private' and 'public', got: %s" % scope)
elif 'public' in scope:
scope = 'public,shared'
else: else:
scope = 'private,shared' scope = ','.join(sorted(scope))
state = module.params['state'] state = module.params['state']
subnet_control = module.params['subnet_control'] subnet_control = module.params['subnet_control']
if subnet_control: if subnet_control:

@ -199,6 +199,8 @@ def main():
], ],
) )
aci = ACIModule(module)
l2_policy = module.params['l2_policy'] l2_policy = module.params['l2_policy']
vlan_scope = module.params['vlan_scope'] vlan_scope = module.params['vlan_scope']
qinq = module.params['qinq'] qinq = module.params['qinq']
@ -208,7 +210,6 @@ def main():
description = module.params['description'] description = module.params['description']
state = module.params['state'] state = module.params['state']
aci = ACIModule(module)
aci.construct_url( aci.construct_url(
root_class=dict( root_class=dict(
aci_class='l2IfPol', aci_class='l2IfPol',

@ -194,13 +194,14 @@ def main():
], ],
) )
aci = ACIModule(module)
lldp_policy = module.params['lldp_policy'] lldp_policy = module.params['lldp_policy']
description = module.params['description'] description = module.params['description']
receive_state = aci.boolean(module.params['receive_state'], 'enabled', 'disabled') receive_state = aci.boolean(module.params['receive_state'], 'enabled', 'disabled')
transmit_state = aci.boolean(module.params['transmit_state'], 'enabled', 'disabled') transmit_state = aci.boolean(module.params['transmit_state'], 'enabled', 'disabled')
state = module.params['state'] state = module.params['state']
aci = ACIModule(module)
aci.construct_url( aci.construct_url(
root_class=dict( root_class=dict(
aci_class='lldpIfPol', aci_class='lldpIfPol',

@ -185,12 +185,13 @@ def main():
], ],
) )
aci = ACIModule(module)
mcp = module.params['mcp'] mcp = module.params['mcp']
description = module.params['description'] description = module.params['description']
admin_state = aci.boolean(module.params['admin_state'], 'enabled', 'disabled') admin_state = aci.boolean(module.params['admin_state'], 'enabled', 'disabled')
state = module.params['state'] state = module.params['state']
aci = ACIModule(module)
aci.construct_url( aci.construct_url(
root_class=dict( root_class=dict(
aci_class='mcpIfPol', aci_class='mcpIfPol',

@ -197,6 +197,8 @@ def main():
], ],
) )
aci = ACIModule(module)
admin_state = aci.boolean(module.params['admin_state'], 'enabled', 'disabled') admin_state = aci.boolean(module.params['admin_state'], 'enabled', 'disabled')
description = module.params['description'] description = module.params['description']
dst_group = module.params['dst_group'] dst_group = module.params['dst_group']
@ -204,7 +206,6 @@ def main():
state = module.params['state'] state = module.params['state']
tenant = module.params['tenant'] tenant = module.params['tenant']
aci = ACIModule(module)
aci.construct_url( aci.construct_url(
root_class=dict( root_class=dict(
aci_class='fvTenant', aci_class='fvTenant',

@ -109,7 +109,7 @@
- modify_subnet.changed != modify_subnet.proposed - modify_subnet.changed != modify_subnet.proposed
- 'modify_subnet.sent == {"fvSubnet": {"attributes": {"ctrl": "querier", "scope": "public,shared"}}}' - 'modify_subnet.sent == {"fvSubnet": {"attributes": {"ctrl": "querier", "scope": "public,shared"}}}'
- create_bad_scope.failed == true - create_bad_scope.failed == true
- 'create_bad_scope.msg.startswith("value of scope must be one of")' - create_bad_scope.msg.startswith("Parameter 'scope' cannot be both 'private' and 'public'")
- create_incomplete_data.failed == true - create_incomplete_data.failed == true
- 'create_incomplete_data.msg == "state is present but all of the following are missing: bd"' - 'create_incomplete_data.msg == "state is present but all of the following are missing: bd"'

Loading…
Cancel
Save