Skip to content

Commit

Permalink
Fixed decoding error during output processing (#1866)
Browse files Browse the repository at this point in the history
Signed-off-by: Yuriy Volynets <yuriyv@mellanox.com>
  • Loading branch information
yvolynets-mlnx authored Jul 13, 2020
1 parent 48c420d commit 5afa492
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions ansible/plugins/connection/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import fcntl
import pwd
import time
import string

from ansible import constants as C
from ansible.errors import AnsibleError, AnsibleConnectionFailure, AnsibleFileNotFound
Expand Down Expand Up @@ -55,6 +56,9 @@ def _build_command(self):
'-o', 'PubkeyAuthentication=no']
self._ssh_command += ['-o', 'ConnectTimeout=' + str(self.timeout)]

def _remove_unprintable(self, buff):
return filter(lambda x: x in string.printable, buff)

def _spawn_connect(self):
last_user = None
client = None
Expand Down Expand Up @@ -231,8 +235,9 @@ def exec_command(self, *args, **kwargs):
self._display.vvv('> %s' % (cmd), host=self.host)
client.sendline(cmd)
client.expect(prompts)
stdout += client.before
self._display.vvv('< %s' % (client.before), host=self.host)
before = self._remove_unprintable(client.before)
stdout += before
self._display.vvv('< %s' % (before), host=self.host)

if self.reboot:
if not self.enable:
Expand All @@ -242,14 +247,14 @@ def exec_command(self, *args, **kwargs):
i = client.expect(['\(y\/n\)\??\s*\[n\]', 'Proceed with reload\? \[confirm\]', 'System configuration has been modified. Save\? \[yes\/no\/cancel\/diff\]:'])
if i == 2:
# EOS behavior
stdout += client.before
stdout += self._remove_unprintable(client.before)
client.sendline('n')
i = client.expect('Proceed with reload\? \[confirm\]')
stdout += client.before
stdout += self._remove_unprintable(client.before)
client.sendline('y')
# The system is going down for reboot NOW: EOS
i = client.expect(['>', '#', 'The system is going down for reboot NOW', pexpect.TIMEOUT, pexpect.EOF])
stdout += client.before
stdout += self._remove_unprintable(client.before)
if i < 2:
raise AnsibleError("Box failed to reboot. stdout = %s" % stdout)
self._display.vvv("Box rebooted", host=self.host)
Expand Down

0 comments on commit 5afa492

Please sign in to comment.