summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSumit Jaiswal <sjaiswal@redhat.com>2018-07-23 23:23:42 +0530
committerMatt Davis <nitzmahone@users.noreply.github.com>2018-07-23 10:53:42 -0700
commit30a0c88c35e6d4f5256d82a363d59f289213d1e7 (patch)
tree57a0c5d0aaa09c4eb58372ce88ef9d5967681318
parentf320b1507d457960b1e0e6f9c5d1d561a9275bf8 (diff)
downloadansible-30a0c88c35e6d4f5256d82a363d59f289213d1e7.tar.gz
To fix EOS_FACTS failure when lldp will be disabled. (#42347)
* to fix the bug 41165 * adding the changelog file * Hook check_rc failure up so that this will actually work * Update eos_facts-failure.yml
-rw-r--r--changelogs/fragments/eos_facts-failure.yml4
-rw-r--r--lib/ansible/module_utils/network/eos/eos.py13
-rw-r--r--lib/ansible/modules/network/eos/eos_facts.py5
3 files changed, 16 insertions, 6 deletions
diff --git a/changelogs/fragments/eos_facts-failure.yml b/changelogs/fragments/eos_facts-failure.yml
new file mode 100644
index 0000000000..5c004fe4a7
--- /dev/null
+++ b/changelogs/fragments/eos_facts-failure.yml
@@ -0,0 +1,4 @@
+---
+bugfixes:
+ - eos_facts - fix failure when lldp will be disabled
+ (https://github.com/ansible/ansible/pull/42347)
diff --git a/lib/ansible/module_utils/network/eos/eos.py b/lib/ansible/module_utils/network/eos/eos.py
index 76903ab0ca..2809abd163 100644
--- a/lib/ansible/module_utils/network/eos/eos.py
+++ b/lib/ansible/module_utils/network/eos/eos.py
@@ -176,7 +176,12 @@ class Cli:
prompt = None
answer = None
- out = connection.get(command, prompt, answer)
+ try:
+ out = connection.get(command, prompt, answer)
+ except ConnectionError as exc:
+ if check_rc:
+ raise
+ out = getattr(exc, 'err', exc)
out = to_text(out, errors='surrogate_or_strict')
try:
@@ -338,7 +343,7 @@ class Eapi:
return response
- def run_commands(self, commands):
+ def run_commands(self, commands, check_rc=True):
"""Runs list of commands on remote device and returns results
"""
output = None
@@ -493,9 +498,9 @@ def get_config(module, flags=None):
return conn.get_config(flags)
-def run_commands(module, commands):
+def run_commands(module, commands, check_rc=True):
conn = get_connection(module)
- return conn.run_commands(to_command(module, commands))
+ return conn.run_commands(to_command(module, commands), check_rc)
def load_config(module, config, commit=False, replace=False):
diff --git a/lib/ansible/modules/network/eos/eos_facts.py b/lib/ansible/modules/network/eos/eos_facts.py
index 5dc7b20312..189a868f3f 100644
--- a/lib/ansible/modules/network/eos/eos_facts.py
+++ b/lib/ansible/modules/network/eos/eos_facts.py
@@ -153,7 +153,7 @@ class FactsBase(object):
self.responses = None
def populate(self):
- self.responses = run_commands(self.module, list(self.COMMANDS))
+ self.responses = run_commands(self.module, list(self.COMMANDS), check_rc=False)
class Default(FactsBase):
@@ -258,7 +258,8 @@ class Interfaces(FactsBase):
self.facts['interfaces'] = self.populate_interfaces(data)
data = self.responses[1]
- self.facts['neighbors'] = self.populate_neighbors(data['lldpNeighbors'])
+ if data:
+ self.facts['neighbors'] = self.populate_neighbors(data['lldpNeighbors'])
def populate_interfaces(self, data):
facts = dict()