Skip to content

Commit

Permalink
Fix unwanted deprecation message in network module args (ansible#28984)
Browse files Browse the repository at this point in the history
* Fix unwanted deprecation message in network module argspec

Fixes ansible#25663
Fixes ansible#24537

*  segregate provider spec and top level arg spec
*  add deprecation key in top level arg spec
*  remove action plugin code to load provider and add
   that logic at a common place in network_common.py file

* Fix CI issue

* Minor change
  • Loading branch information
ganeshrn authored and rcarrillocruz committed Sep 12, 2017
1 parent d52316f commit 599fe23
Show file tree
Hide file tree
Showing 30 changed files with 283 additions and 634 deletions.
27 changes: 12 additions & 15 deletions lib/ansible/module_utils/aireos.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,16 @@
aireos_argument_spec = {
'provider': dict(type='dict', options=aireos_provider_spec)
}
aireos_argument_spec.update(aireos_provider_spec)

# Add argument's default value here
ARGS_DEFAULT_VALUE = {}
aireos_top_spec = {
'host': dict(removed_in_version=2.3),
'port': dict(removed_in_version=2.3, type='int'),
'username': dict(removed_in_version=2.3),
'password': dict(removed_in_version=2.3, no_log=True),
'ssh_keyfile': dict(removed_in_version=2.3, type='path'),
'timeout': dict(removed_in_version=2.3, type='int'),
}
aireos_argument_spec.update(aireos_top_spec)


def sanitize(resp):
Expand All @@ -59,21 +65,12 @@ def sanitize(resp):
return '\n'.join(cleaned).strip()


def get_argspec():
return aireos_argument_spec
def get_provider_argspec():
return aireos_provider_spec


def check_args(module, warnings):
for key in aireos_argument_spec:
if key not in ['provider', 'authorize'] and module.params[key]:
warnings.append('argument %s has been deprecated and will be removed in a future version' % key)

# set argument's default value if not provided in input
# This is done to avoid unwanted argument deprecation warning
# in case argument is not given as input (outside provider).
for key in ARGS_DEFAULT_VALUE:
if not module.params.get(key, None):
module.params[key] = ARGS_DEFAULT_VALUE[key]
pass


def get_config(module, flags=None):
Expand Down
28 changes: 13 additions & 15 deletions lib/ansible/module_utils/aruba.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,25 @@
aruba_argument_spec = {
'provider': dict(type='dict', options=aruba_provider_spec)
}
aruba_argument_spec.update(aruba_provider_spec)

# Add argument's default value here
ARGS_DEFAULT_VALUE = {}
aruba_top_spec = {
'host': dict(removed_in_version=2.3),
'port': dict(removed_in_version=2.3, type='int'),
'username': dict(removed_in_version=2.3),
'password': dict(removed_in_version=2.3, no_log=True),
'ssh_keyfile': dict(removed_in_version=2.3, type='path'),
'timeout': dict(removed_in_version=2.3, type='int'),
}

aruba_argument_spec.update(aruba_top_spec)


def get_argspec():
return aruba_argument_spec
def get_provider_argspec():
return aruba_provider_spec


def check_args(module, warnings):
for key in aruba_argument_spec:
if key not in ['provider', 'authorize'] and module.params[key]:
warnings.append('argument %s has been deprecated and will be removed in a future version' % key)

# set argument's default value if not provided in input
# This is done to avoid unwanted argument deprecation warning
# in case argument is not given as input (outside provider).
for key in ARGS_DEFAULT_VALUE:
if not module.params.get(key, None):
module.params[key] = ARGS_DEFAULT_VALUE[key]
pass


def get_config(module, flags=None):
Expand Down
36 changes: 22 additions & 14 deletions lib/ansible/module_utils/asa.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
_DEVICE_CONFIGS = {}
_CONNECTION = None

asa_argument_spec = {
asa_provider_spec = {
'host': dict(),
'port': dict(type='int'),
'username': dict(fallback=(env_fallback, ['ANSIBLE_NET_USERNAME'])),
Expand All @@ -42,33 +42,41 @@
'authorize': dict(fallback=(env_fallback, ['ANSIBLE_NET_AUTHORIZE']), type='bool'),
'auth_pass': dict(fallback=(env_fallback, ['ANSIBLE_NET_AUTH_PASS']), no_log=True),
'timeout': dict(type='int'),
'provider': dict(type='dict'),
'context': dict(),
'passwords': dict()
}

asa_argument_spec = {
'provider': dict(type='dict', options=asa_provider_spec),
}

asa_top_spec = {
'host': dict(removed_in_version=2.3),
'port': dict(removed_in_version=2.3, type='int'),
'username': dict(removed_in_version=2.3),
'password': dict(removed_in_version=2.3, no_log=True),
'ssh_keyfile': dict(removed_in_version=2.3, type='path'),
'authorize': dict(type='bool'),
'auth_pass': dict(removed_in_version=2.3, no_log=True),
'timeout': dict(removed_in_version=2.3, type='int'),
'context': dict(),
'passwords': dict()
}
asa_argument_spec.update(asa_top_spec)

command_spec = {
'command': dict(key=True),
'prompt': dict(),
'answer': dict()
}


def get_argspec():
return asa_argument_spec
def get_provider_argspec():
return asa_provider_spec


def check_args(module):
provider = module.params['provider'] or {}

for key in asa_argument_spec:
if key not in ['provider', 'authorize'] and module.params[key]:
module.warn('argument %s has been deprecated and will be removed in a future version' % key)

if provider:
for param in ('auth_pass', 'password'):
if provider.get(param):
module.no_log_values.update(return_values(provider[param]))
pass


def get_connection(module):
Expand Down
17 changes: 12 additions & 5 deletions lib/ansible/module_utils/ce.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,21 @@
ce_argument_spec = {
'provider': dict(type='dict', options=ce_provider_spec),
}
ce_argument_spec.update(ce_provider_spec)
ce_top_spec = {
'host': dict(removed_in_version=2.3),
'port': dict(removed_in_version=2.3, type='int'),
'username': dict(removed_in_version=2.3),
'password': dict(removed_in_version=2.3, no_log=True),
'use_ssl': dict(removed_in_version=2.3, type='bool'),
'validate_certs': dict(removed_in_version=2.3, type='bool'),
'timeout': dict(removed_in_version=2.3, type='int'),
'transport': dict(choices=['cli']),
}
ce_argument_spec.update(ce_top_spec)


def check_args(module, warnings):
for key in ce_argument_spec:
if key not in ['provider', 'transport'] and module.params[key]:
warnings.append('argument %s has been deprecated and will be '
'removed in a future version' % key)
pass


def load_params(module):
Expand Down
17 changes: 12 additions & 5 deletions lib/ansible/module_utils/dellos10.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,21 @@
dellos10_argument_spec = {
'provider': dict(type='dict', options=dellos10_provider_spec),
}
dellos10_argument_spec.update(dellos10_provider_spec)
dellos10_top_spec = {
'host': dict(removed_in_version=2.3),
'port': dict(removed_in_version=2.3, type='int'),
'username': dict(removed_in_version=2.3),
'password': dict(removed_in_version=2.3, no_log=True),
'ssh_keyfile': dict(removed_in_version=2.3, type='path'),
'authorize': dict(removed_in_version=2.3, type='bool'),
'auth_pass': dict(removed_in_version=2.3, no_log=True),
'timeout': dict(removed_in_version=2.3, type='int'),
}
dellos10_argument_spec.update(dellos10_top_spec)


def check_args(module, warnings):
for key in dellos10_argument_spec:
if key != 'provider' and module.params[key]:
warnings.append('argument %s has been deprecated and will be '
'removed in a future version' % key)
pass


def get_config(module, flags=None):
Expand Down
17 changes: 12 additions & 5 deletions lib/ansible/module_utils/dellos6.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,21 @@
dellos6_argument_spec = {
'provider': dict(type='dict', options=dellos6_provider_spec),
}
dellos6_argument_spec.update(dellos6_provider_spec)
dellos6_top_spec = {
'host': dict(removed_in_version=2.3),
'port': dict(removed_in_version=2.3, type='int'),
'username': dict(removed_in_version=2.3),
'password': dict(removed_in_version=2.3, no_log=True),
'ssh_keyfile': dict(removed_in_version=2.3, type='path'),
'authorize': dict(removed_in_version=2.3, type='bool'),
'auth_pass': dict(removed_in_version=2.3, no_log=True),
'timeout': dict(removed_in_version=2.3, type='int'),
}
dellos6_argument_spec.update(dellos6_top_spec)


def check_args(module, warnings):
for key in dellos6_argument_spec:
if key != 'provider' and module.params[key]:
warnings.append('argument %s has been deprecated and will be '
'removed in a future version' % key)
pass


def get_config(module, flags=None):
Expand Down
17 changes: 12 additions & 5 deletions lib/ansible/module_utils/dellos9.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,21 @@
dellos9_argument_spec = {
'provider': dict(type='dict', options=dellos9_provider_spec),
}
dellos9_argument_spec.update(dellos9_provider_spec)
dellos9_top_spec = {
'host': dict(removed_in_version=2.3),
'port': dict(removed_in_version=2.3, type='int'),
'username': dict(removed_in_version=2.3),
'password': dict(removed_in_version=2.3, no_log=True),
'ssh_keyfile': dict(removed_in_version=2.3, type='path'),
'authorize': dict(removed_in_version=2.3, type='bool'),
'auth_pass': dict(removed_in_version=2.3, no_log=True),
'timeout': dict(removed_in_version=2.3, type='int'),
}
dellos9_argument_spec.update(dellos9_top_spec)


def check_args(module, warnings):
for key in dellos9_argument_spec:
if key != 'provider' and module.params[key]:
warnings.append('argument %s has been deprecated and will be '
'removed in a future version' % key)
pass


def get_config(module, flags=None):
Expand Down
43 changes: 19 additions & 24 deletions lib/ansible/module_utils/eos.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,45 +49,40 @@
'authorize': dict(fallback=(env_fallback, ['ANSIBLE_NET_AUTHORIZE']), type='bool'),
'auth_pass': dict(no_log=True, fallback=(env_fallback, ['ANSIBLE_NET_AUTH_PASS'])),

'use_ssl': dict(type='bool'),
'validate_certs': dict(type='bool'),
'use_ssl': dict(default=True, type='bool'),
'validate_certs': dict(default=True, type='bool'),
'timeout': dict(type='int'),

'transport': dict(choices=['cli', 'eapi'])
'transport': dict(default='cli', choices=['cli', 'eapi'])
}
eos_argument_spec = {
'provider': dict(type='dict', options=eos_provider_spec),
}
eos_argument_spec.update(eos_provider_spec)
eos_top_spec = {
'host': dict(removed_in_version=2.3),
'port': dict(removed_in_version=2.3, type='int'),
'username': dict(removed_in_version=2.3),
'password': dict(removed_in_version=2.3, no_log=True),
'ssh_keyfile': dict(removed_in_version=2.3, type='path'),

# Add argument's default value here
ARGS_DEFAULT_VALUE = {
'transport': 'cli',
'use_ssl': True,
'validate_certs': True
'authorize': dict(fallback=(env_fallback, ['ANSIBLE_NET_AUTHORIZE']), type='bool'),
'auth_pass': dict(no_log=True, removed_in_version=2.3),

'use_ssl': dict(removed_in_version=2.3, type='bool'),
'validate_certs': dict(removed_in_version=2.3, type='bool'),
'timeout': dict(removed_in_version=2.3, type='int'),

'transport': dict(removed_in_version=2.3, choices=['cli', 'eapi'])
}
eos_argument_spec.update(eos_top_spec)


def get_argspec():
return eos_argument_spec


def check_args(module, warnings):
for key in eos_argument_spec:
if module._name == 'eos_user':
if (key not in ['username', 'password', 'provider', 'transport', 'authorize'] and
module.params[key]):
warnings.append('argument %s has been deprecated and will be removed in a future version' % key)
else:
if key not in ['provider', 'authorize'] and module.params[key]:
warnings.append('argument %s has been deprecated and will be removed in a future version' % key)

# set argument's default value if not provided in input
# This is done to avoid unwanted argument deprecation warning
# in case argument is not given as input (outside provider).
for key in ARGS_DEFAULT_VALUE:
if not module.params.get(key, None):
module.params[key] = ARGS_DEFAULT_VALUE[key]
pass


def load_params(module):
Expand Down
27 changes: 16 additions & 11 deletions lib/ansible/module_utils/ios.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,31 @@
'ssh_keyfile': dict(fallback=(env_fallback, ['ANSIBLE_NET_SSH_KEYFILE']), type='path'),
'authorize': dict(fallback=(env_fallback, ['ANSIBLE_NET_AUTHORIZE']), type='bool'),
'auth_pass': dict(fallback=(env_fallback, ['ANSIBLE_NET_AUTH_PASS']), no_log=True),
'timeout': dict(type='int'),
'timeout': dict(type='int')
}
ios_argument_spec = {
'provider': dict(type='dict', options=ios_provider_spec),
}
ios_argument_spec.update(ios_provider_spec)

ios_top_spec = {
'host': dict(removed_in_version=2.3),
'port': dict(removed_in_version=2.3, type='int'),
'username': dict(removed_in_version=2.3),
'password': dict(removed_in_version=2.3, no_log=True),
'ssh_keyfile': dict(removed_in_version=2.3, type='path'),
'authorize': dict(fallback=(env_fallback, ['ANSIBLE_NET_AUTHORIZE']), type='bool'),
'auth_pass': dict(removed_in_version=2.3, no_log=True),
'timeout': dict(removed_in_version=2.3, type='int')
}
ios_argument_spec.update(ios_top_spec)


def get_argspec():
return ios_argument_spec
def get_provider_argspec():
return ios_provider_spec


def check_args(module, warnings):
for key in ios_argument_spec:
if module._name == 'ios_user':
if key not in ['password', 'provider', 'authorize'] and module.params[key]:
warnings.append('argument %s has been deprecated and will be in a future version' % key)
else:
if key not in ['provider', 'authorize'] and module.params[key]:
warnings.append('argument %s has been deprecated and will be removed in a future version' % key)
pass


def get_defaults_flag(module):
Expand Down
22 changes: 12 additions & 10 deletions lib/ansible/module_utils/iosxr.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,23 @@
iosxr_argument_spec = {
'provider': dict(type='dict', options=iosxr_provider_spec)
}
iosxr_argument_spec.update(iosxr_provider_spec)
iosxr_top_spec = {
'host': dict(removed_in_version=2.3),
'port': dict(removed_in_version=2.3, type='int'),
'username': dict(removed_in_version=2.3),
'password': dict(removed_in_version=2.3, no_log=True),
'ssh_keyfile': dict(removed_in_version=2.3, type='path'),
'timeout': dict(removed_in_version=2.3, type='int'),
}
iosxr_argument_spec.update(iosxr_top_spec)


def get_argspec():
return iosxr_argument_spec
def get_provider_argspec():
return iosxr_provider_spec


def check_args(module, warnings):
for key in iosxr_argument_spec:
if module._name == 'iosxr_user':
if key not in ['password', 'provider'] and module.params[key]:
warnings.append('argument %s has been deprecated and will be in a future version' % key)
else:
if key != 'provider' and module.params[key]:
warnings.append('argument %s has been deprecated and will be removed in a future version' % key)
pass


def get_config(module, flags=None):
Expand Down
Loading

0 comments on commit 599fe23

Please sign in to comment.