From d9a52db17da0ac371ea5be9850b66eae6f200888 Mon Sep 17 00:00:00 2001 From: Corban Johnson Date: Mon, 20 Nov 2017 23:15:13 -0600 Subject: [PATCH] Adding RPC attribute parameters to junos_rpc network module (#32649) * Adding RPC attribute arguments to `junos_rpc` network module. * Specifying module argument version. * Fixing DOCUMENTATION block. * First attempt at new test fixture. * Updated RPC_CLI_MAP. * Use `result` instead of `reply`. --- lib/ansible/modules/network/junos/junos_rpc.py | 17 +++++++++++++++++ .../junos/fixtures/load_configuration_xml.txt | 6 ++++++ .../modules/network/junos/test_junos_rpc.py | 8 +++++++- 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 test/units/modules/network/junos/fixtures/load_configuration_xml.txt diff --git a/lib/ansible/modules/network/junos/junos_rpc.py b/lib/ansible/modules/network/junos/junos_rpc.py index eed1aea78d3..3078f2ba02a 100644 --- a/lib/ansible/modules/network/junos/junos_rpc.py +++ b/lib/ansible/modules/network/junos/junos_rpc.py @@ -39,6 +39,11 @@ options: accepts a set of key=value arguments. required: false default: null + attrs: + description: + - The C(attrs) arguments defines a list of attributes and their values + to set for the RPC call. This accepts a dictionary of key-values. + version_added: "2.5" output: description: - The C(output) argument specifies the desired output of the @@ -66,6 +71,13 @@ EXAMPLES = """ - name: get system information junos_rpc: rpc: get-system-information + +- name: load configuration + junos_rpc: + rpc: load-configuration + attrs: + action: override + url: /tmp/config.conf """ RETURN = """ @@ -101,6 +113,7 @@ def main(): argument_spec = dict( rpc=dict(required=True), args=dict(type='dict'), + attrs=dict(type='dict'), output=dict(default='xml', choices=['xml', 'json', 'text']), ) @@ -120,9 +133,13 @@ def main(): module.fail_json(msg='invalid rpc for running in check_mode') args = module.params['args'] or {} + attrs = module.params['attrs'] or {} xattrs = {'format': module.params['output']} + for key, value in iteritems(attrs): + xattrs.update({key: value}) + element = Element(module.params['rpc'], xattrs) for key, value in iteritems(args): diff --git a/test/units/modules/network/junos/fixtures/load_configuration_xml.txt b/test/units/modules/network/junos/fixtures/load_configuration_xml.txt new file mode 100644 index 00000000000..72ba03fccf8 --- /dev/null +++ b/test/units/modules/network/junos/fixtures/load_configuration_xml.txt @@ -0,0 +1,6 @@ + + + + 0 + + diff --git a/test/units/modules/network/junos/test_junos_rpc.py b/test/units/modules/network/junos/test_junos_rpc.py index 7ac8f89a0e0..8046d61ec38 100644 --- a/test/units/modules/network/junos/test_junos_rpc.py +++ b/test/units/modules/network/junos/test_junos_rpc.py @@ -35,7 +35,8 @@ RPC_CLI_MAP = { 'get-interface-information': 'show interfaces details', 'get-system-memory-information': 'show system memory', 'get-chassis-inventory': 'show chassis hardware', - 'get-system-storage': 'show system storage' + 'get-system-storage': 'show system storage', + 'load-configuration': 'load configuration' } @@ -91,3 +92,8 @@ class TestJunosCommandModule(TestJunosModule): args, kwargs = self.send_request.call_args reply = tostring(args[1]).decode() self.assertTrue(reply.find('em0')) + + def test_junos_rpc_attrs(self): + set_module_args(dict(rpc='load-configuration', output='xml', attrs={'url': '/var/tmp/config.conf'})) + result = self.execute_module(format='xml') + self.assertTrue(result['xml'].find(''))