From 6317678227526c31e53d5fe0e3c16e7a66760e75 Mon Sep 17 00:00:00 2001 From: Tom Strickx Date: Mon, 27 Nov 2017 14:00:04 +0000 Subject: [PATCH 1/3] Fixes #55: Check commit comment length Raise an InvalidInputError when the commit message is longer than 60 characters, as this breaks IOS-XR. --- pyIOSXR/iosxr.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pyIOSXR/iosxr.py b/pyIOSXR/iosxr.py index cc9b41c..b2b222a 100644 --- a/pyIOSXR/iosxr.py +++ b/pyIOSXR/iosxr.py @@ -579,14 +579,17 @@ def commit_config(self, label=None, comment=None, confirmed=None): Commit the candidate config. :param label: Commit comment, displayed in the commit entry on the device. - :param comment: Commit label, displayed instead of the commit ID on the device. + :param comment: Commit label, displayed instead of the commit ID on the device. (Max 60 characters) :param confirmed: Commit with auto-rollback if new commit is not made in 30 to 300 sec """ rpc_command = ' Date: Mon, 27 Nov 2017 15:20:54 +0000 Subject: [PATCH 2/3] Update error message for commit comment length error Rephrase the commit comment error to better reflect the limits. --- pyIOSXR/iosxr.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyIOSXR/iosxr.py b/pyIOSXR/iosxr.py index b2b222a..59c2b85 100644 --- a/pyIOSXR/iosxr.py +++ b/pyIOSXR/iosxr.py @@ -589,7 +589,7 @@ def commit_config(self, label=None, comment=None, confirmed=None): if len(comment) <= 60: rpc_command += ' Comment="%s"' % comment else: - raise InvalidInputError('comment needs to be shorter than 60 characters', self) + raise InvalidInputError('comment should be no more than 60 characters', self) if confirmed: if 30 <= int(confirmed) <= 300: rpc_command += ' Confirmed="%d"' % int(confirmed) From 266179183f085c9720e07a0146984a53a376d9a8 Mon Sep 17 00:00:00 2001 From: Tom Strickx Date: Mon, 16 Apr 2018 12:33:31 +0100 Subject: [PATCH 3/3] Truncate comment length to maximum of 60 Instead of raising an exception, just truncate the comment length to the maximum of 60 --- pyIOSXR/iosxr.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pyIOSXR/iosxr.py b/pyIOSXR/iosxr.py index 59c2b85..5cb3467 100644 --- a/pyIOSXR/iosxr.py +++ b/pyIOSXR/iosxr.py @@ -586,10 +586,7 @@ def commit_config(self, label=None, comment=None, confirmed=None): if label: rpc_command += ' Label="%s"' % label if comment: - if len(comment) <= 60: - rpc_command += ' Comment="%s"' % comment - else: - raise InvalidInputError('comment should be no more than 60 characters', self) + rpc_command += ' Comment="%s"' % comment[:60] if confirmed: if 30 <= int(confirmed) <= 300: rpc_command += ' Confirmed="%d"' % int(confirmed)