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

[BUGFIX 60515] - Fix bug when specifying template_source using net.load_template #67715

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions changelog/60515.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix bug when specifying template_source using net.load_template
13 changes: 1 addition & 12 deletions salt/modules/napalm_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -1940,21 +1940,10 @@ def load_template(
)
return _loaded # exit

# to check if will be rendered by salt or NAPALM
salt_render_prefixes = ("salt://", "http://", "https://", "ftp://")
salt_render = False
file_exists = False
if not isinstance(template_name, (tuple, list)):
for salt_render_prefix in salt_render_prefixes:
if not salt_render:
salt_render = salt_render or template_name.startswith(
salt_render_prefix
)
file_exists = __salt__["file.file_exists"](template_name)

if context is None:
context = {}
context.update(template_vars)

# if needed to render the template send as inline arg
if template_source:
# render the content
Expand Down
8 changes: 7 additions & 1 deletion tests/pytests/unit/modules/napalm/test_network.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
:codeauthor: Anthony Shaw <[email protected]>
:codeauthor: Anthony Shaw <[email protected]>
"""

import pytest
Expand All @@ -20,6 +20,7 @@ def configure_loader_modules():
"file.join": napalm_test_support.join,
"file.get_managed": napalm_test_support.get_managed_file,
"random.hash": napalm_test_support.random_hash,
"file.apply_template_on_contents": MagicMock(),
}
}

Expand Down Expand Up @@ -181,9 +182,14 @@ def test_load_template():
"salt.utils.napalm.get_device",
MagicMock(return_value=napalm_test_support.MockNapalmDevice()),
):
# template_name
ret = napalm_network.load_template("set_ntp_peers", peers=["192.168.0.1"])
assert ret["out"] is None

# template_source
ret = napalm_network.load_template(template_source="ntp server 192.168.0.1")
assert ret["out"] is None


def test_commit():
with patch(
Expand Down
Loading