Fix unwanted deprecation message in network module args (#28984)

* Fix unwanted deprecation message in network module argspec

Fixes #25663
Fixes #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
This commit is contained in:
Ganesh Nalawade 2017-09-12 16:30:01 +05:30 committed by Ricardo Carrillo Cruz
parent d52316fcc2
commit 599fe23ed6
30 changed files with 283 additions and 634 deletions

View file

@ -24,9 +24,8 @@ import copy
from ansible import constants as C
from ansible.plugins.action.normal import ActionModule as _ActionModule
from ansible.module_utils.sros import sros_argument_spec
from ansible.module_utils.basic import AnsibleFallbackNotFound
from ansible.module_utils.six import iteritems
from ansible.module_utils.sros import sros_provider_spec
from ansible.module_utils.network_common import load_provider
try:
from __main__ import display
@ -46,7 +45,7 @@ class ActionModule(_ActionModule):
'got %s' % self._play_context.connection
)
provider = self.load_provider()
provider = load_provider(sros_provider_spec, self._task.args)
pc = copy.deepcopy(self._play_context)
pc.connection = 'network_cli'
@ -72,30 +71,3 @@ class ActionModule(_ActionModule):
result = super(ActionModule, self).run(tmp, task_vars)
return result
def load_provider(self):
provider = self._task.args.get('provider', {})
for key, value in iteritems(sros_argument_spec):
if key != 'provider' and key not in provider:
if key in self._task.args:
provider[key] = self._task.args[key]
elif 'fallback' in value:
provider[key] = self._fallback(value['fallback'])
elif key not in provider:
provider[key] = None
return provider
def _fallback(self, fallback):
strategy = fallback[0]
args = []
kwargs = {}
for item in fallback[1:]:
if isinstance(item, dict):
kwargs = item
else:
args = item
try:
return strategy(*args, **kwargs)
except AnsibleFallbackNotFound:
pass