Fix vyos sending 'None' to device (#33889)

* Fix vyos sending `'None'` to device

* Move bytes handling into common cliconf code
This commit is contained in:
Nathaniel Case 2017-12-15 11:20:53 -05:00 committed by GitHub
parent 22001797a8
commit f71bbdfed5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 2 deletions

View file

@ -25,6 +25,7 @@ from abc import ABCMeta, abstractmethod
from functools import wraps
from ansible.errors import AnsibleError, AnsibleConnectionFailure
from ansible.module_utils._text import to_bytes
from ansible.module_utils.six import with_metaclass
try:
@ -99,10 +100,16 @@ class CliconfBase(with_metaclass(ABCMeta, object)):
the results to the caller. The command output will be returned as a
string
"""
kwargs = {'command': to_bytes(command), 'sendonly': sendonly}
if prompt is not None:
kwargs['prompt'] = to_bytes(prompt)
if answer is not None:
kwargs['answer'] = to_bytes(answer)
if not signal.getsignal(signal.SIGALRM):
signal.signal(signal.SIGALRM, self._alarm_handler)
signal.alarm(self._connection._play_context.timeout)
resp = self._connection.send(command, prompt, answer, sendonly)
resp = self._connection.send(**kwargs)
signal.alarm(0)
return resp

View file

@ -59,7 +59,7 @@ class Cliconf(CliconfBase):
self.send_command(to_bytes(cmd))
def get(self, command, prompt=None, answer=None, sendonly=False):
return self.send_command(to_bytes(command), prompt=to_bytes(prompt), answer=to_bytes(answer), sendonly=sendonly)
return self.send_command(command, prompt=prompt, answer=answer, sendonly=sendonly)
def commit(self, comment=None):
if comment: