On Thu, 2011-08-25 at 09:28 -0400, Rob Crittenden wrote:
> Martin Kosek wrote:
> > 1) Add sudorule docstring headline
> >
> > 2) Fix naming inconsistency in Sudo plugins help and summaries,
> >     especially capitalization of Sudo objects - Sudo Rule, Sudo
> >     Command and Sudo Command Group
> >
> > 3) Add missing summaries for sudorule-add-option and
> >     sudorule-remove-option
> >
> > https://fedorahosted.org/freeipa/ticket/1595
> > https://fedorahosted.org/freeipa/ticket/1596
> 
> This breaks compatibility with old clients:
> 
> $ ipa sudorule-add-option test2
> Sudo Option: foo
> ipa: ERROR: non-public: ValueError: 
> sudorule_add_option.validate_output(): unexpected keys ['summary'] in 
> {'result': {'ipasudoopt': (u'foo',), 'cn': (u'test2',), 
> 'ipaenabledflag': (u'TRUE',)}, 'summary': u'Added option "foo" to Sudo 
> Rule "test2"'}
> Traceback (most recent call last):
>    File "/usr/lib/python2.7/site-packages/ipalib/backend.py", line 125, 
> in execute
>      result = self.Command[_name](*args, **options)
>    File "/usr/lib/python2.7/site-packages/ipalib/frontend.py", line 443, 
> in __call__
>      self.validate_output(ret)
>    File "/usr/lib/python2.7/site-packages/ipalib/frontend.py", line 895, 
> in validate_output
>      nice, extra, output)
> ValueError: sudorule_add_option.validate_output(): unexpected keys 
> ['summary'] in {'result': {'ipasudoopt': (u'foo',), 'cn': (u'test2',), 
> 'ipaenabledflag': (u'TRUE',)}, 'summary': u'Added option "foo" to Sudo 
> Rule "test2"'}
> ipa: ERROR: an internal error has occurred
> 

Thanks for catching this. I wonder if we should let output param
validation skip unexpected keys in order to be able to do the change in
Output + keep backwards compatibility in cases like this one.

I reworked the patch so that the summaries are printed via
output_for_cli() - this solves this problem.

Martin
>From 15d03bfa966f975df33b4cee478906b300abc756 Mon Sep 17 00:00:00 2001
From: Martin Kosek <mko...@redhat.com>
Date: Thu, 25 Aug 2011 12:58:17 +0200
Subject: [PATCH] Fix sudo help and summaries

1) Add sudorule docstring headline

2) Fix naming inconsistency in Sudo plugins help and summaries,
   especially capitalization of Sudo objects - Sudo Rule, Sudo
   Command and Sudo Command Group

3) Add missing summaries for sudorule-add-option and
   sudorule-remove-option. To keep backward compatibility with
   older clients, just print the missing summary with
   output_for_cli(), don't expand Output.

https://fedorahosted.org/freeipa/ticket/1595
https://fedorahosted.org/freeipa/ticket/1596
---
 ipalib/plugins/sudocmd.py                     |   14 ++++----
 ipalib/plugins/sudocmdgroup.py                |   40 +++++++++++-----------
 ipalib/plugins/sudorule.py                    |   46 +++++++++++++++----------
 tests/test_xmlrpc/test_sudocmd_plugin.py      |    8 ++--
 tests/test_xmlrpc/test_sudocmdgroup_plugin.py |   22 ++++++------
 5 files changed, 70 insertions(+), 60 deletions(-)

diff --git a/ipalib/plugins/sudocmd.py b/ipalib/plugins/sudocmd.py
index da78f0ec52f8c3ebb684a4f746c48b5cb055d355..268e3c1bbe7573b11114a219321a87b529cf5a5a 100644
--- a/ipalib/plugins/sudocmd.py
+++ b/ipalib/plugins/sudocmd.py
@@ -97,19 +97,19 @@ api.register(sudocmd)
 
 class sudocmd_add(LDAPCreate):
     """
-    Create new sudo command.
+    Create new Sudo Command.
     """
 
-    msg_summary = _('Added sudo command "%(value)s"')
+    msg_summary = _('Added Sudo Command "%(value)s"')
 
 api.register(sudocmd_add)
 
 class sudocmd_del(LDAPDelete):
     """
-    Delete sudo command.
+    Delete Sudo Command.
     """
 
-    msg_summary = _('Deleted sudo command "%(value)s"')
+    msg_summary = _('Deleted Sudo Command "%(value)s"')
 
 api.register(sudocmd_del)
 
@@ -118,7 +118,7 @@ class sudocmd_mod(LDAPUpdate):
     Modify command.
     """
 
-    msg_summary = _('Modified sudo command "%(value)s"')
+    msg_summary = _('Modified Sudo Command "%(value)s"')
 
 api.register(sudocmd_mod)
 
@@ -128,14 +128,14 @@ class sudocmd_find(LDAPSearch):
     """
 
     msg_summary = ngettext(
-        '%(count)d sudo command matched', '%(count)d sudo command matched', 0
+        '%(count)d Sudo Command matched', '%(count)d Sudo Commands matched', 0
     )
 
 api.register(sudocmd_find)
 
 class sudocmd_show(LDAPRetrieve):
     """
-    Display sudo command.
+    Display Sudo Command.
     """
 
 api.register(sudocmd_show)
diff --git a/ipalib/plugins/sudocmdgroup.py b/ipalib/plugins/sudocmdgroup.py
index e613f465704bce579ecfba5edb591e0b138bbc7e..41d30fb2cd5edf037fd177a8d78e24a582650f5c 100644
--- a/ipalib/plugins/sudocmdgroup.py
+++ b/ipalib/plugins/sudocmdgroup.py
@@ -17,25 +17,25 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 """
-Groups of Sudo commands
+Groups of Sudo Commands
 
-Manage groups of Sudo commands.
+Manage groups of Sudo Commands.
 
 EXAMPLES:
 
- Add a new Sudo command group:
+ Add a new Sudo Command Group:
    ipa sudocmdgroup-add --desc='administrators commands' admincmds
 
- Remove a Sudo command group:
+ Remove a Sudo Command Group:
    ipa sudocmdgroup-del admincmds
 
- Manage Sudo command group membership, commands:
+ Manage Sudo Command Group membership, commands:
    ipa sudocmdgroup-add-member --sudocmds=/usr/bin/less,/usr/bin/vim admincmds
 
- Manage Sudo command group membership, commands:
+ Manage Sudo Command Group membership, commands:
    ipa group-remove-member --sudocmds=/usr/bin/less admincmds
 
- Show a Sudo command group:
+ Show a Sudo Command Group:
    ipa group-show localadmins
 """
 
@@ -48,7 +48,7 @@ topic = ('sudo', 'commands for controlling sudo configuration')
 
 class sudocmdgroup(LDAPObject):
     """
-    Sudo Group object.
+    Sudo Command Group object.
     """
     container_dn = api.env.container_sudocmdgroup
     object_name = _('sudo command group')
@@ -92,42 +92,42 @@ api.register(sudocmdgroup)
 
 class sudocmdgroup_add(LDAPCreate):
     """
-    Create new sudo command group.
+    Create new Sudo Command Group.
     """
 
-    msg_summary = _('Added sudo command group "%(value)s"')
+    msg_summary = _('Added Sudo Command Group "%(value)s"')
 
 api.register(sudocmdgroup_add)
 
 
 class sudocmdgroup_del(LDAPDelete):
     """
-    Delete sudo command group.
+    Delete Sudo Command Group.
     """
 
-    msg_summary = _('Deleted sudo command group "%(value)s"')
+    msg_summary = _('Deleted Sudo Command Group "%(value)s"')
 
 api.register(sudocmdgroup_del)
 
 
 class sudocmdgroup_mod(LDAPUpdate):
     """
-    Modify group.
+    Modify Sudo Command Group.
     """
 
-    msg_summary = _('Modified sudo command group "%(value)s"')
+    msg_summary = _('Modified Sudo Command Group "%(value)s"')
 
 api.register(sudocmdgroup_mod)
 
 
 class sudocmdgroup_find(LDAPSearch):
     """
-    Search for sudo command groups.
+    Search for Sudo Command Groups.
     """
 
     msg_summary = ngettext(
-        '%(count)d sudo command group matched',
-        '%(count)d sudo command groups matched', 0
+        '%(count)d Sudo Command Group matched',
+        '%(count)d Sudo Command Groups matched', 0
     )
 
 api.register(sudocmdgroup_find)
@@ -135,7 +135,7 @@ api.register(sudocmdgroup_find)
 
 class sudocmdgroup_show(LDAPRetrieve):
     """
-    Display sudo command group.
+    Display Sudo Command Group.
     """
 
 api.register(sudocmdgroup_show)
@@ -143,7 +143,7 @@ api.register(sudocmdgroup_show)
 
 class sudocmdgroup_add_member(LDAPAddMember):
     """
-    Add members to sudo command group.
+    Add members to Sudo Command Group.
     """
 
 api.register(sudocmdgroup_add_member)
@@ -151,7 +151,7 @@ api.register(sudocmdgroup_add_member)
 
 class sudocmdgroup_remove_member(LDAPRemoveMember):
     """
-    Remove members from sudo command group.
+    Remove members from Sudo Command Group.
     """
 
 api.register(sudocmdgroup_remove_member)
diff --git a/ipalib/plugins/sudorule.py b/ipalib/plugins/sudorule.py
index 55affa653c3c92d977ff4ec3bd9f48dc08dacf7e..26dcc75707dd44edd2adfda0a072bb2ebb9c1f1f 100644
--- a/ipalib/plugins/sudorule.py
+++ b/ipalib/plugins/sudorule.py
@@ -17,6 +17,8 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 """
+Sudo Rules
+
 Sudo (su "do") allows a system administrator to delegate authority to
 give certain users (or groups of users) the ability to run some (or all)
 commands as root or another user while providing an audit trail of the
@@ -63,7 +65,7 @@ def validate_runasextgroup(ugettext, value):
 
 class sudorule(LDAPObject):
     """
-    Sudo Rule management
+    Sudo Rule object.
     """
     container_dn = api.env.container_sudorule
     object_name = _('sudo rule')
@@ -208,11 +210,11 @@ class sudorule_add(LDAPCreate):
     Create new Sudo Rule.
     """
     def pre_callback(self, ldap, dn, entry_attrs, attrs_list, *keys, **options):
-        # Sudo rules are enabled by default
+        # Sudo Rules are enabled by default
         entry_attrs['ipaenabledflag'] = 'TRUE'
         return dn
 
-    msg_summary = _('Added sudo rule "%(value)s"')
+    msg_summary = _('Added Sudo Rule "%(value)s"')
 
 api.register(sudorule_add)
 
@@ -221,7 +223,7 @@ class sudorule_del(LDAPDelete):
     """
     Delete Sudo Rule.
     """
-    msg_summary = _('Deleted sudo rule "%(value)s"')
+    msg_summary = _('Deleted Sudo Rule "%(value)s"')
 
 api.register(sudorule_del)
 
@@ -230,7 +232,7 @@ class sudorule_mod(LDAPUpdate):
     """
     Modify Sudo Rule.
     """
-    msg_summary = _('Modified sudo rule "%(value)s"')
+    msg_summary = _('Modified Sudo Rule "%(value)s"')
 
 api.register(sudorule_mod)
 
@@ -240,7 +242,7 @@ class sudorule_find(LDAPSearch):
     Search for Sudo Rule.
     """
     msg_summary = ngettext(
-        '%(count)d sudo rule matched', '%(count)d sudo rules matched', 0
+        '%(count)d Sudo Rule matched', '%(count)d Sudo Rules matched', 0
     )
 
 api.register(sudorule_find)
@@ -256,7 +258,7 @@ api.register(sudorule_show)
 
 class sudorule_enable(LDAPQuery):
     """
-    Enable a Sudo rule.
+    Enable a Sudo Rule.
     """
     def execute(self, cn):
         ldap = self.obj.backend
@@ -274,15 +276,14 @@ class sudorule_enable(LDAPQuery):
         return dict(result=True)
 
     def output_for_cli(self, textui, result, cn):
-        textui.print_name(self.name)
-        textui.print_dashed('Enabled Sudo rule "%s".' % cn)
+        textui.print_dashed(_('Enabled Sudo Rule "%s"') % cn)
 
 api.register(sudorule_enable)
 
 
 class sudorule_disable(LDAPQuery):
     """
-    Disable a Sudo rule.
+    Disable a Sudo Rule.
     """
     def execute(self, cn):
         ldap = self.obj.backend
@@ -300,15 +301,14 @@ class sudorule_disable(LDAPQuery):
         return dict(result=True)
 
     def output_for_cli(self, textui, result, cn):
-        textui.print_name(self.name)
-        textui.print_dashed('Disabled Sudo rule "%s".' % cn)
+        textui.print_dashed(_('Disabled Sudo Rule "%s"') % cn)
 
 api.register(sudorule_disable)
 
 
 class sudorule_add_allow_command(LDAPAddMember):
     """
-    Add commands and sudo command groups affected by Sudo Rule.
+    Add commands and Sudo Command Groups affected by Sudo Rule.
     """
     member_attributes = ['memberallowcmd']
     member_count_out = ('%i object added.', '%i objects added.')
@@ -318,7 +318,7 @@ api.register(sudorule_add_allow_command)
 
 class sudorule_remove_allow_command(LDAPRemoveMember):
     """
-    Remove commands and sudo command groups affected by Sudo Rule.
+    Remove commands and Sudo Command Groups affected by Sudo Rule.
     """
     member_attributes = ['memberallowcmd']
     member_count_out = ('%i object removed.', '%i objects removed.')
@@ -328,7 +328,7 @@ api.register(sudorule_remove_allow_command)
 
 class sudorule_add_deny_command(LDAPAddMember):
     """
-    Add commands and sudo command groups affected by Sudo Rule.
+    Add commands and Sudo Command Groups affected by Sudo Rule.
     """
     member_attributes = ['memberdenycmd']
     member_count_out = ('%i object added.', '%i objects added.')
@@ -338,7 +338,7 @@ api.register(sudorule_add_deny_command)
 
 class sudorule_remove_deny_command(LDAPRemoveMember):
     """
-    Remove commands and sudo command groups affected by Sudo Rule.
+    Remove commands and Sudo Command Groups affected by Sudo Rule.
     """
     member_attributes = ['memberdenycmd']
     member_count_out = ('%i object removed.', '%i objects removed.')
@@ -629,7 +629,7 @@ api.register(sudorule_remove_runasgroup)
 
 class sudorule_add_option(LDAPQuery):
     """
-    Add an option to the Sudo rule.
+    Add an option to the Sudo Rule.
     """
 
     takes_options = (
@@ -671,12 +671,17 @@ class sudorule_add_option(LDAPQuery):
 
         return dict(result=entry_attrs)
 
+    def output_for_cli(self, textui, result, cn, **options): 
+        textui.print_dashed(_('Added option "%s" to Sudo Rule "%s"') % \
+                (options['ipasudoopt'], cn))
+        super(sudorule_add_option, self).output_for_cli(textui, result, cn, options)
+
 api.register(sudorule_add_option)
 
 
 class sudorule_remove_option(LDAPQuery):
     """
-    Remove an option from Sudo rule.
+    Remove an option from Sudo Rule.
     """
     takes_options = (
         Str('ipasudoopt',
@@ -720,4 +725,9 @@ class sudorule_remove_option(LDAPQuery):
 
         return dict(result=entry_attrs)
 
+    def output_for_cli(self, textui, result, cn, **options): 
+        textui.print_dashed(_('Removed option "%s" from Sudo Rule "%s"') % \
+                (options['ipasudoopt'], cn))
+        super(sudorule_remove_option, self).output_for_cli(textui, result, cn, options)
+
 api.register(sudorule_remove_option)
diff --git a/tests/test_xmlrpc/test_sudocmd_plugin.py b/tests/test_xmlrpc/test_sudocmd_plugin.py
index a19fefc735d5e1f01c5f2365564eb26c465f67d1..cbbd26cd7061ee73c44f691692072daaf6f84f50 100644
--- a/tests/test_xmlrpc/test_sudocmd_plugin.py
+++ b/tests/test_xmlrpc/test_sudocmd_plugin.py
@@ -67,7 +67,7 @@ class test_sudocmd(Declarative):
             ),
             expected=dict(
                 value=sudocmd1,
-                summary=u'Added sudo command "%s"' % sudocmd1,
+                summary=u'Added Sudo Command "%s"' % sudocmd1,
                 result=dict(
                     dn=lambda x: DN(x) == \
                         DN(('sudocmd',sudocmd1),('cn','sudocmds'),('cn','sudo'),
@@ -115,7 +115,7 @@ class test_sudocmd(Declarative):
             expected=dict(
                 count=1,
                 truncated=False,
-                summary=u'1 sudo command matched',
+                summary=u'1 Sudo Command matched',
                 result=[
                     dict(
                         dn=lambda x: DN(x) == \
@@ -135,7 +135,7 @@ class test_sudocmd(Declarative):
                 description=u'Updated sudo command 1')),
             expected=dict(
                 value=sudocmd1,
-                summary=u'Modified sudo command "%s"' % sudocmd1,
+                summary=u'Modified Sudo Command "%s"' % sudocmd1,
                 result=dict(
                     sudocmd=[sudocmd1],
                     description=[u'Updated sudo command 1'],
@@ -166,7 +166,7 @@ class test_sudocmd(Declarative):
             command=('sudocmd_del', [sudocmd1], {}),
             expected=dict(
                 value=sudocmd1,
-                summary=u'Deleted sudo command "%s"' % sudocmd1,
+                summary=u'Deleted Sudo Command "%s"' % sudocmd1,
                 result=dict(failed=u''),
             ),
         ),
diff --git a/tests/test_xmlrpc/test_sudocmdgroup_plugin.py b/tests/test_xmlrpc/test_sudocmdgroup_plugin.py
index dd89c5d17aab2201f454a0bf5bbd2596cf558e43..8a534b2bf9f8f73c6304555a2bef3c52a367e626 100644
--- a/tests/test_xmlrpc/test_sudocmdgroup_plugin.py
+++ b/tests/test_xmlrpc/test_sudocmdgroup_plugin.py
@@ -47,7 +47,7 @@ class test_sudocmdgroup(Declarative):
             ),
             expected=dict(
                 value=sudocmd1,
-                summary=u'Added sudo command "%s"' % sudocmd1,
+                summary=u'Added Sudo Command "%s"' % sudocmd1,
                 result=dict(
                     objectclass=objectclasses.sudocmd,
                     sudocmd=[u'/usr/bin/sudotestcmd1'],
@@ -110,7 +110,7 @@ class test_sudocmdgroup(Declarative):
             ),
             expected=dict(
                 value=sudocmdgroup1,
-                summary=u'Added sudo command group "testsudocmdgroup1"',
+                summary=u'Added Sudo Command Group "testsudocmdgroup1"',
                 result=dict(
                     cn=[sudocmdgroup1],
                     description=[u'Test desc 1'],
@@ -162,7 +162,7 @@ class test_sudocmdgroup(Declarative):
                     cn=[sudocmdgroup1],
                     description=[u'New desc 1'],
                 ),
-                summary=u'Modified sudo command group "testsudocmdgroup1"',
+                summary=u'Modified Sudo Command Group "testsudocmdgroup1"',
                 value=sudocmdgroup1,
             ),
         ),
@@ -200,7 +200,7 @@ class test_sudocmdgroup(Declarative):
                         description=[u'New desc 1'],
                     ),
                 ],
-                summary=u'1 sudo command group matched',
+                summary=u'1 Sudo Command Group matched',
             ),
         ),
 
@@ -238,7 +238,7 @@ class test_sudocmdgroup(Declarative):
             ),
             expected=dict(
                 value=sudocmdgroup2,
-                summary=u'Added sudo command group "testsudocmdgroup2"',
+                summary=u'Added Sudo Command Group "testsudocmdgroup2"',
                 result=dict(
                     cn=[sudocmdgroup2],
                     description=[u'Test desc 2'],
@@ -290,7 +290,7 @@ class test_sudocmdgroup(Declarative):
                     cn=[sudocmdgroup2],
                     description=[u'New desc 2'],
                 ),
-                summary=u'Modified sudo command group "testsudocmdgroup2"',
+                summary=u'Modified Sudo Command Group "testsudocmdgroup2"',
                 value=sudocmdgroup2,
             ),
         ),
@@ -328,7 +328,7 @@ class test_sudocmdgroup(Declarative):
                         description=[u'New desc 2'],
                     ),
                 ],
-                summary=u'1 sudo command group matched',
+                summary=u'1 Sudo Command Group matched',
             ),
         ),
 
@@ -337,7 +337,7 @@ class test_sudocmdgroup(Declarative):
             desc='Search for all sudocmdgroups',
             command=('sudocmdgroup_find', [], {}),
             expected=dict(
-                summary=u'2 sudo command groups matched',
+                summary=u'2 Sudo Command Groups matched',
                 count=2,
                 truncated=False,
                 result=[
@@ -482,7 +482,7 @@ class test_sudocmdgroup(Declarative):
             expected=dict(
                 result=dict(failed=u''),
                 value=sudocmdgroup1,
-                summary=u'Deleted sudo command group "testsudocmdgroup1"',
+                summary=u'Deleted Sudo Command Group "testsudocmdgroup1"',
             )
         ),
 
@@ -517,7 +517,7 @@ class test_sudocmdgroup(Declarative):
             expected=dict(
                 result=dict(failed=u''),
                 value=sudocmdgroup2,
-                summary=u'Deleted sudo command group "testsudocmdgroup2"',
+                summary=u'Deleted Sudo Command Group "testsudocmdgroup2"',
             )
         ),
 
@@ -552,7 +552,7 @@ class test_sudocmdgroup(Declarative):
             expected=dict(
                 result=dict(failed=u''),
                 value=sudocmd1,
-                summary=u'Deleted sudo command "%s"' % sudocmd1,
+                summary=u'Deleted Sudo Command "%s"' % sudocmd1,
             )
         ),
 
-- 
1.7.6

_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel

Reply via email to