From 4a995f26a3904c5f2fb4805b37c0ca5891a8c5cc Mon Sep 17 00:00:00 2001 From: kakurpiel Date: Sat, 9 Nov 2019 03:33:01 -0600 Subject: [PATCH] Update aruba modules to handle prompt and syntax changes (#54261) * Update prompt matching to handle changes introduced in arubaos 8.x * Update aruba modules to support command changes on arubaos 8.x --- .../modules/network/aruba/aruba_config.py | 20 +++++++++---------- lib/ansible/plugins/cliconf/aruba.py | 2 +- lib/ansible/plugins/terminal/aruba.py | 2 +- .../network/aruba/test_aruba_config.py | 4 ++-- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/ansible/modules/network/aruba/aruba_config.py b/lib/ansible/modules/network/aruba/aruba_config.py index 2123dfbe841..05a107d688f 100644 --- a/lib/ansible/modules/network/aruba/aruba_config.py +++ b/lib/ansible/modules/network/aruba/aruba_config.py @@ -105,13 +105,13 @@ options: changes are not copied to non-volatile storage by default. Using this argument will change that before. If the argument is set to I(always), then the running-config will always be copied to the - startup-config and the I(modified) flag will always be set to + startup configuration and the I(modified) flag will always be set to True. If the argument is set to I(modified), then the running-config - will only be copied to the startup-config if it has changed since - the last save to startup-config. If the argument is set to + will only be copied to the startup configuration if it has changed since + the last save to startup configuration. If the argument is set to I(never), the running-config will never be copied to the - startup-config. If the argument is set to I(changed), then the running-config - will only be copied to the startup-config if the task has made a change. + startup configuration. If the argument is set to I(changed), then the running-config + will only be copied to the startup configuration if the task has made a change. default: never choices: ['always', 'never', 'modified', 'changed'] version_added: "2.5" @@ -120,7 +120,7 @@ options: - When using the C(ansible-playbook --diff) command line argument the module can generate diffs against different sources. - When this option is configure as I(startup), the module will return - the diff of the running-config against the startup-config. + the diff of the running-config against the startup configuration. - When this option is configured as I(intended), the module will return the diff of the running-config against the configuration provided in the C(intended_config) argument. @@ -261,9 +261,9 @@ def get_candidate(module): def save_config(module, result): result['changed'] = True if not module.check_mode: - run_commands(module, 'copy running-config startup-config') + run_commands(module, 'write memory') else: - module.warn('Skipping command `copy running-config startup-config` ' + module.warn('Skipping command `write memory` ' 'due to check_mode. Configuration not copied to ' 'non-volatile storage') @@ -369,7 +369,7 @@ def main(): if module.params['save_when'] == 'always': save_config(module, result) elif module.params['save_when'] == 'modified': - output = run_commands(module, ['show running-config', 'show startup-config']) + output = run_commands(module, ['show running-config', 'show configuration']) running_config = NetworkConfig(contents=output[0], ignore_lines=diff_ignore_lines) startup_config = NetworkConfig(contents=output[1], ignore_lines=diff_ignore_lines) @@ -399,7 +399,7 @@ def main(): elif module.params['diff_against'] == 'startup': if not startup_config: - output = run_commands(module, 'show startup-config') + output = run_commands(module, 'show configuration') contents = output[0] else: contents = startup_config.config_text diff --git a/lib/ansible/plugins/cliconf/aruba.py b/lib/ansible/plugins/cliconf/aruba.py index 8dd146575dd..27583793eff 100644 --- a/lib/ansible/plugins/cliconf/aruba.py +++ b/lib/ansible/plugins/cliconf/aruba.py @@ -72,7 +72,7 @@ class Cliconf(CliconfBase): if source == 'running': cmd = 'show running-config all' else: - cmd = 'show startup-config' + cmd = 'show configuration' return self.send_command(cmd) @enable_mode diff --git a/lib/ansible/plugins/terminal/aruba.py b/lib/ansible/plugins/terminal/aruba.py index 2ab91779c9e..79bce7a2e12 100644 --- a/lib/ansible/plugins/terminal/aruba.py +++ b/lib/ansible/plugins/terminal/aruba.py @@ -37,7 +37,7 @@ class TerminalModule(TerminalBase): ] terminal_stdout_re = [ - re.compile(br"[\r\n]?[\w]*\(.+\) ?#(?:\s*)$"), + re.compile(br"[\r\n]?[\w]*\(.+\)\s*[\^\*]?(?:\[.+\])? ?#(?:\s*)$"), re.compile(br"[pP]assword:$"), re.compile(br"(?<=\s)[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?\s*#\s*$"), re.compile(br"[\r\n]?[\w\+\-\.:\/\[\]]+(?:\([^\)]+\)){0,3}(?:[>#]) ?$"), diff --git a/test/units/modules/network/aruba/test_aruba_config.py b/test/units/modules/network/aruba/test_aruba_config.py index 5c8dc222abc..0112ae408d6 100644 --- a/test/units/modules/network/aruba/test_aruba_config.py +++ b/test/units/modules/network/aruba/test_aruba_config.py @@ -87,7 +87,7 @@ class TestArubaConfigModule(TestArubaModule): self.assertEqual(self.get_config.call_count, 0) self.assertEqual(self.load_config.call_count, 0) args = self.run_commands.call_args[0][1] - self.assertIn('copy running-config startup-config', args) + self.assertIn('write memory', args) def test_aruba_config_save_changed_true(self): src = load_fixture('aruba_config_src.cfg') @@ -104,7 +104,7 @@ class TestArubaConfigModule(TestArubaModule): self.assertEqual(self.get_config.call_count, 1) self.assertEqual(self.load_config.call_count, 1) args = self.run_commands.call_args[0][1] - self.assertIn('copy running-config startup-config', args) + self.assertIn('write memory', args) def test_aruba_config_save_changed_false(self): set_module_args(dict(save_when='changed'))