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

fix(eos_config): Handle multiline config for RCF "code unit" #526

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelogs/fragments/eos_config_multiline_code_unit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
bugfixes:
- eos_config - fixed handling of multiline inputs for route control-function code update_ospf_intefaces_docs.yaml
2 changes: 1 addition & 1 deletion plugins/cliconf/eos.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def get_session_config(
cmd = line["command"]
if cmd == "end":
continue
if cmd.startswith("banner") or multiline:
if cmd.startswith(("banner", "code unit")) or multiline:
multiline = True
elif cmd == "EOF" and multiline:
multiline = False
Expand Down
20 changes: 10 additions & 10 deletions plugins/module_utils/network/eos/eos.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,27 +375,27 @@ def edit_config(self, config, commit=False, replace=False):
"""
session = session_name()
result = {"session": session}
banner_cmd = None
banner_input = []
multiline_cmd = None
multiline_input = []

commands = ["configure session %s" % session]
if replace:
commands.append("rollback clean-config")

for command in config:
if command.startswith("banner"):
banner_cmd = command
banner_input = []
elif banner_cmd:
if command.startswith(("banner", "code unit")):
multiline_cmd = command
multiline_input = []
elif multiline_cmd:
if command == "EOF":
command = {
"cmd": banner_cmd,
"input": "\n".join(banner_input),
"cmd": multiline_cmd,
"input": "\n".join(multiline_input),
}
banner_cmd = None
multiline_cmd = None
commands.append(command)
else:
banner_input.append(command)
multiline_input.append(command)
continue
else:
commands.append(command)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
hostname switch01
!
banner login
*** LOGIN TEST BANNER ***
EOF
!
20 changes: 20 additions & 0 deletions tests/unit/modules/network/eos/test_eos_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,26 @@ def test_eos_config_src_replace(self):
result["commands"],
)

def test_eos_config_src_replace_multiline(self):
src = load_fixture("eos_config_candidate_multiline.cfg")
args = dict(src=src, replace="config")
set_module_args(args)
self.conn.get_diff = MagicMock(
return_value=self.cliconf_obj.get_diff(src, self.running_config),
)
result = self.execute_module(changed=True)
config = [
"hostname switch01",
"banner login",
"*** LOGIN TEST BANNER ***",
"EOF",
]
self.assertEqual(
config,
result["commands"],
result["commands"],
)

def test_eos_config_lines_block(self):
lines = ["hostname switch01", "ip domain-name eng.ansible.com"]
args = dict(lines=lines, replace="block")
Expand Down