updates iosxr modules to support socket (#21231)

* updates all iosxr modules to support persistent socket
* adds iosxr action plugin to connect to device
* adds exec_command() to iosxr shared module
* fixes iosxr_config and iosxr_template local action
* update all unit test cases
* adds base test module for iosxr module testing
This commit is contained in:
Peter Sprygada 2017-02-15 10:47:02 -05:00 committed by GitHub
commit eb1453a366
17 changed files with 466 additions and 623 deletions

View file

@ -34,7 +34,6 @@ description:
commands that are not already configured. The config source can
be a set of commands or a template.
deprecated: Deprecated in 2.2. Use M(iosxr_config) instead.
extends_documentation_fragment: iosxr
options:
src:
description:
@ -99,39 +98,11 @@ updates:
returned: always
type: list
sample: ['...', '...']
start:
description: The time the job started
returned: always
type: str
sample: "2016-11-16 10:38:15.126146"
end:
description: The time the job ended
returned: always
type: str
sample: "2016-11-16 10:38:25.595612"
delta:
description: The time elapsed to perform all operations
returned: always
type: str
sample: "0:00:10.469466"
"""
from ansible.module_utils.local import LocalAnsibleModule
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.netcfg import NetworkConfig, dumps
from ansible.module_utils.iosxr import get_config, load_config
from ansible.module_utils.network import NET_TRANSPORT_ARGS, _transitional_argument_spec
def check_args(module):
warnings = list()
for key in NET_TRANSPORT_ARGS:
if module.params[key]:
warnings.append(
'network provider arguments are no longer supported. Please '
'use connection: network_cli for the task'
)
break
return warnings
from ansible.module_utils.iosxr import iosxr_argument_spec, check_args
def main():
@ -145,17 +116,16 @@ def main():
config=dict(),
)
# Removed the use of provider arguments in 2.3 due to network_cli
# connection plugin. To be removed in 2.5
argument_spec.update(_transitional_argument_spec())
argument_spec.update(iosxr_argument_spec)
mutually_exclusive = [('config', 'backup'), ('config', 'force')]
module = LocalAnsibleModule(argument_spec=argument_spec,
module = AnsibleModule(argument_spec=argument_spec,
mutually_exclusive=mutually_exclusive,
supports_check_mode=True)
warnings = check_args(module)
warnings = list()
check_args(module, warnings)
result = dict(changed=False, warnings=warnings)
@ -178,6 +148,7 @@ def main():
result['changed'] = not module.check_mode
result['updates'] = commands
result['commands'] = commands
module.exit_json(**result)

View file

@ -126,31 +126,15 @@ failed_conditions:
returned: failed
type: list
sample: ['...', '...']
start:
description: The time the job started
returned: always
type: str
sample: "2016-11-16 10:38:15.126146"
end:
description: The time the job ended
returned: always
type: str
sample: "2016-11-16 10:38:25.595612"
delta:
description: The time elapsed to perform all operations
returned: always
type: str
sample: "0:00:10.469466"
"""
import time
from ansible.module_utils.local import LocalAnsibleModule
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.iosxr import run_commands
from ansible.module_utils.network_common import ComplexList
from ansible.module_utils.netcli import Conditional
from ansible.module_utils.six import string_types
VALID_KEYS = ['command', 'output', 'prompt', 'response']
from ansible.module_utils.iosxr import iosxr_argument_spec, check_args
def to_lines(stdout):
for item in stdout:
@ -182,7 +166,6 @@ def parse_commands(module, warnings):
def main():
spec = dict(
# { command: <str>, output: <str>, prompt: <str>, response: <str> }
commands=dict(type='list', required=True),
wait_for=dict(type='list', aliases=['waitfor']),
@ -192,10 +175,14 @@ def main():
interval=dict(default=1, type='int')
)
module = LocalAnsibleModule(argument_spec=spec,
spec.update(iosxr_argument_spec)
module = AnsibleModule(argument_spec=spec,
supports_check_mode=True)
warnings = list()
check_args(module, warnings)
commands = parse_commands(module, warnings)
wait_for = module.params['wait_for'] or list()

View file

@ -31,7 +31,6 @@ description:
for segmenting configuration into sections. This module provides
an implementation for working with IOS XR configuration sections in
a deterministic way.
extends_documentation_fragment: iosxr
options:
lines:
description:
@ -177,26 +176,11 @@ backup_path:
returned: when backup is yes
type: path
sample: /playbooks/ansible/backup/iosxr01.2016-07-16@22:28:34
start:
description: The time the job started
returned: always
type: str
sample: "2016-11-16 10:38:15.126146"
end:
description: The time the job ended
returned: always
type: str
sample: "2016-11-16 10:38:25.595612"
delta:
description: The time elapsed to perform all operations
returned: always
type: str
sample: "0:00:10.469466"
"""
from ansible.module_utils.local import LocalAnsibleModule
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.netcfg import NetworkConfig, dumps
from ansible.module_utils.iosxr import load_config,get_config
from ansible.module_utils.network import NET_TRANSPORT_ARGS, _transitional_argument_spec
from ansible.module_utils.iosxr import iosxr_argument_spec, check_args
DEFAULT_COMMIT_COMMENT = 'configured by iosxr_config'
@ -210,14 +194,6 @@ def check_args(module, warnings):
'match=none instead. This argument will be '
'removed in the future')
for key in NET_TRANSPORT_ARGS:
if module.params[key]:
warnings.append(
'network provider arguments are no longer supported. Please '
'use connection: network_cli for the task'
)
break
def get_running_config(module):
contents = module.params['config']
if not contents:
@ -261,7 +237,7 @@ def run(module, result):
if module.params['after']:
commands.extend(module.params['after'])
result['updates'] = commands
result['commands'] = commands
diff = load_config(module, commands, not check_mode,
replace_config, comment)
@ -293,7 +269,7 @@ def main():
comment=dict(default=DEFAULT_COMMIT_COMMENT),
)
argument_spec.update(_transitional_argument_spec())
argument_spec.update(iosxr_argument_spec)
mutually_exclusive = [('lines', 'src')]
@ -302,10 +278,10 @@ def main():
('replace', 'block', ['lines']),
('replace', 'config', ['src'])]
module = LocalAnsibleModule(argument_spec=argument_spec,
mutually_exclusive=mutually_exclusive,
required_if=required_if,
supports_check_mode=True)
module = AnsibleModule(argument_spec=argument_spec,
mutually_exclusive=mutually_exclusive,
required_if=required_if,
supports_check_mode=True)
if module.params['force'] is True:
module.params['match'] = 'none'

View file

@ -31,7 +31,6 @@ description:
base network fact keys with C(ansible_net_<fact>). The facts
module will always collect a base set of facts from the device
and can enable or disable collection of additional facts.
extends_documentation_fragment: iosxr
options:
gather_subset:
description:
@ -122,9 +121,10 @@ ansible_net_neighbors:
import re
from ansible.module_utils.iosxr import run_commands
from ansible.module_utils.local import LocalAnsibleModule
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.six import iteritems
from ansible.module_utils.six.moves import zip
from ansible.module_utils.iosxr import iosxr_argument_spec, check_args
class FactsBase(object):
@ -359,7 +359,13 @@ def main():
gather_subset=dict(default=['!config'], type='list')
)
module = LocalAnsibleModule(argument_spec=spec, supports_check_mode=True)
spec.update(iosxr_argument_spec)
module = AnsibleModule(argument_spec=spec,
supports_check_mode=True)
warnings = list()
check_args(module, warnings)
gather_subset = module.params['gather_subset']
@ -416,7 +422,7 @@ def main():
key = 'ansible_net_%s' % key
ansible_facts[key] = value
module.exit_json(ansible_facts=ansible_facts)
module.exit_json(ansible_facts=ansible_facts, warnings=warnings)
if __name__ == '__main__':

View file

@ -126,26 +126,12 @@ commands:
sample:
- hostname iosxr01
- ip domain-name eng.ansible.com
start:
description: The time the job started
returned: always
type: str
sample: "2016-11-16 10:38:15.126146"
end:
description: The time the job ended
returned: always
type: str
sample: "2016-11-16 10:38:25.595612"
delta:
description: The time elapsed to perform all operations
returned: always
type: str
sample: "0:00:10.469466"
"""
import re
from ansible.module_utils.local import LocalAnsibleModule
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.iosxr import get_config, load_config
from ansible.module_utils.iosxr import iosxr_argument_spec, check_args
def diff_list(want, have):
adds = set(want).difference(have)
@ -254,11 +240,15 @@ def main():
state=dict(choices=['present', 'absent'], default='present')
)
module = LocalAnsibleModule(argument_spec=argument_spec,
supports_check_mode=True)
argument_spec.update(iosxr_argument_spec)
module = AnsibleModule(argument_spec=argument_spec,
supports_check_mode=True)
result = {'changed': False}
warnings = list()
check_args(module, warnings)
result = {'changed': False, 'warnings': warnings}
want = map_params_to_obj(module)
have = map_config_to_obj(module)