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

nclu: fix 'net pending' delimiter string, and exec commit only if changed #219

Merged
merged 8 commits into from
Mar 9, 2021
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
5 changes: 5 additions & 0 deletions changelogs/fragments/219-nclu-fix-pending.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
bugfixes:
- nclu - fix ``net pending`` delimiter string (https://github.com/ansible-collections/community.network/pull/219).
minor_changes:
- nclu - execute ``net commit description <description>`` only if changed ``net pending``'s diff field (https://github.com/ansible-collections/community.network/pull/219).
11 changes: 7 additions & 4 deletions plugins/modules/network/cumulus/nclu.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
sample: "interface bond0 config updated"
'''

import re
from ansible.module_utils.basic import AnsibleModule


Expand All @@ -165,10 +166,10 @@ def check_pending(module):
"""Check the pending diff of the nclu buffer."""
pending = command_helper(module, "pending", "Error in pending config. You may want to view `net pending` on this target.")

delimeter1 = "net add/del commands since the last 'net commit'"
delimeter1 = re.compile('''net add/del commands since the last ['"]net commit['"]''')
color1 = '\x1b[94m'
if delimeter1 in pending:
pending = pending.split(delimeter1)[0]
if re.search(delimeter1, pending):
pending = re.split(delimeter1, pending)[0]
pending = pending.replace(color1, '')
return pending.strip()

Expand Down Expand Up @@ -209,13 +210,15 @@ def run_nclu(module, command_list, command_string, commit, atomic, abort, descri
_changed = True

# Do the commit.
if do_commit:
if (do_commit and _changed):
result = command_helper(module, "commit description '%s'" % description)
if "commit ignored" in result:
_changed = False
command_helper(module, "abort")
elif command_helper(module, "show commit last") == "":
_changed = False
elif do_abort:
command_helper(module, "abort")

return _changed, output

Expand Down
4 changes: 1 addition & 3 deletions tests/unit/plugins/modules/network/cumulus/test_nclu.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,7 @@ def test_commit_ignored(self):
changed, output = nclu.run_nclu(module, None, None, True, False, False, "ignore me")

self.assertEqual(module.command_history, ['/usr/bin/net pending',
'/usr/bin/net pending',
"/usr/bin/net commit description 'ignore me'",
'/usr/bin/net abort'])
'/usr/bin/net pending'])
self.assertEqual(len(module.pending), 0)
self.assertEqual(module.fail_code, {})
self.assertEqual(changed, False)