Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eos subnet overlap fix #43023

Merged
merged 2 commits into from
Jul 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/ansible/module_utils/network/eos/eos.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def load_config(self, commands, commit=False, replace=False):
try:
response = conn.edit_config(commands, commit, replace)
except ConnectionError as exc:
message = getattr(exc, 'err', exc)
message = getattr(exc, 'err', to_text(exc))
if "check mode is not supported without configuration session" in message:
self._module.warn("EOS can not check config without config session")
response = {'changed': True}
Expand Down Expand Up @@ -341,7 +341,11 @@ def load_config(self, config, commit=False, replace=False):
commands = ['configure session %s' % session, 'abort']
self.send_request(commands)
err = response['error']
self._module.fail_json(msg=err['message'], code=err['code'])
error_text = []
for data in err['data']:
Copy link
Contributor

@justjais justjais Jul 19, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nate, here err['data'] will always return a List right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can tell, data has one entry per command, which should mean a minimum of two, as we start with configure session ....

error_text.extend(data.get('errors', []))
error_text = '\n'.join(error_text) or err['message']
self._module.fail_json(msg=error_text, code=err['code'])

commands = ['configure session %s' % session, 'show session-config diffs']
if commit:
Expand Down
15 changes: 13 additions & 2 deletions lib/ansible/plugins/httpapi/eos.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,12 @@ def edit_config(self, config, commit=False, replace=False):
else:
commands.append(command)

response = self.send_request(commands)
try:
response = self.send_request(commands)
except Exception:
commands = ['configure session %s' % session, 'abort']
response = self.send_request(commands, output='text')
raise

commands = ['configure session %s' % session, 'show session-config diffs']
if commit:
Expand Down Expand Up @@ -152,7 +157,13 @@ def load_config(self, config, commit=False, replace=False):
def handle_response(response):
if 'error' in response:
error = response['error']
raise ConnectionError(error['message'], code=error['code'])

error_text = []
for data in error['data']:
error_text.extend(data.get('errors', []))
error_text = '\n'.join(error_text) or error['message']

raise ConnectionError(error_text, code=error['code'])

results = []
for result in response['result']:
Expand Down
3 changes: 2 additions & 1 deletion lib/ansible/plugins/terminal/eos.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ class TerminalModule(TerminalBase):
re.compile(br"'[^']' +returned error code: ?\d+"),
re.compile(br"[^\r\n]\/bin\/(?:ba)?sh"),
re.compile(br"% More than \d+ OSPF instance", re.I),
re.compile(br"Maximum number of pending sessions has been reached")
re.compile(br"% Subnet [0-9a-f.:/]+ overlaps", re.I),
re.compile(br"Maximum number of pending sessions has been reached"),
]

def on_open_shell(self):
Expand Down