mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-06 21:32:49 +00:00
IOS XR cli tests move to network_cli (#34007)
* Update task definitions for network_cli * Add connection to debug messages * Specify connection for prepare task * pc won't be around for connection=network_cli * Assorted Python 3 fixes * Give default port if ansible_ssh_port missing * delegate -> connection * Extend error regex
This commit is contained in:
@@ -374,7 +374,7 @@ def get_config(module, config_filter=None, source='running'):
|
||||
if is_netconf(module):
|
||||
out = to_xml(conn.get_config(source=source, filter=config_filter))
|
||||
|
||||
cfg = to_bytes(out, errors='surrogate_then_replace').strip()
|
||||
cfg = out.strip()
|
||||
_DEVICE_CONFIGS.update({key: cfg})
|
||||
return cfg
|
||||
|
||||
|
||||
@@ -328,7 +328,7 @@ def convert_key_to_base64(module):
|
||||
splitfile = key.split()[1]
|
||||
|
||||
base64key = b64decode(splitfile)
|
||||
base64file = open('/tmp/publickey_%s.b64' % (name), 'w')
|
||||
base64file = open('/tmp/publickey_%s.b64' % (name), 'bw')
|
||||
base64file.write(base64key)
|
||||
base64file.close()
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@ class ActionModule(_ActionModule):
|
||||
|
||||
# make sure we are in the right cli context which should be
|
||||
# enable mode and not config module
|
||||
if pc.connection == 'network_cli':
|
||||
if (self._play_context.connection == 'local' and pc.connection == 'network_cli') or self._play_context.connection == 'network_cli':
|
||||
if socket_path is None:
|
||||
socket_path = self._connection.socket_path
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ class ActionModule(_ActionModule):
|
||||
try:
|
||||
self._handle_template()
|
||||
except ValueError as exc:
|
||||
return dict(failed=True, msg=exc.message)
|
||||
return dict(failed=True, msg=to_text(exc))
|
||||
|
||||
result = super(ActionModule, self).run(tmp, task_vars)
|
||||
|
||||
@@ -54,7 +54,7 @@ class ActionModule(_ActionModule):
|
||||
|
||||
# strip out any keys that have two leading and two trailing
|
||||
# underscore characters
|
||||
for key in result.keys():
|
||||
for key in list(result.keys()):
|
||||
if PRIVATE_KEYS_RE.match(key):
|
||||
del result[key]
|
||||
|
||||
@@ -74,7 +74,7 @@ class ActionModule(_ActionModule):
|
||||
os.remove(fn)
|
||||
tstamp = time.strftime("%Y-%m-%d@%H:%M:%S", time.localtime(time.time()))
|
||||
filename = '%s/%s_config.%s' % (backup_path, host, tstamp)
|
||||
open(filename, 'w').write(to_bytes(contents))
|
||||
open(filename, 'w').write(contents)
|
||||
return filename
|
||||
|
||||
def _handle_template(self):
|
||||
|
||||
@@ -61,9 +61,9 @@ class Cliconf(CliconfBase):
|
||||
if source not in lookup:
|
||||
return self.invalid_params("fetching configuration from %s is not supported" % source)
|
||||
if filter:
|
||||
cmd = to_bytes(b'show {0} {1}'.format(lookup[source], filter), errors='surrogate_or_strict')
|
||||
cmd = to_bytes('show {0} {1}'.format(lookup[source], filter), errors='surrogate_or_strict')
|
||||
else:
|
||||
cmd = to_bytes(b'show {0}'.format(lookup[source]), errors='surrogate_or_strict')
|
||||
cmd = to_bytes('show {0}'.format(lookup[source]), errors='surrogate_or_strict')
|
||||
|
||||
return self.send_command(cmd)
|
||||
|
||||
@@ -76,10 +76,10 @@ class Cliconf(CliconfBase):
|
||||
|
||||
def commit(self, comment=None):
|
||||
if comment:
|
||||
command = b'commit comment {0}'.format(comment)
|
||||
command = 'commit comment {0}'.format(comment)
|
||||
else:
|
||||
command = b'commit'
|
||||
self.send_command(command)
|
||||
command = 'commit'
|
||||
self.send_command(to_bytes(command))
|
||||
|
||||
def discard_changes(self):
|
||||
self.send_command(b'abort')
|
||||
|
||||
@@ -37,6 +37,7 @@ class TerminalModule(TerminalBase):
|
||||
terminal_stderr_re = [
|
||||
re.compile(br"% ?Error"),
|
||||
re.compile(br"% ?Bad secret"),
|
||||
re.compile(br"% ?This command is not authorized"),
|
||||
re.compile(br"invalid input", re.I),
|
||||
re.compile(br"(?:incomplete|ambiguous) command", re.I),
|
||||
re.compile(br"connection timed out", re.I),
|
||||
|
||||
Reference in New Issue
Block a user