From 35acae7ea7b62aec3d33c6b96630f750e5b2b43b Mon Sep 17 00:00:00 2001 From: Ganesh Nalawade Date: Thu, 30 Nov 2017 20:47:05 +0530 Subject: [PATCH] Fix eos integration test failure (#33407) Fixes #33406 Fixes #33405 * Fix typo in network_cli for sendonly * Send `abort` to remote device in case configuration fails * Fix indentation issue in eos_static_route integration test * Revert network_cli change --- lib/ansible/module_utils/eos.py | 1 + lib/ansible/plugins/action/eos.py | 2 +- lib/ansible/plugins/connection/network_cli.py | 7 +++---- .../targets/eos_static_route/tests/cli/basic.yaml | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/ansible/module_utils/eos.py b/lib/ansible/module_utils/eos.py index 7cc8dcaa4b5..a60219fe5b0 100644 --- a/lib/ansible/module_utils/eos.py +++ b/lib/ansible/module_utils/eos.py @@ -195,6 +195,7 @@ class Cli: rc, out, err = self.send_config(commands) if rc != 0: + self.exec_command('abort') self._module.fail_json(msg=to_text(err, errors='surrogate_then_replace')) self.exec_command('end') diff --git a/lib/ansible/plugins/action/eos.py b/lib/ansible/plugins/action/eos.py index 34ed70e91e5..13aedd03d98 100644 --- a/lib/ansible/plugins/action/eos.py +++ b/lib/ansible/plugins/action/eos.py @@ -108,7 +108,7 @@ class ActionModule(_ActionModule): out = conn.get_prompt() while '(config' in to_text(out, errors='surrogate_then_replace').strip(): display.vvvv('wrong context, sending exit to device', self._play_context.remote_addr) - conn.send_command('exit') + conn.send_command('abort') out = conn.get_prompt() result = super(ActionModule, self).run(tmp, task_vars) diff --git a/lib/ansible/plugins/connection/network_cli.py b/lib/ansible/plugins/connection/network_cli.py index 02483358bae..ba461950d9e 100644 --- a/lib/ansible/plugins/connection/network_cli.py +++ b/lib/ansible/plugins/connection/network_cli.py @@ -114,7 +114,7 @@ class Connection(ConnectionBase): try: cmd = json.loads(to_text(cmd, errors='surrogate_or_strict')) kwargs = {'command': to_bytes(cmd['command'], errors='surrogate_or_strict')} - for key in ('prompt', 'answer', 'send_only'): + for key in ('prompt', 'answer', 'sendonly'): if cmd.get(key) is not None: kwargs[key] = to_bytes(cmd[key], errors='surrogate_or_strict') return self.send(**kwargs) @@ -270,7 +270,6 @@ class Connection(ConnectionBase): recv.seek(offset) window = self._strip(recv.read()) - if prompts and not handled: handled = self._handle_prompt(window, prompts, answer) @@ -279,14 +278,14 @@ class Connection(ConnectionBase): resp = self._strip(self._last_response) return self._sanitize(resp, command) - def send(self, command, prompt=None, answer=None, send_only=False): + def send(self, command, prompt=None, answer=None, sendonly=False): ''' Sends the command to the device in the opened shell ''' try: self._history.append(command) self._ssh_shell.sendall(b'%s\r' % command) - if send_only: + if sendonly: return response = self.receive(command, prompt, answer) return to_text(response, errors='surrogate_or_strict') diff --git a/test/integration/targets/eos_static_route/tests/cli/basic.yaml b/test/integration/targets/eos_static_route/tests/cli/basic.yaml index 21555819e80..ec5b71674c9 100644 --- a/test/integration/targets/eos_static_route/tests/cli/basic.yaml +++ b/test/integration/targets/eos_static_route/tests/cli/basic.yaml @@ -60,8 +60,8 @@ aggregate: - { address: 192.168.4.0/24, next_hop: 192.168.0.1 } - { address: 192.168.5.0/24, next_hop: 192.168.0.1 } - authorize: yes - provider: "{{ cli }}" + authorize: yes + provider: "{{ cli }}" register: result - assert: