Skip to content

Commit

Permalink
[l3_interfaces] fail if encapsulation exists on a different sub-inter…
Browse files Browse the repository at this point in the history
…face. (#857)

* [l3_interfaces] fail if encapsulation exists on a different sub-interface

---------

Signed-off-by: NilashishC <[email protected]>
  • Loading branch information
NilashishC authored May 22, 2024
1 parent 3e0ef7d commit 5b461af
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 20 deletions.
3 changes: 3 additions & 0 deletions changelogs/fragments/nxos_l3_interfaces.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
bugfixes:
- "`nxos_l3_interfaces` - fail if encapsulation exists on a different sub-interface."
65 changes: 46 additions & 19 deletions plugins/cliconf/nxos.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,38 +210,65 @@ def get_config(self, source="running", flags=None, format="text"):

return self.send_command(cmd)

def edit_config(self, candidate=None, commit=True, replace=None, comment=None):
def edit_config(
self,
candidate=None,
commit=True,
replace=None,
comment=None,
err_responses=None,
):
resp = {}
operations = self.get_device_operations()
self.check_edit_config_capability(operations, candidate, commit, replace, comment)
self.check_edit_config_capability(
operations,
candidate,
commit,
replace,
comment,
)
results = []
requests = []

if err_responses:
# update platform default stderr regexes to include modules specific ones
err_responses = [re.compile(to_bytes(err_re)) for err_re in err_responses]
current_stderr_re = self._connection._get_terminal_std_re(
"terminal_stderr_re",
)
current_stderr_re.extend(err_responses)

if replace:
device_info = self.get_device_info()
# not all NX-OS versions support `config replace`
# we let the device throw the invalid command error
candidate = "config replace {0}".format(replace)
candidate = f"config replace {replace}"

if commit:
self.send_command("configure terminal")
try:
if commit:
self.send_command("configure terminal")

for line in to_list(candidate):
if not isinstance(line, Mapping):
line = {"command": line}
for line in to_list(candidate):
if not isinstance(line, Mapping):
line = {"command": line}

cmd = line["command"]
if cmd != "end":
results.append(self.send_command(**line))
requests.append(cmd)
cmd = line["command"]
if cmd != "end":
results.append(self.send_command(**line))
requests.append(cmd)

self.send_command("end")
else:
raise ValueError("check mode is not supported")
self.send_command("end")
else:
raise ValueError("check mode is not supported")

resp["request"] = requests
resp["response"] = results
return resp

resp["request"] = requests
resp["response"] = results
return resp
finally:
# always reset terminal regexes to platform default
if err_responses:
for x in err_responses:
current_stderr_re.remove(x)

def get(
self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class L3_interfaces(ConfigBase):

exclude_params = []

err_responses = [r"encap in use by another sub-interface"]

def __init__(self, module):
super(L3_interfaces, self).__init__(module)

Expand All @@ -70,7 +72,7 @@ def get_l3_interfaces_facts(self, data=None):
return l3_interfaces_facts

def edit_config(self, commands):
return self._connection.edit_config(commands)
return self._connection.edit_config(candidate=commands, err_responses=self.err_responses)

def execute_module(self):
"""Execute the module
Expand Down

0 comments on commit 5b461af

Please sign in to comment.