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: Config module #768

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelogs/fragments/fix_config_module.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
minor_changes:
- "nxos_config - Relax restrictions on I(src) parameter so it can be used more like I(lines). (https://github.com/ansible-collections/cisco.nxos/issues/89)."
6 changes: 3 additions & 3 deletions plugins/modules/nxos_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,9 +415,9 @@ def main():
mutually_exclusive = [("lines", "src", "replace_src"), ("parents", "src")]
ashwini-mhatre marked this conversation as resolved.
Show resolved Hide resolved

required_if = [
("match", "strict", ["lines"]),
("match", "exact", ["lines"]),
("replace", "block", ["lines"]),
("match", "strict", ["lines", "src"], True),
("match", "exact", ["lines", "src"], True),
("replace", "block", ["lines", "src"], True),
("replace", "config", ["replace_src"]),
("diff_against", "intended", ["intended_config"]),
]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ip access-list test
10 permit ip 192.0.2.1/32 any log
20 permit ip 192.0.2.2/32 any log
30 permit ip 192.0.2.3/32 any log
40 permit ip 192.0.2.4/32 any log
35 changes: 35 additions & 0 deletions tests/integration/targets/nxos_config/tests/cli/replace_block.yaml
NilashishC marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
- ansible.builtin.debug: msg="START cli/replace_block.yaml on connection={{ ansible_connection }}"

- name: "setup"
cisco.nxos.nxos_config:
lines:
- "no ip access-list test"
ignore_errors: true

- name: "Populate nxos acls configuration with replace block and lines options"
register: result1
cisco.nxos.nxos_config:
lines: "{{ lookup('template', 'basic/acl_config.j2') }}"
replace: block

- ansible.builtin.assert:
that:
- result1.changed == true

- name: "setup"
cisco.nxos.nxos_config:
lines:
- "no ip access-list test"
ignore_errors: true

- name: "Populate acl configuration with replace block and src options"
register: result2
cisco.nxos.nxos_config:
src: basic/acl_config.j2
replace: block

- ansible.builtin.assert:
that:
- result2.changed == true
- result1.commands == result2.commands
43 changes: 42 additions & 1 deletion tests/unit/modules/network/nxos/test_nxos_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,47 @@ def test_nxos_config_parents(self):

self.assertEqual(config, result["commands"], result["commands"])

def test_nxos_replace_block_src(self):
src = load_fixture("nxos_config", "candidate.cfg")
args = dict(src=src, replace="block")
self.conn.get_diff = MagicMock(
return_value=self.cliconf_obj.get_diff(src, self.running_config),
)
set_module_args(args)

result = self.execute_module(changed=True)
config = [
"hostname switch01",
"interface Ethernet1",
"description test interface",
"no shutdown",
"ip routing",
]

self.assertEqual(sorted(config), sorted(result["commands"]), result["commands"])

def test_nxos_replace_block_lines(self):
lines = ["ip address 1.2.3.4/5", "no shutdown"]
parents = ["interface Ethernet10"]
args = dict(lines=lines, parents=parents, replace="block")
self.conn.get_diff = MagicMock(
return_value=self.cliconf_obj.get_diff(
"\n".join(parents + lines),
self.running_config,
path=parents,
),
)
set_module_args(args)

result = self.execute_module(changed=True)
config = [
"interface Ethernet10",
"ip address 1.2.3.4/5",
"no shutdown",
]

self.assertEqual(config, result["commands"], result["commands"])

def test_nxos_config_src_and_lines_fails(self):
args = dict(src="foo", lines="foo")
set_module_args(args)
Expand All @@ -201,7 +242,7 @@ def test_nxos_config_match_strict_requires_lines(self):
set_module_args(args)
result = self.execute_module(failed=True)

def test_nxos_config_replace_block_requires_lines(self):
def test_nxos_config_replace_block_requires_lines_or_src(self):
args = dict(replace="block")
set_module_args(args)
result = self.execute_module(failed=True)
Expand Down